C++Talk.NET Forum Index C++Talk.NET
C++ language newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

warning to protect virtual destructor firing integrity

 
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ language, library and standards
View previous topic :: View next topic  
Author Message
Kurt Bigler
Guest





PostPosted: Mon May 03, 2004 4:33 pm    Post subject: warning to protect virtual destructor firing integrity Reply with quote



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 ]

Back to top
Steve Clamage
Guest





PostPosted: Tue May 04, 2004 8:00 pm    Post subject: Re: warning to protect virtual destructor firing integrity Reply with quote



Kurt Bigler wrote:
Quote:

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, [email]stephen.clamage (AT) sun (DOT) com[/email]

---
[ 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 ]


Back to top
John Nagle
Guest





PostPosted: Wed May 05, 2004 4:48 pm    Post subject: Re: warning to protect virtual destructor firing integrity Reply with quote



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:
Quote:
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 ]


Back to top
Joe Gottman
Guest





PostPosted: Wed May 05, 2004 10:56 pm    Post subject: Re: warning to protect virtual destructor firing integrity Reply with quote


"John Nagle" <nagle (AT) animats (DOT) com> wrote

Quote:
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 [url]www.boost.org)[/url].

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 ]


Back to top
Display posts from previous:   
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ language, library and standards All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.