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

Vinay Sajip vinay_sajip at yahoo.co.uk
Thu Sep 15 14:34:15 PDT 2011


John McCall <rjmccall at ...> writes:
> This is dictated by C.
> 
> The initializer in V2 is unsigned because the integer literal 0x90000100 falls
outside of the range of a
> signed int (C99 6.4.4.1p5).
> The initializer in V6 is signed because 12 does not fall outside of the range
of a signed int (6.4.4.1p5
> again), and left-shifting a signed int doesn't change its type (6.5.7p3). 
Also, technically,
> left-shifting into the sign bit like this is undefined behavior (6.5.7p4).

Thanks for the explanation. It's my bad luck that those examples are from real
production code:

The 0x90000100 is an encoding enumeration value (NSUTF16BigEndianStringEncoding)
from the OS X Foundation framework, and the 12 << 28 value is a font class
enumeration (NSFontSymbolicClass) from the OS X AppKit framework :-(

Regards,

Vinay Sajip







More information about the cfe-dev mailing list