[cfe-commits] [PATCH] C++0x strongly typed enums

Douglas Gregor dgregor at apple.com
Tue Oct 12 08:06:30 PDT 2010


On Oct 12, 2010, at 5:45 AM, Daniel Wallin wrote:

> On Tue, Oct 12, 2010 at 5:56 AM, Sean Hunt <scshunt at csclub.uwaterloo.ca> wrote:
>> On 10/11/2010 08:57 AM, Daniel Wallin wrote:
>>> On Sat, Oct 9, 2010 at 1:55 AM, Douglas Gregor<dgregor at apple.com>  wrote:
>>>> It'd be great if the declaration printer/dumper was updated to print the "class" in "enum class" and the fixed underlying type (when present), so that our -ast-dump and -ast-print output would be helpful.
>>>> 
>>>> I've gone ahead and committed a tweaked version of your patch in r116122, with the minor tweaks above. It'd be great if you could address the issues above in a separate patch (disambiguation, diagnostics, declaration printer).
>>> 
>>> Sure! The git mirror I'm using is a bit behind, so I'm not 100% sure
>>> these apply cleanly. If not I'll rebase when the mirror catches up.
>> 
>> I believe that
>> 
>> enum A { };
>> class C {
>>   enum A : int();
>> };
>> 
>> is a syntax error for attempting to declare an enumeration with an
>> underlying function type, since the default rule in case of ambiguity is
>> always to consider it a type-id. I do not believe that the patch
>> correctly handles this; I think it should instead attempt to determine
>> if it is a type-id before the semicolon/opening brace, and then act
>> accordingly.
> 
> int() is a integral constant expression and the above code is well
> formed in C++98, and I think it's meant to be in C++0x as well. There
> isn't really an ambiguity here because base-type must be an integral
> type, which of course X() can never satisfy. If we treat everything as
> a type-id the case Doug gave above is ill formed.


There isn't an ambiguity here, but that's not the reason: ambiguity resolution doesn't take semantics into account. It's purely syntactic + determining whether a name refers to a type or a template.

int() is not parsed as a type here because an enum-base is described by the grammar

  : type-specifier-seq

which cannot include parentheses to form a function type.

	- Doug



More information about the cfe-commits mailing list