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) {} }
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
*** Issue 7034 has been marked as a duplicate of this issue. ***
*** Issue 8964 has been marked as a duplicate of this issue. ***
Why isn't this marked as solved?
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