gcc/testsuite/g++.old-deja/g++.robertl/eh990323-5.C
raw| 1 | // { dg-do run } |
| 2 | // check cleanup of partial array objects |
| 3 | extern "C" void abort (void); |
| 4 | extern "C" void exit (int); |
| 5 | |
| 6 | int ctor = 0; |
| 7 | int dtor = 0; |
| 8 | |
| 9 | int cnt = 1; |
| 10 | |
| 11 | struct A { |
| 12 | int x; |
| 13 | A(); |
| 14 | A(const A&); |
| 15 | ~A(); |
| 16 | }; |
| 17 | |
| 18 | A::A() |
| 19 | { |
| 20 | if (cnt == 10) |
| 21 | throw 57; |
| 22 | x = cnt++; |
| 23 | ctor++; |
| 24 | } |
| 25 | |
| 26 | A::A(const A&) |
| 27 | { |
| 28 | if (cnt == 10) |
| 29 | throw 57; |
| 30 | x = cnt++; |
| 31 | ctor++; |
| 32 | } |
| 33 | |
| 34 | A::~A() |
| 35 | { |
| 36 | if (x + 1 != cnt--) |
| 37 | abort(); |
| 38 | dtor++; |
| 39 | } |
| 40 | |
| 41 | void f() |
| 42 | { |
| 43 | A a[] = {A(), A(), A(), A(), A(), A(), A(), A(), A(), A(), A(), A()}; |
| 44 | |
| 45 | throw -1066; |
| 46 | } |
| 47 | |
| 48 | int |
| 49 | main() |
| 50 | { |
| 51 | int flag; |
| 52 | |
| 53 | flag = 0; |
| 54 | try { |
| 55 | f(); |
| 56 | } |
| 57 | catch (int) { |
| 58 | flag = 1; |
| 59 | } |
| 60 | if (!flag) |
| 61 | abort(); |
| 62 | if (ctor != 9) |
| 63 | abort(); |
| 64 | if (dtor != 9) |
| 65 | abort(); |
| 66 | |
| 67 | exit(0); |
| 68 | } |