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