pokeba
pokeba

Reputation: 1

g++ warning about missing imlementation of pure virtual destructor

In CentOS 6.5, I have a class List like:

// list.hpp

namespace foo
{
    class List
    {
    public:
        virtual int reserveMem ( int size) = 0;
        virtual int Insert ( int val) = 0;
        virtual int Find ( int val) = 0;
        virtual bool Empty() = 0;
    };
}

It's part of the source code of a shared library. And I can build the whole library without any error or warning messages with g++ (version 4.4.7). The compiling flags used are

-g -fPIC -Wall -Wextra -Werror

Then we have another app which just includes a header file which includes this header file and got:

list.hpp:14: error: 'class List' has virtual functions and accessible non-virtual destructor

The warning message is valid. But g++ never complains about it when I build the library. Does anyone know why?

Upvotes: 0

Views: 398

Answers (1)

Jonathan Wakely
Jonathan Wakely

Reputation: 171263

The warning is controlled by the -Wnon-virtual-dtor option, which is not included in -Wall or -Wextra. Presumably you are using different warning options to build the app and the library. Building the app seems to be done with -Wnon-virtual-dtor enabled, or maybe the -Weffc++ option which includes -Wnon-virtual-dtor

I consider that warning to be annoying and unhelpful, the -Wdelete-non-virtual-dtor is much more useful because it only warns if you actually try to delete a foo::List*, and is included in -Wall

Upvotes: 1

Related Questions