Skip to content

Commit

Permalink
Merge pull request #1267 from donc/ctfe8857inlineAndAnd
Browse files Browse the repository at this point in the history
8857 [CTFE] does not evaluate to a boolean, only with -inline
  • Loading branch information
WalterBright committed Nov 10, 2012
2 parents b26f49c + 517c80e commit 9adb5a0
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 7 deletions.
20 changes: 13 additions & 7 deletions src/interpret.c
Expand Up @@ -1780,7 +1780,7 @@ Expression *DeclarationExp::interpret(InterState *istate, CtfeGoal goal)
{
ExpInitializer *ie = v->init->isExpInitializer();
if (ie)
e = ie->exp->interpret(istate);
e = ie->exp->interpret(istate, goal);
else if (v->init->isVoidInitializer())
{
e = v->type->voidInitLiteral(v);
Expand Down Expand Up @@ -2795,12 +2795,18 @@ Expression *BinExp::interpretAssignCommon(InterState *istate, CtfeGoal goal, fp_
}

if (newval->op == TOKassocarrayliteral || newval->op == TOKstring ||
newval->op==TOKarrayliteral)
newval->op == TOKarrayliteral)
{
if (needToCopyLiteral(newval))
newval = copyLiteral(newval);
}
returnValue = newval;

// Get the value to return. Note that 'newval' is an Lvalue,
// so if we need an Rvalue, we have to interpret again.
if (goal == ctfeNeedRvalue)
returnValue = newval->interpret(istate);
else
returnValue = newval;
}

// ---------------------------------------
Expand Down Expand Up @@ -3755,13 +3761,13 @@ Expression *AndAndExp::interpret(InterState *istate, CtfeGoal goal)
result = 1;
else
{
error("%s does not evaluate to a boolean", e->toChars());
e->error("%s does not evaluate to a boolean", e->toChars());
e = EXP_CANT_INTERPRET;
}
}
else
{
error("%s cannot be interpreted as a boolean", e->toChars());
e->error("%s cannot be interpreted as a boolean", e->toChars());
e = EXP_CANT_INTERPRET;
}
}
Expand Down Expand Up @@ -3809,14 +3815,14 @@ Expression *OrOrExp::interpret(InterState *istate, CtfeGoal goal)
result = 1;
else
{
error("%s cannot be interpreted as a boolean", e->toChars());
e->error("%s cannot be interpreted as a boolean", e->toChars());
e = EXP_CANT_INTERPRET;
}
}
}
else
{
error("%s cannot be interpreted as a boolean", e->toChars());
e->error("%s cannot be interpreted as a boolean", e->toChars());
e = EXP_CANT_INTERPRET;
}
}
Expand Down
18 changes: 18 additions & 0 deletions test/compilable/interpret3.d
Expand Up @@ -4442,6 +4442,24 @@ bool ice7162()

static assert(ice7162());

/**************************************************
8857, only with -inline (creates an &&)
**************************************************/

struct Result8857 { char[] next; }

void bug8857()() {
Result8857 r;
r.next = null;
if (true) {
auto next = r.next;
}
}
static assert({
bug8857();
return true;
}());

/**************************************************
7527
**************************************************/
Expand Down

0 comments on commit 9adb5a0

Please sign in to comment.