Argument Dependent Lookup inside a template class

Discussion in 'C++' started by fabio.tesser@gmail.com, Apr 8, 2009.

  1. Guest

    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
     
    , Apr 8, 2009
    #1
    1. Advertising

  2. On Apr 8, 11:24 am, "" <>
    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)
     
    Vladyslav Lazarenko, Apr 8, 2009
    #2
    1. Advertising

  3. Balog Pal Guest

    <>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?
     
    Balog Pal, Apr 9, 2009
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Martin Vorbrodt

    argument dependent lookup

    Martin Vorbrodt, Oct 25, 2005, in forum: C++
    Replies:
    13
    Views:
    543
    Default User
    Oct 25, 2005
  2. siddhu

    Argument-Dependent Lookup

    siddhu, May 14, 2007, in forum: C++
    Replies:
    1
    Views:
    368
    Old Wolf
    May 14, 2007
  3. siddhu

    Argument-Dependent Lookup

    siddhu, May 14, 2007, in forum: C++
    Replies:
    4
    Views:
    519
    James Kanze
    May 15, 2007
  4. Belebele
    Replies:
    6
    Views:
    452
    Belebele
    Dec 11, 2007
  5. neverhoodboy
    Replies:
    1
    Views:
    473
    Johannes Schaub
    Mar 4, 2012
Loading...

Share This Page