xref: /aosp_15_r20/external/libcxxabi/test/unwind_01.pass.cpp (revision c05d8e5dc3e10f6ce4317e8bc22cc4a25f55fa94)
1*c05d8e5dSAndroid Build Coastguard Worker //===------------------------- unwind_01.cpp ------------------------------===//
2*c05d8e5dSAndroid Build Coastguard Worker //
3*c05d8e5dSAndroid Build Coastguard Worker //                     The LLVM Compiler Infrastructure
4*c05d8e5dSAndroid Build Coastguard Worker //
5*c05d8e5dSAndroid Build Coastguard Worker // This file is dual licensed under the MIT and the University of Illinois Open
6*c05d8e5dSAndroid Build Coastguard Worker // Source Licenses. See LICENSE.TXT for details.
7*c05d8e5dSAndroid Build Coastguard Worker //
8*c05d8e5dSAndroid Build Coastguard Worker //===----------------------------------------------------------------------===//
9*c05d8e5dSAndroid Build Coastguard Worker 
10*c05d8e5dSAndroid Build Coastguard Worker // UNSUPPORTED: libcxxabi-no-exceptions
11*c05d8e5dSAndroid Build Coastguard Worker 
12*c05d8e5dSAndroid Build Coastguard Worker #include <assert.h>
13*c05d8e5dSAndroid Build Coastguard Worker 
14*c05d8e5dSAndroid Build Coastguard Worker #if defined(__GNUC__)
15*c05d8e5dSAndroid Build Coastguard Worker #pragma GCC diagnostic ignored "-Wunreachable-code"
16*c05d8e5dSAndroid Build Coastguard Worker #endif
17*c05d8e5dSAndroid Build Coastguard Worker 
18*c05d8e5dSAndroid Build Coastguard Worker struct A
19*c05d8e5dSAndroid Build Coastguard Worker {
20*c05d8e5dSAndroid Build Coastguard Worker     static int count;
21*c05d8e5dSAndroid Build Coastguard Worker     int id_;
AA22*c05d8e5dSAndroid Build Coastguard Worker     A() : id_(++count) {}
~AA23*c05d8e5dSAndroid Build Coastguard Worker     ~A() {assert(id_ == count--);}
24*c05d8e5dSAndroid Build Coastguard Worker 
25*c05d8e5dSAndroid Build Coastguard Worker private:
26*c05d8e5dSAndroid Build Coastguard Worker     A(const A&);
27*c05d8e5dSAndroid Build Coastguard Worker     A& operator=(const A&);
28*c05d8e5dSAndroid Build Coastguard Worker };
29*c05d8e5dSAndroid Build Coastguard Worker 
30*c05d8e5dSAndroid Build Coastguard Worker int A::count = 0;
31*c05d8e5dSAndroid Build Coastguard Worker 
32*c05d8e5dSAndroid Build Coastguard Worker struct B
33*c05d8e5dSAndroid Build Coastguard Worker {
34*c05d8e5dSAndroid Build Coastguard Worker     static int count;
35*c05d8e5dSAndroid Build Coastguard Worker     int id_;
BB36*c05d8e5dSAndroid Build Coastguard Worker     B() : id_(++count) {}
~BB37*c05d8e5dSAndroid Build Coastguard Worker     ~B() {assert(id_ == count--);}
38*c05d8e5dSAndroid Build Coastguard Worker 
39*c05d8e5dSAndroid Build Coastguard Worker private:
40*c05d8e5dSAndroid Build Coastguard Worker     B(const B&);
41*c05d8e5dSAndroid Build Coastguard Worker     B& operator=(const B&);
42*c05d8e5dSAndroid Build Coastguard Worker };
43*c05d8e5dSAndroid Build Coastguard Worker 
44*c05d8e5dSAndroid Build Coastguard Worker int B::count = 0;
45*c05d8e5dSAndroid Build Coastguard Worker 
46*c05d8e5dSAndroid Build Coastguard Worker struct C
47*c05d8e5dSAndroid Build Coastguard Worker {
48*c05d8e5dSAndroid Build Coastguard Worker     static int count;
49*c05d8e5dSAndroid Build Coastguard Worker     int id_;
CC50*c05d8e5dSAndroid Build Coastguard Worker     C() : id_(++count) {}
~CC51*c05d8e5dSAndroid Build Coastguard Worker     ~C() {assert(id_ == count--);}
52*c05d8e5dSAndroid Build Coastguard Worker 
53*c05d8e5dSAndroid Build Coastguard Worker private:
54*c05d8e5dSAndroid Build Coastguard Worker     C(const C&);
55*c05d8e5dSAndroid Build Coastguard Worker     C& operator=(const C&);
56*c05d8e5dSAndroid Build Coastguard Worker };
57*c05d8e5dSAndroid Build Coastguard Worker 
58*c05d8e5dSAndroid Build Coastguard Worker int C::count = 0;
59*c05d8e5dSAndroid Build Coastguard Worker 
f2()60*c05d8e5dSAndroid Build Coastguard Worker void f2()
61*c05d8e5dSAndroid Build Coastguard Worker {
62*c05d8e5dSAndroid Build Coastguard Worker     C c;
63*c05d8e5dSAndroid Build Coastguard Worker     A a;
64*c05d8e5dSAndroid Build Coastguard Worker     throw 55;
65*c05d8e5dSAndroid Build Coastguard Worker     B b;
66*c05d8e5dSAndroid Build Coastguard Worker }
67*c05d8e5dSAndroid Build Coastguard Worker 
f1()68*c05d8e5dSAndroid Build Coastguard Worker void f1()
69*c05d8e5dSAndroid Build Coastguard Worker {
70*c05d8e5dSAndroid Build Coastguard Worker     A a;
71*c05d8e5dSAndroid Build Coastguard Worker     B b;
72*c05d8e5dSAndroid Build Coastguard Worker     f2();
73*c05d8e5dSAndroid Build Coastguard Worker     C c;
74*c05d8e5dSAndroid Build Coastguard Worker }
75*c05d8e5dSAndroid Build Coastguard Worker 
main()76*c05d8e5dSAndroid Build Coastguard Worker int main()
77*c05d8e5dSAndroid Build Coastguard Worker {
78*c05d8e5dSAndroid Build Coastguard Worker     try
79*c05d8e5dSAndroid Build Coastguard Worker     {
80*c05d8e5dSAndroid Build Coastguard Worker         f1();
81*c05d8e5dSAndroid Build Coastguard Worker         assert(false);
82*c05d8e5dSAndroid Build Coastguard Worker     }
83*c05d8e5dSAndroid Build Coastguard Worker     catch (int* i)
84*c05d8e5dSAndroid Build Coastguard Worker     {
85*c05d8e5dSAndroid Build Coastguard Worker         assert(false);
86*c05d8e5dSAndroid Build Coastguard Worker     }
87*c05d8e5dSAndroid Build Coastguard Worker     catch (long i)
88*c05d8e5dSAndroid Build Coastguard Worker     {
89*c05d8e5dSAndroid Build Coastguard Worker         assert(false);
90*c05d8e5dSAndroid Build Coastguard Worker     }
91*c05d8e5dSAndroid Build Coastguard Worker     catch (int i)
92*c05d8e5dSAndroid Build Coastguard Worker     {
93*c05d8e5dSAndroid Build Coastguard Worker         assert(i == 55);
94*c05d8e5dSAndroid Build Coastguard Worker     }
95*c05d8e5dSAndroid Build Coastguard Worker     catch (...)
96*c05d8e5dSAndroid Build Coastguard Worker     {
97*c05d8e5dSAndroid Build Coastguard Worker         assert(false);
98*c05d8e5dSAndroid Build Coastguard Worker     }
99*c05d8e5dSAndroid Build Coastguard Worker     assert(A::count == 0);
100*c05d8e5dSAndroid Build Coastguard Worker     assert(B::count == 0);
101*c05d8e5dSAndroid Build Coastguard Worker     assert(C::count == 0);
102*c05d8e5dSAndroid Build Coastguard Worker }
103