简体   繁体   中英

Overload resolution of a qualified name

Consider this function call:

foo::bar();

11.3.1.1.1, paragraph 3 [over.call.func] ( N4778 ) covers this case:

In unqualified function calls, the name is not qualified by an -> or . operator and has the more general form of a primary-expression . The name is looked up in the context of the function call following the normal rules for name lookup in function calls...

Here, foo::bar is an unqualified name, in the sense that it's not qualified by -> or . . So this paragraph applies. Now, the meaning of the phrase "looked up in the context of" is explained in 6.4, paragraph 2 [basic.lookup]:

A name “looked up in the context of an expression” is looked up as an unqualified name in the scope where the expression is found.

However, foo::bar is a qualified name in the realm of name lookup . In other words, this combination of paragraphs basically say that, the qualified name foo::bar is looked up by the rule of unqualified name lookup. However, I don't think that unqualified name lookup is capable of recursively entering into a narrower scope, ie, foo to bar . Is this a defect?

No, I don't think this is a defect. It says

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

As you can see from the part that I highlighted, the standard specifies how the name is supposed to be looked up: By name lookup.

Name lookup involves unqualified, qualified and argument-dependent lookup, so your name is indeed resolved by the qualified name lookup rules.

The "looked up in the context of expr " rule doesn't apply here, as it is specified what rule is used. That paragraph only comes into play when it's not. For example, in [class.qual]p1 :

the names in a template-argument of a template-id are looked up in the context in which the entire postfix-expression occurs.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM