[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:20:51 PST 2023


nridge added inline comments.


================
Comment at: clang-tools-extra/clangd/refactor/tweaks/ExtractVariable.cpp:84
+  // Local variables declared inside of the selected lambda cannot go out of
+  // scope. The DeclRefExprs that are important are the lambda captures and
+  // capture var intitializers.
----------------
What about variables referenced implicitly via a capture-default?

For example, consider:

```
int main() {
  if (int a = 1)
    if ([[ [&](){ return a + 1; } ]]() == 4)
      a = a + 1;
}
```

Here, the attempted extraction point is before the outer `if`, which is before the declaration of `a`, and the fact that the lambda references `a` should prevent that.


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