Topic: nested name ambiguity?
Author: sdouglass%_%junk@_arm.com (scott douglass)
Date: 1997/10/24 Raw View
Is this legal?
struct X { struct Y { /* ... */ }; };
extern struct X Y;
struct X ::Y; // trying to refer to the 'Y' declared on the previous line
[I understand the '::' is not needed and that the whitespace is not
significant -- those are not my point.]
The syntax in the Dec 1996 working paper seems ambiguous here. How does
one decide if the decl-specifier in last line is 'struct X' or 'struct
X::Y'? In the first case the declarator-id would be '::Y' and in the
second it would be missing.
I expected to find a rule to disambiguate saying that nested-name-specifier
was "greedy" or some such but I couldn't find any.
Section 8.3 [Meaning of declarators, dcl.meaning] does say the following
which seems to indicate that a declarator-id '::Y' would be ill-formed
except that the note implies that '::' can be used to refer to names in
global scope so perhaps I don't really grasp the meaning of the paragraph.
I also don't understand the rationale behind making the code in the example
illegal.
A declarator-id shall not be
qualified except for the definition of a member function
(_class.mfct_) or static data member (_class.static_) or nested class
(_class.nest_) outside of its class, the definition or explicit
instantiation of a function, variable or class member of a namespace
outside of its namespace, or the definition of a previously declared
explicit specialization outside of its namespace, or the declaration
of a friend function that is a member of another class or namespace
(_class.friend_). When the declarator-id is qualified, the declara-
tion shall refer to a previously declared member of the class or
namespace to which the qualifier refers, and the member shall not have
been introduced by a using-declaration in the scope of the class or
namespace nominated by the nested-name-specifier of the declarator-id.
[Note: if the qualifier is the global :: scope resolution operator,
the declarator-id refers to a name declared in the global namespace
scope. ] In the qualified declarator-id for a class or namespace mem-
ber definition that appears outside of the member's class or names-
pace, the nested-name-specifier shall not name any of the namespaces
that enclose the member's definition. [Example:
namespace A {
struct B {
void f();
};
void A::B::f() { } // ill-formed: the declarator must not be
// qualified with A::
}
--end example]
I do not believe that just because a declarator-id '::Y' is ill-formed
means that the ambiguity can be resolved.
I appeal to those more worthy than I to give me a clue.
Thanks,
--scott
---
[ comp.std.c++ is moderated. To submit articles: try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ FAQ: http://reality.sgi.com/employees/austern_mti/std-c++/faq.html ]
[ Policy: http://reality.sgi.com/employees/austern_mti/std-c++/policy.html ]
[ Comments? mailto:std-c++-request@ncar.ucar.edu ]