1// GROUPS passed destructors
2// Check that virtual destructors work correctly.  Specifically,
3// check that when you destruct an object of a derived class for
4// which the base class had an explicitly declared virtual destructor
5// no infinite recursion occurs.
6//
7// Bug description:
8//    The generated g++ code apparently calls the base class destructor via
9//    the virtual table, rather than directly. This, of course, results in the
10//    infinite recursion.
11
12extern "C" int printf (const char *, ...);
13
14int errors = 0;
15
16struct base {
17	int member;
18	base();
19	virtual ~base();
20};
21
22base::base()
23{
24}
25
26base::~base()
27{
28}
29
30struct derived : public base
31{
32	int member;
33	derived();
34	~derived();
35};
36
37derived::derived() : base()
38{
39}
40
41int derived_destructor_calls = 0;
42
43extern void exit (int);
44
45derived::~derived()
46{
47	if (++derived_destructor_calls > 2)
48		errors++;
49}
50
51void test ();
52
53int main ()
54{
55	test ();
56
57	if (errors)
58	  { printf ("FAIL\n"); return 1; }
59	else
60	  printf ("PASS\n");
61
62	return 0;
63}
64
65base* bp;
66
67void test()
68{
69	derived a;
70
71	a.member = 99;
72	bp = new derived;
73	delete bp;
74}
75