In the current draft of the C++ standard (march 2019) [class.friend] p.6 states (emphasis mine):
A function can be defined in a friend declaration of a class if and only if the class is a non-local class ([class.local]), the function name is unqualified, and the function has namespace scope. [...]
What does "the function has namespace scope" mean?
The only situation that I could come up with in which the function does not have namespace scope is the following:
struct A
{
static void f();
struct B
{
friend void f() {};
};
};
However both clang and gcc do not associate the friend definition inside B
to the static method inside A
, but to a function that belongs to the global namespace.
Are there other situations I am missing?