mirror of
https://github.com/xomboverlord/ldc.git
synced 2026-09-16 02:17:07 +02:00
Merge DMD r321: bugzilla 3575 CTFE: member structs not initialized correctly
--- dmd/expression.c | 4 +--- dmd/interpret.c | 32 +++++++++----------------------- dmd/mtype.c | 48 +++++++++++++++++++++++++++++++++++++++++++----- dmd/mtype.h | 2 ++ 4 files changed, 55 insertions(+), 31 deletions(-)
This commit is contained in:
+43
-5
@@ -569,12 +569,9 @@ int Type::checkBoolean()
|
||||
|
||||
void Type::checkDeprecated(Loc loc, Scope *sc)
|
||||
{
|
||||
Type *t;
|
||||
Dsymbol *s;
|
||||
|
||||
for (t = this; t; t = t->next)
|
||||
for (Type *t = this; t; t = t->next)
|
||||
{
|
||||
s = t->toDsymbol(sc);
|
||||
Dsymbol *s = t->toDsymbol(sc);
|
||||
if (s)
|
||||
s->checkDeprecated(loc, sc);
|
||||
}
|
||||
@@ -589,6 +586,18 @@ Expression *Type::defaultInit(Loc loc)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/***************************************
|
||||
* Use when we prefer the default initializer to be a literal,
|
||||
* rather than a global immutable variable.
|
||||
*/
|
||||
Expression *Type::defaultInitLiteral(Loc loc)
|
||||
{
|
||||
#if LOGDEFAULTINIT
|
||||
printf("Type::defaultInitLiteral() '%s'\n", toChars());
|
||||
#endif
|
||||
return defaultInit(loc);
|
||||
}
|
||||
|
||||
int Type::isZeroInit(Loc loc)
|
||||
{
|
||||
return 0; // assume not
|
||||
@@ -4707,6 +4716,35 @@ Expression *TypeStruct::defaultInit(Loc loc)
|
||||
return new VarExp(sym->loc, d);
|
||||
}
|
||||
|
||||
/***************************************
|
||||
* Use when we prefer the default initializer to be a literal,
|
||||
* rather than a global immutable variable.
|
||||
*/
|
||||
Expression *TypeStruct::defaultInitLiteral(Loc loc)
|
||||
{
|
||||
#if LOGDEFAULTINIT
|
||||
printf("TypeStruct::defaultInitLiteral() '%s'\n", toChars());
|
||||
#endif
|
||||
Expressions *structelems = new Expressions();
|
||||
structelems->setDim(sym->fields.dim);
|
||||
for (size_t j = 0; j < structelems->dim; j++)
|
||||
{
|
||||
VarDeclaration *vd = (VarDeclaration *)(sym->fields.data[j]);
|
||||
Expression *e;
|
||||
if (vd->init)
|
||||
e = vd->init->toExpression();
|
||||
else
|
||||
e = vd->type->defaultInitLiteral();
|
||||
structelems->data[j] = e;
|
||||
}
|
||||
StructLiteralExp *structinit = new StructLiteralExp(loc, (StructDeclaration *)sym, structelems);
|
||||
// Why doesn't the StructLiteralExp constructor do this, when
|
||||
// sym->type != NULL ?
|
||||
structinit->type = sym->type;
|
||||
return structinit;
|
||||
}
|
||||
|
||||
|
||||
int TypeStruct::isZeroInit(Loc loc)
|
||||
{
|
||||
return sym->zeroInit;
|
||||
|
||||
Reference in New Issue
Block a user