Title
INT_MIN % -1
Status
cd3
Section
7.6.5 [expr.mul]
Submitter
Richard Smith

Created on 2012-01-31.00:00:00 last changed 131 months ago

Messages

Date: 2012-10-15.00:00:00

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

Date: 2012-02-15.00:00:00

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.
Date: 2012-01-31.00:00:00

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?

History
Date User Action Args
2014-03-03 00:00:00adminsetstatus: drwp -> cd3
2013-05-03 00:00:00adminsetstatus: dr -> drwp
2012-11-03 00:00:00adminsetmessages: + msg4135
2012-11-03 00:00:00adminsetstatus: ready -> dr
2012-02-27 00:00:00adminsetmessages: + msg3705
2012-01-31 00:00:00admincreate