[PATCH] D141757: [clangd] allow extracting to variable for complete lambda expressions

Nathan Ridge via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Tue Feb 21 01:30:01 PST 2023


nridge added inline comments.


================
Comment at: clang-tools-extra/clangd/refactor/tweaks/ExtractVariable.cpp:86
+  // capture var intitializers.
+  if (const auto *const LExpr = llvm::dyn_cast<LambdaExpr>(Expr)) {
+    FindDeclRefsVisitor Visitor;
----------------
On the other hand, the exclusion of local variables declared inside lambdas should also apply to lambdas which are **subexpressions** of the selected expression. Consider:

```
template <typename T>
auto call(T t) { return t(); }

int main() {
  return [[ call([](){ int a = 1; return a + 1; }) ]] + 5;
}
```

Here, the presence of the local variable `a` inside the lambda should not interfere with the ability to extract the `call(...)` expression.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D141757



More information about the cfe-commits mailing list