April 28, 2020
The spec doesn't seem to explicitly mention what happens when the left operand
of a shift expression is signed and negative. [1]
But I know that D follows C's semantics for this sort of stuff, and the C
standard specifies that the result of a negative left operand is undefined
for `<<`, and implementation-defined for `>>`. [2][3]

Is D's behaviour the same as C in this regard?

[1]: https://dlang.org/spec/expression.html#shift_expressions
[2]: https://port70.net/~nsz/c/c89/c89-draft.html#3.3.7
[3]: https://port70.net/~nsz/c/c11/n1570.html#6.5.7

April 28, 2020
On Tue, Apr 28, 2020 at 08:30:27PM +0000, Harry Gillanders via Digitalmars-d-learn wrote:
> The spec doesn't seem to explicitly mention what happens when the left
> operand of a shift expression is signed and negative. [1]
> But I know that D follows C's semantics for this sort of stuff, and
> the C standard specifies that the result of a negative left operand is
> undefined for `<<`, and implementation-defined for `>>`. [2][3]
[...]

Yes, it's UB.  Don't do it.


T

-- 
One Word to write them all, One Access to find them, One Excel to count them all, And thus to Windows bind them. -- Mike Champion