Bug 8614 – Cannot change the iteration index during CTFE

Status
RESOLVED
Resolution
DUPLICATE
Severity
normal
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2012-09-03T10:22:00Z
Last change time
2012-09-03T11:06:18Z
Assigned to
nobody
Creator
philippe.sigaud

Comments

Comment #0 by philippe.sigaud — 2012-09-03T10:22:36Z
During runtime execution of a foreach loop, you can change the index. This doesn't work at compile-time and gives a different result when foo is called through CTFE or at runtime: import std.stdio; int[] foo(int[] data) { foreach (i, ref x; data) { x++; i++; } return data; } void main() { // Compile-time enum result1 = foo([10, 20, 30, 40]); assert(result1 == [11, 21, 31, 41]); // Runtime auto result2 = foo([10, 20, 30, 40]); assert(result2 == [11, 20, 31, 40]); }
Comment #1 by timon.gehr — 2012-09-03T11:06:18Z
*** This issue has been marked as a duplicate of issue 8498 ***