Idea for improvement to g++ - warning
Jonathan Wakely
jwakely.gcc@gmail.com
Fri Dec 12 23:41:00 GMT 2014
On 12 December 2014 at 23:38, Kendrick Hamilton <hamilton@sedsystems.ca> wrote:
> Hello,
>
> I had an idea of a warning g++ might be able to add. The purpose of the
> warning is to help prevent bugs. The warning is to occur when you might
> destroy an inherited class using the base classes pointer. To illustrate
> consider
>
> class base
> {
> public:
> base();
> ~base();
> };
>
> class inherit : public base
> {
> public:
> inherit();
> ~inherit();
> }
>
> Note that the base class's destructor is not virtual.
GCC already has -Wnon-virtual-dtor and -Wdelete-non-virtual-dtor warnings.
They don't warn for your example because you have no virtual
functions. It's assumed that if you don't have a polymorphic type then
there is no point in accessing it through a pointer to base.
More information about the Gcc
mailing list