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 12struct A 13{ 14 static int count; 15 int id_; 16 A() : id_(++count) {} 17 ~A() {assert(id_ == count--);} 18 19private: 20 A(const A&); 21 A& operator=(const A&); 22}; 23 24int A::count = 0; 25 26struct B 27{ 28 static int count; 29 int id_; 30 B() : id_(++count) {} 31 ~B() {assert(id_ == count--);} 32 33private: 34 B(const B&); 35 B& operator=(const B&); 36}; 37 38int B::count = 0; 39 40struct C 41{ 42 static int count; 43 int id_; 44 C() : id_(++count) {} 45 ~C() {assert(id_ == count--);} 46 47private: 48 C(const C&); 49 C& operator=(const C&); 50}; 51 52int C::count = 0; 53 54void f2() 55{ 56 C c; 57 A a; 58 throw 55; 59 B b; 60} 61 62void f1() throw (long, char, int, double) 63{ 64 A a; 65 B b; 66 f2(); 67 C c; 68} 69 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