| 1 |
// { dg-do run } |
| 2 |
// GROUPS passed destructors |
| 3 |
// Check that when an object of a derived class is (implicitly) |
| 4 |
// destructed (on exit from the block in which it is declared) |
| 5 |
// that the destructor for the base class also gets executed. |
| 6 |
// |
| 7 |
// (also check that this execution doesn't seg-fault) |
| 8 |
|
| 9 |
extern "C" int printf (const char *, ...); |
| 10 |
|
| 11 |
int derived_destructed; |
| 12 |
int base_destructed; |
| 13 |
|
| 14 |
struct base { |
| 15 |
int base_data_member; |
| 16 |
|
| 17 |
base() |
| 18 |
{ |
| 19 |
base_data_member = 0x5e5e; |
| 20 |
} |
| 21 |
~base() |
| 22 |
{ |
| 23 |
base_destructed = 0x781f; |
| 24 |
} |
| 25 |
}; |
| 26 |
|
| 27 |
struct derived : public base { |
| 28 |
int derived_data_member; |
| 29 |
|
| 30 |
derived() |
| 31 |
{ |
| 32 |
derived_data_member = 0xe5e5; |
| 33 |
} |
| 34 |
~derived() |
| 35 |
{ |
| 36 |
derived_destructed = 0xf178; |
| 37 |
} |
| 38 |
}; |
| 39 |
|
| 40 |
|
| 41 |
void test2 (); |
| 42 |
|
| 43 |
int main () |
| 44 |
{ |
| 45 |
test2 (); |
| 46 |
if ((base_destructed != 0x781f) || (derived_destructed != 0xf178)) |
| 47 |
{ printf ("FAIL\n"); return 1; } |
| 48 |
else |
| 49 |
printf ("PASS\n"); |
| 50 |
} |
| 51 |
|
| 52 |
void test2 () |
| 53 |
{ |
| 54 |
derived derived_object; |
| 55 |
|
| 56 |
derived_object.derived_data_member = 99; |
| 57 |
} |