I have a template class myclass for which I have defined a template member function operator+=, which takes as an argument an instantiation of the template class. I wanted to make the function a friend of other instantiations of myclass. For example, I wanted the function myclass <float> & myclass<float>::operator+=(const myclass<double> &) to be a friend of myclass<double>. To accomplish this I tried the following code. template <class T> class myclass { protected: T data; public: myclass(){ data = 0; } myclass(const myclass<T> & mc) { data = mc.data; } ~myclass(){}; myclass & operator=(const myclass<T> & mc) { if(this==&mc) return(*this); data = mc.data; return(*this); } template<class U> myclass<T> & operator+=(const myclass<U> & mc) { data += mc.data; } template<class U> template<class V> friend myclass<U> & myclass<U>::operator+=(const myclass<V> & mc); }; int main(int argc, char * argv[]) { myclass<float> fmc; myclass<double> dmc; dmc += fmc; } I got the following error test.C: In function 'int main(int, char**)': test.C:43: Internal compiler error in retrieve_specialization, at cp/pt.c:739 Please submit a full bug report. with preprocessed source if appropriate. See <URL:http://www.gnu.org/software/gcc/bugs.html> for instructions. Release: 3.0.3 Environment: System: Linux eraserhead 2.4.7-10enterprise #1 SMP Thu Sep 6 16:48:20 EDT 2001 i686 unknown
Fix: Fixed in GCC 3.3, GCC 3.4 with: http://gcc.gnu.org/ml/gcc-patches/2003-03/msg01871.html
State-Changed-From-To: open->analyzed State-Changed-Why: Confirmed.
From: Volker Reichelt <reichelt@igpm.rwth-aachen.de> To: gcc-gnats@gcc.gnu.org, gcc-bugs@gcc.gnu.org, nobody@gcc.gnu.org, mbritton@gps.caltech.edu Cc: Subject: Re: c++/6412: ice in template friend member function Date: Wed, 4 Dec 2002 13:54:17 +0100 The code compiles fine with gcc 2.95.x, but fails since 3.0. Thus, we have a regression. Regards, Volker http://gcc.gnu.org/cgi-bin/gnatsweb.pl?cmd=view%20audit-trail&database=gcc&pr=6412
Responsible-Changed-From-To: unassigned->mmitchel Responsible-Changed-Why: Working on a fix.
From: Wolfgang Bangerth <bangerth@ticam.utexas.edu> To: gcc-gnats@gcc.gnu.org Cc: Subject: Re: c++/6412 Date: Thu, 13 Mar 2003 17:20:30 -0600 (CST) A simpler testcase is this: --------------------------- template <class T> struct X { template <class U> void operator+=(U); template <class V> template <class U> friend void X<V>::operator+=(U); }; int main() { X<int>() += 1.0; } -------------------------- It ICEs in retrieve_specialization, in 3.2, 3.3 and mainline. The ICE goes away if the befriended function is not an operator, or if in the one line in main I call X<int>().operator+= (1.0) instead. W. ------------------------------------------------------------------------- Wolfgang Bangerth email: bangerth@ticam.utexas.edu www: http://www.ticam.utexas.edu/~bangerth/
Responsible-Changed-From-To: mmitchel->lerdsuwa Responsible-Changed-Why: Master of friendship
From: mmitchel@gcc.gnu.org To: gcc-gnats@gcc.gnu.org Cc: Subject: c++/6412 Date: 21 Mar 2003 07:09:37 -0000 CVSROOT: /cvs/gcc Module name: gcc Branch: gcc-3_3-branch Changes by: mmitchel@gcc.gnu.org 2003-03-21 07:09:36 Modified files: gcc/cp : ChangeLog decl2.c pt.c gcc/testsuite : ChangeLog Added files: gcc/testsuite/g++.dg/template: friend17.C Log message: PR c++/6412 * g++.dg/template/friend17.C: New test. PR c++/6412 * cp/decl2.c (arg_assoc_class): Correct check for namespace-scope friends. * cp/pt.c (instantiate_class_template): Fix formatting. Patches: http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/ChangeLog.diff?cvsroot=gcc&only_with_tag=gcc-3_3-branch&r1=1.3076.2.92&r2=1.3076.2.93 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/decl2.c.diff?cvsroot=gcc&only_with_tag=gcc-3_3-branch&r1=1.575.2.22&r2=1.575.2.23 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/pt.c.diff?cvsroot=gcc&only_with_tag=gcc-3_3-branch&r1=1.635.2.15&r2=1.635.2.16 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/ChangeLog.diff?cvsroot=gcc&only_with_tag=gcc-3_3-branch&r1=1.2261.2.106&r2=1.2261.2.107 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/g++.dg/template/friend17.C.diff?cvsroot=gcc&only_with_tag=gcc-3_3-branch&r1=NONE&r2=1.1.2.1
Responsible-Changed-From-To: lerdsuwa->unassigned Responsible-Changed-Why: Mark fixed it for 3.3/3.4.
State-Changed-From-To: analyzed->closed State-Changed-Why: Fixed for the next release (3.3).