[Issue 22836] [Reg 2.070/2.093] foreach using ubyte index over static array of length 256 or ushort index over static array of length 65536 does not execute the foreach body

d-bugmail at puremagic.com d-bugmail at puremagic.com
Wed Mar 2 17:11:42 UTC 2022


https://issues.dlang.org/show_bug.cgi?id=22836

Dennis <dkorpel at live.nl> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |dkorpel at live.nl

--- Comment #1 from Dennis <dkorpel at live.nl> ---
The compiler lowers it to
```
ubyte[] __r3 = array[];
ubyte __key2 = cast(ubyte)0u;
for (; cast(int)__key2 < cast(int)cast(ubyte)__r3.length; cast(int)__key2 += 1)
{
        ref ubyte a = __r3[cast(ulong)__key2];
        const const(ubyte) i = __key2;
        a = i;
}
```
As you can see, the length is cast to a `ubyte`, so it overflows to a length of
0, which is why the loop body isn't entered.

--


More information about the Digitalmars-d-bugs mailing list