This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

typedefs and elaborated type specifiers


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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]