Namespace 'using' at global scope, recently broken
Josh Stern
jstern@citilink.com
Thu Aug 27 06:52:00 GMT 1998
>> Simple attempts at namespace 'using' directives with global
>> scope mis-fire with the 08-24 snapshot. This did work fairly
>> recently.
>You did not mention what the error message is. I get
>dumm.cc:6: conflicting types for `class ::Some::Display'
>/usr/include/X11/Xlib.h:480: previous declaration as
>`typedef struct _XDisplay Display'
>dumm.cc:6: using directive `Display' introduced ambiguous type
>`::Some::Display'
That's right.
>This seems like an error to me: X11R6 defines a global type called
>Display, and your using declaration also introduces a global type
>(i.e. a member of the default namespace) with the name Display. This
>is an error.
You may be right, but I am not convinced. From the CD2 version
of the standard, in 7.3.4.2:
" During unqualified name look up (_basic.lookup.unqual_),
the names appear as if they were declared in
the nearest enclosing namespace which contains both the
using-direc-tive and the nominated namespace. [Note: in this
context, "contains" means "contains directly or indirectly". ]
A using-directive does not add any members to the declarative
region in which it appears."
I interpret that last sentence to be at odds with your explanation,
and expect the "appear as if" behavior to be what I intentended in
my example code (overriding the unqualified name 'Display').
On the other hand, it is possible that what this text meant to
convey (somewhat uncessarily in this context) is that the using
directive doesn't have any effect in other places where it is
not applied (in my example, I don't expect it to have any effect
in other translation units).
I checked back and found that at least the August 03 egcs snapshot
agreed with the behavior I expected, so if someone changed this
intentionally they can probably speak up with their (probably
correct) interpretation.
- Josh
jstern@citilink.com
More information about the Gcc-bugs
mailing list