This is the mail archive of the gcc@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]
Other format: [Raw text]

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



On Apr 13, 2004, at 10:01, Michael Veksler wrote:


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;
  }

Note changing DEBUG to print out this you can see what is going on here and adding a DEBUG in the B construtor.

A<T>::A() [with T = double] 0xbffec900
A<T>::A(constU&) [with U = A<double>, T = int] 0xbffec910
B<T1, T2>::B(constA<T1>&) [with T1 = int, T2 = double] 0xbffec920
A<T>::~A() [with T = int] 0xbffec910
A<T>::~A() [with T = double] 0xbffec900
A<T>::~A() [with T = int] 0xbffec920


Note the code is also equivalent to:


#include <iostream>
#define DEBUG std::cout << __PRETTY_FUNCTION__ << " " <<(void*)this <<"\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<T1>(var) {DEBUG;}
  };

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

Which has the same (similar, just the order of the deconstructors are different) output:
A<T>::A() [with T = double] 0xbffec920
A<T>::A(constU&) [with U = A<double>, T = int] 0xbffec900
B<T1, T2>::B(constA<T1>&) [with T1 = int, T2 = double] 0xbffec910
A<T>::~A() [with T = int] 0xbffec900
A<T>::~A() [with T = int] 0xbffec910
A<T>::~A() [with T = double] 0xbffec920



So this is not a bug.


Thanks,
Andrew Pinski


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