home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.std.c++
- Path: sparky!uunet!munnari.oz.au!cs.mu.OZ.AU!munta.cs.mu.OZ.AU!fjh
- From: fjh@munta.cs.mu.OZ.AU (Fergus James HENDERSON)
- Subject: Re: Compiler should generate virtual destructors
- Message-ID: <9300301.307@mulga.cs.mu.OZ.AU>
- Sender: news@cs.mu.OZ.AU
- Organization: Computer Science, University of Melbourne, Australia
- References: <1992Dec31.050150.28929@ucc.su.OZ.AU>
- Date: Sat, 2 Jan 1993 14:03:43 GMT
- Lines: 46
-
- maxtal@extro.ucc.su.OZ.AU (John MAX Skaller) writes:
-
- >I would like to propose that if a class has virtual functions,
- >then any destructor generated by the compiler will be virtual
- >by default.
- >
- >Advantages: much safer, ensures correct deletion of objects
- >by default. Removes a source of bugs. Removes the reminder
- >that its wise to do this from the FAQ.
- >
- >Disadvantage: might slow down destruction a little. Can be
- >fixed by the programmer explicitly declaring a non-virtual
- >destructor.
-
- I think that this situation should cause a compiler warning, rather
- than adding another arbitrary rule in the language for programmers to
- remember. Bugs would still occur if a programmer accidentally forgot to
- make the destructor virtual. A good compiler will generate a warning
- in this situation anyway (eg. g++ does, I believe).
-
- Mind you, I do believe that there is a place in the standard for
- required warnings. Claims that these are a "quality of implementation"
- issue ignore the social effect of standards. There are never *any*
- genuinely 100% conformant compilers, no matter what it says on the
- box you bought it in. (Read the fine print on the license inside :-( ).
- The truth is that standards provide a strong incentive for compiler
- vendors to ship products with certain characteristics. Provided (as
- with all other aspects of a standard) that they don't require an
- excessive difficulty of implementation, I don't see any good reason
- not to include particular required warnings as part of a standard.
-
- [Off the topic, another situation that should have a required warning
- is the (void *) to (T *) conversion. It is definitely a hole in the
- type system, but making such conversion *illegal* breaks many C programs.
- It broke ALL of my C programs (well, ok, except for the hello world ones :-).
- A warning would have closed the hole in the type system just as well -
- after all, programmers can always achieve the same effect with a cast,
- so it doesn't actually "close" the hole anyway - the error message is
- just like a warning, except that you have to actually modify the
- program text to get it to compile.]
-
- --
- Fergus Henderson fjh@munta.cs.mu.OZ.AU
- This .signature virus is a self-referential statement that is true - but
- you will only be able to consistently believe it if you copy it to your own
- .signature file!
-