[Voted into WP at August, 2010 meeting.]
Proposed Resolution (November, 2006): Change 6.5.7 [basic.lookup.udir] paragraph 1 as follows:
When looking up a namespace-name in a using-directive or
namespace-alias-definition, In a using-directive
or namespace-alias-definition, during the lookup for a
namespace-name or for a name in a nested-name-specifier,
only namespace names are considered.
Is this case valid? G++ compiles it. The relevant citation from the standard is
6.5.7 [basic.lookup.udir]: "When looking up a
namespace-name in a using-directive or namespace-alias-definition, only
namespace names are considered." This statement could reasonably be
interpreted to apply only to the last element of a qualified name, and
that's the way EDG and Microsoft seem to interpret it. However, since a class can't contain a namespace, it seems to me that this
interpretation is, shall we say, sub optimal. If the X qualifiers in the
above example are interpreted as referring to the struct X, an error of some
sort is inevitable, since there can be no namespace for the qualified name
to refer to. G++ apparently interprets 6.5.7 [basic.lookup.udir]
as applying to
nested-name-specifiers in those contexts as well, which makes a valid
interpretation of the test possible. I'm thinking it might be worth
tweaking the words in 6.5.7 [basic.lookup.udir]
to basically mandate the more useful
interpretation. Of course a person could argue that the difference would
matter only to a perverse program. On the other hand, namespaces were
invented specifically to enable the building of programs that would
otherwise be considered perverse. Where name clashes are concerned, one
man's perverse is another man's real world.
namespace X {
namespace Y {
struct X {
void f()
{
using namespace X::Y;
namespace Z = X::Y;
}
};
}
}