[docs] Add LICENSE.txt to the root of the mono-repo
[llvm-project.git] / libcxxabi / test / unwind_01.pass.cpp
blob1b8ed01365aafa2f7c44217ddbadac6bbf82f984
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 //===----------------------------------------------------------------------===//
9 // UNSUPPORTED: no-exceptions
11 #include <assert.h>
13 #if defined(__GNUC__)
14 #pragma GCC diagnostic ignored "-Wunreachable-code"
15 #endif
17 struct A
19 static int count;
20 int id_;
21 A() : id_(++count) {}
22 ~A() {assert(id_ == count--);}
24 private:
25 A(const A&);
26 A& operator=(const A&);
29 int A::count = 0;
31 struct B
33 static int count;
34 int id_;
35 B() : id_(++count) {}
36 ~B() {assert(id_ == count--);}
38 private:
39 B(const B&);
40 B& operator=(const B&);
43 int B::count = 0;
45 struct C
47 static int count;
48 int id_;
49 C() : id_(++count) {}
50 ~C() {assert(id_ == count--);}
52 private:
53 C(const C&);
54 C& operator=(const C&);
57 int C::count = 0;
59 void f2()
61 C c;
62 A a;
63 throw 55;
64 B b;
67 void f1()
69 A a;
70 B b;
71 f2();
72 C c;
75 int main(int, char**)
77 try
79 f1();
80 assert(false);
82 catch (int* i)
84 assert(false);
86 catch (long i)
88 assert(false);
90 catch (int i)
92 assert(i == 55);
94 catch (...)
96 assert(false);
98 assert(A::count == 0);
99 assert(B::count == 0);
100 assert(C::count == 0);
102 return 0;