Comment #0 by bearophile_hugs — 2011-03-10T05:19:30Z
Problem found by Magnus Lie Hetland.
This program produces two infinite loops, DMD 2.052:
void main() {
alias ubyte T1;
T1[T1.max + 1] array1;
foreach (T1 i, _; array1) {}
alias ushort T2;
T2[T2.max + 1] array2;
foreach (T2 i, _; array2) {}
}
Comment #1 by bearophile_hugs — 2011-06-26T01:54:29Z
Related. This compiles with no errors, and maybe goes in infinite loop:
import std.stdio;
void main() {
auto array = new int[270];
foreach (ubyte i, ref x; array)
x = i;
writeln(array);
}
If the range of the fixed-sized array is larger than the max number that the index can represent, then I suggest to raise a compile-time error, just like this program does:
void main() {
ubyte x = 270;
}
test.d(2): Error: cannot implicitly convert expression (270) of type int to ubyte
Comment #2 by yebblies — 2013-01-16T18:54:13Z
*** Issue 7034 has been marked as a duplicate of this issue. ***
Comment #3 by yebblies — 2013-01-16T19:02:25Z
*** Issue 8964 has been marked as a duplicate of this issue. ***
Comment #4 by tiberiulepadatu14 — 2019-03-08T11:40:23Z
Why isn't this marked as solved?
Comment #5 by b2.temp — 2019-03-17T17:01:37Z
fixed at some point:
/tmp/temp_7F8FB1CE2190.d(4,5): Error: index type `ubyte` cannot cover index range 0..256
/tmp/temp_7F8FB1CE2190.d(7,5): Error: index type `ushort` cannot cover index range 0..65536