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