arocc icon indicating copy to clipboard operation
arocc copied to clipboard

Single-narrow-char char literals should be sign extended on platforms where `char` is signed.

Open ehaas opened this issue 2 years ago • 1 comments

The following issues no errors on x86_64-linux but 2 errors for aro:

_Static_assert('\xFF' == -1, "");

#if '\xFF' != -1
#error comparison failed
#endif

This only applies to single-character literals; the following currently works as expected:

_Static_assert('\x00\xFF' == 255, "");
_Static_assert('\xFF\xFF' == 65535, "");

ehaas avatar Oct 01 '23 07:10 ehaas

This should be fixable by intCast'ing the value from char -> destination type (int or intmax_t depending on if we're in the parser or preprocessor) if all the conditions are met (char is signed for the target, it's a regular char literal, it's a single byte, value is >= 128)

ehaas avatar Oct 01 '23 16:10 ehaas