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

Nathan Ridge via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Mon Sep 4 01:19:26 PDT 2023


nridge added inline comments.


================
Comment at: clang-tools-extra/clangd/refactor/tweaks/ExtractVariable.cpp:102
+
+      if (clang::Expr *const RequiresClause =
+              LExpr->getTrailingRequiresClause();
----------------
nit: just `if (clang::Expr *const RequiresClause = LExpr->getTrailingRequiresClause())` is equivalent


================
Comment at: clang-tools-extra/clangd/refactor/tweaks/ExtractVariable.cpp:187
+        // Allow expressions, but only allow completely selected lambda
+        // expressions or unselected lambda expressions that are the parent of
+        // the originally selected node, not partially selected lambda
----------------
5chmidti wrote:
> nridge wrote:
> > I think it's worth adding to the comment *why* we allow unselected lambda expressions (to allow extracting from capture initializers), as it's not obvious
> I changed the previous return of `!isa<LambdaExpr>(Stmt) || InsertionPoint->Selected != SelectionTree::Partial;` to a simple `return true;`. None of my partial selection tests fail and I can't think of a case where the lambda would be partially selected.
Hmm, so what actually happens in these testcases?

```
      // lambdas: partially selected
      [][[(){}]];
      []()[[{}]];
      [ [[ ](){}]];
```


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

https://reviews.llvm.org/D141757



More information about the cfe-commits mailing list