A different fix to #218 and DMD2682 that does not lead to constant folding regressions.

Fixes run/const_15, run/c/const_16_B.
The price is removing the lvalueness of struct literals. If it turns out too
much code depends on this behavior or we don't want to break with DMD, we
could keep struct literals as lvalues and instead convert struct literals used
as expression initializers into struct initializers.
This commit is contained in:
Christian Kamm
2009-03-29 11:43:45 +02:00
parent 875a8b25b2
commit d7de486493
3 changed files with 7 additions and 2 deletions

View File

@@ -3234,10 +3234,13 @@ int StructLiteralExp::isLvalue()
}
#endif
/*
Removed in LDC. See declaration.
Expression *StructLiteralExp::toLvalue(Scope *sc, Expression *e)
{
return this;
}
*/
int StructLiteralExp::checkSideEffect(int flag)

View File

@@ -502,7 +502,9 @@ struct StructLiteralExp : Expression
void scanForNestedRef(Scope *sc);
Expression *optimize(int result);
Expression *interpret(InterState *istate);
Expression *toLvalue(Scope *sc, Expression *e);
// LDC: struct literals aren't lvalues! Taking their address can lead to
// incorrect behavior, see LDC#218, DMD#2682
// Expression *toLvalue(Scope *sc, Expression *e);
int inlineCost(InlineCostState *ics);
Expression *doInline(InlineDoState *ids);

View File

@@ -46,7 +46,7 @@ Expression *fromConstInitializer(Expression *e1)
if (e1->op == TOKvar)
{ VarExp *ve = (VarExp *)e1;
VarDeclaration *v = ve->var->isVarDeclaration();
if (v && v->isConst() && v->init && !v->init->isStructInitializer())
if (v && v->isConst() && v->init)
{ Expression *ei = v->init->toExpression();
if (ei && ei->type)
e1 = ei;