Bug 5306 – Disallow foreach ref on numeric interval
Status
RESOLVED
Resolution
INVALID
Severity
minor
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
x86
OS
Windows
Creation time
2010-12-01T18:24:00Z
Last change time
2012-01-21T19:43:09Z
Keywords
accepts-invalid
Assigned to
nobody
Creator
bearophile_hugs
Comments
Comment #0 by bearophile_hugs — 2010-12-01T18:24:54Z
This code compiles and runs with no errors with DMD 2.050, but I think this code is meaningless so it needs to be disallowed statically (items in the interval are not lvalues):
void main() {
foreach (ref i; 0 .. 10) {
i++;
}
}
Comment #1 by bearophile_hugs — 2011-06-26T02:08:07Z
See a newer proposal bug 6214
Comment #2 by bugzilla — 2012-01-20T12:36:27Z
It is not meaningless. The following program:
import core.stdc.stdio;
void main() {
foreach (ref i; 0 .. 10) {
printf("i = %d\n", i);
i++;
}
}
works as expected:
i = 0
i = 2
i = 4
i = 6
i = 8
Comment #3 by bearophile_hugs — 2012-01-21T19:43:09Z