diff --git a/clang/lib/AST/Interp/ByteCodeExprGen.cpp b/clang/lib/AST/Interp/ByteCodeExprGen.cpp index 0ce55f115a1a0..4fa12a66bbf76 100644 --- a/clang/lib/AST/Interp/ByteCodeExprGen.cpp +++ b/clang/lib/AST/Interp/ByteCodeExprGen.cpp @@ -243,12 +243,6 @@ bool ByteCodeExprGen::VisitBinaryOperator(const BinaryOperator *BO) { std::optional RT = classify(RHS->getType()); std::optional T = classify(BO->getType()); - auto Discard = [this, T, BO](bool Result) { - if (!Result) - return false; - return DiscardResult ? this->emitPop(*T, BO) : true; - }; - // Deal with operations which have composite or void types. if (BO->isCommaOp()) { if (!this->discard(LHS)) @@ -256,9 +250,7 @@ bool ByteCodeExprGen::VisitBinaryOperator(const BinaryOperator *BO) { if (RHS->getType()->isVoidType()) return this->discard(RHS); - // Otherwise, visit RHS and optionally discard its value. - return Discard(Initializing ? this->visitInitializer(RHS) - : this->visit(RHS)); + return this->delegate(RHS); } if (!LT || !RT || !T) @@ -285,6 +277,12 @@ bool ByteCodeExprGen::VisitBinaryOperator(const BinaryOperator *BO) { return true; }; + auto Discard = [this, T, BO](bool Result) { + if (!Result) + return false; + return DiscardResult ? this->emitPop(*T, BO) : true; + }; + switch (BO->getOpcode()) { case BO_EQ: return MaybeCastToBool(this->emitEQ(*LT, BO)); diff --git a/clang/test/AST/Interp/literals.cpp b/clang/test/AST/Interp/literals.cpp index 69a3edc87b6ec..dae1d5af6f7ae 100644 --- a/clang/test/AST/Interp/literals.cpp +++ b/clang/test/AST/Interp/literals.cpp @@ -929,6 +929,7 @@ namespace DiscardExprs { (bool)1; __null; __builtin_offsetof(A, a); + 1,2; return 0; }