Topic: Should we do a public derivation from a base class without virtual destructor ?


Author: Waranun Bunjongsat <bunjonwa@elk.CS.ORST.EDU>
Date: 1999/08/18
Raw View
On 18 Aug 1999, Ron Natalie wrote:

> Waranun Bunjongsat wrote:
> >
> > O
> >
> >         The case which is made for the trivial destructor, implies that
> > public derivation from a concrete data type is a standard way to do.
>
> I don't know what you're trying to say, but the language spec
> is clear.  If you delete through the base class pointer, and
> the destructor is NOT virtual, the results are undefined.
>
> >
> >         Except in the industries where people are paranoid about
> > any situation, which can cause damages. You may get laid off if the
> > customers deleted your derived class from its base class pointer whose
> > class do not have virtual destruction, and it resulted in major and
> > frequent crashes of the system, which are found out later; after the
> > customers already delivered their product to their major customer or
>
> If you persist in writing code that becomes a support and maintenance
> nightmare because you insist on relying on undefined behavior, you
> won't last long in my company whether the product is one of our
> medical products or a little image display program for the remote
> sensing product.

 What I persist is in pursuing whatever make senses in the
philosophy of the language. I'm not persisting in writing the code that
can have problems. I finally think language needs some improve, so that
people will not have to keep saying that don't do this, don't do that
because it can cause the problem, despite that it is a part of the concept
of the language.

Regards,

Waranun,


[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html              ]






Author: Waranun Bunjongsat <bunjonwa@trek.CS.ORST.EDU>
Date: 1999/08/18
Raw View
On 17 Aug 1999, Waranun Bunjongsat wrote:

> On Tue, 17 Aug 1999, Nick Ambrose wrote:
>
> >
> >
> > Ron Natalie wrote:
> >
> > > Albela Kela wrote:
> > > >
> > > > You should not do this in cases 2 & 3, and in some cases avoid for 1 also.
> > > >
> > > > The reason is that if you do
> > > > base* pB = new derived;
> > > >
> > > > delete pB;
> > > >
> > > > B::~B is called. This will surely leak memory in 2 and 3.
> > > >
> > >
> > > Actually, the spec unconditionally requires a virtual
> > > destructor in this case, even if the destructors are
> > > trivial or even implicitlly generated.
> >
> > So, what is the case in which the exception is made for the trivial destructor ?
> > (I forget)
>
>  The case which is made for the trivial destructor, implies that
> public derivation from a concrete data type is a standard way to do.
>
>  Except in the industries where people are paranoid about
> any situation, which can cause damages. You may get laid off if the
> customers deleted your derived class from its base class pointer whose
> class do not have virtual destruction, and it resulted in major and
> frequent crashes of the system, which are found out later; after the
> customers already delivered their product to their major customer or after
> their product is on the shelf in the market .....
>
>  It seems the best way for this is that C++ is to change delete
> operation to always check RTTI.

 Hmmm, wait a minute ...  this can only prevent the case which the
base class defines some virtual functions but it fails to define the
destructor to be virtual. RTTI can only be recovered for the object with a
pointer to its virtual table, right ?

 Hmmmm, what to do then ..... ???? How about preventing the
class derived from the base class without virtual destructor not to be
able to be assigned to the pointer of its base, only the reference of its
base can refer to an instance of its derived.

Regards,

Waranun,


[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html              ]






Author: Ron Natalie <ron@sensor.com>
Date: 1999/08/18
Raw View
Waranun Bunjongsat wrote:
>
> O
>
>         The case which is made for the trivial destructor, implies that
> public derivation from a concrete data type is a standard way to do.

I don't know what you're trying to say, but the language spec
is clear.  If you delete through the base class pointer, and
the destructor is NOT virtual, the results are undefined.

>
>         Except in the industries where people are paranoid about
> any situation, which can cause damages. You may get laid off if the
> customers deleted your derived class from its base class pointer whose
> class do not have virtual destruction, and it resulted in major and
> frequent crashes of the system, which are found out later; after the
> customers already delivered their product to their major customer or

If you persist in writing code that becomes a support and maintenance
nightmare because you insist on relying on undefined behavior, you
won't last long in my company whether the product is one of our
medical products or a little image display program for the remote
sensing product.
---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html              ]





Author: Waranun Bunjongsat <bunjonwa@trek.CS.ORST.EDU>
Date: 1999/08/17
Raw View
On Tue, 17 Aug 1999, Nick Ambrose wrote:

>
>
> Ron Natalie wrote:
>
> > Albela Kela wrote:
> > >
> > > You should not do this in cases 2 & 3, and in some cases avoid for 1 also.
> > >
> > > The reason is that if you do
> > > base* pB = new derived;
> > >
> > > delete pB;
> > >
> > > B::~B is called. This will surely leak memory in 2 and 3.
> > >
> >
> > Actually, the spec unconditionally requires a virtual
> > destructor in this case, even if the destructors are
> > trivial or even implicitlly generated.
>
> So, what is the case in which the exception is made for the trivial destructor ?
> (I forget)

 The case which is made for the trivial destructor, implies that
public derivation from a concrete data type is a standard way to do.

 Except in the industries where people are paranoid about
any situation, which can cause damages. You may get laid off if the
customers deleted your derived class from its base class pointer whose
class do not have virtual destruction, and it resulted in major and
frequent crashes of the system, which are found out later; after the
customers already delivered their product to their major customer or after
their product is on the shelf in the market .....

 It seems the best way for this is that C++ is to change delete
operation to always check RTTI.

Regards,

Waranun,

> Nick

---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html              ]