Question w.r.t. `'class Foo' has virtual functions but non-virtual destructor` warning.

Michael N. Moran mike@mnmoran.org
Sat Mar 5 14:01:00 GMT 2005


Frank Ch. Eigler wrote:
> Karel Gardas <kgardas@objectsecurity.com> writes:
> 
> 
>>[...]
>>class Foo
>>{
>>public:
>>    virtual unsigned short
>>    iiop_version() const = 0;
>>};
>>
>>and when I compile it, GCC emits warning from subject, although this class
>>is really abstract and will never be instantiated. [...]
> 
> 
> I guess GCC assumes that some instances of a derived class will
> eventually exist, and will be dealt with via a Foo* abstract pointer.
> Is it common to never attempt to delete it via that Foo* value (which
> would require a virtual destructor)?

In embedded system work, and I'm sure in other circumstances,
it is the case that "placement new" is the norm and destructors
invoked explicitly (never on an abstract reference,) and the
delete operator goes unused.

It is also true that embedded systems are resource constrained
and that in keeping with the C++ philosophy of not paying for
things that are not used, any unused storage overhead created
by *requiring* a virtual destructor is ... not good.

To make matters more interesting, I *always* compile with -Werror.

I am (shamefully) un-aware of any --no-virtual-destructor-warning
style flag, that would allow me to compile under these conditions
without adding the virtual destructor to all of my many abstract
base classes.

IOW, it's bad juju in some programming styles/domains, but not
in others.

back to lurking...


-- 
Michael N. Moran           (h) 770 516 7918
5009 Old Field Ct.         (c) 678 521 5460
Kennesaw, GA, USA 30144    http://mnmoran.org

"So often times it happens, that we live our lives in chains
   and we never even know we have the key."
The Eagles, "Already Gone"

The Beatles were wrong: 1 & 1 & 1 is 1





More information about the Gcc mailing list