[cfe-dev] ParseClassSpecifier: can "unions" inherit?
steve naroff
snaroff at apple.com
Thu Sep 4 09:25:11 PDT 2008
On Sep 4, 2008, at 12:19 PM, Nico Weber wrote:
> Hi,
>
> On 04.09.2008, at 18:01, Ted Kremenek 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?
>
> it seems not to be allowed -- at least both gcc and clang reject it.
> Clang does it in ActOnBaseSpecifier in Sema:
>
> // C++ [class.union]p1:
> // A union shall not be used as a base class.
> if (BaseType->isUnionType()) {
> Diag(BaseLoc, diag::err_union_as_base_class, SpecifierRange);
> return;
> }
>
That's odd - it seems like this should be diagnosed by the parser.
Since I'm not very familiar with all the "challenges" of implementing C
++:-), I'll understand if this isn't convenient.
snaroff
> Nico
> _______________________________________________
> cfe-dev mailing list
> cfe-dev at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev
More information about the cfe-dev
mailing list