Dead
[official-gcc.git] / gomp-20050608-branch / gcc / testsuite / g++.old-deja / g++.brendan / dtors2.C
blob924bf4a0bac81fe8737c3895592ab756e2f0c0d2
1 // { dg-do run  }
2 // GROUPS passed destructors
3 // Check that virtual destructors work correctly.  Specifically,
4 // check that when you destruct an object of a derived class for
5 // which the base class had an explicitly declared virtual destructor
6 // no infinite recursion occurs.
7 //
8 // Bug description:
9 //    The generated g++ code apparently calls the base class destructor via
10 //    the virtual table, rather than directly. This, of course, results in the
11 //    infinite recursion.
13 extern "C" int printf (const char *, ...); 
15 int errors = 0;
17 struct base {
18         int member;
19         base();
20         virtual ~base();
22   
23 base::base()
27 base::~base()
31 struct derived : public base
33         int member;
34         derived();
35         ~derived();
37   
38 derived::derived() : base()
42 int derived_destructor_calls = 0;
44 extern void exit (int);
46 derived::~derived()
48         if (++derived_destructor_calls > 2)
49                 errors++;
52 void test ();
54 int main ()
56         test ();
58         if (errors)
59           { printf ("FAIL\n"); return 1; }
60         else
61           printf ("PASS\n");
63         return 0;
66 base* bp;
68 void test()
70         derived a;
72         a.member = 99;
73         bp = new derived;
74         delete bp;