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