Ramifications of C++20 requiring two's complement
One of the specific questions considered by the committee was what to do about -INT_MIN
, and the results of that poll were:
addition / subtraction / multiplication and
-INT_MIN
overflow is currently undefined behavior, it should instead be:4: wrap
6: wrap or trap
5: intermediate values are mathematical integers
14: status quo (remain undefined behavior)
This was explicitly considered and people felt that the best option was keeping it undefined behavior.
To clarify on "intermediate values are mathematical integers", there is a other part of the paper which clarifies that means that (int)a + (int)b > INT_MAX
might be true.
Note that implementations are free to define specific behavior in these cases if they so choose. I don't know if any of them do.