<div class="gmail_quote">On Tue, Jan 31, 2012 at 2:12 PM, Eli Friedman <span dir="ltr"><<a href="mailto:eli.friedman@gmail.com">eli.friedman@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div class="HOEnZb"><div class="h5">On Tue, Jan 31, 2012 at 2:04 PM, Richard Smith <<a href="mailto:richard@metafoo.co.uk">richard@metafoo.co.uk</a>> wrote:<br>
> On Tue, Jan 31, 2012 at 12:44 AM, Abramo Bagnara <<a href="mailto:abramo.bagnara@gmail.com">abramo.bagnara@gmail.com</a>><br>
> wrote:<br>
>><br>
>> Il 31/01/2012 05:08, Richard Smith ha scritto:<br>
>> > Author: rsmith<br>
>> > Date: Mon Jan 30 22:08:20 2012<br>
>> > New Revision: 149344<br>
>> ><br>
>> > URL: <a href="http://llvm.org/viewvc/llvm-project?rev=149344&view=rev" target="_blank">http://llvm.org/viewvc/llvm-project?rev=149344&view=rev</a><br>
>> > Log:<br>
>> > constexpr: catch a collection of integral undefined behaviors:<br>
>> >   -INT_MIN and INT_MIN / -1<br>
>><br>
>> Don't forget INT_MIN % -1. It is tied to INT_MIN / -1 in modern standards.<br>
><br>
><br>
> I didn't forget it, but my interpretation of the standard is that it does<br>
> not have undefined behavior.<br>
><br>
> In particular, [expr.mul]p4 says: "if the quotient a/b is representable in<br>
> the type of the result, (a/b)*b + a%b is equal to a." This would presumably<br>
> give INT_MIN % -1 undefined behavior, except that the antecedent is not met,<br>
> so it does not apply. So we're left with INT_MIN % -1 being defined by "the<br>
> binary % operator yields the remainder from the division of the first<br>
> expression by the second", which is 0. I don't see where the standard would<br>
> require that the division itself fit within the relevant type.<br>
<br>
</div></div>Both the C11 standard and common practice (from both clang and gcc)<br>
agree that it is undefined behavior.  If C++11 doesn't agree, we<br>
should get the standard fixed.<br></blockquote></div><div><br></div>I see. This change is new in C11 (C99+TC1+TC2+TC3 does not contain it, for instance), and is not in C++11.<br><div><br></div><div>- Richard</div>