On Friday, 23 May 2014 at 15:25:37 UTC, Meta wrote:
On Friday, 23 May 2014 at 15:14:47 UTC, Chris wrote:
The following:
import std.stdio;
void main() {
int[5] arg;
arg[10] = 3; // Compiler says (of course):
Error: array index 10 is out of bounds arg[0 .. 5]
}
import std.stdio;
void main() {
int[5] arg;
foreach (i; 0..10) {
arg[i] = i;
}
}
Compiler says nothing, but we get a runtime error 'Range
violation'.
Bug or design?
It is design I believe, but it should be possible for the
compiler to unroll this loop at compile time and detect the out
of bounds access.
That's what I thought too.