gcc-3.4: critical C++ bug, too many destructors

Michael Veksler VEKSLER@il.ibm.com
Tue Apr 13 14:13:00 GMT 2004


A proper bug report will follow later (4 hours from now, together
with the other bug I sent to this list).

Disclaimer:
  All I want is to benchmark my old C++ code gcc-3.2 vs. gcc-3.4.
  I am not familiar with GCC internals.

I think that gcc-3.4.0 should be delayed until a fix is committed.
The following example illustrates how specialized allocators break
much of STL code.

  $ cat t3.cc
  #include <iostream>

  #define DEBUG std::cout << __PRETTY_FUNCTION__ << "\n"
  template <class T>
  class A {
  public:
    A() { DEBUG; }
    template <class U> 
    A(const U&) { DEBUG; }
    ~A() { DEBUG; }
  };

  template <class T1, class T2>
  class B : public A<T1> {
  public:
    B(const A<T1> & var = A<T2>()) : A<T1>(var) {}
  };

  int main()
  {
    B<int, double> b;
  }

  $ $gcc34/bin/g++ t3.cc
  $ ./a.out

  A<T>::A() [with T = double]
  A<T>::A(const U&) [with U = A<double>, T = int]
  A<T>::~A() [with T = int] 
  A<T>::~A() [with T = double]
  A<T>::~A() [with T = int] 

Note that there are two destructors called with T=int, but only one 
constructor.
  $ $gcc34/bin/g++ -v
  Reading specs from 
/home/veksler/gcc/lib/gcc/i686-pc-linux-gnu/3.4.0/specs
  Configured with: ../gcc-3.4.0-20040406/configure 
--prefix=/home/veksler/gcc --enable-languages=c++
  Thread model: posix
  gcc version 3.4.0 20040407 (prerelease)
 



More information about the Gcc mailing list