[clang-format] `BreakAfterOpenBracketIf` has no effect when function call inside `if` statement is preceded by an unary operator
- 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
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