#include <iostream>
typedef int f;
namespace N
{
struct A
{
friend void f( A &a ) { std::cout << "F( " << a.i << " )\n"; }
operator int() const { return i; }
static void g( A &a )
{
f( a );
}
private:
int i = 10;
};
};
int main()
{
N::A a;
N::A::g( a );
}
As you see the friend function f is defined withing the class A. So it is in the lexical scope of the class. However in the expression statement of the static member function g
f( a );
the compiler considers this statement as a variable declaration with the type specifier int according to the typedef defined outside the namespace N.
I did not find a corresponding description in the C++ Standard that would confirm that such a behavior of the compiler is correct. It seems that if the friend function is in the lexical scope of the class A its declaration should hide the definition of the typedef outside the namespace N.
MS VC++ considers the above statement as a postfix expression of the friend function call. However gcc and clang behave differently even if the expression to enclose in parentheses..
So I would like to know the corresponding paragraphs from the Standard that shed light on this situation.
With best regards,