public inbox for gcc-prs@sourceware.org
help / color / mirror / Atom feed
From: mbritton@gps.caltech.edu
To: gcc-gnats@gcc.gnu.org
Subject: c++/6412: ice in template friend member function
Date: Mon, 22 Apr 2002 18:16:00 -0000	[thread overview]
Message-ID: <20020423011241.32253.qmail@sources.redhat.com> (raw)


>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:


             reply	other threads:[~2002-04-23  1:16 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2002-04-22 18:16 mbritton [this message]
2002-06-05  8:31 lerdsuwa
2002-12-04  4:06 Volker Reichelt

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20020423011241.32253.qmail@sources.redhat.com \
    --to=mbritton@gps.caltech.edu \
    --cc=gcc-gnats@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).