OSDN Git Service

* call.c (add_candidates): Add first_arg and return_type parms.
[pf3gnuchains/gcc-fork.git] / gcc / testsuite / g++.old-deja / g++.brendan / dtors2.C
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.
12
13 extern "C" int printf (const char *, ...); 
14
15 int errors = 0;
16
17 struct base {
18         int member;
19         base();
20         virtual ~base();
21 };
22   
23 base::base()
24 {
25 }
26
27 base::~base()
28 {
29 }
30
31 struct derived : public base
32 {
33         int member;
34         derived();
35         ~derived();
36 };
37   
38 derived::derived() : base()
39 {
40 }
41
42 int derived_destructor_calls = 0;
43
44 extern void exit (int);
45
46 derived::~derived()
47 {
48         if (++derived_destructor_calls > 2)
49                 errors++;
50 }
51
52 void test ();
53
54 int main ()
55 {
56         test ();
57
58         if (errors)
59           { printf ("FAIL\n"); return 1; }
60         else
61           printf ("PASS\n");
62
63         return 0;
64 }
65
66 base* bp;
67
68 void test()
69 {
70         derived a;
71
72         a.member = 99;
73         bp = new derived;
74         delete bp;
75 }