Example in [basic.lookup.argdep]/3:
namespace NS {
class T { };
void f(T);
void g(T, int);
}
NS::T parm;
void g(NS::T, float);
int main() {
f(parm); // OK: calls NS::f
extern void g(NS::T, float);
g(parm, 1); // OK: calls g(NS::T, float)
}
For the call g(parm, 1)
we have in the set X the declaration void g(NS::T, float);
in global scope. AFAICT, we also have in set Y the declaration void g(T, int);
in namespace NS
, an associate namespace of the argument parm
of type NS::T
. Thus, if I'm not wrong, the two declarations are candidates for overload resolution. Then, is it the case that the declaration in global scope is preferred in relation to the one in namespace NS
? Why? I would very much appreciate a quote from the Standard as an answer.
In that section, we have:
Unqualified lookup finds the block scope function declaration -
extern void g(NS::T, float)
. Not the declaration at global scope::g
.Hence,
Y
is empty, which makes the union ofX
andY
trivially justX
, which just contains that one declaration, which is a viable candidate.If that declaration were not there, then unqualified lookup would find
void g(NS::T, float)
and we'd go on to perform ADL, which would findN::g(T, int)
, which is a better match.