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]
Other format: [Raw text]

Re: Idea for improvement to g++ - warning


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.


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