[clang-tools-extra] [clang-tidy] Fix performance-noexcept-move-constructor for implicit noexcept(false) (PR #226488)

Zeyi Xu via cfe-commits cfe-commits at lists.llvm.org
Sun Sep 27 02:55:15 PDT 2026


================
@@ -181,6 +183,25 @@ 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;
----------------
zeyi2 wrote:

Nit: The new ·P::operator=· expectation already passes with the pre-patch checker ([Godbolt](https://godbolt.org/z/Kx4hcvqdv)). Could we add a move-assignment case that fails before this change? For example:

```
#include <string>
#include <vector>

struct WithVectorFirst {
  std::vector<std::string> cache;
  ThrowOnAnything value;
  WithVectorFirst& operator=(WithVectorFirst&&) = default;
  // CHECK-MESSAGES: :[[@LINE-1]]:20: warning: move assignment operators should be marked noexcept 
};

void use(WithVectorFirst& a, WithVectorFirst& b) {
  a = std::move(b);
}
```

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


More information about the cfe-commits mailing list