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(
20882088 if (T->isRecordType ()) {
20892089 const CXXConstructorDecl *Ctor = E->getConstructor ();
20902090
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+
20912106 // Zero initialization.
20922107 if (E->requiresZeroInitialization ()) {
20932108 const Record *R = getRecord (E->getType ());
@@ -2108,19 +2123,6 @@ bool ByteCodeExprGen<Emitter>::VisitCXXConstructExpr(
21082123 assert (Func->hasThisPointer ());
21092124 assert (!Func->hasRVO ());
21102125
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-
21242126 // The This pointer is already on the stack because this is an initializer,
21252127 // but we need to dup() so the call() below has its own copy.
21262128 if (!this ->emitDupPtr (E))
Original file line number Diff line number Diff line change @@ -1459,3 +1459,13 @@ namespace TemporaryWithInvalidDestructor {
14591459 // both-note {{in call to}}
14601460#endif
14611461}
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