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