This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: gcc-3.4: critical C++ bug, too many destructors
- From: Andrew Pinski <pinskia at physics dot uc dot edu>
- To: Michael Veksler <VEKSLER at il dot ibm dot com>
- Cc: gcc at gcc dot gnu dot org, Andrew Pinski <pinskia at physics dot uc dot edu>
- Date: Tue, 13 Apr 2004 11:20:40 -0400
- Subject: Re: gcc-3.4: critical C++ bug, too many destructors
- References: <OFE15EF804.DBE980CE-ONC2256E75.004BC92F-C2256E75.004CF639@il.ibm.com>
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