blob: 3dea2aadde5943d2370a1abe6f59a92cfc41cbce [file] [log] [blame]
Saleem Abdulrasoolb8771592015-04-24 20:20:54 +00001//===------------------------- unwind_05.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 <exception>
13#include <stdlib.h>
14#include <assert.h>
15
16struct A
17{
18 static int count;
19 int id_;
20 A() : id_(++count) {}
21 ~A() {assert(id_ == count--);}
22
23private:
24 A(const A&);
25 A& operator=(const A&);
26};
27
28int A::count = 0;
29
30struct B
31{
32 static int count;
33 int id_;
34 B() : id_(++count) {}
35 ~B() {assert(id_ == count--);}
36
37private:
38 B(const B&);
39 B& operator=(const B&);
40};
41
42int B::count = 0;
43
44struct C
45{
46 static int count;
47 int id_;
48 C() : id_(++count) {}
49 ~C() {assert(id_ == count--);}
50
51private:
52 C(const C&);
53 C& operator=(const C&);
54};
55
56int C::count = 0;
57
58void f2()
59{
60 C c;
61 A a;
62 throw 55;
63 B b;
64}
65
66void f1() throw (long, char, double, std::bad_exception)
67{
68 A a;
69 B b;
70 f2();
71 C c;
72}
73
74void u_handler()
75{
76 throw;
77}
78
79int main()
80{
81 std::set_unexpected(u_handler);
82 try
83 {
84 f1();
85 assert(false);
86 }
87 catch (int* i)
88 {
89 assert(false);
90 }
91 catch (long i)
92 {
93 assert(false);
94 }
95 catch (int i)
96 {
97 assert(false);
98 }
99 catch (char c)
100 {
101 assert(false);
102 }
103 catch (const std::bad_exception& e)
104 {
105 assert(true);
106 }
107 catch (...)
108 {
109 assert(false);
110 }
111 assert(A::count == 0);
112 assert(B::count == 0);
113 assert(C::count == 0);
114}