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

Andrew Pinski pinskia@physics.uc.edu
Tue Apr 13 16:36:00 GMT 2004


On Apr 13, 2004, at 11:01, Andrew Pinski wrote:

>
> On Apr 13, 2004, at 10:01, Michael Veksler wrote:
>>
>>   $ 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; }
>>   };

Here is an explanation of why "template <class U> A(const U&) { DEBUG; 
}" is not a
copy constructor.

By 10.8:3 " A member function template is never instantiated to perform 
the
copy of a class object to an object of its class type"


So when you do B:


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

You are calling the copy constructor for A<T1> so it is calling the 
implicit defined one
(12.8:10) which happens to be trivial (12.8:11).

So this is not a bug, except in your code not understanding what is 
happening here.

Thanks,
Andrew Pinski



More information about the Gcc mailing list