This is an unofficial snapshot of the ISO/IEC JTC1 SC22 WG21 Core Issues List revision 116a. See http://www.open-std.org/jtc1/sc22/wg21/ for the official list.

2024-12-19


1450. INT_MIN % -1

Section: 7.6.5  [expr.mul]     Status: CD3     Submitter: Richard Smith     Date: 2012-01-31

[Moved to DR at the October, 2012 meeting.]

Issue 614 adopted the corresponding C99 wording for 7.6.5 [expr.mul] paragraph 4,

...if the quotient a/b is representable in the type of the result, (a/b)*b + a%b is equal to a.

in an attempt to ensure that INT_MAX % -1 produces undefined behavior (because the result is not specified by the Standard). However, the new C draft makes the undefined behavior explicit:

If the quotient a/b is representable, the expression (a/b) * b + a%b shall equal a; otherwise, the behavior of both a/b and a%b is undefined.

Should C++ adopt similar wording?

Proposed resolution (February, 2012):

Change 7.6.5 [expr.mul] paragraph 4 as follows:

...If the second operand of / or % is zero the behavior is undefined. For integral operands the / operator yields the algebraic quotient with any fractional part discarded;81 if the quotient a/b is representable in the type of the result, (a/b)*b + a%b is equal to a; otherwise, the behavior of both a/b and a%b is undefined.