1 //===------------------------- unwind_03.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_; AA18 A() : id_(++count) {} ~AA19 ~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_; BB32 B() : id_(++count) {} ~BB33 ~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_; CC46 C() : id_(++count) {} ~CC47 ~C() {assert(id_ == count--);} 48 49 private: 50 C(const C&); 51 C& operator=(const C&); 52 }; 53 54 int C::count = 0; 55 f2()56void f2() 57 { 58 C c; 59 A a; 60 throw 55; 61 B b; 62 } 63 f1()64void f1() throw (long, char, double) 65 { 66 A a; 67 B b; 68 f2(); 69 C c; 70 } 71 u_handler()72void u_handler() 73 { 74 exit(0); 75 } 76 main()77int 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(i == 55); 96 } 97 catch (...) 98 { 99 assert(false); 100 } 101 assert(false); 102 } 103