[all-commits] [llvm/llvm-project] 63b5d1: [clangd] Don't offer Extract to Function for contr...

Christian Kandeler via All-commits all-commits at lists.llvm.org
Tue Sep 22 07:49:19 PDT 2026


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: 63b5d1388f6ca68954ad22bc36fb73613507ceb1
      https://github.com/llvm/llvm-project/commit/63b5d1388f6ca68954ad22bc36fb73613507ceb1
  Author: Christian Kandeler <christian.kandeler at qt.io>
  Date:   2026-09-22 (Tue, 22 Sep 2026)

  Changed paths:
    M clang-tools-extra/clangd/refactor/tweaks/ExtractFunction.cpp
    M clang-tools-extra/clangd/unittests/tweaks/ExtractFunctionTests.cpp

  Log Message:
  -----------
  [clangd] Don't offer Extract to Function for control-flow conditions (#223409)

Extracting the condition of an `if`/`while`/`do`/`for`/`switch` (or a
condition-variable
declaration) was treated the same as extracting a discardable
expression-statement, producing a `void`-returning function called
where the construct needs a value, e.g.:

```cpp
void extracted(int &event1, bool &event2, double &event3) {
event1 == 2 && event2 && event3 == 10.3;
}
int example(int event1, bool event2, double event3) {
      if (extracted(event1, event2, event3))   // doesn't compile
        return 1;
```

This slot was previously unreachable in practice because a blanket
"never extract a single `Expr`" check happened to also block it, but
that check was removed in #219945 to allow extracting genuine
expression-statements. This adds back a narrower, correctly-scoped
check instead: reject when the selected node occupies a
condition slot specifically, which also finally
resolves two long-standing FIXMEs about this exact gap.

Assisted-by: Claude



To unsubscribe from these emails, change your notification settings at https://github.com/llvm/llvm-project/settings/notifications


More information about the All-commits mailing list