https://gcc.gnu.org/bugzilla/show_bug.cgi?id=71882
--- Comment #2 from Jonathan Wakely <redi at gcc dot gnu.org> --- GCC adds a declaration of struct S to the enclosing namespace, and makes that a friend, rather than the struct S in the unnamed namespace. 10.3.1.2 [namespace.memdef] p3 says "the lookup to determine whether the entity has been previously declared shall not consider any scopes outside the innermost enclosing namespace." The struct S is not declared in the innermost enclosing namespace, but it is visible there, so normal name lookup would find it. But then this isn't normal name lookup, because it doesn't keep looking in enclosing namespaces, only the innermost. Given that this seems to be valid (at least, accepted by all of GCC, Clang and EDG): namespace { struct S { }; } struct S { }; It is apparently OK to declare ::S, but it's unclear to me whether the friend declaration should do that. EDG agrees with GCC and rejects the original testcase.