1// RUN: %check_clang_tidy -std=c++11,c++14 %s modernize-use-noexcept %t -- \
2// RUN: -config="{CheckOptions: {modernize-use-noexcept.ReplacementString: 'NOEXCEPT'}}" \
3// RUN: -- -fexceptions
4// This test is not run in C++17 or later because dynamic exception
5// specifications were removed in C++17.
6
7// Example definition of NOEXCEPT -- simplified test to see if noexcept is supported.
8#if (__has_feature(cxx_noexcept))
9#define NOEXCEPT noexcept
10#else
11#define NOEXCEPT throw()
12#endif
13
14void bar() throw() {}
15// CHECK-MESSAGES: :[[@LINE-1]]:12: warning: dynamic exception specification 'throw()' is deprecated; consider using 'NOEXCEPT' instead [modernize-use-noexcept]
16// CHECK-FIXES: void bar() NOEXCEPT {}
17
18// Should not trigger a FixItHint, since macros only support noexcept, and this
19// case throws.
20class A {};
21class B {};
22void foobar() throw(A, B);
23// CHECK-MESSAGES: :[[@LINE-1]]:15: warning: dynamic exception specification 'throw(A, B)' is deprecated; consider removing it instead [modernize-use-noexcept]
24
25// Should not trigger a replacement.
26void foo() noexcept(true);
27
28struct Z {
29 void operator delete(void *ptr) throw();
30 void operator delete[](void *ptr) throw(int);
31 ~Z() throw(int) {}
32};
33// CHECK-MESSAGES: :[[@LINE-4]]:35: warning: dynamic exception specification 'throw()' is deprecated; consider using 'NOEXCEPT' instead [modernize-use-noexcept]
34// CHECK-MESSAGES: :[[@LINE-4]]:37: warning: dynamic exception specification 'throw(int)' is deprecated; consider removing it instead [modernize-use-noexcept]
35// CHECK-MESSAGES: :[[@LINE-4]]:8: warning: dynamic exception specification 'throw(int)' is deprecated; consider removing it instead [modernize-use-noexcept]
36// CHECK-FIXES: void operator delete(void *ptr) NOEXCEPT;
37// CHECK-FIXES: void operator delete[](void *ptr) throw(int);
38// CHECK-FIXES: ~Z() throw(int) {}
39

source code of clang-tools-extra/test/clang-tidy/checkers/modernize/use-noexcept-macro.cpp