[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: ClaudeWelcome to the LLVM project!
This repository contains the source code for LLVM, a toolkit for the construction of highly optimized compilers, optimizers, and run-time environments.
The LLVM project has multiple components. The core of the project is itself called “LLVM”. This contains all of the tools, libraries, and header files needed to process intermediate representations and convert them into object files. Tools include an assembler, disassembler, bitcode analyzer, and bitcode optimizer.
C-like languages use the Clang frontend. This component compiles C, C++, Objective-C, and Objective-C++ code into LLVM bitcode -- and from there into object files, using LLVM.
Other components include: the libc++ C++ standard library, the LLD linker, and more.
Consult the Getting Started with LLVM page for information on building and running LLVM.
For information on how to contribute to the LLVM project, please take a look at the Contributing to LLVM guide.
Join the LLVM Discourse forums, Discord chat, LLVM Office Hours or Regular sync-ups.
The LLVM project has adopted a code of conduct for participants to all modes of communication within the project.