The following C/C++ code:
long long foo = -9223372036854775808LL; // -2^63
compiles (g++) with the warning
integer constant is so large that it is unsigned.
clang++ gives a similar warning.
Thanks to this bug report: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=52661. I now understand why GCC gives this warning. Unfortunately, the response to the bug report didn't explain the reason for this behaviour very well.
Questions:
- Why is no warning given for the equivalent code for a 32/16/8-bit signed integer constant?
- GCC and Clang both give this warning, so it is clearly intentional behaviour and not just 'to make it easier to parse,' as is suggested in response to the bug report. Why?
- Is this behaviour mandated by the C/C++ standard? Some other standard?
0x8000000000000000LL
doesn't generate the warning, but it too is so large that it is unsigned. But in this case the standard got it covered by well-defined behavior, even though it isn't obvious.