| 1 |
// Test that we clean up the right number of array elements when |
| 2 |
// a temporary destructor throws. |
| 3 |
// { dg-do run } |
| 4 |
|
| 5 |
#if __cplusplus > 201100L |
| 6 |
#define THROWING noexcept(false) |
| 7 |
#else |
| 8 |
#define THROWING |
| 9 |
#endif |
| 10 |
|
| 11 |
extern "C" void abort (); |
| 12 |
|
| 13 |
int b; |
| 14 |
int d = -1; |
| 15 |
struct A { |
| 16 |
A() { } |
| 17 |
A(const A&); |
| 18 |
~A() THROWING { |
| 19 |
if (b == d) throw b; |
| 20 |
} |
| 21 |
}; |
| 22 |
struct B { |
| 23 |
B(const A& = A()) { ++b; } |
| 24 |
B(const B&); |
| 25 |
~B() { --b; } |
| 26 |
}; |
| 27 |
void f() |
| 28 |
{ |
| 29 |
b = 0; |
| 30 |
try |
| 31 |
{ |
| 32 |
B bs[3]; |
| 33 |
if (b != 3) abort (); |
| 34 |
} |
| 35 |
catch (int i) { } |
| 36 |
if (b != 0) abort (); |
| 37 |
} |
| 38 |
|
| 39 |
int main() |
| 40 |
{ |
| 41 |
for (d = 0; d <= 3; ++d) |
| 42 |
f(); |
| 43 |
} |