Showing with 17 additions and 3 deletions.
  1. +3 −3 src/dinterpret.d
  2. +14 −0 test/compilable/interpret3.d
6 changes: 3 additions & 3 deletions src/dinterpret.d
Original file line number Diff line number Diff line change
Expand Up @@ -1470,7 +1470,7 @@ public:
result = e; // bubbled up from ReturnStatement
return;
}
e = interpret(s.increment, istate); // TODO: ctfeNeedNothing is better?
e = interpret(s.increment, istate, ctfeNeedNothing);
if (exceptionOrCant(e))
return;
}
Expand Down Expand Up @@ -5446,9 +5446,9 @@ public:
if (exceptionOrCant(e1))
return;
// If the expression has been cast to void, do nothing.
if (e.to.ty == Tvoid && goal == ctfeNeedNothing)
if (e.to.ty == Tvoid)
{
result = e1;
result = CTFEExp.voidexp;
return;
}
if (e.to.ty == Tpointer && e1.op != TOKnull)
Expand Down
14 changes: 14 additions & 0 deletions test/compilable/interpret3.d
Original file line number Diff line number Diff line change
Expand Up @@ -7652,3 +7652,17 @@ auto structInCaseScope()
}

static assert(!structInCaseScope());

/**************************************************
15251 - void cast in ForStatement.increment
**************************************************/

int test15251()
{
for (ubyte lwr = 19;
lwr != 20;
cast(void)++lwr) // have to to be evaluated with ctfeNeedNothing
{}
return 1;
}
static assert(test15251());