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