4 ms·
Not sure what you think the source code "says". I mean, I know what you want it to mean, but just because integer wrapping is intuitive to you doesn't imply tha
by MauranKilom 5y ago
Not sure what you think the source code "says". I mean, I know what you want it to mean, but just because integer wrapping is intuitive to you doesn't imply that that is what the code means. C++ abstract machine and all.
But to answer the actual question: For C++20, integer types were revisited. It is now (finally) guaranteed that signed integers are two's complement, along with a list of other changes. See http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2018/p0907r4.html http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2018/p090... also for how the committee voted on the individual issues.
Note in particular:
> The main change between [P0907r0] and the subsequent revision is to maintain undefined behavior when signed integer overflow occurs, instead of defining wrapping behavior. This direction was motivated by:
> - Performance concerns, whereby defining the behavior prevents optimizers from assuming that overflow never occurs;
> - Implementation leeway for tools such as sanitizers;
> - Data from Google suggesting that over 90% of all overflow is a bug, and defining wrapping behavior would not have solved the bug.
So yes, the committee very recently revisited this specific issue, and re-affirmed that signed integer overflow should be UB.
- ttt0 5y agoI haven't noticed the signed integer overflow, which does indeed complicate things, and I thought it was just the infinite loop UB. > Data from Google suggesting that over 90% of all overflow is a bug, and defining wrapping behavior would not have solved the bug. Of all overflow? Including unsigned integers where the behavior is defined?
- aliceryhl 5y agoThat 90% of all overflows are bugs doesn't surprise me at all, even if you include unsigned integers.