blob: 053bb0dae7abd5bf21ec126091b4ea2fbcc13e34 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
|
// { dg-do run }
// GROUPS passed destructors
// Check that member and base classes get properly destructed
// when an object of a derived class is destructed via a pointer
// to it which only has a "compile-time" type of "pointer-to-base".
//
// Note that in order for this test to work properly, the destructor
// for the base class should be explicitly declared to be virtual.
extern "C" int printf (const char *, ...);
int member_destructor_calls = 0;
int middle_destructor_calls = 0;
struct member_type {
int data_member;
member_type () {}
~member_type ();
};
struct base {
int data_member;
base () {}
virtual ~base ();
};
struct middle : public base {
member_type member1;
member_type member2;
middle () {}
~middle (); // should be implicitly virtual
};
struct derived : public middle {
member_type member1;
member_type member2;
//~derived () {}
};
int main ()
{
base* bp = new derived;
delete bp;
derived *dp = new derived;
delete dp;
if ((member_destructor_calls != 8) || (middle_destructor_calls != 2))
{ printf ("FAIL\n"); return 1; }
else
printf ("PASS\n");
return 0;
}
member_type::~member_type ()
{
member_destructor_calls++;
}
base::~base ()
{
}
middle::~middle ()
{
middle_destructor_calls++;
}
|