Permalink
Browse files

Merge pull request #1452 from 9rnsr/fix9278

Issue 9278 - ICE todt.c:692 when float containing struct is defined after use
  • Loading branch information...
2 parents 704eb37 + 7ca2ea9 commit dabff86eb271c951e6bbf10923f575f30c3f2401 @WalterBright WalterBright committed Jan 14, 2013
Showing with 37 additions and 1 deletion.
  1. +5 −1 src/mtype.c
  2. +16 −0 test/compilable/test9278a.d
  3. +16 −0 test/compilable/test9278b.d
View
6 src/mtype.c
@@ -8154,6 +8154,7 @@ Expression *TypeStruct::defaultInitLiteral(Loc loc)
for (size_t j = 0; j < structelems->dim; j++)
{
VarDeclaration *vd = sym->fields[j];
+ Type *telem = vd->type->addMod(this->mod);
Expression *e;
if (vd->init)
{ if (vd->init->isVoidInitializer())
@@ -8164,7 +8165,10 @@ Expression *TypeStruct::defaultInitLiteral(Loc loc)
else
e = vd->type->defaultInitLiteral(loc);
if (e && vd->scope)
- e = e->semantic(vd->scope);
+ {
+ e = e->semantic(vd->scope);
+ e = e->implicitCastTo(vd->scope, telem);
+ }
(*structelems)[j] = e;
}
StructLiteralExp *structinit = new StructLiteralExp(loc, (StructDeclaration *)sym, structelems);
View
16 test/compilable/test9278a.d
@@ -0,0 +1,16 @@
+// PREMUTE_ARGS:
+
+// Works fine here
+struct datum { float num = 0.0; }
+
+datum emitOne()
+{
+ datum t;
+ return t;
+}
+const dataArr = [emitOne()];
+
+// A very bad day
+//struct datum { float num = 0.0; }
+
+void main(){}
View
16 test/compilable/test9278b.d
@@ -0,0 +1,16 @@
+// PREMUTE_ARGS:
+
+// Works fine here
+//struct datum { float num = 0.0; }
+
+datum emitOne()
+{
+ datum t;
+ return t;
+}
+const dataArr = [emitOne()];
+
+// A very bad day
+struct datum { float num = 0.0; }
+
+void main(){}

0 comments on commit dabff86

Please sign in to comment.