onqtam
onqtam

Reputation: 4528

name lookup troubles with fundamental and user defined types

This compiles:

struct type{};

template<typename T>
void foo(T in) { bar(in, type()); }

void bar(int, const type&) {}
int main() { foo(42); }

And this does not (as I learned in my previous question from today):

template<typename T>
void foo(T in) { bar(in); }

void bar(int) {}
int main() { foo(42); }

Is the reason the first snippet compiles also explained with ADL? If so, how?

The template parameter is a fundamental type and ADL is not supposed to work for it... Why does using the type type make any difference?

Upvotes: 0

Views: 34

Answers (1)

Columbo
Columbo

Reputation: 60979

Although in your concrete specialization in is of fundamental type, bar is still a dependent name, and hence the argument dependent part of its lookup is performed in the instantiation context. The fact that the argument that made it dependent has no associated namespaces is irrelevant. All non-dependent arguments still contribute to the set of associated namespaces and classes.

Upvotes: 2

Related Questions