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