1 // RUN: %check_clang_tidy -std=c++17-or-later %s modernize-use-uncaught-exceptions %t
2
3 #define MACRO std::uncaught_exception
4 // CHECK-FIXES: #define MACRO std::uncaught_exception
5
uncaught_exception()6 bool uncaught_exception() {
7 return 0;
8 }
9
10 namespace std {
uncaught_exception()11 bool uncaught_exception() {
12 return false;
13 }
14
uncaught_exceptions()15 int uncaught_exceptions() {
16 return 0;
17 }
18 }
19
20 template <typename T>
doSomething(T t)21 bool doSomething(T t) {
22 return t();
23 // CHECK-FIXES: return t();
24 }
25
26 template <bool (*T)()>
doSomething2()27 bool doSomething2() {
28 return T();
29 // CHECK-MESSAGES: [[@LINE-1]]:10: warning: 'std::uncaught_exception' is deprecated, use 'std::uncaught_exceptions' instead
30 // CHECK-FIXES: return T();
31 }
32
no_warn()33 void no_warn() {
34
35 uncaught_exception();
36 // CHECK-FIXES: uncaught_exception();
37
38 doSomething(uncaught_exception);
39 // CHECK-FIXES: doSomething(uncaught_exception);
40 }
41
warn()42 void warn() {
43
44 std::uncaught_exception();
45 // CHECK-MESSAGES: [[@LINE-1]]:3: warning: 'std::uncaught_exception' is deprecated, use 'std::uncaught_exceptions' instead
46 // CHECK-FIXES: std::uncaught_exceptions();
47
48 using std::uncaught_exception;
49 // CHECK-MESSAGES: [[@LINE-1]]:14: warning: 'std::uncaught_exception' is deprecated, use 'std::uncaught_exceptions' instead
50 // CHECK-FIXES: using std::uncaught_exceptions;
51
52 uncaught_exception();
53 // CHECK-MESSAGES: [[@LINE-1]]:3: warning: 'std::uncaught_exception' is deprecated, use 'std::uncaught_exceptions' instead
54 // CHECK-FIXES: uncaught_exceptions();
55
56 bool b{uncaught_exception()};
57 // CHECK-MESSAGES: [[@LINE-1]]:10: warning: 'std::uncaught_exception' is deprecated, use 'std::uncaught_exceptions' instead
58 // CHECK-FIXES: bool b{std::uncaught_exceptions() > 0};
59
60 MACRO();
61 // CHECK-MESSAGES: [[@LINE-1]]:3: warning: 'std::uncaught_exception' is deprecated, use 'std::uncaught_exceptions' instead
62 // CHECK-FIXES: MACRO();
63
64 doSomething(std::uncaught_exception);
65 // CHECK-MESSAGES: [[@LINE-1]]:15: warning: 'std::uncaught_exception' is deprecated, use 'std::uncaught_exceptions' instead
66 // CHECK-FIXES: doSomething(std::uncaught_exception);
67
68 doSomething(uncaught_exception);
69 // CHECK-MESSAGES: [[@LINE-1]]:15: warning: 'std::uncaught_exception' is deprecated, use 'std::uncaught_exceptions' instead
70 // CHECK-FIXES: doSomething(uncaught_exception);
71
72 bool (*foo)();
73 foo = &uncaught_exception;
74 // CHECK-MESSAGES: [[@LINE-1]]:10: warning: 'std::uncaught_exception' is deprecated, use 'std::uncaught_exceptions' instead
75 // CHECK-FIXES: foo = &uncaught_exception;
76
77 doSomething2<uncaught_exception>();
78 // CHECK-MESSAGES: [[@LINE-1]]:16: warning: 'std::uncaught_exception' is deprecated, use 'std::uncaught_exceptions' instead
79 // CHECK-FIXES: doSomething2<uncaught_exception>();
80 }
81