Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > Argument Dependent Lookup inside a template class

Reply
Thread Tools

Argument Dependent Lookup inside a template class

 
 
fabio.tesser@gmail.com
Guest
Posts: n/a
 
      04-08-2009
Hello all,

I would like to know what you think of this different behaviour
between different versions of gcc.

The following code:

$ 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);
}
/////////////////////////////////////////

compiles without errors with gcc version 4.2.4, but give me the
following error with gcc 4.3.2:

$ 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)’

I know that there is the Argument Dependent Lookup, so the ftest2
should be recognised using the namespace of the types of the function
arguments.

Do you think this is a bug of gcc 4.3.2?

Thank you in advance for answers and/or comments.

Fabio Tesser
 
Reply With Quote
 
 
 
 
Vladyslav Lazarenko
Guest
Posts: n/a
 
      04-08-2009
On Apr 8, 11:24*am, "(E-Mail Removed)" <(E-Mail Removed)>
wrote:
> Hello all,
>
> I would like to know what you think of this different behaviour
> between different versions of gcc.
>
> The following code:
>
> $ 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);}
>
> /////////////////////////////////////////
>
> compiles without errors with gcc version 4.2.4, but give me the
> following error with gcc 4.3.2:
>
> $ 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)’
>
> I know that there is the Argument Dependent Lookup, so the ftest2
> should be recognised using the namespace of the types of the function
> arguments.
>
> Do you think this is a bug of gcc 4.3.2?
>
> Thank you in advance for answers and/or comments.
>
> Fabio Tesser


It's strange. I have GCC 4.3.2 and it compiles this code just fine.

Using built-in specs.
Target: x86_64-unknown-linux-gnu
Thread model: posix
gcc version 4.3.2 (GCC)
 
Reply With Quote
 
 
 
 
Balog Pal
Guest
Posts: n/a
 
      04-09-2009
<(E-Mail Removed)>Hello all,


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


>gcc 4.3.2:


>test_template_friend_function.cpp:12: error: no matching function for

call to ‘ftest2(test)’

>I know that there is the Argument Dependent Lookup, so the ftest2

should be recognised using the namespace of the types of the function
arguments.

ADL has nothing to do here, as T is int, and int has no namespaces
associated with it to search... Neither do you have namespaces...

But your code is okay as is, ftest2 must be visible at template definition,
and bound, then called. The code compiles with Cameau.

>Do you think this is a bug of gcc 4.3.2?


Must be, though another post suggest it compiles.

The error msg is even more interesting, if the the name ftest2 was not
correctly produced, the error should be reported right at the template
definition, well before an instantiation attempt.

And if it got to the instantiation, the already bound function is bound, and
could be called.

Are you sure you compiled this very code?


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
How does Argument-Dependent-Lookup work for namespace-scope friend fucntion? neverhoodboy C++ 1 03-04-2012 11:51 AM
user-defined conversion combined with argument-dependent lookup Belebele C++ 6 12-11-2007 12:45 PM
Argument-Dependent Lookup siddhu C++ 4 05-15-2007 09:36 AM
Argument-Dependent Lookup siddhu C++ 1 05-14-2007 10:57 PM
argument dependent lookup Martin Vorbrodt C++ 13 10-25-2005 10:21 PM



Advertisments