typedefs and elaborated type specifiers

Matt Austern austern@apple.com
Thu Jan 20 01:42:00 GMT 2005


Consider the following code sample:
struct A { };
typedef struct A A;
struct A a;                     // [1]

struct wrapper {
   struct B { };
   typedef struct B B;
   struct B b;                   // [2]
};

When I compile this with mainline, the compiler rejects it.  It gives 
an error for line [2]:
foo.cc:8: error: using typedef-name 'wrapper::B' after 'struct'
foo.cc:7: error: 'wrapper::B' has a previous declaration here

I don't have much trouble understanding why the compiler gives an error 
message for line [2].  3.4.4/2, which describes how name look for 
elaborated type specifiers works, says that "the identifier is looked 
up according to 3.4.1 but ignoring any non-type names that have been 
declared.  If this name lookup finds a typedef-name, the 
elaborated-type-specifier is ill-formed".  (Incidentally, I found two 
other places in the standard that also explicitly says you can't use a 
typedef-name in an elaborated type specifier.  I guess the committee 
really wanted to make sure we knew they meant it!)

Where I'm having trouble: why don't we get the same error in [1]?  I've 
searched in vain for any hint that the two cases should be treated 
differently.

Have I missed something?

			--Matt



More information about the Gcc mailing list