This is the mail archive of the gcc-bugs@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]

(egcs-1.1) bug in linkonce for auto-generated virt destructors


The following code shows a bug in egcs-1.1 branch for all x86-win32
targets when derived template classes don't define virtual destructors.
If the destructor is not defined for the derived class, then when
explicitly instantiating the template, the compiler generated
destructor does not get put in required/expected linkonce sections
causing multiple definition errors.

This seems to be fixed in the development tree however, but I'd like
to figure out the change that did fix it (and hopefully get that added
to the release branch). 

With auto-generated destructor for explicitly instantiated Derived<double> 
(wrong):

  $ i386-mingw32-nm tinst-linkonce.o | grep \$_t7Derived1Zd
  00000000 T __$_t7Derived1Zd

With defined destructor for explicitly instantiated Derived<double>, get 
the expected (and correct) linkage:

  $ i386-mingw32-nm tinst-linkonce.o | grep \$_t7Derived1Zd
  00000000 t .text$_$_t7Derived1Zd
  00000000 T __$_t7Derived1Zd

============ test case

  template <class T>
  struct Base {
    virtual ~Base () { }
  };

  template <class T>
  struct Derived : Base<T> {
  #ifdef DEFINE_DESTRUCTOR_TO_AVOID_BUG
    virtual ~Derived () { }
  #endif
    int bar (Derived* d) { delete d; }
  };

  template class Derived<double>;

============

Regards,
Mumit


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