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 13extern "C" int printf (const char *, ...); 14 15int errors = 0; 16 17struct base { 18 int member; 19 base(); 20 virtual ~base(); 21}; 22 23base::base() 24{ 25} 26 27base::~base() 28{ 29} 30 31struct derived : public base 32{ 33 int member; 34 derived(); 35 ~derived(); 36}; 37 38derived::derived() : base() 39{ 40} 41 42int derived_destructor_calls = 0; 43 44extern void exit (int); 45 46derived::~derived() 47{ 48 if (++derived_destructor_calls > 2) 49 errors++; 50} 51 52void test (); 53 54int 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 66base* bp; 67 68void test() 69{ 70 derived a; 71 72 a.member = 99; 73 bp = new derived; 74 delete bp; 75} 76