Skip to content

Commit

Permalink
[CTFE] Cannot evaluate SliceExp on if condition
Browse files Browse the repository at this point in the history
  • Loading branch information
9rnsr committed Jul 16, 2011
1 parent e0e891e commit d836692
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/expression.c
Original file line number Diff line number Diff line change
Expand Up @@ -8610,6 +8610,11 @@ Expression *SliceExp::modifiableLvalue(Scope *sc, Expression *e)
return this;
}

int SliceExp::isBool(int result)
{
return e1->isBool(result);
}

void SliceExp::toCBuffer(OutBuffer *buf, HdrGenState *hgs)
{
expToCBuffer(buf, hgs, e1, precedence[op]);
Expand Down
1 change: 1 addition & 0 deletions src/expression.h
Original file line number Diff line number Diff line change
Expand Up @@ -1101,6 +1101,7 @@ struct SliceExp : UnaExp
int isLvalue();
Expression *toLvalue(Scope *sc, Expression *e);
Expression *modifiableLvalue(Scope *sc, Expression *e);
int isBool(int result);
void toCBuffer(OutBuffer *buf, HdrGenState *hgs);
Expression *optimize(int result);
Expression *interpret(InterState *istate, CtfeGoal goal = ctfeNeedRvalue);
Expand Down
12 changes: 12 additions & 0 deletions test/compilable/interpret3.d
Original file line number Diff line number Diff line change
Expand Up @@ -1914,3 +1914,15 @@ int bug4448b()
}

static assert(bug4448b()==3);

/**************************************************
6331 - evaluate SliceExp on if condition
**************************************************/

bool bug6331(string s)
{
if (s[0..1])
return true;
return false;
}
static assert(bug6331("str"));

0 comments on commit d836692

Please sign in to comment.