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

Richard Smith richard at metafoo.co.uk
Tue Jan 31 14:04:35 PST 2012


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.

- Richard
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20120131/a1e01ce1/attachment.html>


More information about the cfe-commits mailing list