[Issue 17633] New: Unary negation has the wrong type
via Digitalmars-d-bugs
digitalmars-d-bugs at puremagic.com
Mon Jul 10 14:27:42 PDT 2017
https://issues.dlang.org/show_bug.cgi?id=17633
Issue ID: 17633
Summary: Unary negation has the wrong type
Product: D
Version: D2
Hardware: All
URL: http://dlang.org/
OS: All
Status: NEW
Severity: enhancement
Priority: P3
Component: dlang.org
Assignee: nobody at puremagic.com
Reporter: eyal at weka.io
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!
}
--
More information about the Digitalmars-d-bugs
mailing list