https://gcc.gnu.org/bugzilla/show_bug.cgi?id=65365
Bug ID: 65365 Summary: false positive signed negation Product: gcc Version: 4.9.2 Status: UNCONFIRMED Severity: normal Priority: P3 Component: sanitizer Assignee: unassigned at gcc dot gnu.org Reporter: joerg.rich...@pdv-fs.de CC: dodji at gcc dot gnu.org, dvyukov at gcc dot gnu.org, jakub at gcc dot gnu.org, kcc at gcc dot gnu.org cat > t.c <<EOF int neg( unsigned v ) { return -(int)(v-1)-1; } int main( int, char** ) { neg( 2147483648u ); return 0; } EOF g++ -o t t.c -fsanitize=undefined ./t Gives this output: t.c:3:22: runtime error: negation of -2147483648 cannot be represented in type 'int'; cast to an unsigned type to negate this value to itself AFAIKS all operations are defined. If the subtraction with "-1" is removed the error about negation disappears.