Quote:
> >>> using foo::X::Y;
> >> This should be an error - there is no item named foo::X::Y (see
> >> below).
> > I agree that this should probably be an error, however, it is not, at
> > least not in VC++ 2003.
> Yeah, it's a known bug.
> > The line "using foo;" would give an error, because only qualified
> > names are allowed in using declaration - the scope that has the using
> > declaration already uses foo.
> You're right!
> > My thinking is this:
> > - The using declaration brings a name and all its nested names to
> > that scope containing the using declaration.
> > - enum declares a name (or doesn't it???).
> enum declares a name, but no nested names - there is no name foo::X::Y in
> your example.
> > - If the above are both true, I would expect the following to work -
> > however it doesn't in VC++ 2003 (it did in previous versions).
> > struct foo { enum X { Y }; }; // declaring nested names
> > using foo::X; // bringing foo::X and
> > all nested names into the current scope
> > X func() { return X::Y; } // exploiting the fact that X
> > is now "virtually" in current scope
> > Any clues, like where in the C++ standard this behaviour is
> > prescribed?
> 7.2/10
> The enum name and each enumerator declared by an enum-specifier is
declared
> in the scope that immediately contains the enum specifier. These names
obey
> the scope rules defined for all names in (3.3) and (3.4). An enumerator
> declared in class scope can be referred to using the class member access
> operators (::, . (dot) and -> (arrow)), see 5.2.5.
> 7.3.3/2
> The member name specified in a using declaration is declared in the
> declarative region in which the using declaration appears. [Note: only the
> specified name is so declared; specifying an enumeration name in a using
> declaration does not declare its enumerators in the using declaration's
> declarative region. ]
> So, you ought to be able to write
> using foo::Y;
> using foo::X;
> X func()
> {
> return Y;
> }
> ... which does indeed compile with VC 7.1.
> -cd
Thanks a lot for the explanation - the standard excerpts and your example
cleared it out.
However, it might be interesting to think about if it wouldn't be better if
the enumerators were declared inside the enum-specifier, not on the same
level. Then if there were say 10 enumerators, one wouldn't have to type the
using declaration for each one of them but instead wrote a single using
declaration for the enum-specifier and refered to the enumerators by their
qualified name specifier::enumerator.