限定名称的重载解析
Overload resolution of a qualified name
考虑这个函数调用:
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 [...]
从我突出显示的部分可以看出,该标准指定了应该如何查找名称:通过名称查找。
名称查找涉及非限定、限定和参数相关查找,因此您的名称确实由限定名称查找规则解析。
"looked up in the context of 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.
考虑这个函数调用:
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 [...]
从我突出显示的部分可以看出,该标准指定了应该如何查找名称:通过名称查找。
名称查找涉及非限定、限定和参数相关查找,因此您的名称确实由限定名称查找规则解析。
"looked up in the context of 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.