DirectXShaderCompiler icon indicating copy to clipboard operation
DirectXShaderCompiler copied to clipboard

Missing warning for implicit cast to signed int from literal > max int

Open tex3d opened this issue 3 years ago • 0 comments

Generally, implicit casts from literal values that don't fit into the range of a target type will produce a warning and tell you the different value that will actually be used (based on truncation, etc...).

Here's an example:

// warning: implicit conversion from 'literal int' to 'int' changes value from -3000000000 to 1294967296
int val = -3000000000;

However, if the value is larger than the maximum positive value for a signed int, but fits into the equivalent bit-sized unsigned value limit, no such warning is emitted:

// no warning, because it fits into unsigned limit for same bit-sized int
int val = 3000000000;

I think we should emit a warning for this case.

tex3d avatar Sep 22 '22 20:09 tex3d