[c++0x] =default on template class virtual destructor fails to link

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



In the code below, in CFoo's class definition I declare CFoo's
destructor as virtual.
I then externally define CFoo's destructor.
If I define it using {} it compiles fine.
However, if I use =default, it fails to generate the object code for
CFoo::~CFoo() and I get a link error.
Shouldn't these two definitions be identical (except form {} making
CFoo non-POD).
The compiler recognizes the need to generate ~CFoo<type> if
~CBar<type> is called, as is demonstrated by using {}.
Is this a bug?
It would suck if this isn't a bug, as this would mean =default
couldn't be used on any template virtual destructors.

(Note: =default should be identical to {} in this case, but that
shouldn't matter anyway.)

[test.hpp]
========
template <typename tTYPE>
class CFoo
  {
    public:
      virtual ~CFoo();
  };
template <typename tTYPE> CFoo<tTYPE>::~CFoo() =default; // This doesn't work.
//template <typename tTYPE> CFoo<tTYPE>::~CFoo() {}; // This works

template <typename tTYPE>
class CBar : public CFoo<tTYPE>
  {
    public:
      virtual ~CBar();
  };
template <typename tTYPE> CBar<tTYPE>::~CBar() =default;

int main(int argc, char* argv[])
  {
    CBar<int> bar;
  }
=========
/tmp/ccyx65EY.o:(.rodata._ZTV4CBarIiE[vtable for CBar<int>]+0x10):
undefined reference to `CBar<int>::~CBar()'
/tmp/ccyx65EY.o:(.rodata._ZTV4CBarIiE[vtable for CBar<int>]+0x18):
undefined reference to `CBar<int>::~CBar()'
/tmp/ccyx65EY.o:(.rodata._ZTV4CFooIiE[vtable for CFoo<int>]+0x10):
undefined reference to `CFoo<int>::~CFoo()'
/tmp/ccyx65EY.o:(.rodata._ZTV4CFooIiE[vtable for CFoo<int>]+0x18):
undefined reference to `CFoo<int>::~CFoo()'
collect2: ld returned 1 exit status
=========

Specs:
=====
GCC 4.4.0 (20090205).
Ubuntu Jaunty 64 bit.
x86-64.

Is this a bug?
Is this fixed in later GCC versions?

Thanks,
Simon.

[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux