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: Michael Veksler <VEKSLER at il dot ibm dot com>
- To: gcc at gcc dot gnu dot org, Andrew Pinski <pinskia at physics dot uc dot edu>
- Date: Tue, 13 Apr 2004 20:38:16 +0300
- Subject: Re: gcc-3.4: critical C++ bug, too many destructors
You are right, how embarrassing. I just got too comfortable with buggy C++
compilers...
I forgot 2 basic rules:
1. Only about 3 exact forms guarantee that a
constructor/operator= will be considered copy/assignment.
Otherwise the compiler generates its own (and templates
are not one of those).
(the forms include variants of different qualifiers, and by
reference/by
value - except for copy ctor).
2. Look-up for templates are done differently than non-template
functions.
Sorry for my cries for wolf.
Michael
Andrew Pinski
<pinskia@physics. To: Andrew Pinski <pinskia@physics.uc.edu>
uc.edu> cc: gcc@gcc.gnu.org, Michael Veksler/Haifa/IBM@IBMIL
Sent by: Subject: Re: gcc-3.4: critical C++ bug, too many destructors
gcc-owner@gcc.gnu
.org
2004-04-13 19:01
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