c – 限定名称的重载分辨率

考虑这个函数调用:

foo::bar();

11.3.1.1.1,第3段[over.call.func](N4778)涵盖了这种情况:

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…

在这里,foo :: bar是一个不合格的名称,在某种意义上它不符合 – >或..所以本段适用.现在,在第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.

但是,foo :: bar是名称查找领域中的限定名称.换句话说,段落的这种组合基本上说,通过非限定名称查找规则查找限定名称foo :: bar.但是,我不认为不合格的名称查找能够递归地进入更窄的范围,即foo到bar.这是一个缺陷吗?

最佳答案 不,我不认为这是一个缺陷.它说

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

从我突出显示的部分可以看出,标准指定了如何查找名称:通过名称查找.

名称查找涉及非限定,限定和依赖于参数的查找,因此您的名称确实由限定名称查找规则解析.

“在expr的上下文中查找”规则在此处不适用,因为它指定了使用的规则.只有当它不是时才会发挥作用.例如,在[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.

点赞