1// RUN: %check_clang_tidy -std=c++11-or-later %s bugprone-exception-escape %t -- \
2// RUN: -- -fexceptions
3
4void rethrower() {
5 throw;
6}
7
8void callsRethrower() {
9 rethrower();
10}
11
12void callsRethrowerNoexcept() noexcept {
13 rethrower();
14}
15
16int throwsAndCallsRethrower() noexcept {
17// CHECK-MESSAGES: :[[@LINE-1]]:5: warning: an exception may be thrown in function 'throwsAndCallsRethrower' which should not throw exceptions
18 try {
19 throw 1;
20 } catch(...) {
21 rethrower();
22 }
23 return 1;
24}
25// CHECK-MESSAGES: :[[@LINE-6]]:9: note: frame #0: unhandled exception of type 'int' may be thrown in function 'throwsAndCallsRethrower' here
26
27int throwsAndCallsCallsRethrower() noexcept {
28// CHECK-MESSAGES: :[[@LINE-1]]:5: warning: an exception may be thrown in function 'throwsAndCallsCallsRethrower' which should not throw exceptions
29 try {
30 throw 1;
31 } catch(...) {
32 callsRethrower();
33 }
34 return 1;
35}
36// CHECK-MESSAGES: :[[@LINE-6]]:9: note: frame #0: unhandled exception of type 'int' may be thrown in function 'throwsAndCallsCallsRethrower' here
37
38void rethrowerNoexcept() noexcept {
39 throw;
40}
41

source code of clang-tools-extra/test/clang-tidy/checkers/bugprone/exception-escape-rethrow.cpp