[clang-tools-extra] [clang-tidy] Add AllowFalseEvaluated flag to clang-tidy noexcept-move-constructor check (PR #126897)

Dmitry Nechitaev via cfe-commits cfe-commits at lists.llvm.org
Fri Jun 6 02:25:44 PDT 2025


================
@@ -0,0 +1,46 @@
+// RUN: %check_clang_tidy -check-suffix=CONFIG %s performance-noexcept-move-constructor,performance-noexcept-destructor %t -- \
+// RUN: -config="{CheckOptions: {performance-noexcept-move-constructor.AllowFalseEvaluated: true}}" \
+// RUN: -- -fexceptions
+
+namespace std
+{
+  template <typename T>
+  struct is_nothrow_move_constructible
+  {
+    static constexpr bool value = __is_nothrow_constructible(T, __add_rvalue_reference(T));
+  };
+} // namespace std
+
+struct ThrowOnAnything {
+  ThrowOnAnything() noexcept(false);
+  ThrowOnAnything(ThrowOnAnything&&) noexcept(false);
+  ThrowOnAnything& operator=(ThrowOnAnything &&) noexcept(false);
+  ~ThrowOnAnything() noexcept(false);
+};
+
+struct C_1 {
+    static constexpr bool kFalse = false;
+    C_1(C_1&&) noexcept(kFalse) = default;
+    C_1 &operator=(C_1 &&) noexcept(kFalse);
+};
+
+struct C_2 {
+    static constexpr bool kEval = std::is_nothrow_move_constructible<ThrowOnAnything>::value;
+    static_assert(!kEval); // kEval == false;
+
+    C_2(C_2&&) noexcept(kEval) = default;
+    C_2 &operator=(C_2 &&) noexcept(kEval);
+
+    ThrowOnAnything field;
+};
+
+struct C_3 {
+    static constexpr bool kEval = std::is_nothrow_move_constructible<ThrowOnAnything>::value;
+    static_assert(!kEval); // kEval == false;
+
+    C_3(C_3&&) noexcept(kEval) = default;
+    ~C_3() noexcept(kEval) = default;
+    // CHECK-MESSAGES-CONFIG: :[[@LINE-1]]:21: warning: noexcept specifier on the destructor evaluates to 'false'
+
+    ThrowOnAnything field;
+};
----------------
Nechda wrote:

I'm sorry, I don't quite understand what test case you are referring to. It looks like the default behavior of this check is already covered by another test case. https://github.com/llvm/llvm-project/blob/a663e78a6eb6bbd20c0c74b3e6a78e24ee423544/clang-tools-extra/test/clang-tidy/checkers/performance/noexcept-move-constructor.cpp

After the test simplification, only one line should be displayed in the output if the option in the config is enabled.

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


More information about the cfe-commits mailing list