[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 15:28:51 PST 2012


On Tue, Jan 31, 2012 at 3:04 PM, Richard Smith <richard at metafoo.co.uk>wrote:

> On Tue, Jan 31, 2012 at 2:12 PM, Eli Friedman <eli.friedman at gmail.com>wrote:
>
>> 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.
>>
>
> I see. This change is new in C11 (C99+TC1+TC2+TC3 does not contain it, for
> instance), and is not in C++11.
>

OK, I've mailed CWG about this. Given precedent, I'll proceed on the
assumption that this is a defect :) r149448 treats this case as a
non-constant-expression.

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


More information about the cfe-commits mailing list