llvm / llvm/llvm-project

[clang-format] Newline inserted before inline lambda body when ColumnLimit set to 0

Open
#188,111 8 comments 0 reactions 0 assignees View on GitHub
clang-format confirmed
Dominant language
LLVM
Stars
40.5k
Forks
18.7k
PR merge metrics
PR metrics pending

Description

## Description

When `ColumnLimit` is set to `0` together with `BreakBeforeBraces` set to `Allman`, clang-format inserts a newline before lambda body even though it should be left inline, which is what it does without setting `ColumnLimit`.

## Steps to reproduce

Use the following `.clang-format` configuration:

```yaml
BreakBeforeBraces: Allman
ColumnLimit: 0
```

Format following code:

```cpp
// Inline function
void example() { return 69; }

void test()
{
// Inline lambda
func([]() { return 420; });
}
```

## Expected output

```cpp
// Inline function
void example() { return 69; }

void test()
{
// Inline lambda
func([]() { return 420; });
}
```

The same as without `ColumnLimit` set.

## Actual output

```cpp
// Inline function
void example() { return 69; }

void test()
{
// Inline lambda
func([]()
{ return 420; });
}
```

## Environment

clang-format version 22.1.1

Contributor guide

Open the contributing guide

Research direction

Start by running clang-format 22.1.1 on the supplied C++ reproducer with BreakBeforeBraces: Allman and ColumnLimit: 0, then compare the output with the expected inline lambda form. Trace the clang-format formatting path responsible for lambda braces and verify that the newline is not inserted while preserving Allman formatting elsewhere.

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
Active
Clarity
Mostly clear
Newbie friendliness
65/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.