1 //===------------------------- unwind_04.cpp ------------------------------===// 2 // 3 // The LLVM Compiler Infrastructure 4 // 5 // This file is dual licensed under the MIT and the University of Illinois Open 6 // Source Licenses. See LICENSE.TXT for details. 7 // 8 //===----------------------------------------------------------------------===// 9 10 // UNSUPPORTED: libcxxabi-no-exceptions 11 12 #include <exception> 13 #include <stdlib.h> 14 #include <assert.h> 15 16 #if defined(__GNUC__) 17 #pragma GCC diagnostic ignored "-Wunreachable-code" 18 #endif 19 20 struct A 21 { 22 static int count; 23 int id_; 24 A() : id_(++count) {} 25 ~A() {assert(id_ == count--);} 26 27 private: 28 A(const A&); 29 A& operator=(const A&); 30 }; 31 32 int A::count = 0; 33 34 struct B 35 { 36 static int count; 37 int id_; 38 B() : id_(++count) {} 39 ~B() {assert(id_ == count--);} 40 41 private: 42 B(const B&); 43 B& operator=(const B&); 44 }; 45 46 int B::count = 0; 47 48 struct C 49 { 50 static int count; 51 int id_; 52 C() : id_(++count) {} 53 ~C() {assert(id_ == count--);} 54 55 private: 56 C(const C&); 57 C& operator=(const C&); 58 }; 59 60 int C::count = 0; 61 62 void f2() 63 { 64 C c; 65 A a; 66 throw 55; 67 B b; 68 } 69 70 void f1() throw (long, char, double) 71 { 72 A a; 73 B b; 74 f2(); 75 C c; 76 } 77 78 void u_handler() 79 { 80 throw 'a'; 81 } 82 83 int main() 84 { 85 std::set_unexpected(u_handler); 86 try 87 { 88 f1(); 89 assert(false); 90 } 91 catch (int* i) 92 { 93 assert(false); 94 } 95 catch (long i) 96 { 97 assert(false); 98 } 99 catch (int i) 100 { 101 assert(false); 102 } 103 catch (char c) 104 { 105 assert(c == 'a'); 106 } 107 catch (...) 108 { 109 assert(false); 110 } 111 assert(A::count == 0); 112 assert(B::count == 0); 113 assert(C::count == 0); 114 } 115