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