• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 //===------------------------- unwind_03.cpp ------------------------------===//
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 <exception>
13 #include <stdlib.h>
14 #include <assert.h>
15 
16 #if defined(__GNUC__)
17 #pragma GCC diagnostic ignored "-Wunreachable-code"
18 #endif
19 
20 struct A
21 {
22     static int count;
23     int id_;
AA24     A() : id_(++count) {}
~AA25     ~A() {assert(id_ == count--);}
26 
27 private:
28     A(const A&);
29     A& operator=(const A&);
30 };
31 
32 int A::count = 0;
33 
34 struct B
35 {
36     static int count;
37     int id_;
BB38     B() : id_(++count) {}
~BB39     ~B() {assert(id_ == count--);}
40 
41 private:
42     B(const B&);
43     B& operator=(const B&);
44 };
45 
46 int B::count = 0;
47 
48 struct C
49 {
50     static int count;
51     int id_;
CC52     C() : id_(++count) {}
~CC53     ~C() {assert(id_ == count--);}
54 
55 private:
56     C(const C&);
57     C& operator=(const C&);
58 };
59 
60 int C::count = 0;
61 
f2()62 void f2()
63 {
64     C c;
65     A a;
66     throw 55;
67     B b;
68 }
69 
f1()70 void f1() throw (long, char, double)
71 {
72     A a;
73     B b;
74     f2();
75     C c;
76 }
77 
u_handler()78 void u_handler()
79 {
80     exit(0);
81 }
82 
main(int,char **)83 int main(int, char**)
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(i == 55);
102     }
103     catch (...)
104     {
105         assert(false);
106     }
107     assert(false);
108 
109     return 0;
110 }
111