[Issue 24232] New: ref for index of foreach for arrays is not allowed by spec but accepted by compiler.
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Tue Nov 7 18:05:16 UTC 2023
https://issues.dlang.org/show_bug.cgi?id=24232
Issue ID: 24232
Summary: ref for index of foreach for arrays is not allowed by
spec but accepted by compiler.
Product: D
Version: D2
Hardware: x86_64
OS: Linux
Status: NEW
Severity: normal
Priority: P1
Component: dmd
Assignee: nobody at puremagic.com
Reporter: james.gray at remss.net
According to
https://dlang.org/spec/statement.html#foreach_over_arrays
point 2, "ref" on "index" is not allowed. However,
the following compiles:
import std;
void main() {
foreach(ref i, x; [1,2,3,4,5]) {
writeln(x);
i++;
}
}
and produces:
1
3
5
--
More information about the Digitalmars-d-bugs
mailing list