Issuing a break statement will not cause the foreach loop to exit but instead will perform another iteration before jumping out. --- import std.stdio; void main() { int[int] test; test[0] = 0; test[1] = 1; bool flag = false; foreach( k, v; test){ writefln("loop: %s %s", k, v); assert(!flag); // fails on second loop! flag = true; break; // should exit here after the first iteration } } --- output: --- loop: 0 0 loop: 1 1 core.exception.AssertError@test(12): Assertion failure ---
This bug is present in dmd 2.043, and it's absent in dmd 1.058 and 1.042.
changeset druntime 287
Fixed DMD2.044