xref: /llvm-project/clang-tools-extra/test/clang-tidy/checkers/bugprone/exception-escape-throw.cpp (revision 5545f1bbd4e18b9ffda993ee13460d417194941a)
1 // RUN: %check_clang_tidy -std=c++11,c++14 %s bugprone-exception-escape %t -- -- -fexceptions
2 
throwing_throw_nothing()3 void throwing_throw_nothing() throw() {
4 // CHECK-MESSAGES: :[[@LINE-1]]:6: warning: an exception may be thrown in function 'throwing_throw_nothing' which should not throw exceptions
5   throw 1;
6 }
7 
8 void explicit_int_thrower() throw(int);
9 
implicit_int_thrower()10 void implicit_int_thrower() {
11   throw 5;
12 }
13 
indirect_implicit()14 void indirect_implicit() throw() {
15 // CHECK-MESSAGES: :[[@LINE-1]]:6: warning: an exception may be thrown in function 'indirect_implicit' which should not throw exceptions
16   implicit_int_thrower();
17 }
18 
indirect_explicit()19 void indirect_explicit() throw() {
20 // CHECK-MESSAGES: :[[@LINE-1]]:6: warning: an exception may be thrown in function 'indirect_explicit' which should not throw exceptions
21   explicit_int_thrower();
22 }
23 
24 struct super_throws {
super_throwssuper_throws25   super_throws() throw(int) { throw 42; }
26 };
27 
28 struct sub_throws : super_throws {
sub_throwssub_throws29   sub_throws() throw() : super_throws() {}
30   // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: an exception may be thrown in function 'sub_throws' which should not throw exceptions
31 };
32