llvm / llvm/llvm-project

[clang-format] `BreakAfterOpenBracketIf` has no effect when function call inside `if` statement is preceded by an unary operator

Open
#212,206 2 comments 0 reactions 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:
```yaml
ContinuationIndentWidth: 2
BinPackArguments: false
BreakAfterOpenBracketIf: true
BreakBeforeCloseBracketIf: true
```

C++ file:
```c++
#include

int main() {
if (!printf("%s %s %s %s %s %s", "foobar", "foobar", "foobar", "foobar", "foobar", "foobar")) {
return 1;
}
}
```

Expected formatting:
```c++
#include

int main() {
if (
!printf("%s %s %s %s %s %s",
"foobar",
"foobar",
"foobar",
"foobar",
"foobar",
"foobar")
) {
return 1;
}
}
```

Actual formatting:
```c++
#include

int main() {
if (!printf("%s %s %s %s %s %s",
"foobar",
"foobar",
"foobar",
"foobar",
"foobar",
"foobar")) {
return 1;
}
}
```

Using `== false` check after `printf` call instead of `!` unary operator results in the correct formatting.

---
clang-format version is 22.1.8

Contributor guide

Open the contributing guide

Research direction

Start by running clang-format 22.1.8 with the shown .clang-format settings on the provided C++ file and compare the actual output with the expected output. Trace the BreakAfterOpenBracketIf handling for a function call preceded by the unary ! operator, then verify that formatting produces the expected line breaks without changing the == false case.

Written by the indexing model from the issue text.

Assessment

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.