有符号整数溢出未定义行为
Signed integer overflow undefined behavior
在, there is 说明
Signed integer overflow is undefined behaviour
但它没有给出 C++ 标准的参考,所以我尝试自己在 ISO/IEC 14882(第六版 2020-12)中查找它。在第 148 页的第 7.7 节中,我发现 (5.7)
an operation that would have undefined behavior as specified in Clause 4 through Clause 15 ^84;
参考脚注 84(草案中的76)告诉我
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).
接下来我在7.2 and I just got 7.2.1 (11) and (11.3) and 7.2.2 (1)章节中搜索了“undefined”,但我要么不理解这些句子,要么与有符号整数溢出无关。
脚注 84 中的引用不正确吗?它应该指代 7.1 (4) 吗?
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.
如果参考是正确的,有人可以用简单的语言解释 7.2 在哪里以及如何导致签名溢出未定义的行为吗?
由于a pull request本案开案,看来7.2章的引用有误,应该是7.1章。
在
Signed integer overflow is undefined behaviour
但它没有给出 C++ 标准的参考,所以我尝试自己在 ISO/IEC 14882(第六版 2020-12)中查找它。在第 148 页的第 7.7 节中,我发现 (5.7)
an operation that would have undefined behavior as specified in Clause 4 through Clause 15 ^84;
参考脚注 84(草案中的76)告诉我
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).
接下来我在7.2 and I just got 7.2.1 (11) and (11.3) and 7.2.2 (1)章节中搜索了“undefined”,但我要么不理解这些句子,要么与有符号整数溢出无关。
脚注 84 中的引用不正确吗?它应该指代 7.1 (4) 吗?
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.
如果参考是正确的,有人可以用简单的语言解释 7.2 在哪里以及如何导致签名溢出未定义的行为吗?
由于a pull request本案开案,看来7.2章的引用有误,应该是7.1章。