Using undeclared function in template function

Discussion in 'C++' started by Juha Nieminen, Apr 10, 2012.

  1. Consider the following program:

    //-----------------------------------------------------------------------
    template<typename T>
    void foo(T v) { bar(v); }

    void bar(int) {}

    int main() { foo(5); }
    //-----------------------------------------------------------------------

    gcc compiles this just fine, but clang gives an error:

    error: call to function 'bar' that is neither visible in the
    template definition nor found by argument-dependent lookup

    Which one is right?
    Juha Nieminen, Apr 10, 2012
    #1
    1. Advertising

  2. Juha Nieminen

    Miles Bader Guest

    Juha Nieminen <> writes:
    > gcc compiles this just fine, but clang gives an error:
    >
    > error: call to function 'bar' that is neither visible in the
    > template definition nor found by argument-dependent lookup


    I assume that's gcc 4.6 or earlier.

    gcc 4.7 and later give an error similar to clang's.

    -miles

    --
    Once, adj. Enough.
    Miles Bader, Apr 10, 2012
    #2
    1. Advertising

  3. Juha Nieminen

    Jorgen Grahn Guest

    On Tue, 2012-04-10, Miles Bader wrote:
    > Juha Nieminen <> writes:
    >> gcc compiles this just fine, but clang gives an error:
    >>
    >> error: call to function 'bar' that is neither visible in the
    >> template definition nor found by argument-dependent lookup

    >
    > I assume that's gcc 4.6 or earlier.
    >
    > gcc 4.7 and later give an error similar to clang's.


    g++ 4.4.5 (in common use) behaves as he describes, even with full
    conformance enabled. (Which is surprising to me -- I thought such bugs
    had been ironed out ages ago.)

    /Jorgen

    --
    // Jorgen Grahn <grahn@ Oo o. . .
    \X/ snipabacken.se> O o .
    Jorgen Grahn, Apr 13, 2012
    #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. Brad Smallridge

    undeclared loop variable

    Brad Smallridge, Mar 23, 2005, in forum: VHDL
    Replies:
    7
    Views:
    674
    Michael
    Mar 25, 2005
  2. learning_C++
    Replies:
    1
    Views:
    584
    Phillip Mills
    Sep 19, 2004
  3. kyung seop kim
    Replies:
    2
    Views:
    1,038
    Asfand Yar Qazi
    Nov 11, 2004
  4. Peter Rothenbuecher
    Replies:
    4
    Views:
    856
    Larry I Smith
    Dec 10, 2005
  5. Peter Rothenbuecher
    Replies:
    6
    Views:
    2,904
Loading...

Share This Page