Debian Codegraph @

gcc/testsuite/g++.dg/eh/return1.C

raw
1 // PR c++/33799
2 // { dg-do run }
3
4 extern "C" void abort();
5
6 int c, d;
7
8 #if __cplusplus >= 201103L
9 #define THROWS noexcept(false)
10 #else
11 #define THROWS
12 #endif
13
14 extern "C" int printf (const char *, ...);
15 #define DEBUG // printf ("%p %s\n", this, __PRETTY_FUNCTION__)
16
17 struct X
18 {
19 X(bool throws) : i(-42), throws_(throws) { ++c; DEBUG; }
20 X(const X& x); // not defined
21 ~X() THROWS
22 {
23 i = ++d; DEBUG;
24 if (throws_) { throw 1; }
25 }
26 int i;
27 private:
28 bool throws_;
29 };
30
31 X f()
32 {
33 X x(true);
34 return X(false);
35 }
36
37 X f2()
38 {
39 foo:
40 X x(true);
41 return X(false);
42 }
43
44 X g()
45 {
46 return X(true),X(false);
47 }
48
49 void h()
50 {
51 #if __cplusplus >= 201103L
52 []{ return X(true),X(false); }();
53 #endif
54 }
55
56 X i()
57 {
58 try {
59 X x(true);
60 return X(false);
61 } catch(...) {}
62 return X(false);
63 }
64
65 X i2()
66 {
67 try {
68 foo:
69 X x(true);
70 return X(false);
71 } catch(...) {}
72 return X(false);
73 }
74
75 // c++/112301
76 X i3()
77 {
78 try {
79 X x(true);
80 return X(false);
81 } catch(...) { throw; }
82 }
83
84 X i4()
85 {
86 try {
87 X x(true);
88 X x2(false);
89 return x2;
90 } catch(...) { throw; }
91 }
92
93 X i4a()
94 {
95 try {
96 X x2(false);
97 X x(true);
98 return x2;
99 } catch(...) { throw; }
100 }
101
102 X i4b()
103 {
104 X x(true);
105 X x2(false);
106 return x2;
107 }
108
109 X i4c()
110 {
111 X x2(false);
112 X x(true);
113 return x2;
114 }
115
116 X i5()
117 {
118 X x2(false);
119
120 try {
121 X x(true);
122 return x2;
123 } catch(...) {
124 if (x2.i != -42)
125 d += 42;
126 throw;
127 }
128 }
129
130 X i6()
131 {
132 X x2(false);
133
134 try {
135 X x(true);
136 return x2;
137 } catch(...) {
138 if (x2.i != -42)
139 d += 42;
140 }
141 return x2;
142 }
143
144 X j()
145 {
146 try {
147 return X(true),X(false);
148 } catch(...) {}
149 return X(false);
150 }
151
152 template <class T>
153 T k()
154 {
155 try {
156 return T(true),T(false);
157 } catch (...) {}
158 return T(true),T(false);
159 }
160
161 X l() try { return X(true),X(false); }
162 catch (...) { return X(true),X(false); }
163
164 template <class T>
165 T m()
166 try { return T(true),T(false); }
167 catch (...) { return T(true),T(false); }
168
169 int main()
170 {
171 try { f(); }
172 catch (...) {}
173
174 try { f2(); } catch (...) {}
175
176 try { g(); }
177 catch (...) {}
178
179 try { h(); }
180 catch (...) {}
181
182 try { i(); }
183 catch (...) {}
184
185 try { i2(); } catch (...) {}
186 try { i3(); } catch (...) {}
187 try { i4(); } catch (...) {}
188 try { i4a(); } catch (...) {}
189 try { i4b(); } catch (...) {}
190 try { i4c(); } catch (...) {}
191 try { i5(); } catch (...) {}
192 try { i6(); } catch (...) {}
193
194 try { j(); } catch (...) {}
195
196 try { k<X>(); } catch (...) {}
197
198 try { l(); } catch (...) {}
199 try { m<X>(); } catch (...) {}
200
201 return c - d;
202 }