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