Re: BUG: compiler allows for creation of objects without destructor compiled

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance

From: David Olsen (qg4h9ykc5m_at_yahoo.com)
Date: 04/08/04


Date: Thu, 08 Apr 2004 14:34:53 -0700

Maxim Yegorushkin wrote:
> David Olsen wrote:
>> According to the C++ standard (12.4/5) it is not an error to define a
>> class whose destructor cannot be defined (class "derived" in your
>> example). But it is an error to actually call the destructor of that
>> class.
>
> Does it mean that Comeau is wrong about producing the error message in
> Hendrik Schober's posting?

Yes and no. Comeau online (http://www.comeaucomputing.com/tryitout/)
seems to have it bugs in this area, which are different than VC's bugs.
  It correctly accepts:

class base { virtual ~base() { } };
class derived : public base { };

But it rejects the following, which should be valid code because the
destructor is never used:

class base { virtual ~base() { } };
class derived : public base { };
derived *f() { return new derived; }

And it accepts the following, which it should reject because the
destructor is used:

class base { virtual ~base() { } };
class derived : public base { };
void f(derived *x) { delete x; }

-- 
David Olsen
qg4h9ykc5m@yahoo.com


Relevant Pages

  • Re: Polymorphism
    ... then also making derived classes destructors virtual ... So I am thinking that if the Base class destructor is not made virtual ... class X: public Base {public: virtual void Print() ...
    (alt.comp.lang.learn.c-cpp)
  • Re: Deleteing Objects from std::vector
    ... I have given Base a virtual destructor. ... class Derived1: public Base ...
    (comp.lang.cpp)
  • Re: BUG: compiler allows for creation of objects without destructor compiled
    ... > seems to have it bugs in this area, which are different than VC's bugs. ... I believe Comeau rejects it correctly. ... the base subobject destructor must be called (and then operator delete to ...
    (microsoft.public.dotnet.languages.vc)