public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "redi at gcc dot gnu.org" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug c++/17122] Unable to compile friend operator within template
Date: Thu, 12 Apr 2012 14:07:00 -0000	[thread overview]
Message-ID: <bug-17122-4-aR2cF3S2HU@http.gcc.gnu.org/bugzilla/> (raw)
In-Reply-To: <bug-17122-4@http.gcc.gnu.org/bugzilla/>

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=17122

--- Comment #15 from Jonathan Wakely <redi at gcc dot gnu.org> 2012-04-12 14:07:00 UTC ---

> pr17122.C:17:33: warning: friend declaration ‘void operator-(int, foo<blah>)’
> declares a non-template function [-Wnon-template-friend]
>    friend void operator-(int, foo);//eliminating <> generates warning to add 
>                                  ^
> pr17122.C:17:33: note: (if this is not what you intended, make sure the
> function template has already been declared and add <> after the function name
> here) 
>    friend void operator-(int, foo);//eliminating <> generates warning to add 
>                                  ^

Well at least this warning is correct.  For operator- it's 100% correct.  It
causes a problem for operator+ because that clashes with the name of a member
function, so the hint is right but not sufficient to tell you how to make the
code compile, because there's still another error.  You also need to prevent
name lookup from finding the member with the same name.


The example can be reduced to this, replacing operators with named functions:

template <class blah>
struct foo;

template <class blah>
void f(int, foo<blah>) { }

template <class blah>
void g(int, foo<blah>) { }

template <class blah>
struct foo
{
  void f(int) {}

  friend void f<>(int, foo);

  friend void g(int, foo);
};

The warning about 'g' is correct.  The error for 'f' is different now, giving
the "declared void" instead of "as non-function"


  parent reply	other threads:[~2012-04-12 14:07 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <bug-17122-4@http.gcc.gnu.org/bugzilla/>
2012-04-12 12:44 ` redi at gcc dot gnu.org
2012-04-12 13:06 ` manu at gcc dot gnu.org
2012-04-12 14:07 ` redi at gcc dot gnu.org [this message]
2012-04-12 14:56 ` redi at gcc dot gnu.org
2015-04-14 16:02 ` sixenin at hotmail dot com
     [not found] <bug-17122-2867@http.gcc.gnu.org/bugzilla/>
2005-10-22 13:58 ` lerdsuwa at gcc dot gnu dot org
2006-01-20  4:39 ` pinskia at gcc dot gnu dot org
2006-01-22  4:15 ` relf at os2 dot ru
2006-01-24  2:38 ` relf at os2 dot ru
2006-03-12  4:15 ` relf at os2 dot ru
2004-08-20 15:04 [Bug c++/17122] New: " ron at vaniwaarden dot org
2004-08-20 15:20 ` [Bug c++/17122] " bangerth at dealii dot org
2004-08-20 15:53 ` pinskia at gcc dot gnu dot org
2004-08-20 16:35 ` ron at vaniwaarden dot org
2004-08-23 18:30 ` ron at vaniwaarden dot org
2004-08-23 18:35 ` pinskia at gcc dot gnu dot org
2004-10-17 15:19 ` lerdsuwa at gcc dot gnu dot org
2004-10-17 15:21 ` lerdsuwa at gcc dot gnu dot org
2005-01-16  1:26 ` pinskia at gcc dot gnu dot org

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=bug-17122-4-aR2cF3S2HU@http.gcc.gnu.org/bugzilla/ \
    --to=gcc-bugzilla@gcc.gnu.org \
    --cc=gcc-bugs@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).