This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: Proposal for improvement to C++ warnings


Robert Dick wrote:
> 
> That's not the warning to which I am referring.

Ok, that may be the reason why I didn't understand your last point.


> > I propose that gcc warn only if delete is invoked on a pointer to such a
> > class.
> 
> Warnings exist to help developers avoid writing dangerous code.  In
> general, a library developed with such a policy would be dangerous to use
> on a platform without the warning enabled.

I see it differently.

Either you develop a class hierarchy in a way that allows objects of derived
classes to be owned through a pointer to base class. Then you will have
library test code applying delete on a pointer to that base class; if you
forget to declare the dtor virtual, you get a warning. Fine.

Or your develop a class hierarchy where objects of derived classes are not
to be owned through a poiner to base class (this can be enforced by making
the base class destructor protected). Then there's no need for the base
class destructor to be virtual, and there shouldn't be a warning.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]