This is the mail archive of the
mailing list for the GCC project.
Idea for improvement to g++ - warning
- From: Kendrick Hamilton <hamilton at sedsystems dot ca>
- To: gcc at gcc dot gnu dot org
- Date: Fri, 12 Dec 2014 17:38:35 -0600
- Subject: Idea for improvement to g++ - warning
- Authentication-results: sourceware.org; auth=none
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
class inherit : public base
Note that the base class's destructor is not virtual.
Creating a derived class from a base class when the base class'
destructor is not virtual could be enough to generate the warning. A
more elaborate version would issue the warning if a pointer to the base
class was assigned the address of a derived class when the base class'
destructor is not virtual (base *b = new inherit()).
Just an idea to consider. I spent a while trying to debug random crashes
in code where the author forgot to mark the destructors as virtual.