Why does intpromote spew warnings for ~ operator?
Steven Schveighoffer
schveiguy at gmail.com
Tue Sep 14 11:53:48 UTC 2021
On 9/13/21 6:27 PM, Alexey wrote:
> On Monday, 13 September 2021 at 21:03:41 UTC, Guillaume Piolat wrote:
>> On Sunday, 12 September 2021 at 14:14:03 UTC, Steven Schveighoffer wrote:
>
> It's also not exactly clear why:
> 1. D should be backward compatible with C, which is 50 years old soon.
> 2. why exactly somebody should copy / paste (how many? thousands?) many
> lines of code without thinking and rechecking. Probably D can't be and
> shouldn't be compatible with C / C++ to that distinct.
> 3. Is really backward comparability with C/C++ so important?
This is missing the point.
Yes, part of the rationale of intpromote (which despite its flaws, I
happen to agree with the main thrust of), is that we want D code that
looks like C and compiles to behave like C. But also, the C behavior is
what people who have no cares about C would expect.
In other words, if you have:
```d
ushort x = 500;
int y = -x;
```
you would expect y to be -500. But in D it's 65036. Which makes almost
no sense at all.
Another alternative would be to disable negation on unsigned types. That
would be also extremely disruptive.
We have a chance here to
1. Make D compatible with C
2. Continue to compile code that is correct in C, and makes sense in D
(i.e. `short y = -someShort`)
3. Warn and fix surprising results that are 99% likely bugs.
If we do it smartly.
-Steve
More information about the Digitalmars-d
mailing list