blob: e7a8479f9b634c09e0853c639cf6e3cf529459d3 [file] [log] [blame]
Saleem Abdulrasoolac18e062015-04-24 20:20:54 +00001//===------------------------- unwind_02.cpp ------------------------------===//
2//
Chandler Carruth57b08b02019-01-19 10:56:40 +00003// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
Saleem Abdulrasoolac18e062015-04-24 20:20:54 +00006//
7//===----------------------------------------------------------------------===//
8
Asiri Rathnayake57e446d2016-05-31 12:01:32 +00009// UNSUPPORTED: libcxxabi-no-exceptions
Eric Fiselier5aeb8802017-01-24 10:28:23 +000010// REQUIRES: c++98 || c++03 || c++11 || c++14
Asiri Rathnayake57e446d2016-05-31 12:01:32 +000011
Saleem Abdulrasoolac18e062015-04-24 20:20:54 +000012#include <assert.h>
13
Eric Fiselier47570b82016-12-24 05:01:55 +000014#if defined(__GNUC__)
15#pragma GCC diagnostic ignored "-Wunreachable-code"
16#endif
17
Saleem Abdulrasoolac18e062015-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() throw (long, char, int, double)
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}