Unary negating a ubyte has type ubyte. This is a bug because it contradicts the behavior of the same unary operator syntax in C:
enum ubyte x = 1;
void assert_minus_1(int y) { assert(y == -1); }
static assert(is(typeof(-x) == int), "Violating C's type rules");
unittest {
assert_minus_1(-x); // -x is 255, it's zero-extended instead of sign-extended!
}
Comment #1 by eyal — 2017-07-10T21:39:05Z
If C's rules are not desirable here. That's fine.
assert_minus_1 should STILL not fail.
instead of -ubyte becoming int as in C, -ubyte can at least become byte.