|
| 1 | +// RUN: %check_clang_tidy %s performance-noexcept-move-constructor %t -- -- -fexceptions |
| 2 | + |
| 3 | +// RUN: %check_clang_tidy -check-suffix=CONFIG %s performance-noexcept-move-constructor,performance-noexcept-destructor %t -- \ |
| 4 | +// RUN: -config="{CheckOptions: {performance-noexcept-move-constructor.AllowFalseEvaluated: true}}" \ |
| 5 | +// RUN: -- -fexceptions |
| 6 | + |
| 7 | +namespace std |
| 8 | +{ |
| 9 | + template <typename T> |
| 10 | + struct is_nothrow_move_constructible |
| 11 | + { |
| 12 | + static constexpr bool value = __is_nothrow_constructible(T, __add_rvalue_reference(T)); |
| 13 | + }; |
| 14 | +} // namespace std |
| 15 | + |
| 16 | +struct ThrowOnAnything { |
| 17 | + ThrowOnAnything() noexcept(false); |
| 18 | + ThrowOnAnything(ThrowOnAnything&&) noexcept(false); |
| 19 | + // CHECK-MESSAGES-NOT: :[[@LINE-1]]:3: warning: move constructors should be marked noexcept |
| 20 | + // CHECK-MESSAGES-CONFIG-NOT: :[[@LINE-2]]:3: warning: move constructors should be marked noexcept |
| 21 | + ThrowOnAnything& operator=(ThrowOnAnything &&) noexcept(false); |
| 22 | + ~ThrowOnAnything() noexcept(false); |
| 23 | +}; |
| 24 | + |
| 25 | +struct C_1 { |
| 26 | + static constexpr bool kFalse = false; |
| 27 | + C_1(C_1&&) noexcept(kFalse) = default; |
| 28 | + // CHECK-MESSAGES: :[[@LINE-1]]:25: warning: noexcept specifier on the move constructor evaluates to 'false' [performance-noexcept-move-constructor] |
| 29 | + // CHECK-MESSAGES-CONFIG-NOT: :[[@LINE-2]]:25: warning: noexcept specifier on the move constructor evaluates to 'false' [performance-noexcept-move-constructor] |
| 30 | + |
| 31 | + C_1 &operator=(C_1 &&) noexcept(kFalse); |
| 32 | + // CHECK-MESSAGES: :[[@LINE-1]]:37: warning: noexcept specifier on the move assignment operator evaluates to 'false' [performance-noexcept-move-constructor] |
| 33 | + // CHECK-MESSAGES-CONFIG-NOT: :[[@LINE-2]]:37: warning: noexcept specifier on the move assignment operator evaluates to 'false' [performance-noexcept-move-constructor] |
| 34 | +}; |
| 35 | + |
| 36 | +struct C_2 { |
| 37 | + static constexpr bool kEval = std::is_nothrow_move_constructible<ThrowOnAnything>::value; |
| 38 | + static_assert(!kEval); // kEval == false; |
| 39 | + |
| 40 | + C_2(C_2&&) noexcept(kEval) = default; |
| 41 | + // CHECK-MESSAGES: :[[@LINE-1]]:25: warning: noexcept specifier on the move constructor evaluates to 'false' [performance-noexcept-move-constructor] |
| 42 | + // CHECK-MESSAGES-CONFIG-NOT: :[[@LINE-2]]:25: warning: noexcept specifier on the move constructor evaluates to 'false' [performance-noexcept-move-constructor] |
| 43 | + |
| 44 | + C_2 &operator=(C_2 &&) noexcept(kEval); |
| 45 | + // CHECK-MESSAGES: :[[@LINE-1]]:37: warning: noexcept specifier on the move assignment operator evaluates to 'false' [performance-noexcept-move-constructor] |
| 46 | + // CHECK-MESSAGES-CONFIG-NOT: :[[@LINE-2]]:37: warning: noexcept specifier on the move assignment operator evaluates to 'false' [performance-noexcept-move-constructor] |
| 47 | + |
| 48 | + ThrowOnAnything field; |
| 49 | +}; |
| 50 | + |
| 51 | +struct C_3 { |
| 52 | + static constexpr bool kEval = std::is_nothrow_move_constructible<ThrowOnAnything>::value; |
| 53 | + static_assert(!kEval); // kEval == false; |
| 54 | + |
| 55 | + C_3(C_3&&) noexcept(kEval) = default; |
| 56 | + // CHECK-MESSAGES: :[[@LINE-1]]:25: warning: noexcept specifier on the move constructor evaluates to 'false' [performance-noexcept-move-constructor] |
| 57 | + // CHECK-MESSAGES-CONFIG-NOT: :[[@LINE-2]]:25: warning: noexcept specifier on the move constructor evaluates to 'false' [performance-noexcept-move-constructor] |
| 58 | + |
| 59 | + ~C_3() noexcept(kEval) = default; |
| 60 | + // CHECK-MESSAGES-CONFIG: :[[@LINE-1]]:21: warning: noexcept specifier on the destructor evaluates to 'false' |
| 61 | + |
| 62 | + ThrowOnAnything field; |
| 63 | +}; |
0 commit comments