virtual destructor unexpected pass

Martin von Loewis martin@mira.isdn.cs.tu-berlin.de
Wed Sep 2 11:38:00 GMT 1998


> Then I reassert that the compiler should say something about this - if not
> an error, then a warning.  

Certainly not an error. To bring some standard text in here, please
check [class.dtor]/7:

>> A destructor can be declared virtual (10.3) or pure virtual (10.4);
>> if any objects of that class or any derived class are created in
>> the program, the destructor shall be defined. If a class has a base
>> class with a virtual destructor, its destructor (whether user­ or
>> implicitly­ declared) is virtual.

So the program

struct X{
  virtual ~X()=0;
};

struct Y:X{
  virtual ~Y(){}
};

int main()
{
  Y y;
}

X::~X(){}

is standard C++, and should be accepted. It is also meaningful; it
says that class X is abstract, and no instances of it should be
created. So I'm not sure I want a warning.

If I forget to implement the destructor, I'll get a linker error, just
as I get for any other destructor that is used and not implemented.

Regards,
Martin



More information about the Gcc-bugs mailing list