Consider the following snippet:
template<typename T>
int foo(T) {
return 1;
}
struct my_struct{};
template<typename T>
int do_foo(T t) {
return
foo(my_struct{}) + // 1
foo(t); // 2 (via ADL)
}
int foo(my_struct) {
return 2;
}
int main () {
return do_foo(my_struct{});
}
At first glance, the "non-dependent" call to foo will return 1, and the "dependent" one will return 2.
However, in the Standard we find the following paragraph:
If the call would <...> find a better match had the lookup within the associated namespaces considered all the function declarations with external linkage introduced in those namespaces in all translation units, not just considering those declarations found in the template definition and template instantiation contexts, then the program has undefined behavior.
It is unclear whether this paragraph speaks about dependent names lookup only - so I am wondering if it applies to the above code, thus making it ill-formed.
Could you please construct an example that would illustrate this paragraph's meaning?