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]

Idea for improvement to g++ - warning


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.

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.

Kendrick Hamilton





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