Re: GCC 4.0's std::binary_function and non-virtual dtors
On 12 Nov., 21:20, Dan Caugherty <dan.caughe...@gmail.com> wrote:
Hi,
I'm putting together a small project with GCC 4.0 (via MacOS X Leopard
and Xcode 3.0), and I keep running into this warning whenever I follow
an example out of Bjarne S.'s "The C++ Programming Language":
warning: base class 'struct std::binary_function<myClass, myClass,
bool>' has a non-virtual destructor
And yes, there is *no* dtor explicitly defined for
std::binary_function, so I assume we're using a non-virtual default
empty dtor instead. I'd expect as much for this particular struct
definition (no data members within it, just one reference). But IMO
the compiler is correct to flag this folly as a potential bug -- no
base class should ever use a non-virtual destructor, let alone a
standard library class.
This is not correct. Virtual destructors are only needed when deleting
via a base pointer.
Unfortunately, even if I were to ignore this warning, the build system
for the ultimate target platform for this work will not; it has a
policy of treating all warnings as errors.
Any ideas on how I can get around this? Is there another way to use
std::binary_function and std::binder2nd that won't trigger these
warnings? Or must I just accept that the STL as implemented by GCC is
just ever-so-slightly broken?
(A nit: it is not the STL, but the standard C++ library)
It is not the library that is broken, but the warning. The only way
you can work yourself out of it is by convincing the providers of your
build system that this warning is not appropriate or by not using
std::binary_function. After all, it is mostly a convenience function
that can be spared away with a little extra effort on your side.
You could also lobby the gcc folks to only issue the warning when it
is needed - namely when an actual delete is performed, but that
solution is unlikely to be practical.
/Peter
--
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]