Comment #0 by pro.mathias.lang — 2020-03-17T03:31:47Z
The current rule for triggering the integral deprecation message are way too lax and intrusive...
The following is perfectly valid:
```
struct BitField
{
private ushort[] data;
private enum BitsPerT = (ushort.sizeof * 8);
public bool opIndexAssign (bool value, size_t index)
{
if (!value)
{
this.data[index / BitsPerT] &= ~mask(index); // HERE
}
return value;
}
static ushort mask (size_t index)
{
return (1 << ( BitsPerT - 1 - (index % BitsPerT)));
}
}
```
But it forces the user to insert a dumb cast on the line annotated with `// HERE`.
This can be seen in https://issues.dlang.org/show_bug.cgi?id=19614
Comment #1 by bugzilla — 2020-08-20T08:38:20Z
This is not actually a bug, it is adherence to the integral promotion rules.
Comment #2 by pro.mathias.lang — 2021-11-22T08:27:41Z
Reduced example:
```
immutable ushort X = ~ushort.max;
```
I'm sorry but if "the rules" dictate that the above code must trigger an error, those rules are wrong.
Comment #3 by robert.schadek — 2024-12-13T19:07:46Z