https://gcc.gnu.org/bugzilla/show_bug.cgi?id=109507
Andrew Pinski <pinskia at gcc dot gnu.org> changed: What |Removed |Added ---------------------------------------------------------------------------- Resolution|--- |INVALID Status|UNCONFIRMED |RESOLVED --- Comment #2 from Andrew Pinski <pinskia at gcc dot gnu.org> --- -fsanitize=undefined, at runtime gives: /app/example.cpp:4:7: runtime error: negation of -2147483648 cannot be represented in type 'int'; cast to an unsigned type to negate this value to itself Note the message is slightly wrong but points you to the right reason. There is an overflow. because ~0x80000000 is 2147483648 and then you add 1 to it giving you an overflow which is undefined. Note ~a+1 is the same as -a as both cases will overflow at the same time with 0x80000000 which is why GCC is providing that error message rather then on dealing with +1 like clang does: Note clang gives: /app/example.cpp:4:15: runtime error: signed integer overflow: 2147483647 + 1 cannot be represented in type 'int'