xref: /llvm-project/clang-tools-extra/test/clang-tidy/checkers/bugprone/exception-escape-rethrow.cpp (revision daac014fec427eda305f93da7891c0122a161bb3)
1*daac014fSDeniz Evrenci // RUN: %check_clang_tidy -std=c++11,c++14,c++17,c++20 %s bugprone-exception-escape %t -- \
2*daac014fSDeniz Evrenci // RUN:     -- -fexceptions
3*daac014fSDeniz Evrenci 
rethrower()4*daac014fSDeniz Evrenci void rethrower() {
5*daac014fSDeniz Evrenci     throw;
6*daac014fSDeniz Evrenci }
7*daac014fSDeniz Evrenci 
callsRethrower()8*daac014fSDeniz Evrenci void callsRethrower() {
9*daac014fSDeniz Evrenci     rethrower();
10*daac014fSDeniz Evrenci }
11*daac014fSDeniz Evrenci 
callsRethrowerNoexcept()12*daac014fSDeniz Evrenci void callsRethrowerNoexcept() noexcept {
13*daac014fSDeniz Evrenci     rethrower();
14*daac014fSDeniz Evrenci }
15*daac014fSDeniz Evrenci 
throwsAndCallsRethrower()16*daac014fSDeniz Evrenci int throwsAndCallsRethrower() noexcept {
17*daac014fSDeniz Evrenci // CHECK-MESSAGES: :[[@LINE-1]]:5: warning: an exception may be thrown in function 'throwsAndCallsRethrower' which should not throw exceptions
18*daac014fSDeniz Evrenci     try {
19*daac014fSDeniz Evrenci         throw 1;
20*daac014fSDeniz Evrenci     } catch(...) {
21*daac014fSDeniz Evrenci         rethrower();
22*daac014fSDeniz Evrenci     }
23*daac014fSDeniz Evrenci }
24*daac014fSDeniz Evrenci 
throwsAndCallsCallsRethrower()25*daac014fSDeniz Evrenci int throwsAndCallsCallsRethrower() noexcept {
26*daac014fSDeniz Evrenci // CHECK-MESSAGES: :[[@LINE-1]]:5: warning: an exception may be thrown in function 'throwsAndCallsCallsRethrower' which should not throw exceptions
27*daac014fSDeniz Evrenci     try {
28*daac014fSDeniz Evrenci         throw 1;
29*daac014fSDeniz Evrenci     } catch(...) {
30*daac014fSDeniz Evrenci         callsRethrower();
31*daac014fSDeniz Evrenci     }
32*daac014fSDeniz Evrenci }
33*daac014fSDeniz Evrenci 
rethrowerNoexcept()34*daac014fSDeniz Evrenci void rethrowerNoexcept() noexcept {
35*daac014fSDeniz Evrenci     throw;
36*daac014fSDeniz Evrenci }
37