[Issue 22988] Error: shift by -1 is outside the range `0..31`
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Tue Apr 5 07:57:18 UTC 2022
https://issues.dlang.org/show_bug.cgi?id=22988
Dennis <dkorpel at live.nl> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|NEW |RESOLVED
CC| |dkorpel at live.nl
Resolution|--- |INVALID
--- Comment #1 from Dennis <dkorpel at live.nl> ---
Because AddExpression has precedence over ShiftExpression, it's parsed as:
```
enum b = a ? 1 << (a - 1) : 0;
```
Since a = 0, it results in a shift by -1, which gives an error. To fix, add
parentheses around the shift:
```
enum b = a ? (1 << a) - 1 : 0;
```
--
More information about the Digitalmars-d-bugs
mailing list