[Issue 18495] Integral promotion for a ~ operator

2018-02-22 Thread d-bugmail--- via Digitalmars-d-bugs
https://issues.dlang.org/show_bug.cgi?id=18495

--- Comment #3 from Steven Schveighoffer  ---
Although this bug is invalid, there legitimately is a problem with the spec:
https://issues.dlang.org/show_bug.cgi?id=18496

--


[Issue 18495] Integral promotion for a ~ operator

2018-02-22 Thread d-bugmail--- via Digitalmars-d-bugs
https://issues.dlang.org/show_bug.cgi?id=18495

Steven Schveighoffer  changed:

   What|Removed |Added

 Status|NEW |RESOLVED
 CC||schvei...@yahoo.com
 Resolution|--- |INVALID

--- Comment #2 from Steven Schveighoffer  ---
This is recent, and as designed.

Please see: https://dlang.org/changelog/2.078.0.html#fix16997

See the original bug report here:
https://issues.dlang.org/show_bug.cgi?id=16997

Note that in C:

unsigned char x = 0x80;
int y = ~x; // 0xff7f

In D, without any switches:

ubyte x = 0x80;
int y = ~x; // 0x007f

With the intpromote switch, it's the same as C. This is the point behind the
change -- it was a bug that the integer promotion didn't happen before the
complement. 

Yes, in C, you don't have to cast an int back down to unsigned char explicitly,
it just truncates without complaint. D does not. This is the difference you are
seeing that requires the cast.

--


[Issue 18495] Integral promotion for a ~ operator

2018-02-22 Thread d-bugmail--- via Digitalmars-d-bugs
https://issues.dlang.org/show_bug.cgi?id=18495

--- Comment #1 from Kirill  ---
Of course if I do add "-transition=intpromote" as advised by the compiler, it
just gives an error: "cannot implicitly convert expression `~cast(int)d1` of
type `int` to `ubyte`. Fixing this requires to add some ugly looking code like
" d2 = 0xFF & ~d1; " ore something even worse like " d2 = cast(ubyte) ~d1; ".
This just can not be right.

--