[clang] [Clang] Fix constant evaluating a captured variable in a lambda (PR #68090)

via cfe-commits cfe-commits at lists.llvm.org
Tue Oct 3 05:21:35 PDT 2023


================
@@ -8366,8 +8366,14 @@ bool LValueExprEvaluator::VisitVarDecl(const Expr *E, const VarDecl *VD) {
       return false;
 
     if (auto *FD = Info.CurrentCall->LambdaCaptureFields.lookup(VD)) {
+      auto *MD = cast<CXXMethodDecl>(Info.CurrentCall->Callee);
       // Start with 'Result' referring to the complete closure object...
-      Result = *Info.CurrentCall->This;
+      if (MD->isExplicitObjectMemberFunction()) {
+        APValue *RefValue =
+            Info.getParamSlot(Info.CurrentCall->Arguments, MD->getParamDecl(0));
+        Result.setFrom(Info.Ctx, *RefValue);
+      } else
+        Result = *Info.CurrentCall->This;
----------------
cor3ntin wrote:

I'd rather not pretend that there is a `this` object even though it would not correspond to an actual this pointer (and evaluating `this` is ill formed. I imagine it might make things more difficult to maintain in the future

https://github.com/llvm/llvm-project/pull/68090


More information about the cfe-commits mailing list