When optimising, GCC sometimes tells me
assuming signed overflow does not occur when simplifying
/
or%
to>>
or&
[-Wstrict-overflow
]
I failed to make a reproducible test-case for this, but my production code contains something like
int left = a.left() + (a.width() - b.width()) / 2;
where all the methods return int
values.
Why might the compiler's replacement of /2
with >>1
or (e.g.) %4
with &3
lead to integer overflow?