Repository navigation
Fixes C99 Enumeration Integer Promotions - #416
Conversation
…nts signed int types independently of enum storage. Preserves enum variables’ width and signedness by reusing the existing declaration when resolving enum Tag. Rejects C enumerator values outside the target’s int range by validating explicit and implicit values before narrowing.
|
C23 now also supports the explicit underlying type for enums, so this should be taken over from the C++ to allow enum values of a specified type in C. |
|
Providing a constant out of the valid range would be a warning, not an error |
|
Added the addition and the diagnostic fix. |
|
The enumeration value range is limited to the provided constants by design to give the compiler more information on the value range to expeced. So it should not be initialized with the base type value range. |
…it underlying types.
|
Reverted the initialisation range. |
|
Might make sense to use the "mBase" member of the "enum" type declaration to point to the base instead of the DTF_FIXED_ENUM. This way one could check for IsSame() and avoid the additional flag |
|
Some of the size promotions should also be done for ALL integer types, not just enums:
should print 1, 2 and not 1, 1 |
…them with IsSame instead of using a fixed-enum flag.
…g, constant folding and code generation. Adds integer promotion tests.
|
Made the change and added the promotion tests. They found a few promotion issues which were also fixed. |
This fixes the enumerations not conforming to the C99 specification It specifies that enumeration constants have type int and that their values must be representable as int (6.7.2.2 paragraphs 2 and 3). An enum object has an implementation-defined compatible integer type (paragraph 4), which determines its integer promotions. Integer promotions and usual arithmetic conversions are specified in 6.3.1.1 and 6.3.1.8. Right shift of a negative signed value is implementation-defined (6.5.7 paragraph 5). See the C99 committee draft N1256.