1 //===------------------------- unwind_02.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 <assert.h> 11 12 struct A 13 { 14 static int count; 15 int id_; AA16 A() : id_(++count) {} ~AA17 ~A() {assert(id_ == count--);} 18 19 private: 20 A(const A&); 21 A& operator=(const A&); 22 }; 23 24 int A::count = 0; 25 26 struct B 27 { 28 static int count; 29 int id_; BB30 B() : id_(++count) {} ~BB31 ~B() {assert(id_ == count--);} 32 33 private: 34 B(const B&); 35 B& operator=(const B&); 36 }; 37 38 int B::count = 0; 39 40 struct C 41 { 42 static int count; 43 int id_; CC44 C() : id_(++count) {} ~CC45 ~C() {assert(id_ == count--);} 46 47 private: 48 C(const C&); 49 C& operator=(const C&); 50 }; 51 52 int C::count = 0; 53 f2()54void f2() 55 { 56 C c; 57 A a; 58 throw 55; 59 B b; 60 } 61 f1()62void f1() throw (long, char, int, double) 63 { 64 A a; 65 B b; 66 f2(); 67 C c; 68 } 69 main()70int main() 71 { 72 try 73 { 74 f1(); 75 assert(false); 76 } 77 catch (int* i) 78 { 79 assert(false); 80 } 81 catch (long i) 82 { 83 assert(false); 84 } 85 catch (int i) 86 { 87 assert(i == 55); 88 } 89 catch (...) 90 { 91 assert(false); 92 } 93 assert(A::count == 0); 94 assert(B::count == 0); 95 assert(C::count == 0); 96 } 97