arocc icon indicating copy to clipboard operation
arocc copied to clipboard

Warn if implicit integer conversion truncates value

Open ehaas opened this issue 1 year ago • 0 comments

unsigned char x = 1000;

We currently issue no warning; it should look something like:

test.c:1:19: warning: implicit conversion from 'int' to 'unsigned char' changes value from 1000 to 232 [-Wconstant-conversion]
unsigned char x = 1000;
                  ^

Value.intCast currently returns void on success; we can have it return a value that indicates whether truncation happens and then issue a diagnostic if so (similar to how Value.floatToInt is handled)

ehaas avatar May 03 '24 17:05 ehaas