考虑这个函数调用:
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
是一个不合格的名字,在它没有被 ->
限定的意义上或 .
强>。所以本段适用。现在,短语“looked up in the context of”的含义在 6.4 的第 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.
关于c++ - 限定名称的重载解析,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52889777/