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

Mariya Podchishchaeva via cfe-commits cfe-commits at lists.llvm.org
Wed Oct 4 01:44:26 PDT 2023


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

I think LLVM code style suggests curleys in case other branch had them
```suggestion
      } else {
        Result = *Info.CurrentCall->This;
      }
```

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


More information about the cfe-commits mailing list