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?

Thomas Weller
  • 55,411
  • 20
  • 125
  • 222
  • 1
    7.2 is a whole section https://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. – KamilCuk Sep 08 '21 at 07: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 – 463035818_is_not_an_ai Sep 08 '21 at 08:17
  • You may want to refer to C++20 draft https://timsong-cpp.github.io/cppwp/n4868/ – Language Lawyer Sep 08 '21 at 08: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. – Thomas Weller Sep 08 '21 at 09: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](https://github.com/cplusplus/draft/pull/4880) – Language Lawyer Sep 08 '21 at 09:17

1 Answers1

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.

Thomas Weller
  • 55,411
  • 20
  • 125
  • 222