This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: Idea for improvement to g++ - warning
- From: Jonathan Wakely <jwakely dot gcc at gmail dot com>
- To: Kendrick Hamilton <hamilton at sedsystems dot ca>
- Cc: "gcc at gcc dot gnu dot org" <gcc at gcc dot gnu dot org>
- Date: Fri, 12 Dec 2014 23:41:42 +0000
- Subject: Re: Idea for improvement to g++ - warning
- Authentication-results: sourceware.org; auth=none
- References: <548B7C7B dot 8090907 at sedsystems dot ca>
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.