https://issues.dlang.org/show_bug.cgi?id=23618

Walter Bright <bugzi...@digitalmars.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |bugzi...@digitalmars.com

--- Comment #2 from Walter Bright <bugzi...@digitalmars.com> ---
The issue comes up because (ee >>= 5) is done as a signed right shift, even
though ee is an unsigned type.

Step by step:

https://dlang.org/spec/expression.html#assignment_operator_expressions says:

    a op= b
    are semantically equivalent to:
    a = cast(typeof(a))(a op b)

so, (ee >>= 5) is rewritten to:

    ee = cast(ushort)(ee >> b);

https://dlang.org/spec/expression.html#shift_expressions says:

    the operands undergo integral promotions

    ee = cast(ushort)(cast(int)ee >> b)

or:

    ee = cast(ushort)((ee & 0x0000_FFFF) >> b)

then:

    >> is a signed right shift

but the sign bit is 0, so it is, in effect, an unsigned right shift. The
compiler generates a signed right shift, though.

--

Reply via email to