[PATCH] D122768: [Clang][C++20] Support capturing structured bindings in lambdas

Erich Keane via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Thu Jul 28 08:19:11 PDT 2022


erichkeane added inline comments.


================
Comment at: clang/lib/AST/ExprCXX.cpp:1214-1216
+  return (C->capturesVariable() && isa<VarDecl>(C->getCapturedVar()) &&
+          cast<VarDecl>(C->getCapturedVar())->isInitCapture() &&
           (getCallOperator() == C->getCapturedVar()->getDeclContext()));
----------------
aaron.ballman wrote:
> I think early returns help make this a bit more clear.
I might suggest making that:

```
if (const auto *VD = dyn_cast<VarDecl(C->getCapturedVar())
   return VD->...
return false;
```

But otherwise agree with the suggestion.


================
Comment at: clang/lib/Analysis/AnalysisDeclContext.cpp:173
+    ValueDecl *VD = LC.getCapturedVar();
+    if (isSelfDecl(dyn_cast<VarDecl>(VD)))
       return dyn_cast<ImplicitParamDecl>(VD);
----------------
aaron.ballman wrote:
> This looks dangerous -- `isSelfDecl()` uses the pointer variable in ways that would be Bad News for null pointers.
Yep, `isSelfDecl` seems to do:

`return isa<ImplicitParamDecl>(VD) && VD->getName() == "self";`

`isa` isn't nullptr safe, we have `isa_and_nonnull` for that (if we want to update `isSelfDecl`).


================
Comment at: clang/lib/Sema/SemaDecl.cpp:14594-14596
+      ValueDecl *VD = C.getCapturedVar();
+      if (VarDecl *Var = dyn_cast<VarDecl>(VD)) {
+        if (Var->isInitCapture())
----------------



Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D122768/new/

https://reviews.llvm.org/D122768



More information about the cfe-commits mailing list