[Issue 18495] Integral promotion for a ~ operator

d-bugmail at puremagic.com d-bugmail at puremagic.com
Thu Feb 22 15:26:28 UTC 2018


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

Steven Schveighoffer <schveiguy at yahoo.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
                 CC|                            |schveiguy at yahoo.com
         Resolution|---                         |INVALID

--- Comment #2 from Steven Schveighoffer <schveiguy at yahoo.com> ---
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; // 0xffffff7f

In D, without any switches:

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

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.

--


More information about the Digitalmars-d-bugs mailing list