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

source code of libcxxabi/test/unwind_01.pass.cpp