[clang] [libclang]Visit lambda init-capture as VarDeclaration (PR #174116)

Aaron Ballman via cfe-commits cfe-commits at lists.llvm.org
Mon Mar 2 04:53:39 PST 2026


================
@@ -3901,19 +3901,18 @@ bool CursorVisitor::RunVisitorWorkList(VisitorWorkList &WL) {
       for (LambdaExpr::capture_iterator C = E->explicit_capture_begin(),
                                         CEnd = E->explicit_capture_end();
            C != CEnd; ++C) {
-        if (!C->capturesVariable())
-          continue;
-        // TODO: handle structured bindings here ?
-        if (!isa<VarDecl>(C->getCapturedVar()))
-          continue;
-        if (Visit(MakeCursorVariableRef(cast<VarDecl>(C->getCapturedVar()),
-                                        C->getLocation(), TU)))
-          return true;
-      }
-      // Visit init captures
-      for (auto InitExpr : E->capture_inits()) {
-        if (InitExpr && Visit(InitExpr))
-          return true;
+
+        if (const auto *CV = C->getCapturedVar(); CV && isa<VarDecl>(CV)) {
----------------
AaronBallman wrote:

```suggestion
        if (const auto *CV = dyn_cast_or_null<VarDecl>(C->getCapturedVar())) {
```
Then you can remove some explicit casts below as well.

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


More information about the cfe-commits mailing list