This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

c++/6412: ice in template friend member function



>Number:         6412
>Category:       c++
>Synopsis:       ice in template friend member function
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    unassigned
>State:          open
>Class:          ice-on-legal-code
>Submitter-Id:   net
>Arrival-Date:   Mon Apr 22 18:16:01 PDT 2002
>Closed-Date:
>Last-Modified:
>Originator:     Matthew Britton
>Release:        3.0.3
>Organization:
>Environment:
System: Linux eraserhead 2.4.7-10enterprise #1 SMP Thu Sep 6 16:48:20 EDT 2001 i686 unknown
>Description:
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.





>How-To-Repeat:

>Fix:
I don't know of any workaround
>Release-Note:
>Audit-Trail:
>Unformatted:


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]