C++ Logo


Advanced search

Re: [ub] ub due to left operand of shift

From: Jean-Marc Bourguet <jm_at_[hidden]>
Date: Sat, 26 Oct 2013 23:16:31 +0200
On 26/10/2013 20:09, Howard Hinnant wrote:
> Might we reword [expr.shift]/p2 in terms of shifting 1 bits off of the most significant end, instead of in terms of E1*2^E2?
> The value of E1 << E2 is E1 left-shifted E2 bit positions; vacated bits are zero-filled. <del>If E1 has an unsigned type, the value of the result is E1 2^E2, reduced modulo one more than the maximum value representable in the result type. Otherwise, if E1 has a signed type and non-negative value, and E1 2^E2 is representable in the corresponding unsigned type of the result type, then that value, converted to the result type, is the resulting value; otherwise<del><ins>If E1 has signed type and the result would have fewer non-zero bits than E1</ins>, the behavior is undefined.
If I'm not mistaken, the only case you seem to define is a left shift by
0 of a negative value. (I'd not mind converting E1 to the corresponding
unsigned type, do the shift, then converting back to the signed type; I
know of two machines which have an arithmetic shift left instruction
with a sticky sign bit -- System/360 and PDP-10 --, and if I'm not
mistaken C and C++ compilers for them are using the logical shift when
shifting left -- someone with an access to a zSeries could check if it
hasn't been done when processing DR1457, the PDP-10 has been irrelevant
for about 3 decades).



Received on 2013-10-26 23:16:48