Bring back foreach int indexes
Steven Schveighoffer
schveiguy at gmail.com
Wed Nov 29 19:27:56 UTC 2023
On Wednesday, 29 November 2023 at 16:56:54 UTC, deadalnix wrote:
>
> It cannot work in the general case, slice's size is a size_t .
>
> But if the compiler can prove it fits in 32bits, then there
> should be no problem. VRP could do that.
VRP does not work here. The array comes from anywhere and can
have any length. It needs to be validated (if you insist) at
runtime.
But it's very very *VERY* uncommon to have an array with 2
billion elements.
Note, this worked for years, pretty much without incident. I
don't even remember why we removed it. It seems like one of those
problems nobody had or was looking to solve. Yet, we solved it.
Actually, I just tested it out, and it gives a deprecation
warning, but builds! This means it's actually quite easy to fix
this, just remove the deprecation, and add the assert.
A great point from CyberShadow on the original PR that added the
deprecation:
https://github.com/dlang/dmd/pull/8941#issuecomment-496306412
And note this was to "fix" an issue with foreach_reverse on int
indexes, it was just snuck in there...
And here is another bug report that had a more detailed
conversation (including from me):
https://issues.dlang.org/show_bug.cgi?id=16149
-Steve
More information about the Digitalmars-d
mailing list