public inbox for gcc-help@gcc.gnu.org
 help / color / mirror / Atom feed
From: Fabio Tesser <fabio.tesser@gmail.com>
To: Ian Lance Taylor <iant@google.com>
Cc: gcc-help@gcc.gnu.org
Subject: Re: different friend functions behaviour
Date: Wed, 08 Apr 2009 09:38:00 -0000	[thread overview]
Message-ID: <49DC70A4.6050705@gmail.com> (raw)
In-Reply-To: <m3d4bo5s6u.fsf@google.com>

Thanks for reply Ian.

The Argument Dependent Lookup should be active even inside a template class?
If I try put the friend function inside a template, g++ (version 4.3.2) 
gives me the following error:

$ cat test_template_friend_function.cpp
////////////////////////////////////
class test {
public:
friend void ftest2(test x) {
}
};

template <class T>
class simple_template
{
public:
void ftest3(T){
ftest2(test());
}
};

int main(int argc, char *argv[]) {
simple_template<int> a;
a.ftest3(0);
}
/////////////////////////////////////////

$ g++ test_template_friend_function.cpp
test_template_friend_function.cpp: In member function ‘void 
simple_template<T>::ftest3(T) [with T = int]’:
test_template_friend_function.cpp:18: instantiated from here
test_template_friend_function.cpp:12: error: no matching function for 
call to ‘ftest2(test)’

The same code compiles without errors with gcc version 4.2.4.
In your opinion what is the correct behavior?

Thanks

Fabio




On 04/07/2009 06:44 PM, Ian Lance Taylor wrote:
> Fabio Tesser <fabio.tesser@gmail.com> writes:
>
>   
>> The difference between the two friend functions is that the first has
>> not any test class as argument while the second has a test class as
>> argument.
>>
>> Is this the right behaviour?
>>     
>
> Yes, this is correct.  This is Argument Dependent Lookup, also known as
> Koenig lookup.
>
> http://en.wikipedia.org/wiki/Argument_dependent_lookup
>
> Ian
>   

  reply	other threads:[~2009-04-08  9:38 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-04-07 15:37 Fabio Tesser
2009-04-07 16:45 ` Ian Lance Taylor
2009-04-08  9:38   ` Fabio Tesser [this message]
2009-04-08 13:48     ` Ian Lance Taylor

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=49DC70A4.6050705@gmail.com \
    --to=fabio.tesser@gmail.com \
    --cc=gcc-help@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).