* Victor Bazarov:
Alf said:
[..]
Perhaps you could cite the relevant part of the standard that allows
an anonymous namespace to be extended (in the same translation unit)?
I am not going to cite it. Open it on page 115 and read 7.3.1.1.
Pay special attention to the words "where _all_ occurrences..."
(emphasis mine).
Yep, you're right about that.
That leaves the second part I addressed in that posting, your statement
"Now, notice that if you remove the 'NS::' from the 'friend'
declaration in 'class A', the friend declaration will _introduce_ the
name 'Y' into the _global_ namespace."
Yes, that's how current compilers behave, but finding that in the
standard is beyond me.
§3.3/4 says a friend declaration "may introduce a (possibly not visible)
name into an enclosing namespace".
§3.3.1/6 contrariwise says friend declarations "do not introduce new
names into [the nearest enclosing namespace]".
§7.3.1.2/3 is perhaps the one nearest to saying what you say (and
current compilers do), namely that
"If a friend declaration in a non-local class first declares a class
or function[note 83] the friend class or function is a member of the
innermost enclosing namespace."
where note 83 is "this implies that the name of the class or function is
unqualified".
A using-declaration is a declaration, so
using SomeNameSpace::foo;
should suffice as a pre-declaration of foo() in the namespace enclosing
the class -- but it does not, with current compilers.
§11.4/7, in the "Friends" section, requires that
"A name nominated by a friend declaration shall be accessible in the
scope of the class containing the friend declaration"
And there is no other requirement, as far as I can see.
Is there perhaps something I have overlooked?