On 1/17/11 2:47 AM, Don wrote:
Andrei Alexandrescu wrote:
[snip]
This is a new example of an old issue; it is in no way specific to 64 bits.
Any expression which contains a size-extension AND a signed<->unsigned
implicit conversion is almost always a bug. (unsigned - unsigned leaves
the carry flag unknown, so sign extension is impossible).

It happens a lot with ushort, ubyte. There are several examples of it in
bugzilla. short a=-1; a = a>>>1; is a particularly horrific example.

That doesn't compile. This does:

short a = -1;
a >>>= 1;

a becomes 32767, which didn't surprise me. Replacing >>>= with >>= keeps a unchanged, which I also didn't find surprising.

I think it should be forbidden in all cases. I think it can be done with
a flag in the range propagation.

Yes, that would be awesome!


Andrei

Reply via email to