File tree Expand file tree Collapse file tree 2 files changed +25
-13
lines changed Expand file tree Collapse file tree 2 files changed +25
-13
lines changed Original file line number Diff line number Diff line change @@ -2088,6 +2088,21 @@ bool ByteCodeExprGen<Emitter>::VisitCXXConstructExpr(
2088
2088
if (T->isRecordType ()) {
2089
2089
const CXXConstructorDecl *Ctor = E->getConstructor ();
2090
2090
2091
+ // If we're discarding a construct expression, we still need
2092
+ // to allocate a variable and call the constructor and destructor.
2093
+ if (DiscardResult) {
2094
+ if (Ctor->isTrivial ())
2095
+ return true ;
2096
+ assert (!Initializing);
2097
+ std::optional<unsigned > LocalIndex = allocateLocal (E);
2098
+
2099
+ if (!LocalIndex)
2100
+ return false ;
2101
+
2102
+ if (!this ->emitGetPtrLocal (*LocalIndex, E))
2103
+ return false ;
2104
+ }
2105
+
2091
2106
// Zero initialization.
2092
2107
if (E->requiresZeroInitialization ()) {
2093
2108
const Record *R = getRecord (E->getType ());
@@ -2108,19 +2123,6 @@ bool ByteCodeExprGen<Emitter>::VisitCXXConstructExpr(
2108
2123
assert (Func->hasThisPointer ());
2109
2124
assert (!Func->hasRVO ());
2110
2125
2111
- // If we're discarding a construct expression, we still need
2112
- // to allocate a variable and call the constructor and destructor.
2113
- if (DiscardResult) {
2114
- assert (!Initializing);
2115
- std::optional<unsigned > LocalIndex = allocateLocal (E);
2116
-
2117
- if (!LocalIndex)
2118
- return false ;
2119
-
2120
- if (!this ->emitGetPtrLocal (*LocalIndex, E))
2121
- return false ;
2122
- }
2123
-
2124
2126
// The This pointer is already on the stack because this is an initializer,
2125
2127
// but we need to dup() so the call() below has its own copy.
2126
2128
if (!this ->emitDupPtr (E))
Original file line number Diff line number Diff line change @@ -1459,3 +1459,13 @@ namespace TemporaryWithInvalidDestructor {
1459
1459
// both-note {{in call to}}
1460
1460
#endif
1461
1461
}
1462
+
1463
+ namespace IgnoredCtorWithZeroInit {
1464
+ struct S {
1465
+ int a;
1466
+ };
1467
+
1468
+ bool get_status () {
1469
+ return (S (), true );
1470
+ }
1471
+ }
You can’t perform that action at this time.
0 commit comments