81 lines · cpp
1// RUN: %check_clang_tidy -std=c++17-or-later %s modernize-use-uncaught-exceptions %t2 3#define MACRO std::uncaught_exception4// CHECK-FIXES: #define MACRO std::uncaught_exception5 6bool uncaught_exception() {7 return 0;8}9 10namespace std {11 bool uncaught_exception() {12 return false;13 }14 15 int uncaught_exceptions() {16 return 0;17 }18}19 20template <typename T>21bool doSomething(T t) { 22 return t();23 // CHECK-FIXES: return t();24}25 26template <bool (*T)()>27bool doSomething2() { 28 return T();29 // CHECK-MESSAGES: [[@LINE-1]]:10: warning: 'std::uncaught_exception' is deprecated, use 'std::uncaught_exceptions' instead30 // CHECK-FIXES: return T();31}32 33void no_warn() {34 35 uncaught_exception();36 // CHECK-FIXES: uncaught_exception();37 38 doSomething(uncaught_exception);39 // CHECK-FIXES: doSomething(uncaught_exception);40}41 42void warn() {43 44 std::uncaught_exception();45 // CHECK-MESSAGES: [[@LINE-1]]:3: warning: 'std::uncaught_exception' is deprecated, use 'std::uncaught_exceptions' instead46 // 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' instead50 // 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' instead54 // 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' instead58 // 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' instead62 // 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' instead66 // 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' instead70 // 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' instead75 // 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' instead79 // CHECK-FIXES: doSomething2<uncaught_exception>();80}81