Bug 8498 – modifying foreach range iterator fails in CTFE
Status
RESOLVED
Resolution
FIXED
Severity
regression
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2012-08-02T13:54:00Z
Last change time
2012-11-01T23:56:44Z
Keywords
CTFE, wrong-code
Assigned to
nobody
Creator
timon.gehr
Comments
Comment #0 by timon.gehr — 2012-08-02T13:54:00Z
Passes with DMD 2.059, asserts with DMD 2.060:
int fun(){
int r;
foreach(i;0..10) r+=i++;
return r;
}
enum x = fun();
void main(){ assert(fun()==x); }
Comment #1 by clugdbug — 2012-09-03T00:52:40Z
Here's a reduced test case. There are 10 iterations, even though the iteration variable is changed.
int fun(){
int r=0;
foreach(i;0..10) {
++r;
i= 100;
assert(i==100); // ok -- but doesn't affect the foreach
}
return r;
}
static assert(fun() == 1);
Interestingly this is in direct conflict with enhancement bug 6214, which asks for the behaviour we see in CTFE to be used at run time.
Comment #2 by timon.gehr — 2012-09-03T08:09:07Z
(In reply to comment #1)
> Here's a reduced test case. There are 10 iterations, even though the iteration
> variable is changed.
>
> int fun(){
> int r=0;
> foreach(i;0..10) {
> ++r;
> i= 100;
> assert(i==100); // ok -- but doesn't affect the foreach
> }
> return r;
> }
> static assert(fun() == 1);
>
>
> Interestingly this is in direct conflict with enhancement bug 6214, which asks
> for the behaviour we see in CTFE to be used at run time.
Interestingly the original bug report/title wasn't as it explicitly took this into account. :o)
Comment #3 by timon.gehr — 2012-09-03T11:06:18Z
*** Issue 8614 has been marked as a duplicate of this issue. ***
Comment #4 by github-bugzilla — 2012-11-01T23:49:34Z