Using undeclared function in template function

J

Juha Nieminen

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?
 
M

Miles Bader

Juha Nieminen said:
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
 
J

Jorgen Grahn

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
 

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,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top