gcc/testsuite/g++.dg/ext/cleanup-dtor.C
raw| 1 | // Check that destructors are run after cleanup functions. |
| 2 | // { dg-do run } |
| 3 | |
| 4 | extern "C" void abort (); |
| 5 | |
| 6 | int i; |
| 7 | |
| 8 | struct S { |
| 9 | ~S() { |
| 10 | if (i != 1) |
| 11 | abort (); |
| 12 | i = 2; |
| 13 | } |
| 14 | }; |
| 15 | |
| 16 | void f(void *) { |
| 17 | if (i != 0) |
| 18 | abort (); |
| 19 | i = 1; |
| 20 | } |
| 21 | |
| 22 | int main () { |
| 23 | { |
| 24 | S s __attribute__((cleanup (f))); |
| 25 | } |
| 26 | if (i != 2) |
| 27 | abort (); |
| 28 | } |