llvm-project
105 строк · 1.7 Кб
1//===----------------------------------------------------------------------===//
2//
3// 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
6//
7//===----------------------------------------------------------------------===//
8
9// UNSUPPORTED: no-exceptions
10// REQUIRES: c++03 || c++11 || c++14
11
12#include <assert.h>
13
14#if defined(__GNUC__)
15#pragma GCC diagnostic ignored "-Wunreachable-code"
16#pragma GCC diagnostic ignored "-Wdeprecated" // dynamic exception specifications are deprecated
17#endif
18
19struct A
20{
21static int count;
22int id_;
23A() : id_(++count) {}
24~A() {assert(id_ == count--);}
25
26private:
27A(const A&);
28A& operator=(const A&);
29};
30
31int A::count = 0;
32
33struct B
34{
35static int count;
36int id_;
37B() : id_(++count) {}
38~B() {assert(id_ == count--);}
39
40private:
41B(const B&);
42B& operator=(const B&);
43};
44
45int B::count = 0;
46
47struct C
48{
49static int count;
50int id_;
51C() : id_(++count) {}
52~C() {assert(id_ == count--);}
53
54private:
55C(const C&);
56C& operator=(const C&);
57};
58
59int C::count = 0;
60
61void f2()
62{
63C c;
64A a;
65throw 55;
66B b;
67}
68
69void f1() throw (long, char, int, double)
70{
71A a;
72B b;
73f2();
74C c;
75}
76
77int main(int, char**)
78{
79try
80{
81f1();
82assert(false);
83}
84catch (int* i)
85{
86assert(false);
87}
88catch (long i)
89{
90assert(false);
91}
92catch (int i)
93{
94assert(i == 55);
95}
96catch (...)
97{
98assert(false);
99}
100assert(A::count == 0);
101assert(B::count == 0);
102assert(C::count == 0);
103
104return 0;
105}
106