llvm / llvm/llvm-project

[clang-format] AlignOperands: DontAlign produces incorrect lambda body indentation in range pipelines

Open
#204,884 1 comment 1 reaction 0 assignees View on GitHub
clang-format
Dominant language
LLVM
Stars
40.5k
Forks
18.7k
PR merge metrics
PR metrics pending

Description

**clang-format version 22.1.8**

When `.clang-format` combines `AlignOperands: DontAlign` with `LambdaBodyIndentation: Signature`, the body of a lambda nested inside a range pipeline (`|` operator chain) is indented excessively — far beyond what `Signature` mode should produce.

The same code formatted under three different `AlignOperands` values (all with `LambdaBodyIndentation: Signature`):

```cpp
namespace rv = std::views;

int main(int argc, char* argv[]) {
auto nums =
std::vector{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20};

// AlignOperands: DontAlign, LambdaBodyIndentation: Signature
auto _ = nums
| rv::filter([](int x) { return x % 3 == 0 || x % 5 == 0; })
| rv::transform([](int x) -> std::string {
if (x % 15 == 0) return "FizzBuzz"; //< BUG: indented to col 11
if (x % 3 == 0) return "Fizz"; //<
return "Buzz"; //<
}) //<
| rv::take(10);

// AlignOperands: Align, LambdaBodyIndentation: Signature
auto _ = nums
| rv::filter([](int x) { return x % 3 == 0 || x % 5 == 0; })
| rv::transform([](int x) -> std::string {
if (x % 15 == 0) return "FizzBuzz";
if (x % 3 == 0) return "Fizz";
return "Buzz";
})
| rv::take(10);

// AlignOperands: AlignAfterOperator, LambdaBodyIndentation: Signature
auto _ = nums
| rv::filter([](int x) { return x % 3 == 0 || x % 5 == 0; })
| rv::transform([](int x) -> std::string {
if (x % 15 == 0) return "FizzBuzz";
if (x % 3 == 0) return "Fizz";
return "Buzz";
})
| rv::take(10);
}
```

expect:
```cpp
// AlignOperands: DontAlign, LambdaBodyIndentation: Signature
auto _ = nums
| rv::filter([](int x) { return x % 3 == 0 || x % 5 == 0; })
| rv::transform([](int x) -> std::string {
if (x % 15 == 0) return "FizzBuzz";
if (x % 3 == 0) return "Fizz";
return "Buzz";
})
| rv::take(10);
```

Contributor guide

Open the contributing guide

Research direction

Reproduce the formatting shown with AlignOperands: DontAlign and LambdaBodyIndentation: Signature, then compare it with Align and AlignAfterOperator. Trace the clang-format handling of range-pipeline operands and nested lambda bodies. Done means the DontAlign output matches the expected indentation while the other modes remain unchanged.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp
Domain
tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
58/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.