blob: df1e429730bcc2e628161b8621c84c1b35d8ffbb [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
Eric Fiseliera3f48932016-12-24 05:01:55 +000016#if defined(__GNUC__)
17#pragma GCC diagnostic ignored "-Wunreachable-code"
18#endif
19
Saleem Abdulrasoolb8771592015-04-24 20:20:54 +000020struct A
21{
22 static int count;
23 int id_;
24 A() : id_(++count) {}
25 ~A() {assert(id_ == count--);}
26
27private:
28 A(const A&);
29 A& operator=(const A&);
30};
31
32int A::count = 0;
33
34struct B
35{
36 static int count;
37 int id_;
38 B() : id_(++count) {}
39 ~B() {assert(id_ == count--);}
40
41private:
42 B(const B&);
43 B& operator=(const B&);
44};
45
46int B::count = 0;
47
48struct C
49{
50 static int count;
51 int id_;
52 C() : id_(++count) {}
53 ~C() {assert(id_ == count--);}
54
55private:
56 C(const C&);
57 C& operator=(const C&);
58};
59
60int C::count = 0;
61
62void f2()
63{
64 C c;
65 A a;
66 throw 55;
67 B b;
68}
69
70void f1() throw (long, char, double, std::bad_exception)
71{
72 A a;
73 B b;
74 f2();
75 C c;
76}
77
78void u_handler()
79{
80 throw;
81}
82
83int main()
84{
85 std::set_unexpected(u_handler);
86 try
87 {
88 f1();
89 assert(false);
90 }
91 catch (int* i)
92 {
93 assert(false);
94 }
95 catch (long i)
96 {
97 assert(false);
98 }
99 catch (int i)
100 {
101 assert(false);
102 }
103 catch (char c)
104 {
105 assert(false);
106 }
107 catch (const std::bad_exception& e)
108 {
109 assert(true);
110 }
111 catch (...)
112 {
113 assert(false);
114 }
115 assert(A::count == 0);
116 assert(B::count == 0);
117 assert(C::count == 0);
118}