Topic: warning to protect virtual destructor firing integrity


Author: kkb@breathsense.com (Kurt Bigler)
Date: Mon, 3 May 2004 16:33:02 +0000 (UTC)
Raw View
Actually this warning is more general than that, but my primary motivation
for suggesting it is that I'd like to see the hole plugged that allows a
delete without the usually desired destructor calls occurring.  In short...

I'd like to see a warning when a class makes a function virtual that
was not virtual in one of its base class.  For destructors I'd like this to
include the case when a base class has no explicit destructor.

I'm suggesting that such a warning be made a requirement of the standard.

Someone I talked to thought that this idea had been brought up before, but
that it seems to have been lost.

Alternatively I'd like to see an empty virtual destructor generated by the
compiler if no destructor is present, whenever there are other virtual
functions in the class, and therefore an unsolicited vtable would not
result.  I was forewarned that such an idea would not be received favorably
here, which is why I suggested the warning instead.  The warning does also
cover much more ground.

There is another conceivable approach to aid in reliable destructor usage.
It leaves more responsibility with the programmer but also probably has
broader utiity.  Correct me if I'm wrong I believe there is currently no way
for a class to specify (directly or indirectly) simply that it can not be
derived from.  It strikes me that a mechanism for achieving this would be
useful in many situations, since there are various coding practices that are
safe in a leaf class that are not safe elsewhere, including defining a
non-virtual destructor in a simple class currently intended not to have a
vtable and not intended to be derived from.

Thanks,
Kurt Bigler

---
[ 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://www.jamesd.demon.co.uk/csc/faq.html                       ]





Author: stephen.clamage@sun.com (Steve Clamage)
Date: Tue, 4 May 2004 20:00:05 +0000 (UTC)
Raw View
Kurt Bigler wrote:
>
> I'd like to see a warning when a class makes a function virtual that
> was not virtual in one of its base class.  For destructors I'd like this to
> include the case when a base class has no explicit destructor.
>
> I'm suggesting that such a warning be made a requirement of the standard.

The standard describes what constitutes a well-formed program, and
says what the program means, or that no meaning is assigned, or that
the meaning is determined by the implementation.

There is no end to the kinds of questionable practices a compiler
could warn about. Which warnings should be required? Your pet peeves?
Mine?

The C++ Committee (the C Committee, too) feels that requirements for
warnings about legal code have no place in the standard. Such things
are better left as "quality of implementation" issues, for the
marketplace to decide.

--
Steve Clamage, stephen.clamage@sun.com

---
[ 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://www.jamesd.demon.co.uk/csc/faq.html                       ]





Author: nagle@animats.com (John Nagle)
Date: Wed, 5 May 2004 16:48:08 +0000 (UTC)
Raw View
   Arguably, overriding a non-virtual function should be
an error.  But there's some obscure situation in which this feature
is useful, although few remember what it is.  Someone may have
used that feature deliberately at some time in the past, so it
can't be fixed.

   If something is an error 99+% of the time, and useful
<1% of the time, policy seems to be that it should not be
prohibited.

    John Nagle
    Animats

Steve Clamage wrote:
> Kurt Bigler wrote:
>
>>
>> I'd like to see a warning when a class makes a function virtual that
>> was not virtual in one of its base class.  For destructors I'd like
>> this to
>> include the case when a base class has no explicit destructor.
>>
>> I'm suggesting that such a warning be made a requirement of the standard.
>
>
> The standard describes what constitutes a well-formed program, and says
> what the program means, or that no meaning is assigned, or that the
> meaning is determined by the implementation.
>
> There is no end to the kinds of questionable practices a compiler could
> warn about. Which warnings should be required? Your pet peeves? Mine?
>
> The C++ Committee (the C Committee, too) feels that requirements for
> warnings about legal code have no place in the standard. Such things are
> better left as "quality of implementation" issues, for the marketplace
> to decide.

---
[ 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://www.jamesd.demon.co.uk/csc/faq.html                       ]





Author: jgottman@carolina.rr.com ("Joe Gottman")
Date: Wed, 5 May 2004 22:56:03 +0000 (UTC)
Raw View
"John Nagle" <nagle@animats.com> wrote in message
news:BV_lc.60326$Cg4.751@newssvr25.news.prodigy.com...
>    Arguably, overriding a non-virtual function should be
> an error.  But there's some obscure situation in which this feature
> is useful, although few remember what it is.  Someone may have
> used that feature deliberately at some time in the past, so it
> can't be fixed.

   To see some code where this feature is used, look at the boost
iterator_adaptor library (at www.boost.org).

Joe Gottman

---
[ 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://www.jamesd.demon.co.uk/csc/faq.html                       ]