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