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