Skip to content

Commit

Permalink
Merge pull request #80 from 9rnsr/fix3688
Browse files Browse the repository at this point in the history
Retry to fix issue 3688 & 6072
  • Loading branch information
WalterBright committed Jun 1, 2011
2 parents c1b7e0a + 1bcae90 commit 8515537
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 15 deletions.
3 changes: 2 additions & 1 deletion src/interpret.c
Expand Up @@ -3338,7 +3338,8 @@ Expression *CommaExp::interpret(InterState *istate, CtfeGoal goal)
// If the comma returns a temporary variable, it needs to be an lvalue
// (this is particularly important for struct constructors)
if (e1->op == TOKdeclaration && e2->op == TOKvar
&& ((DeclarationExp *)e1)->declaration == ((VarExp*)e2)->var)
&& ((DeclarationExp *)e1)->declaration == ((VarExp*)e2)->var
&& ((VarExp*)e2)->var->storage_class & STCctfe) // same as Expression::isTemp
{
VarExp* ve = (VarExp *)e2;
VarDeclaration *v = ve->var->isVarDeclaration();
Expand Down
22 changes: 8 additions & 14 deletions src/statement.c
Expand Up @@ -2315,9 +2315,6 @@ Statement *IfStatement::syntaxCopy()

Statement *IfStatement::semantic(Scope *sc)
{
condition = condition->semantic(sc);
condition = resolveProperties(sc, condition);

// Evaluate at runtime
unsigned cs0 = sc->callSuper;
unsigned cs1;
Expand All @@ -2331,24 +2328,21 @@ Statement *IfStatement::semantic(Scope *sc)
sym->parent = sc->scopesym;
scd = sc->push(sym);

Type *t = arg->type ? arg->type : condition->type;
match = new VarDeclaration(loc, t, arg->ident, NULL);
match = new VarDeclaration(loc, arg->type, arg->ident, new ExpInitializer(loc, condition));
match->noscope = 1;
match->semantic(scd);
if (!scd->insert(match))
assert(0);
match->parent = sc->func;

/* Generate:
* ((arg = condition), arg)
*/
VarExp *v = new VarExp(0, match);
condition = new AssignExp(loc, v, condition);
condition = new CommaExp(loc, condition, v);
DeclarationExp *de = new DeclarationExp(loc, match);
VarExp *ve = new VarExp(0, match);
condition = new CommaExp(loc, de, ve);
condition = condition->semantic(scd);
}
else
{
condition = condition->semantic(sc);
condition = resolveProperties(sc, condition);
scd = sc->push();
}

// Convert to boolean after declaring arg so this works:
// if (S arg = S()) {}
Expand Down

0 comments on commit 8515537

Please sign in to comment.