Reputation: 59279
In this question, there is this answer stating
Signed integer overflow is undefined behaviour
but it gives no reference to the C++ standard, so I tried to look it up myself in ISO/IEC 14882 (sixth edition 2020-12). In § 7.7 on page 148 I found (5.7)
an operation that would have undefined behavior as specified in Clause 4 through Clause 15 ^84;
referring to footnote 84 (76 in the draft) telling me
This includes, for example, signed integer overflow (7.2), certain pointer arithmetic (7.6.6), division by zero (7.6.5), or certain shift operations (7.6.7).
Next I searched for "undefined" in chapter 7.2 and I just got 7.2.1 (11) and (11.3) and 7.2.2 (1) but I either don't understand these sentences or they are not related to signed integer overflow.
Is that reference in footnote 84 incorrect? Should it have referred to 7.1 (4) instead?
If during the evaluation of an expression, the result is not mathematically defined or not in the range of representable values for its type, the behavior is undefined.
If the reference is correct, could someone explain in simple words where and how 7.2 makes signed overflow undefined behavior?
Upvotes: 3
Views: 205
Reputation: 59279
Since a pull request was opened for this case, it seems that the reference to chapter 7.2 was wrong and it should have been 7.1 instead.
Upvotes: 1