1 | // RUN: %check_clang_tidy -std=c++11,c++14 %s modernize-use-noexcept %t -- \ |
2 | // RUN: -config="{CheckOptions: {modernize-use-noexcept.UseNoexceptFalse: false}}" \ |
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 | using size_t = __SIZE_TYPE__; |
8 | class A {}; |
9 | class B {}; |
10 | |
11 | void foo() throw(); |
12 | // CHECK-MESSAGES: :[[@LINE-1]]:12: warning: dynamic exception specification 'throw()' is deprecated; consider using 'noexcept' instead [modernize-use-noexcept] |
13 | // CHECK-FIXES: void foo() noexcept; |
14 | |
15 | void bar() throw(...); |
16 | // CHECK-MESSAGES: :[[@LINE-1]]:12: warning: dynamic exception specification 'throw(...)' is deprecated; consider removing it instead [modernize-use-noexcept] |
17 | // CHECK-FIXES: void bar() ; |
18 | |
19 | void k() throw(int(int)); |
20 | // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: dynamic exception specification 'throw(int(int))' is deprecated; consider removing it instead [modernize-use-noexcept] |
21 | // CHECK-FIXES: void k() ; |
22 | |
23 | // Shouldn't crash due to llvm_unreachable in canThrow() on EST_Uninstantiated |
24 | template <int> class c { void *operator new(size_t) throw (int);}; |
25 | void s() { c<1> doesnt_crash; } |
26 | // CHECK-MESSAGES: :[[@LINE-2]]:53: warning: dynamic exception specification 'throw (int)' is deprecated; consider removing it instead [modernize-use-noexcept] |
27 | |
28 | void foobar() throw(A, B) |
29 | {} |
30 | // CHECK-MESSAGES: :[[@LINE-2]]:15: warning: dynamic exception specification 'throw(A, B)' is deprecated; consider removing it instead [modernize-use-noexcept] |
31 | // CHECK-FIXES: void foobar() |
32 | |
33 | void baz(int = (throw A(), 0)) throw(A, B) {} |
34 | // CHECK-MESSAGES: :[[@LINE-1]]:32: warning: dynamic exception specification 'throw(A, B)' is deprecated; consider removing it instead [modernize-use-noexcept] |
35 | // CHECK-FIXES: void baz(int = (throw A(), 0)) {} |
36 | |
37 | void g(void (*fp)(void) throw()); |
38 | // CHECK-MESSAGES: :[[@LINE-1]]:25: warning: dynamic exception specification 'throw()' is deprecated; consider using 'noexcept' instead [modernize-use-noexcept] |
39 | // CHECK-FIXES: void g(void (*fp)(void) noexcept); |
40 | |
41 | void f(void (*fp)(void) throw(int)) throw(char); |
42 | // CHECK-MESSAGES: :[[@LINE-1]]:25: warning: dynamic exception specification 'throw(int)' is deprecated; consider removing it instead [modernize-use-noexcept] |
43 | // CHECK-MESSAGES: :[[@LINE-2]]:37: warning: dynamic exception specification 'throw(char)' is deprecated; consider removing it instead [modernize-use-noexcept] |
44 | // CHECK-FIXES: void f(void (*fp)(void) ) ; |
45 | |
46 | #define THROW throw |
47 | void h(void (*fp)(void) THROW(int)) THROW(char); |
48 | // CHECK-MESSAGES: :[[@LINE-1]]:25: warning: dynamic exception specification 'THROW(int)' is deprecated; consider removing it instead [modernize-use-noexcept] |
49 | // CHECK-MESSAGES: :[[@LINE-2]]:37: warning: dynamic exception specification 'THROW(char)' is deprecated; consider removing it instead [modernize-use-noexcept] |
50 | // CHECK-FIXES: void h(void (*fp)(void) ) ; |
51 | |
52 | void j() throw(int(int) throw(void(void) throw(int))); |
53 | // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: dynamic exception specification 'throw(int(int) throw(void(void) throw(int)))' is deprecated; consider removing it instead [modernize-use-noexcept] |
54 | // CHECK-FIXES: void j() ; |
55 | |
56 | class Y { |
57 | Y() throw() = default; |
58 | }; |
59 | // CHECK-MESSAGES: :[[@LINE-2]]:7: warning: dynamic exception specification 'throw()' is deprecated; consider using 'noexcept' instead [modernize-use-noexcept] |
60 | // CHECK-FIXES: Y() noexcept = default; |
61 | |
62 | struct Z { |
63 | void operator delete(void *ptr) throw(); |
64 | void operator delete[](void *ptr) throw(int); |
65 | ~Z() throw(int) {} |
66 | }; |
67 | // CHECK-MESSAGES: :[[@LINE-4]]:35: warning: dynamic exception specification 'throw()' is deprecated; consider using 'noexcept' instead [modernize-use-noexcept] |
68 | // CHECK-MESSAGES: :[[@LINE-4]]:37: warning: dynamic exception specification 'throw(int)' is deprecated; consider using 'noexcept(false)' instead [modernize-use-noexcept] |
69 | // CHECK-MESSAGES: :[[@LINE-4]]:8: warning: dynamic exception specification 'throw(int)' is deprecated; consider using 'noexcept(false)' instead [modernize-use-noexcept] |
70 | // CHECK-FIXES: void operator delete(void *ptr) noexcept; |
71 | // CHECK-FIXES: void operator delete[](void *ptr) noexcept(false); |
72 | // CHECK-FIXES: ~Z() noexcept(false) {} |
73 | |
74 | struct S { |
75 | void f() throw(); |
76 | }; |
77 | void f(void (S::*)() throw()); |
78 | // CHECK-MESSAGES: :[[@LINE-3]]:12: warning: dynamic exception specification 'throw()' is deprecated; consider using 'noexcept' instead [modernize-use-noexcept] |
79 | // CHECK-MESSAGES: :[[@LINE-2]]:22: warning: dynamic exception specification 'throw()' is deprecated; consider using 'noexcept' instead [modernize-use-noexcept] |
80 | // CHECK-FIXES: void f() noexcept; |
81 | // CHECK-FIXES: void f(void (S::*)() noexcept); |
82 | |
83 | typedef void (*fp)(void (*fp2)(int) throw()); |
84 | // CHECK-MESSAGES: :[[@LINE-1]]:37: warning: dynamic exception specification 'throw()' is deprecated; consider using 'noexcept' instead [modernize-use-noexcept] |
85 | // CHECK-FIXES: typedef void (*fp)(void (*fp2)(int) noexcept); |
86 | |
87 | // Should not trigger a replacement. |
88 | void titi() noexcept {} |
89 | void toto() noexcept(true) {} |
90 | |
91 | // Should not trigger a replacement. |
92 | void bad() |
93 | #if !__has_feature(cxx_noexcept) |
94 | throw() |
95 | #endif |
96 | ; |
97 | |