llvmorg-github-actions[bot] wrote:

<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-clang-tools-extra

Author: cpp-engine

<details>
<summary>Changes</summary>

The `performance-noexcept-move-constructor` check incorrectly handles move 
constructors and move assignment operators whose exception specification is 
implicitly `noexcept(false)`.

To avoid this, I added a check for a valid source range corresponding to the 
`noexcept specifier`.

---
Full diff: https://github.com/llvm/llvm-project/pull/226488.diff


2 Files Affected:

- (modified) 
clang-tools-extra/clang-tidy/performance/NoexceptFunctionBaseCheck.cpp (+5-3) 
- (modified) 
clang-tools-extra/test/clang-tidy/checkers/performance/noexcept-move-constructor.cpp
 (+20) 


``````````diff
diff --git 
a/clang-tools-extra/clang-tidy/performance/NoexceptFunctionBaseCheck.cpp 
b/clang-tools-extra/clang-tidy/performance/NoexceptFunctionBaseCheck.cpp
index 33d80615fb19f1..71474a41ebe1d6 100644
--- a/clang-tools-extra/clang-tidy/performance/NoexceptFunctionBaseCheck.cpp
+++ b/clang-tools-extra/clang-tidy/performance/NoexceptFunctionBaseCheck.cpp
@@ -30,9 +30,11 @@ void NoexceptFunctionBaseCheck::check(const 
MatchFinder::MatchResult &Result) {
   const Expr *NoexceptExpr = ProtoType->getNoexceptExpr();
   if (NoexceptExpr) {
     NoexceptExpr = NoexceptExpr->IgnoreImplicit();
-    if (!isa<CXXBoolLiteralExpr>(NoexceptExpr))
-      reportNoexceptEvaluatedToFalse(FuncDecl, NoexceptExpr);
-    return;
+    if (FuncDecl->getExceptionSpecSourceRange().isValid()) {
+      if (!isa<CXXBoolLiteralExpr>(NoexceptExpr))
+        reportNoexceptEvaluatedToFalse(FuncDecl, NoexceptExpr);
+      return;
+    }
   }
 
   const auto Diag = reportMissingNoexcept(FuncDecl);
diff --git 
a/clang-tools-extra/test/clang-tidy/checkers/performance/noexcept-move-constructor.cpp
 
b/clang-tools-extra/test/clang-tidy/checkers/performance/noexcept-move-constructor.cpp
index 76e1d9e4934213..592de82c362d32 100644
--- 
a/clang-tools-extra/test/clang-tidy/checkers/performance/noexcept-move-constructor.cpp
+++ 
b/clang-tools-extra/test/clang-tidy/checkers/performance/noexcept-move-constructor.cpp
@@ -2,6 +2,8 @@
 // RUN: %check_clang_tidy -std=c++17-or-later -check-suffixes=,ERR %s 
performance-noexcept-move-constructor %t \
 // RUN:                   -- --fix-errors -- -fexceptions -DENABLE_ERROR
 
+#include <utility>
+
 namespace std
 {
   template <typename T>
@@ -181,6 +183,24 @@ struct O : virtual IntWrapper, ThrowOnAnything {
   // CHECK-FIXES: O &operator=(O &&)  noexcept = default;
 };
 
+struct P {
+  P() = default;
+
+  P(P &&) = default;
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: move constructors should be 
marked noexcept [performance-noexcept-move-constructor]
+  // CHECK-FIXES: P(P &&)  noexcept = default;
+  P &operator=(P &&) = default;
+  // CHECK-MESSAGES: :[[@LINE-1]]:6: warning: move assignment operators should 
be marked noexcept [performance-noexcept-move-constructor]
+  // CHECK-FIXES: P &operator=(P &&)  noexcept = default;
+
+  InheritFromThrowOnAnything IFF;
+};
+
+void p() {
+  P P1{};
+  P P2{std::move(P1)};
+}
+
 class OK {};
 
 void f() {

``````````

</details>


https://github.com/llvm/llvm-project/pull/226488
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to