public inbox for gcc@gcc.gnu.org
 help / color / mirror / Atom feed
From: "Richard Guenther" <richard.guenther@gmail.com>
To: "Ian Lance Taylor" <iant@google.com>
Cc: "Dragan Milenkovic" <dragan@plusplus.co.yu>, gcc@gcc.gnu.org
Subject: Re: A simple sample code involving templates, friends and lookup
Date: Thu, 17 Jan 2008 18:09:00 -0000	[thread overview]
Message-ID: <84fc9c000801170911p199d1913i796e92bba9a17cb7@mail.gmail.com> (raw)
In-Reply-To: <m3fxwwl6p9.fsf@localhost.localdomain>

On 17 Jan 2008 09:09:38 -0800, Ian Lance Taylor <iant@google.com> wrote:
>
> "Richard Guenther" <richard.guenther@gmail.com> writes:
>
> > On Jan 17, 2008 2:12 PM, Dragan Milenkovic <dragan@plusplus.co.yu> wrote:
> > > Richard Guenther wrote:
> > > [snip]
> > > >> template <typename T>
> > > >> struct Foo
> > > >> {
> > > >>      template <typename Z>
> > > >>      friend void func(const Foo &);
> > > >> };
> > > >>
> > > >> void check(const Foo<int> & x)
> > > >> {
> > > >>      // Foo<int> weird;  // uncomment this line and all works
> > > >>
> > > >>      func<int>(x);    // <-- ERROR
> > > >> }
> > > >>
> > > >>
> > > >> Tested with gcc 4.0 - 4.3, and all behave the same:
> > > >>
> > > >> "error: 'func' was not declared in this scope"
> > > >>
> > > >> but it works if you uncomment the weird line.
> > > >
> > > > Actually even with the weird line the program is invalid.  What are
> > > > you trying to do? ;)
> > > >
> > > > Richard.
> > >
> > > Ok... afaik, that func should be defined on that very place where it is
> > > declared as friend. But could you please elaborate why it is invalid,
> > > since you made me start questioning my C++ knowledge... :-D
> >
> > How should name-lookup find func?
>
> It should use argument dependent lookup.  This is like the common case
> of
>
> class x
> {
>   friend x operator+(const& x, const& x) { return x.var + x.var; }
> };
>
> in which x::operator+ is found without taking special action.

Well, first I think you'd need friend-injection or otherwise a global
decl of the function.  Second I thought argument dependent
name-lookup only applies to namespaces, not classes.

EDG rejects this consistently btw.

Richard.

  reply	other threads:[~2008-01-17 17:12 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-01-17 11:08 Dragan Milenkovic
2008-01-17 12:56 ` Richard Guenther
2008-01-17 13:24   ` Dragan Milenkovic
2008-01-17 14:46     ` Richard Guenther
2008-01-17 17:12       ` Ian Lance Taylor
2008-01-17 18:09         ` Richard Guenther [this message]
2008-01-17 22:23           ` Ian Lance Taylor
2008-01-17 22:59             ` Richard Guenther
2008-01-18  7:10               ` Jonathan Wakely
2008-01-18  7:35                 ` Jonathan Wakely
2008-01-18 14:17                 ` Dragan Milenkovic
2008-01-19  8:21                   ` Jonathan Wakely
2008-01-17 13:35   ` Paolo Bonzini

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=84fc9c000801170911p199d1913i796e92bba9a17cb7@mail.gmail.com \
    --to=richard.guenther@gmail.com \
    --cc=dragan@plusplus.co.yu \
    --cc=gcc@gcc.gnu.org \
    --cc=iant@google.com \
    /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).