@@ -1410,10 +1410,10 @@ namespace Cpp {
1410
1410
const std::string& class_name, int indent_level) {
1411
1411
// Make a code string that follows this pattern:
1412
1412
//
1413
- // new ClassName(args...)
1413
+ // ClassName(args...)
1414
1414
//
1415
1415
1416
- callbuf << " new " << class_name << " (" ;
1416
+ callbuf << class_name << " (" ;
1417
1417
for (unsigned i = 0U ; i < N; ++i) {
1418
1418
const ParmVarDecl* PVD = FD->getParamDecl (i);
1419
1419
QualType Ty = PVD->getType ();
@@ -1575,16 +1575,9 @@ namespace Cpp {
1575
1575
std::ostringstream& buf, int indent_level) {
1576
1576
// Make a code string that follows this pattern:
1577
1577
//
1578
- // if (ret) {
1579
- // (*(ClassName**)ret) = new ClassName(args...);
1580
- // }
1581
- // else {
1582
- // new ClassName(args...);
1583
- // }
1578
+ // (*(ClassName**)ret) = (obj) ?
1579
+ // new (*(ClassName**)ret) ClassName(args...) : new ClassName(args...);
1584
1580
//
1585
- indent (buf, indent_level);
1586
- buf << " if (ret) {\n " ;
1587
- ++indent_level;
1588
1581
{
1589
1582
std::ostringstream typedefbuf;
1590
1583
std::ostringstream callbuf;
@@ -1593,40 +1586,23 @@ namespace Cpp {
1593
1586
//
1594
1587
indent (callbuf, indent_level);
1595
1588
callbuf << " (*(" << class_name << " **)ret) = " ;
1589
+ callbuf << " (obj) ? new (*(" << class_name << " **)ret) " ;
1590
+ make_narg_ctor (FD, N, typedefbuf, callbuf, class_name, indent_level);
1591
+
1592
+ callbuf << " : new " ;
1596
1593
//
1597
- // Write the actual new expression.
1594
+ // Write the actual expression.
1598
1595
//
1599
1596
make_narg_ctor (FD, N, typedefbuf, callbuf, class_name, indent_level);
1600
1597
//
1601
1598
// End the new expression statement.
1602
1599
//
1603
1600
callbuf << " ;\n " ;
1604
- indent (callbuf, indent_level);
1605
- callbuf << " return;\n " ;
1606
1601
//
1607
1602
// Output the whole new expression and return statement.
1608
1603
//
1609
1604
buf << typedefbuf.str () << callbuf.str ();
1610
1605
}
1611
- --indent_level;
1612
- indent (buf, indent_level);
1613
- buf << " }\n " ;
1614
- indent (buf, indent_level);
1615
- buf << " else {\n " ;
1616
- ++indent_level;
1617
- {
1618
- std::ostringstream typedefbuf;
1619
- std::ostringstream callbuf;
1620
- indent (callbuf, indent_level);
1621
- make_narg_ctor (FD, N, typedefbuf, callbuf, class_name, indent_level);
1622
- callbuf << " ;\n " ;
1623
- indent (callbuf, indent_level);
1624
- callbuf << " return;\n " ;
1625
- buf << typedefbuf.str () << callbuf.str ();
1626
- }
1627
- --indent_level;
1628
- indent (buf, indent_level);
1629
- buf << " }\n " ;
1630
1606
}
1631
1607
1632
1608
void make_narg_call_with_return (compat::Interpreter& I,
@@ -2838,7 +2814,7 @@ namespace Cpp {
2838
2814
auto * const Ctor = GetDefaultConstructor (Class);
2839
2815
if (JitCall JC = MakeFunctionCallable (Ctor)) {
2840
2816
if (arena) {
2841
- JC.Invoke (arena);
2817
+ JC.Invoke (& arena, {}, ( void *)~ 0U ); // Tell Invoke to use placement new.
2842
2818
return arena;
2843
2819
}
2844
2820
0 commit comments