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