| 1 | // RUN: %check_clang_tidy -std=c++11,c++14 %s bugprone-exception-escape %t -- -- -fexceptions |
| 2 | |
| 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 | // CHECK-MESSAGES: :[[@LINE-2]]:3: note: frame #0: unhandled exception of type 'int' may be thrown in function 'throwing_throw_nothing' here |
| 8 | |
| 9 | void explicit_int_thrower() throw(int); |
| 10 | |
| 11 | void implicit_int_thrower() { |
| 12 | throw 5; |
| 13 | } |
| 14 | |
| 15 | void indirect_implicit() throw() { |
| 16 | // CHECK-MESSAGES: :[[@LINE-1]]:6: warning: an exception may be thrown in function 'indirect_implicit' which should not throw exceptions |
| 17 | implicit_int_thrower(); |
| 18 | } |
| 19 | // CHECK-MESSAGES: :[[@LINE-7]]:3: note: frame #0: unhandled exception of type 'int' may be thrown in function 'implicit_int_thrower' here |
| 20 | // CHECK-MESSAGES: :[[@LINE-3]]:3: note: frame #1: function 'indirect_implicit' calls function 'implicit_int_thrower' here |
| 21 | |
| 22 | void indirect_explicit() throw() { |
| 23 | // CHECK-MESSAGES: :[[@LINE-1]]:6: warning: an exception may be thrown in function 'indirect_explicit' which should not throw exceptions |
| 24 | explicit_int_thrower(); |
| 25 | } |
| 26 | // CHECK-MESSAGES: :[[@LINE-17]]:29: note: frame #0: unhandled exception of type 'int' may be thrown in function 'explicit_int_thrower' here |
| 27 | // CHECK-MESSAGES: :[[@LINE-3]]:3: note: frame #1: function 'indirect_explicit' calls function 'explicit_int_thrower' here |
| 28 | |
| 29 | struct super_throws { |
| 30 | super_throws() throw(int) { throw 42; } |
| 31 | }; |
| 32 | |
| 33 | struct sub_throws : super_throws { |
| 34 | sub_throws() throw() : super_throws() {} |
| 35 | // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: an exception may be thrown in function 'sub_throws' which should not throw exceptions |
| 36 | }; |
| 37 | // CHECK-MESSAGES: :[[@LINE-7]]:31: note: frame #0: unhandled exception of type 'int' may be thrown in function 'super_throws' here |
| 38 | // CHECK-MESSAGES: :[[@LINE-4]]:26: note: frame #1: function 'sub_throws' calls function 'super_throws' here |
| 39 | |
| 40 | struct base_throwing_ctor { |
| 41 | base_throwing_ctor() throw(int) { throw 123; } |
| 42 | }; |
| 43 | |
| 44 | struct intermediate_ctor : base_throwing_ctor { |
| 45 | intermediate_ctor() throw(int) : base_throwing_ctor() {} |
| 46 | }; |
| 47 | |
| 48 | struct final_no_throw : intermediate_ctor { |
| 49 | final_no_throw() throw() : intermediate_ctor() {} |
| 50 | // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: an exception may be thrown in function 'final_no_throw' which should not throw exceptions |
| 51 | }; |
| 52 | // CHECK-MESSAGES: :[[@LINE-11]]:37: note: frame #0: unhandled exception of type 'int' may be thrown in function 'base_throwing_ctor' here |
| 53 | // CHECK-MESSAGES: :[[@LINE-8]]:36: note: frame #1: function 'intermediate_ctor' calls function 'base_throwing_ctor' here |
| 54 | // CHECK-MESSAGES: :[[@LINE-5]]:30: note: frame #2: function 'final_no_throw' calls function 'intermediate_ctor' here |
| 55 | |
| 56 | // Member initializer with call stack |
| 57 | struct member_thrower { |
| 58 | member_thrower() throw(double) { throw 3.14; } |
| 59 | }; |
| 60 | |
| 61 | struct has_throwing_member { |
| 62 | member_thrower member; |
| 63 | has_throwing_member() throw() : member() {} |
| 64 | // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: an exception may be thrown in function 'has_throwing_member' which should not throw exceptions |
| 65 | }; |
| 66 | // CHECK-MESSAGES: :[[@LINE-8]]:36: note: frame #0: unhandled exception of type 'double' may be thrown in function 'member_thrower' here |
| 67 | // CHECK-MESSAGES: :[[@LINE-4]]:35: note: frame #1: function 'has_throwing_member' calls function 'member_thrower' here |
| 68 | |
| 69 | void multi_spec_thrower() throw(int, double, const char*); |
| 70 | |
| 71 | void calls_multi_spec() throw() { |
| 72 | // CHECK-MESSAGES: :[[@LINE-1]]:6: warning: an exception may be thrown in function 'calls_multi_spec' which should not throw exceptions |
| 73 | multi_spec_thrower(); |
| 74 | } |
| 75 | // CHECK-MESSAGES: :[[@LINE-6]]:27: note: frame #0: unhandled exception of type '{{(int|double|const char \*)}}' may be thrown in function 'multi_spec_thrower' here |
| 76 | // CHECK-MESSAGES: :[[@LINE-3]]:3: note: frame #1: function 'calls_multi_spec' calls function 'multi_spec_thrower' here |
| 77 | |