]> gcc.gnu.org Git - gcc.git/blame - gcc/testsuite/g++.dg/eh/return1.C
c++: retval dtor on rethrow [PR112301]
[gcc.git] / gcc / testsuite / g++.dg / eh / return1.C
CommitLineData
7c82dd6c 1// PR c++/33799
bcfc2227 2// { dg-do run }
7c82dd6c
JM
3
4extern "C" void abort();
5
6int c, d;
7
8#if __cplusplus >= 201103L
9#define THROWS noexcept(false)
10#else
11#define THROWS
12#endif
13
b10e0314
JM
14extern "C" int printf (const char *, ...);
15#define DEBUG // printf ("%p %s\n", this, __PRETTY_FUNCTION__)
16
7c82dd6c
JM
17struct X
18{
d237e7b2
JM
19 X(bool throws) : i(-42), throws_(throws) { ++c; DEBUG; }
20 X(const X& x): i(x.i), throws_(x.throws_) { ++c; DEBUG; }
7c82dd6c
JM
21 ~X() THROWS
22 {
d237e7b2 23 i = ++d; DEBUG;
7c82dd6c
JM
24 if (throws_) { throw 1; }
25 }
d237e7b2 26 int i;
7c82dd6c
JM
27private:
28 bool throws_;
29};
30
31X f()
32{
33 X x(true);
34 return X(false);
35}
36
e62dd770
JM
37X f2()
38{
39 foo:
40 X x(true);
41 return X(false);
42}
43
bcfc2227
JM
44X g()
45{
46 return X(true),X(false);
47}
48
49void h()
50{
51#if __cplusplus >= 201103L
52 []{ return X(true),X(false); }();
53#endif
54}
55
b10e0314
JM
56X i()
57{
58 try {
59 X x(true);
60 return X(false);
61 } catch(...) {}
62 return X(false);
63}
64
e62dd770
JM
65X i2()
66{
67 try {
68 foo:
69 X x(true);
70 return X(false);
71 } catch(...) {}
72 return X(false);
73}
74
d237e7b2
JM
75// c++/112301
76X i3()
77{
78 try {
79 X x(true);
80 return X(false);
81 } catch(...) { throw; }
82}
83
84X i4()
85{
86 try {
87 X x(true);
88 X x2(false);
89 return x2;
90 } catch(...) { throw; }
91}
92
93X i4a()
94{
95 try {
96 X x2(false);
97 X x(true);
98 return x2;
99 } catch(...) { throw; }
100}
101
102X i4b()
103{
104 X x(true);
105 X x2(false);
106 return x2;
107}
108
109X i4c()
110{
111 X x2(false);
112 X x(true);
113 return x2;
114}
115
116X 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
130X 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
b10e0314
JM
144X j()
145{
146 try {
147 return X(true),X(false);
148 } catch(...) {}
149 return X(false);
150}
151
152template <class T>
153T k()
154{
155 try {
156 return T(true),T(false);
157 } catch (...) {}
158 return T(true),T(false);
159}
160
161X l() try { return X(true),X(false); }
162 catch (...) { return X(true),X(false); }
163
164template <class T>
165T m()
166 try { return T(true),T(false); }
167 catch (...) { return T(true),T(false); }
168
7c82dd6c
JM
169int main()
170{
171 try { f(); }
172 catch (...) {}
173
e62dd770
JM
174 try { f2(); } catch (...) {}
175
bcfc2227
JM
176 try { g(); }
177 catch (...) {}
178
179 try { h(); }
180 catch (...) {}
181
b10e0314
JM
182 try { i(); }
183 catch (...) {}
184
e62dd770 185 try { i2(); } catch (...) {}
d237e7b2
JM
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 (...) {}
e62dd770 193
b10e0314
JM
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;
7c82dd6c 202}
This page took 2.591193 seconds and 5 git commands to generate.