Title
Unqualified function name lookup
Status
cd6
Section
6.5.3 [basic.lookup.unqual]
Submitter
William M. Miller

Created on 2003-04-14.00:00:00 last changed 20 months ago

Messages

Date: 2020-11-15.00:00:00

[Accepted at the November, 2020 meeting as part of paper P1787R6 and moved to DR at the February, 2021 meeting.]

There seems to be some confusion in the Standard regarding the relationship between 6.5.3 [basic.lookup.unqual] (Unqualified name lookup) and 6.5.4 [basic.lookup.argdep] (Argument-dependent lookup). For example, 6.5.3 [basic.lookup.unqual] paragraph 3 says,

The lookup for an unqualified name used as the postfix-expression of a function call is described in 6.5.4 [basic.lookup.argdep].

In other words, nothing in 6.5.3 [basic.lookup.unqual] applies to function names; the entire lookup is described in 6.5.4 [basic.lookup.argdep].

6.5.4 [basic.lookup.argdep] does not appear to share this view of its responsibility. The closest it comes is in 6.5.4 [basic.lookup.argdep] paragraph 2a:

...the set of declarations found by the lookup of the function name is the union of the set of declarations found using ordinary unqualified lookup and the set of declarations found in the namespaces and classes associated with the argument types.

Presumably, "ordinary unqualified lookup" is a reference to the processing described in 6.5.3 [basic.lookup.unqual], but, as noted above, 6.5.3 [basic.lookup.unqual] explicitly precludes applying that processing to function names. The details of "ordinary unqualified lookup" of function names are not described anywhere.

The other clauses that reference 6.5.4 [basic.lookup.argdep], clauses Clause 12 [over] and Clause 13 [temp], are split over the question of the relationship between 6.5.3 [basic.lookup.unqual] and 6.5.4 [basic.lookup.argdep]. 12.2.2.2.2 [over.call.func] paragraph 3, for instance, says

The name is looked up in the context of the function call following the normal rules for name lookup in function calls (6.5.4 [basic.lookup.argdep]).

I.e., this reference assumes that 6.5.4 [basic.lookup.argdep] is self-contained. The same is true of 12.2.2.3 [over.match.oper] paragraph 3, second bullet:

The set of non-member candidates is the result of the unqualified lookup of operator@ in the context of the expression according to the usual rules for name lookup in unqualified function calls (6.5.4 [basic.lookup.argdep]), except that all member functions are ignored.

On the other hand, however, 13.8.4.2 [temp.dep.candidate] paragraph 1 explicitly assumes that 6.5.3 [basic.lookup.unqual] and 6.5.4 [basic.lookup.argdep] are both involved in function name lookup and do different things:

For a function call that depends on a template parameter, if the function name is an unqualified-id but not a template-id, the candidate functions are found using the usual lookup rules (6.5.3 [basic.lookup.unqual], 6.5.4 [basic.lookup.argdep]) except that:
  • For the part of the lookup using unqualified name lookup (6.5.3 [basic.lookup.unqual]), only function declarations with external linkage from the template definition context are found.
  • For the part of the lookup using associated namespaces (6.5.4 [basic.lookup.argdep]), only function declarations with external linkage found in either the template definition context or the template instantiation context are found.

Suggested resolution:

Change 6.5.3 [basic.lookup.unqual] paragraph 1 from

...name lookup ends as soon as a declaration is found for the name.

to

...name lookup ends with the first scope containing one or more declarations of the name.

Change the first sentence of 6.5.3 [basic.lookup.unqual] paragraph 3 from

The lookup for an unqualified name used as the postfix-expression of a function call is described in 6.5.4 [basic.lookup.argdep].

to

An unqualified name used as the postfix-expression of a function call is looked up as described below. In addition, argument-dependent lookup (6.5.4 [basic.lookup.argdep]) is performed on this name to complete the resulting set of declarations.
History
Date User Action Args
2022-08-19 07:54:33adminsetstatus: drwp -> cd6
2021-02-24 00:00:00adminsetstatus: accepted -> drwp
2020-12-15 00:00:00adminsetstatus: open -> accepted
2003-04-14 00:00:00admincreate