I want to understand why the call to the template f
below doesn't compile:
struct A
{
template<class...>
friend void f(A) { }
} x;
int main()
{
f<>(x);
}
ADL requires the postfix expression in a function call to be an unqualified-id. Is a simple-template-id (f<>
) not an unqualified-id?
The relevant clause seems to be 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). ...
That is, the only way to find this name is through ADL. However, to apply the template arguments, the name needs to be found already according to 14.2 [temp.names] paragraph 2:
For a template-name to be explicitly qualified by the template arguments, the name must be known to refer to a template.