llvm / llvm/llvm-project

[clang-format] fails to enforce ColumnLimit for certain parenthesized expressions

Open
#195,071 2 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

Expected: expressions wrapped at whitespace to comply with ColumnLimit.
Actual behaviour: some lines are up to 115 chars long limit despite 80 char limit and each identifier is 35 chars or shorter.

.clang-format:
```
BasedOnStyle: Mozilla
Language: Cpp
AlignAfterOpenBracket: AlwaysBreak
BreakBeforeBinaryOperators: All
ColumnLimit: 80
ContinuationIndentWidth: 2
IndentWidth: 4
```

C++ file:
```
// wraps as expected
bar = baz_baz_baz_baz_baz_baz_baz_baz_baz_baz
== qux_qux_qux_qux_qux_qux_qux_qux_qux_qux_qux;
bar = f(
baz_baz_baz_baz_baz_baz_baz_baz_baz_baz
== qux_qux_qux_qux_qux_qux_qux_qux_qux_qux_qux);

// fails to wrap parenthesized, line limit exceeded
bar
= (baz_baz_baz_baz_baz_baz_baz_baz_baz_baz == qux_qux_qux_qux_qux_qux_qux_qux_qux_qux_qux);

// fails to wrap too, line limit exceeded
bar
= (baz_baz_baz_baz_baz_baz_baz_baz_baz().baz() == qux_qux_qux_qux_qux_qux_qux_qux_qux().qux());

// fails to wrap as well, line limit exceeded;
// note baz_baz_baz_baz_baz_baz_baz_baz_baz is not called
{
bar_bar_bar_bar
= (baz_baz_baz_baz_baz_baz_baz_baz_baz.baz() == qux_qux_qux_qux_qux_qux_qux_qux_qux().qux());
}

// now baz_baz_baz_baz_baz_baz_baz_baz_baz is called
// fails to wrap even the assignment! line limit exceeded as well
{
bar_bar_bar_bar = (baz_baz_baz_baz_baz_baz_baz_baz_baz().baz() == qux_qux_qux_qux_qux_qux_qux_qux_qux().qux());
}

// keeps manual wrapping as it is, with odd indents
{
bar_bar_bar_bar
= (baz_baz_baz_baz_baz_baz_baz_baz_baz().baz()
== qux_qux_qux_qux_qux_qux_qux_qux_qux().qux());
}
```
Reproduces with `clang-format version 23.0.0 (++20260403081745+a7bf24919f87-1~exp1~20260403081920.1558)` and `clang-format version 22.1.0 (https://github.com/llvm/llvm-project.git 4434dabb69916856b824f68a64b029c67175e532)`

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.