Thread overview | ||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
July 22, 2017 Problem with integral promotions | ||||
---|---|---|---|---|
| ||||
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. |
July 22, 2017 Re: Problem with integral promotions | ||||
---|---|---|---|---|
| ||||
Posted in reply to Walter Bright | Walter Bright wrote:
> 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.
i'd say "codify, and add warning". since i patched the warning into the compiler, i have no more problems with the current rules: compiler tells me about possible incompatibilities with C, and i can either add `()` to silent the warning, or explicitly cast to the type i want.
i think most other people will prefer to get warning instead of code breakage too. at least i hope so. ;-)
|
July 22, 2017 Re: Problem with integral promotions | ||||
---|---|---|---|---|
| ||||
Posted in reply to Walter Bright | This affects: ~ubyte: all values -ubyte: all values -byte: -128 (0x80) ~ushort: all values -ushort: all values -short: -32768 (0x8000) |
July 22, 2017 Re: Problem with integral promotions | ||||
---|---|---|---|---|
| ||||
Posted in reply to ketmar | On Saturday, 22 July 2017 at 10:51:05 UTC, ketmar wrote:
> Walter Bright wrote:
>
>> 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.
>
> i'd say "codify, and add warning".
I'd vote for the ketmar solution if workable.
Another argument for this is that C code that has already been converted to D, and is currently silently broken, would benefit from a new warning as a way of gathering attention. However matching C promotion might make this code work too but silently.
|
July 22, 2017 Re: Problem with integral promotions | ||||
---|---|---|---|---|
| ||||
Posted in reply to Walter Bright | On Saturday, 22 July 2017 at 10:44:04 UTC, Walter Bright wrote: > 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? Git blames you: https://github.com/dlang/dlang.org/commit/4cd3f38bbabdde30b280738dab4f4184c06f05f9 |
July 22, 2017 Re: Problem with integral promotions | ||||
---|---|---|---|---|
| ||||
Posted in reply to ketmar | On Saturday, 22 July 2017 at 10:51:05 UTC, ketmar wrote:
> Walter Bright wrote:
>
>> 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.
>
> i'd say "codify, and add warning". since i patched the warning into the compiler, i have no more problems with the current rules: compiler tells me about possible incompatibilities with C, and i can either add `()` to silent the warning, or explicitly cast to the type i want.
>
> i think most other people will prefer to get warning instead of code breakage too. at least i hope so. ;-)
Good luck adding a warning into DMD. After years there still isn't a warning for unsigned/signed comparisons.
What code would break? Are there any examples of D code that would break as a result of the change?
|
July 22, 2017 Re: Problem with integral promotions | ||||
---|---|---|---|---|
| ||||
Posted in reply to Jerry | Jerry wrote:
> What code would break? Are there any examples of D code that would break as a result of the change?
basically, any template that has small integral type T and does unary +/-/~ on it. and there *is* such code in phobos, and it's not explicitly tested for different integral sizes. when i added a warning, i had to fix phobos in several places, but i'm pretty sure that there are ALOT more.
|
July 22, 2017 Re: Problem with integral promotions | ||||
---|---|---|---|---|
| ||||
Posted in reply to Vladimir Panteleev | On 7/22/2017 1:07 PM, Vladimir Panteleev wrote: > Git blames you: > > https://github.com/dlang/dlang.org/commit/4cd3f38bbabdde30b280738dab4f4184c06f05f9 Ah, thanks for finding this. It was in response to: https://issues.dlang.org/show_bug.cgi?id=5132 i.e. it was documenting existing behavior. |
July 24, 2017 Re: Problem with integral promotions | ||||
---|---|---|---|---|
| ||||
Posted in reply to Walter Bright | OT: https://issues.dlang.org/show_bug.cgi?id=17417 can we also reconsider this? |
July 24, 2017 Re: Problem with integral promotions | ||||
---|---|---|---|---|
| ||||
Posted in reply to Kagamin | On 7/24/2017 1:50 AM, Kagamin wrote:
> OT: https://issues.dlang.org/show_bug.cgi?id=17417 can we also reconsider this?
The bugzilla page was pretty clear about it.
|
Copyright © 1999-2021 by the D Language Foundation