xref: /aosp_15_r20/external/cronet/third_party/libc++abi/src/test/unwind_02.pass.cpp (revision 6777b5387eb2ff775bb5750e3f5d96f37fb7352b)
1 //===----------------------------------------------------------------------===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 
9 // UNSUPPORTED: no-exceptions
10 // REQUIRES: c++03 || c++11 || c++14
11 
12 #include <assert.h>
13 
14 #if defined(__GNUC__)
15 #pragma GCC diagnostic ignored "-Wunreachable-code"
16 #pragma GCC diagnostic ignored "-Wdeprecated" // dynamic exception specifications are deprecated
17 #endif
18 
19 struct A
20 {
21     static int count;
22     int id_;
AA23     A() : id_(++count) {}
~AA24     ~A() {assert(id_ == count--);}
25 
26 private:
27     A(const A&);
28     A& operator=(const A&);
29 };
30 
31 int A::count = 0;
32 
33 struct B
34 {
35     static int count;
36     int id_;
BB37     B() : id_(++count) {}
~BB38     ~B() {assert(id_ == count--);}
39 
40 private:
41     B(const B&);
42     B& operator=(const B&);
43 };
44 
45 int B::count = 0;
46 
47 struct C
48 {
49     static int count;
50     int id_;
CC51     C() : id_(++count) {}
~CC52     ~C() {assert(id_ == count--);}
53 
54 private:
55     C(const C&);
56     C& operator=(const C&);
57 };
58 
59 int C::count = 0;
60 
f2()61 void f2()
62 {
63     C c;
64     A a;
65     throw 55;
66     B b;
67 }
68 
f1()69 void f1() throw (long, char, int, double)
70 {
71     A a;
72     B b;
73     f2();
74     C c;
75 }
76 
main(int,char **)77 int main(int, char**)
78 {
79     try
80     {
81         f1();
82         assert(false);
83     }
84     catch (int* i)
85     {
86         assert(false);
87     }
88     catch (long i)
89     {
90         assert(false);
91     }
92     catch (int i)
93     {
94         assert(i == 55);
95     }
96     catch (...)
97     {
98         assert(false);
99     }
100     assert(A::count == 0);
101     assert(B::count == 0);
102     assert(C::count == 0);
103 
104     return 0;
105 }
106