189a1d03eSRichard // RUN: %check_clang_tidy -std=c++11,c++14 %s modernize-use-noexcept %t -- \
2*e8a3ddafSNathan James // RUN: -config="{CheckOptions: {modernize-use-noexcept.ReplacementString: 'NOEXCEPT'}}" \
389a1d03eSRichard // RUN: -- -fexceptions
489a1d03eSRichard // This test is not run in C++17 or later because dynamic exception
589a1d03eSRichard // specifications were removed in C++17.
689a1d03eSRichard
789a1d03eSRichard // Example definition of NOEXCEPT -- simplified test to see if noexcept is supported.
889a1d03eSRichard #if (__has_feature(cxx_noexcept))
989a1d03eSRichard #define NOEXCEPT noexcept
1089a1d03eSRichard #else
1189a1d03eSRichard #define NOEXCEPT throw()
1289a1d03eSRichard #endif
1389a1d03eSRichard
bar()1489a1d03eSRichard void bar() throw() {}
1589a1d03eSRichard // CHECK-MESSAGES: :[[@LINE-1]]:12: warning: dynamic exception specification 'throw()' is deprecated; consider using 'NOEXCEPT' instead [modernize-use-noexcept]
1689a1d03eSRichard // CHECK-FIXES: void bar() NOEXCEPT {}
1789a1d03eSRichard
1889a1d03eSRichard // Should not trigger a FixItHint, since macros only support noexcept, and this
1989a1d03eSRichard // case throws.
2089a1d03eSRichard class A {};
2189a1d03eSRichard class B {};
2289a1d03eSRichard void foobar() throw(A, B);
2389a1d03eSRichard // CHECK-MESSAGES: :[[@LINE-1]]:15: warning: dynamic exception specification 'throw(A, B)' is deprecated; consider removing it instead [modernize-use-noexcept]
2489a1d03eSRichard
2589a1d03eSRichard // Should not trigger a replacement.
2689a1d03eSRichard void foo() noexcept(true);
2789a1d03eSRichard
2889a1d03eSRichard struct Z {
2989a1d03eSRichard void operator delete(void *ptr) throw();
3089a1d03eSRichard void operator delete[](void *ptr) throw(int);
~ZZ3189a1d03eSRichard ~Z() throw(int) {}
3289a1d03eSRichard };
3389a1d03eSRichard // CHECK-MESSAGES: :[[@LINE-4]]:35: warning: dynamic exception specification 'throw()' is deprecated; consider using 'NOEXCEPT' instead [modernize-use-noexcept]
3489a1d03eSRichard // CHECK-MESSAGES: :[[@LINE-4]]:37: warning: dynamic exception specification 'throw(int)' is deprecated; consider removing it instead [modernize-use-noexcept]
3589a1d03eSRichard // CHECK-MESSAGES: :[[@LINE-4]]:8: warning: dynamic exception specification 'throw(int)' is deprecated; consider removing it instead [modernize-use-noexcept]
3689a1d03eSRichard // CHECK-FIXES: void operator delete(void *ptr) NOEXCEPT;
3789a1d03eSRichard // CHECK-FIXES: void operator delete[](void *ptr) throw(int);
3889a1d03eSRichard // CHECK-FIXES: ~Z() throw(int) {}
39