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 #include <exception> 11 #include <stdlib.h> 12 #include <assert.h> 13 14 struct A 15 { 16 static int count; 17 int id_; 18 A() : id_(++count) {} 19 ~A() {assert(id_ == count--);} 20 21 private: 22 A(const A&); 23 A& operator=(const A&); 24 }; 25 26 int A::count = 0; 27 28 struct B 29 { 30 static int count; 31 int id_; 32 B() : id_(++count) {} 33 ~B() {assert(id_ == count--);} 34 35 private: 36 B(const B&); 37 B& operator=(const B&); 38 }; 39 40 int B::count = 0; 41 42 struct C 43 { 44 static int count; 45 int id_; 46 C() : id_(++count) {} 47 ~C() {assert(id_ == count--);} 48 49 private: 50 C(const C&); 51 C& operator=(const C&); 52 }; 53 54 int C::count = 0; 55 56 void f2() 57 { 58 C c; 59 A a; 60 throw 55; 61 B b; 62 } 63 64 void f1() throw (long, char, double) 65 { 66 A a; 67 B b; 68 f2(); 69 C c; 70 } 71 72 void u_handler() 73 { 74 throw 'a'; 75 } 76 77 int main() 78 { 79 std::set_unexpected(u_handler); 80 try 81 { 82 f1(); 83 assert(false); 84 } 85 catch (int* i) 86 { 87 assert(false); 88 } 89 catch (long i) 90 { 91 assert(false); 92 } 93 catch (int i) 94 { 95 assert(false); 96 } 97 catch (char c) 98 { 99 assert(c == 'a'); 100 } 101 catch (...) 102 { 103 assert(false); 104 } 105 assert(A::count == 0); 106 assert(B::count == 0); 107 assert(C::count == 0); 108 } 109