[cfe-commits] r149344 - in /cfe/trunk: include/clang/Basic/DiagnosticASTKinds.td lib/AST/ExprConstant.cpp test/CXX/expr/expr.const/p2-0x.cpp

Eli Friedman eli.friedman at gmail.com
Tue Jan 31 14:12:53 PST 2012


On Tue, Jan 31, 2012 at 2:04 PM, Richard Smith <richard at metafoo.co.uk> wrote:
> On Tue, Jan 31, 2012 at 12:44 AM, Abramo Bagnara <abramo.bagnara at gmail.com>
> wrote:
>>
>> Il 31/01/2012 05:08, Richard Smith ha scritto:
>> > Author: rsmith
>> > Date: Mon Jan 30 22:08:20 2012
>> > New Revision: 149344
>> >
>> > URL: http://llvm.org/viewvc/llvm-project?rev=149344&view=rev
>> > Log:
>> > constexpr: catch a collection of integral undefined behaviors:
>> >   -INT_MIN and INT_MIN / -1
>>
>> Don't forget INT_MIN % -1. It is tied to INT_MIN / -1 in modern standards.
>
>
> I didn't forget it, but my interpretation of the standard is that it does
> not have undefined behavior.
>
> In particular, [expr.mul]p4 says: "if the quotient a/b is representable in
> the type of the result, (a/b)*b + a%b is equal to a." This would presumably
> give INT_MIN % -1 undefined behavior, except that the antecedent is not met,
> so it does not apply. So we're left with INT_MIN % -1 being defined by "the
> binary % operator yields the remainder from the division of the first
> expression by the second", which is 0. I don't see where the standard would
> require that the division itself fit within the relevant type.

Both the C11 standard and common practice (from both clang and gcc)
agree that it is undefined behavior.  If C++11 doesn't agree, we
should get the standard fixed.

-Eli




More information about the cfe-commits mailing list