[cfe-dev] C++ typedef merging
Chris Lattner
clattner at apple.com
Mon Dec 3 15:04:14 PST 2007
On Dec 2, 2007, at 3:57 PM, James Widman wrote:
> On Dec 2, 2007, at 1:42 PM, Chris Lattner wrote:
>> There is also the
>> strangeness in C++ where you have:
>>
>>
>> struct stat { .. };
>> struct stat stat();
>>
>> "stat" is a function, but "struct stat" is the type,
>
> Yep, according to 3.4.4 basic.lookup.elab.
>
>> even though the
>> tag namespace is normally searched for normal identifiers.
>
> Note, in ISO C++ there is no concept of "tag names", "ordinary names",
> "tag name space" or "ordinary name space" as in ISO C.
Right. This is part of the fun of handling C and C++ in a unified
parser and representation: merging the two concepts together and
making them self consistent. C++ does have a separate namespace for
labels though still.
> In the pre-Standard days, C++ did not even allow the struct stat case,
> but eventually the following rule from 3.3.7 basic.scope.hiding was
> added (because losing compatibility with POSIX (and probably other
> libraries) would have been a deal-breaker):
>
> A class name (9.1) or enumeration name (7.2) can be
> hidden by the name of an object, function, or enumerator
> declared in the same scope. If a class or enumeration
> name and an object, function, or enumerator are declared
> in the same scope (in any order) with the same name, the
> class or enumeration name is hidden wherever the object,
> function, or enumerator name is visible.
Implementing this should be fairly straight-forward I think.
Basically, when doing a scope lookup in C++ mode, it should search
for anything with "IDNS_Tag or IDNS_Ordinary". If after "struct",
just search the IDNS_Tag namespace. The end effect would be that C++
would see tag+ordinary as a unified namespace in most cases.
-Chris
More information about the cfe-dev
mailing list