3

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?

5
  • 1
    7.2 is a whole section eel.is/c++draft/expr#prop | My guess would be, that the section numbering changed over time and the link in the footnote was not corrected, and the stuff in 7.1.4 was in section 7.2 at the time the footnote was created. Commented Sep 8, 2021 at 7:51
  • @KamilCuk before, 7.2 was Array-to-pointer conversion and before that it was Enum Declarations. Maybe "7.2" was never the correct number Commented Sep 8, 2021 at 8:17
  • You may want to refer to C++20 draft timsong-cpp.github.io/cppwp/n4868 Commented Sep 8, 2021 at 8:57
  • @LanguageLawyer Sorry if the links are wrong. This is my first language lawyer question. It seems I need become more familiar how questions are written in this tag and I need to familirize myself with online sources of the C++ standard. For this question, it doesn't really matter, IMHO. Even these (older version?) links are incorrect. Commented Sep 8, 2021 at 9:05
  • 1
    The links are incorrect, but the paragraph and note numbers are the same as in the published standard and also stable. Here is the fix Commented Sep 8, 2021 at 9:17

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.