// RUN: %check_clang_tidy %s performance-noexcept-swap %t -- -- -fexceptions namespace std { template struct is_nothrow_move_constructible { static constexpr bool value = __is_nothrow_constructible(T, __add_rvalue_reference(T)); }; } // namespace std void throwing_function() noexcept(false); void noexcept_function() noexcept; template struct TemplateNoexceptWithInt { static void f() {} }; template <> struct TemplateNoexceptWithInt { static void f() noexcept {} }; class A { void swap(A &); // CHECK-MESSAGES: :[[@LINE-1]]:8: warning: swap functions should be marked noexcept [performance-noexcept-swap] // CHECK-FIXES: void swap(A &) noexcept ; }; void swap(A &, A &); // CHECK-MESSAGES: :[[@LINE-1]]:6: warning: swap functions should be marked noexcept [performance-noexcept-swap] // CHECK-FIXES: void swap(A &, A &) noexcept ; void iter_swap(A &, A &); // CHECK-MESSAGES: :[[@LINE-1]]:6: warning: swap functions should be marked noexcept [performance-noexcept-swap] // CHECK-FIXES: void iter_swap(A &, A &) noexcept ; struct B { static constexpr bool kFalse = false; void swap(B &) noexcept(kFalse); // CHECK-MESSAGES: :[[@LINE-1]]:27: warning: noexcept specifier on swap function evaluates to 'false' [performance-noexcept-swap] }; void swap(B &, B &) noexcept(B::kFalse); // CHECK-MESSAGES: :[[@LINE-1]]:30: warning: noexcept specifier on swap function evaluates to 'false' [performance-noexcept-swap] template struct C { void swap(C&); // CHECK-MESSAGES: :[[@LINE-1]]:8: warning: swap functions should be marked noexcept [performance-noexcept-swap] // CHECK-FIXES: void swap(C&) noexcept ; }; template void swap(C&, C&); // CHECK-MESSAGES: :[[@LINE-1]]:6: warning: swap functions should be marked noexcept [performance-noexcept-swap] // CHECK-FIXES: void swap(C&, C&) noexcept ; void swap(C&, C&); // CHECK-MESSAGES: :[[@LINE-1]]:6: warning: swap functions should be marked noexcept [performance-noexcept-swap] // CHECK-FIXES: void swap(C&, C&) noexcept ; template struct D { static constexpr bool kFalse = false; void swap(D &) noexcept(kFalse); // CHECK-MESSAGES: :[[@LINE-1]]:27: warning: noexcept specifier on swap function evaluates to 'false' [performance-noexcept-swap] }; void swap(D &, D &) noexcept(D::kFalse); // CHECK-MESSAGES: :[[@LINE-1]]:40: warning: noexcept specifier on swap function evaluates to 'false' [performance-noexcept-swap] struct E { void swap(E &) noexcept(noexcept(throwing_function())); // CHECK-MESSAGES: :[[@LINE-1]]:27: warning: noexcept specifier on swap function evaluates to 'false' [performance-noexcept-swap] }; void swap(E &, E &) noexcept(noexcept(throwing_function())); // CHECK-MESSAGES: :[[@LINE-1]]:30: warning: noexcept specifier on swap function evaluates to 'false' [performance-noexcept-swap] template struct F { void swap(F &) noexcept(noexcept(throwing_function())); // CHECK-MESSAGES: :[[@LINE-1]]:27: warning: noexcept specifier on swap function evaluates to 'false' [performance-noexcept-swap] }; template void swap(F &, F &) noexcept(noexcept(throwing_function())); // CHECK-MESSAGES: :[[@LINE-1]]:36: warning: noexcept specifier on swap function evaluates to 'false' [performance-noexcept-swap] void swap(F &, F &) noexcept(noexcept(throwing_function())); // CHECK-MESSAGES: :[[@LINE-1]]:40: warning: noexcept specifier on swap function evaluates to 'false' [performance-noexcept-swap] struct G { void swap(G &) noexcept(noexcept(TemplateNoexceptWithInt::f())); // CHECK-MESSAGES: :[[@LINE-1]]:27: warning: noexcept specifier on swap function evaluates to 'false' [performance-noexcept-swap] }; void swap(G &, G &) noexcept(noexcept(TemplateNoexceptWithInt::f())); // CHECK-MESSAGES: :[[@LINE-1]]:30: warning: noexcept specifier on swap function evaluates to 'false' [performance-noexcept-swap] class OK {}; struct OK1 { void swap(OK1 &) noexcept; }; void swap(OK1 &, OK1 &) noexcept; struct OK2 { static constexpr bool kTrue = true; void swap(OK2 &) noexcept(kTrue) {} }; void swap(OK2 &, OK2 &) noexcept(OK2::kTrue); struct OK3 { void swap(OK3 &) = delete; }; void swap(OK3 &, OK3 &) = delete; struct OK4 { void swap(OK4 &) noexcept(false); }; void swap(OK4 &, OK4 &) noexcept(false); struct OK5 { void swap(OK5 &) noexcept(true); }; void swap(OK5 &, OK5 &)noexcept(true); struct OK12 { void swap(OK12 &) noexcept(noexcept(noexcept_function())); }; void swap(OK12 &, OK12 &) noexcept(noexcept(noexcept_function())); struct OK13 { void swap(OK13 &) noexcept(noexcept(TemplateNoexceptWithInt::f())); }; void swap(OK13 &, OK13 &) noexcept(noexcept(TemplateNoexceptWithInt::f())); template class OK14 {}; template struct OK15 { void swap(OK15 &) noexcept; }; template void swap(OK15 &, OK15 &) noexcept; void swap(OK15 &, OK15 &) noexcept; template struct OK16 { static constexpr bool kTrue = true; void swap(OK16 &) noexcept(kTrue); }; template void swap(OK16 &, OK16 &) noexcept(OK16::kTrue); template void swap(OK16 &, OK16 &) noexcept(OK16::kTrue); template struct OK17 { void swap(OK17 &) = delete; }; template void swap(OK17 &, OK17 &) = delete; void swap(OK17 &, OK17 &) = delete; template struct OK18 { void swap(OK18 &) noexcept(false); }; template void swap(OK18 &, OK18 &) noexcept(false); void swap(OK18 &, OK18 &) noexcept(false); template struct OK19 { void swap(OK19 &) noexcept(true); }; template void swap(OK19 &, OK19 &)noexcept(true); void swap(OK19 &, OK19 &)noexcept(true); template struct OK20 { void swap(OK20 &) noexcept(noexcept(noexcept_function())); }; template void swap(OK20 &, OK20 &) noexcept(noexcept(noexcept_function())); void swap(OK20 &, OK20 &) noexcept(noexcept(noexcept_function())); template struct OK21 { void swap(OK21 &) noexcept(noexcept(TemplateNoexceptWithInt::f())); }; template void swap(OK21 &, OK21 &) noexcept(noexcept(TemplateNoexceptWithInt::f())); void swap(OK21 &, OK21 &) noexcept(noexcept(TemplateNoexceptWithInt::f())); namespace PR64303 { void swap(); void swap(int&, bool&); void swap(int&, int&, int&); void swap(int&); struct Test { void swap(); void swap(Test&, Test&); void swap(int&); static void swap(int&, int&); friend void swap(Test&, Test&); // CHECK-MESSAGES: :[[@LINE-1]]:17: warning: swap functions should be marked noexcept [performance-noexcept-swap] }; } // namespace PR64303 namespace gh68101 { template class Container { public: void swap(Container&) noexcept(std::is_nothrow_move_constructible::value); }; } // namespace gh68101