Bug 6412 - [3.2 regression] ice in retrieve_specialization
Summary: [3.2 regression] ice in retrieve_specialization
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 3.0.3
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords: ice-on-valid-code
Depends on:
Blocks:
 
Reported: 2002-04-22 18:16 UTC by mbritton
Modified: 2003-07-25 17:33 UTC (History)
6 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description mbritton 2002-04-22 18:16:01 UTC
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 mbritton 2002-04-22 18:16:01 UTC
Fix:
Fixed in GCC 3.3, GCC 3.4 with:

  http://gcc.gnu.org/ml/gcc-patches/2003-03/msg01871.html
Comment 2 Kriang Lerdsuwanakij 2002-06-05 08:31:15 UTC
State-Changed-From-To: open->analyzed
State-Changed-Why: Confirmed.
Comment 3 Volker Reichelt 2002-12-04 13:54:17 UTC
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 Mark Mitchell 2002-12-17 14:07:49 UTC
Responsible-Changed-From-To: unassigned->mmitchel
Responsible-Changed-Why: Working on a fix.
Comment 5 Wolfgang Bangerth 2003-03-13 17:20:30 UTC
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 Wolfgang Bangerth 2003-03-13 23:20:55 UTC
Responsible-Changed-From-To: mmitchel->lerdsuwa
Responsible-Changed-Why: Master of friendship
Comment 7 Mark Mitchell 2003-03-21 07:09:37 UTC
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 Mark Mitchell 2003-03-21 07:09:37 UTC
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 Kriang Lerdsuwanakij 2003-04-01 14:11:09 UTC
Responsible-Changed-From-To: lerdsuwa->unassigned
Responsible-Changed-Why: Mark fixed it for 3.3/3.4.
Comment 10 Joe Buck 2003-04-25 20:02:47 UTC
State-Changed-From-To: analyzed->closed
State-Changed-Why: Fixed for the next release (3.3).