// { dg-do run }
|
// { dg-do run }
|
// GROUPS passed destructors
|
// GROUPS passed destructors
|
// Check that virtual destructors work correctly. Specifically,
|
// Check that virtual destructors work correctly. Specifically,
|
// check that when you destruct an object of a derived class for
|
// check that when you destruct an object of a derived class for
|
// which the base class had an explicitly declared virtual destructor
|
// which the base class had an explicitly declared virtual destructor
|
// no infinite recursion occurs.
|
// no infinite recursion occurs.
|
//
|
//
|
// Bug description:
|
// Bug description:
|
// The generated g++ code apparently calls the base class destructor via
|
// The generated g++ code apparently calls the base class destructor via
|
// the virtual table, rather than directly. This, of course, results in the
|
// the virtual table, rather than directly. This, of course, results in the
|
// infinite recursion.
|
// infinite recursion.
|
|
|
extern "C" int printf (const char *, ...);
|
extern "C" int printf (const char *, ...);
|
|
|
int errors = 0;
|
int errors = 0;
|
|
|
struct base {
|
struct base {
|
int member;
|
int member;
|
base();
|
base();
|
virtual ~base();
|
virtual ~base();
|
};
|
};
|
|
|
base::base()
|
base::base()
|
{
|
{
|
}
|
}
|
|
|
base::~base()
|
base::~base()
|
{
|
{
|
}
|
}
|
|
|
struct derived : public base
|
struct derived : public base
|
{
|
{
|
int member;
|
int member;
|
derived();
|
derived();
|
~derived();
|
~derived();
|
};
|
};
|
|
|
derived::derived() : base()
|
derived::derived() : base()
|
{
|
{
|
}
|
}
|
|
|
int derived_destructor_calls = 0;
|
int derived_destructor_calls = 0;
|
|
|
extern void exit (int);
|
extern void exit (int);
|
|
|
derived::~derived()
|
derived::~derived()
|
{
|
{
|
if (++derived_destructor_calls > 2)
|
if (++derived_destructor_calls > 2)
|
errors++;
|
errors++;
|
}
|
}
|
|
|
void test ();
|
void test ();
|
|
|
int main ()
|
int main ()
|
{
|
{
|
test ();
|
test ();
|
|
|
if (errors)
|
if (errors)
|
{ printf ("FAIL\n"); return 1; }
|
{ printf ("FAIL\n"); return 1; }
|
else
|
else
|
printf ("PASS\n");
|
printf ("PASS\n");
|
|
|
return 0;
|
return 0;
|
}
|
}
|
|
|
base* bp;
|
base* bp;
|
|
|
void test()
|
void test()
|
{
|
{
|
derived a;
|
derived a;
|
|
|
a.member = 99;
|
a.member = 99;
|
bp = new derived;
|
bp = new derived;
|
delete bp;
|
delete bp;
|
}
|
}
|
|
|