https://github.com/cpp-engine created 
https://github.com/llvm/llvm-project/pull/226488

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`.

>From 2fe2370dd5a0d943b99c2ee14443a84c82472844 Mon Sep 17 00:00:00 2001
From: Agaev G <[email protected]>
Date: Fri, 25 Sep 2026 13:04:11 +0000
Subject: [PATCH] [clang-tidy] Fix performance-noexcept-move-constructor for
 implicit noexcept(false)

---
 .../performance/NoexceptFunctionBaseCheck.cpp |  8 +++++---
 .../performance/noexcept-move-constructor.cpp | 20 +++++++++++++++++++
 2 files changed, 25 insertions(+), 3 deletions(-)

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() {

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

Reply via email to