Why does intpromote spew warnings for ~ operator?
Steven Schveighoffer
schveiguy at gmail.com
Sun Sep 12 14:14:03 UTC 2021
```d
import std.stdio;
import std.meta;
void main()
{
int nbad;
foreach(T; AliasSeq!(short, ushort))
{
foreach(int i; T.min .. T.max + 1)
{
T x = cast(T)i;
T y = ~x;
T newy = cast(T)~cast(int)x;
if(y != newy)
{
writefln("%s: x: %s, y: %s, newy: %s", T.stringof, x,
y, newy);
++nbad;
}
}
}
writeln("Number of affected cases: ", nbad);
}
```
Output:
```
onlineapp.d(11): Deprecation: integral promotion not done for `~x`, use
'-preview=intpromote' switch or `~cast(int)(x)`
onlineapp.d(11): Deprecation: integral promotion not done for `~x`, use
'-preview=intpromote' switch or `~cast(int)(x)`
Number of affected cases: 0
```
Note that with `-de` these become errors. With the -preview=intpromote
switch, the uncasted negation compiles and runs as expected.
Right now, the deprecation is telling users *under penalty of not
compiling* to do something that will achieve nothing when intpromote is
enabled.
-Steve
More information about the Digitalmars-d
mailing list