diff --git a/compiler/src/dmd/e2ir.d b/compiler/src/dmd/e2ir.d index a57780678c..0dad2e10f6 100644 --- a/compiler/src/dmd/e2ir.d +++ b/compiler/src/dmd/e2ir.d @@ -1277,7 +1277,7 @@ elem* toElem(Expression e, ref IRState irs) if (ne.placement) { ex = toElem(ne.placement, irs); - ex = addressElem(ex, tclass, false); + //ex = addressElem(ex, tclass, false); } else if (auto lowering = ne.lowering) // Call _d_newitemT() @@ -1316,18 +1316,32 @@ elem* toElem(Expression e, ref IRState irs) /* Structs return a ref, which gets automatically dereferenced. * But we want a pointer to the instance. */ - ez = el_una(OPaddr, TYnptr, ez); + if (!ne.placement) + ez = el_una(OPaddr, TYnptr, ez); } else { StructLiteralExp sle = StructLiteralExp.create(ne.loc, sd, ne.arguments, t); ez = toElemStructLit(sle, irs, EXP.construct, ev.Vsym, false); - if (tybasic(ez.Ety) == TYstruct) + if (tybasic(ez.Ety) == TYstruct && !ne.placement) ez = el_una(OPaddr, TYnptr, ez); } - //elem_print(ex); - //elem_print(ey); - //printf("ez:\n"); elem_print(ez); + static if (0) + { + if (ex) { printf("ex:\n"); elem_print(ex); } + if (ey) { printf("ey:\n"); elem_print(ey); } + if (ew) { printf("ew:\n"); elem_print(ew); } + if (ezprefix) { printf("ezprefix:\n"); elem_print(ezprefix); } + if (ez) { printf("ez:\n"); elem_print(ez); } + printf("\n"); + } + + if (ne.placement) + { + ez = el_bin(OPstreq,TYstruct,el_copytree(ev),ez); + ez.ET = ev.ET; + ez = el_una(OPaddr, TYnptr, ez); + } e = el_combine(ex, ey); e = el_combine(e, ew); diff --git a/compiler/test/runnable/placenew.d b/compiler/test/runnable/placenew.d index d90d10a5e7..9b5a3a4fb3 100644 --- a/compiler/test/runnable/placenew.d +++ b/compiler/test/runnable/placenew.d @@ -93,6 +93,21 @@ void test6() /*************************************************/ +struct S7 +{ + int x = 10; + int y = 20; +} + +void test7() +{ + S7 t = void; + new (t) S7(10,20); + assert(t.x == 10 && t.y == 20); +} + +/*************************************************/ + int main() { test1(); @@ -101,6 +116,7 @@ int main() test4(); test5(); test6(); + test7(); return 0; }