Problem with integral promotions

Walter Bright via Digitalmars-d digitalmars-d at puremagic.com
Sat Jul 22 03:44:04 PDT 2017


They are supposed to match C. But they don't for unary operators + - ~, and as 
far as I can tell never did.

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

Note that the spec says:

"Note: unlike in C and C++, the usual integral promotions are not performed 
prior to the complement operation."

   http://dlang.org/spec/expression.html#complement_expressions

Where did that come from?

And the spec says nothing about unary - or unary +.

   http://dlang.org/spec/expression.html#unary-expression

It's been like this at least since D1, both the code and the Spec.

So, we have a choice:

1. Fix it so it matches C, as has been generally promised. Fixing it will break 
existing code such as:

   https://github.com/dlang/phobos/pull/5646

but worse, it may silently break code. I don't know of a reasonable way to 
detect this.

2. Codify existing practice, since it has been that way forever. Not matching C 
has caused problems, see 16997 and 17637. It may cause more serious silent 
problems for people converting C code to D code.


More information about the Digitalmars-d mailing list