[cfe-dev] SwitchStmt cond type and EnumConstantDecl type problems

Michal korgulec at gmail.com
Sat Jan 30 06:57:41 PST 2010


On Tue, Jan 12, 2010 at 1:26 AM, Douglas Gregor <dgregor at apple.com> wrote:
>
> On Jan 8, 2010, at 4:29 PM, Michal wrote:
>
>> Hi,
>> when clang parses such code :
>>
>> enum X {
>> A,
>> B,
>> C };
>>
>> void foo(enum X)
>> {
>>  switch(X) {
>>   case A:
>>     break;
>>  }
>> }
>>
>> value of switch condition expr and CaseStmt->getLHS->evaluateAsInt()
>> for each case stmt is ASPInt holding an unsigned value, but type of
>> EnumConstantDecl->getInitVal() representing A,B,C is ASPInt holding a
>> signed value.
>>
>> Is this intentional?
>
> Yes. The enum constants have type 'int', which is signed, while the case
> expressions will be converted to the type of the enum (whose promoted type
> may not be 'int').

For such enum :
enum unsignedEnum {
        A,
        Z = 4294967286
};
A is signed and Z is unsigned. Is it a bug or I misunderstood something?
Anyway gcc casts Z to signed integer giving Z == -10.

Michal.




More information about the cfe-dev mailing list