Bug List: (This bug is not in your last search results)   Show last search results      Search page      Enter new bug
Bug#: 6412
Product:  
Component:  
Status: RESOLVED
Resolution: FIXED
Assigned To: Not yet assigned to anyone <unassigned@gcc.gnu.org>
Host:
Reported against  
Priority:  
Severity:  
Target Milestone:  
 
 
Target:
Reporter: mbritton@gps.caltech.edu
Add CC:
CC:
Remove selected CCs
Build:
URL:
Summary:
Keywords:
Known to work:
Known to fail:

Attachment Description Type Created Size Actions
Create a New Attachment (proposed patch, testcase, etc.) View All

Bug 6412 depends on: Show dependency tree
Show dependency graph
Bug 6412 blocks:

Additional Comments:






View Bug Activity   |   Format For Printing   |   Clone This Bug


Description:   Last confirmed: Opened: 2002-04-22 18:16
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

------- Comment #1 From mbritton@gps.caltech.edu 2002-04-22 18:16 -------
Fix:
Fixed in GCC 3.3, GCC 3.4 with:

  http://gcc.gnu.org/ml/gcc-patches/2003-03/msg01871.html

------- Comment #2 From Kriang Lerdsuwanakij 2002-06-05 08:31 -------
State-Changed-From-To: open->analyzed
State-Changed-Why: Confirmed.

------- Comment #3 From Volker Reichelt 2002-12-04 13:54 -------
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
 
 

------- Comment #4 From Mark Mitchell 2002-12-17 14:07 -------
Responsible-Changed-From-To: unassigned->mmitchel
Responsible-Changed-Why: Working on a fix.

------- Comment #5 From Wolfgang Bangerth 2003-03-13 17:20 -------
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/
 
 


------- Comment #6 From Wolfgang Bangerth 2003-03-13 23:20 -------
Responsible-Changed-From-To: mmitchel->lerdsuwa
Responsible-Changed-Why: Master of friendship

------- Comment #7 From Mark Mitchell 2003-03-21 07:09 -------
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
 


------- Comment #8 From Mark Mitchell 2003-03-21 07:09 -------
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
 

------- Comment #9 From Kriang Lerdsuwanakij 2003-04-01 14:11 -------
Responsible-Changed-From-To: lerdsuwa->unassigned
Responsible-Changed-Why: Mark fixed it for 3.3/3.4.

------- Comment #10 From Joe Buck 2003-04-25 20:02 -------
State-Changed-From-To: analyzed->closed
State-Changed-Why: Fixed for the next release (3.3).

Bug List: (This bug is not in your last search results)   Show last search results      Search page      Enter new bug