14 Templates [temp]

14.6 Name resolution [temp.res]

14.6.4 Dependent name resolution [temp.dep.res]

14.6.4.2 Candidate functions [temp.dep.candidate]

For a function call that depends on a template parameter, the candidate functions are found using the usual lookup rules ([basic.lookup.unqual], [basic.lookup.argdep], [basic.lookup.qual]) except that:

  • For the part of the lookup using unqualified name lookup ([basic.lookup.unqual]) or qualified name lookup ([basic.lookup.qual]), only function declarations from the template definition context are found.

  • For the part of the lookup using associated namespaces ([basic.lookup.argdep]), only function declarations found in either the template definition context or the template instantiation context are found.

If the function name is an unqualified-id and the call would be ill-formed or 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.