ADL 未选取带有模板参数列表的后缀表达式
Postfix expression with template-argument-list not being picked up by ADL
我想了解为什么对下面的模板 f
的调用无法编译:
struct A
{
template<class...>
friend void f(A) { }
} x;
int main()
{
f<>(x);
}
ADL 要求函数调用中的后缀表达式为非限定 ID。 simple-template-id (f<>
) 不是 unqualified-id 吗?
相关条款好像是7.3.1.2 [namespace.memdef] paragraph 3:
Every name first declared in a namespace is a member of that namespace. If a friend declaration in a non-local class first declares a class, function, class template or function template the friend is a member of the innermost enclosing namespace. The friend declaration does not by itself make the name visible to unqualified lookup (3.4.1) or qualified lookup (3.4.3). ...
也就是说,找到这个名字的唯一方法是通过ADL。但是,要应用模板参数,需要根据 14.2 [temp.names] 第 2 段找到名称:
For a template-name to be explicitly qualified by the template arguments, the name must be known to refer to a template.
我想了解为什么对下面的模板 f
的调用无法编译:
struct A
{
template<class...>
friend void f(A) { }
} x;
int main()
{
f<>(x);
}
ADL 要求函数调用中的后缀表达式为非限定 ID。 simple-template-id (f<>
) 不是 unqualified-id 吗?
相关条款好像是7.3.1.2 [namespace.memdef] paragraph 3:
Every name first declared in a namespace is a member of that namespace. If a friend declaration in a non-local class first declares a class, function, class template or function template the friend is a member of the innermost enclosing namespace. The friend declaration does not by itself make the name visible to unqualified lookup (3.4.1) or qualified lookup (3.4.3). ...
也就是说,找到这个名字的唯一方法是通过ADL。但是,要应用模板参数,需要根据 14.2 [temp.names] 第 2 段找到名称:
For a template-name to be explicitly qualified by the template arguments, the name must be known to refer to a template.