[cfe-dev] ParseClassSpecifier: can "unions" inherit?

Ted Kremenek kremenek at apple.com
Thu Sep 4 09:55:22 PDT 2008


On Sep 4, 2008, at 9:45 AM, Doug Gregor wrote:

> On Thu, Sep 4, 2008 at 12:01 PM, Ted Kremenek <kremenek at apple.com>  
> wrote:
>> I just noticed the following code fragment in ParseClassSpecifier:
>>
>>  // Parse the tag portion of this.
>>  DeclTy *TagDecl = Actions.ActOnTag(CurScope, TagType, TK, StartLoc,
>> Name,
>>                                     NameLoc, Attr);
>>
>>  // Parse the optional base clause (C++ only).
>>  if (getLang().CPlusPlus && Tok.is(tok::colon)) {
>>    ParseBaseClause(TagDecl);
>>  }
>>
>> It appears from the code that the 'if' branch can be taken even if  
>> the
>> tag decl is a union.  Is this valid in the C++ grammar?  That is, can
>> there be a "base clause" for unions in C++, and if so, what does that
>> mean?
>
> In the C++ grammar, unions can have base classes, but it's
> semantically incorrect according to [class.union]p1. So, the parser
> parses it and Sema gives an error (see Sema::ActOnBaseSpecifier).
>
>  - Doug

Okay, that makes sense.  If the Parser is suppose to strictly follow  
the grammar then it makes sense why the error is handled in Sema.



More information about the cfe-dev mailing list