[cfe-dev] libclang - inconsistent signs for enumeration constants

Eli Friedman eli.friedman at gmail.com
Thu Sep 15 12:51:15 PDT 2011


On Thu, Sep 15, 2011 at 12:02 PM, Vinay Sajip <vinay_sajip at yahoo.co.uk> wrote:
> Given the source
>
> enum ABC {
>    V1 = 1,
>    V2 = 0x90000100
> };
> enum DEF {
>    V3 = 1,
>    V4 = -100
> };
> enum GHI {
>    V5 = 1 << 28,
>    V6 = 12 << 28
> };
>
> The libclang API returns inconsistent signs for the different
> enumeration constants. On a 32-bit machine, The EnumConstantDecl for the
> various values have the following types:
>
> V1 - Int - as expected
> V2 - UInt - seems reasonable, though it's negative if viewed as a 32-bit int
> V3 - Int - as expected
> V4 - Int - as expected
> V5 - Int - seems reasonable
> V6 - Int - not consistent with the interpretation of V2.
>
> Both V2 and V6 have bit 31 set, yet one is interpreted as unsigned and the
> other as signed.
>
> Is this a known issue? I just thought I'd mention it here before opening an
> issue on the tracker (I didn't find any existing issue covering this).

As far as I can tell, the type checking for the given enums is working
as expected (i.e. in a gcc-compatible manner) for your example.

-Eli




More information about the cfe-dev mailing list