Argument Dependent Lookup inside a template class

F

fabio.tesser

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
 
V

Vladyslav Lazarenko

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)
 
B

Balog Pal

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?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,764
Messages
2,569,564
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top