| Issue |
242827
|
| Summary |
[clang-format] Extend BreakBinaryOperations to support unconditional breaks (`AlwaysOnePerLine`/`AlwaysRespectPrecedence`)
|
| Labels |
clang-format
|
| Assignees |
|
| Reporter |
damster101
|
Especially within vertical formatting styles, it may be desirable to unconditionally break binary operation chains (or specific operators such as `&&` and `||` past a `MinChainLength`) onto one operand per line **even when the entire _expression_ fits within `ColumnLimit`**, similar to what is supported with `PackParameters: UseBreakAfter`.
My concrete proposal is to extend `BreakBinaryOperationsStyle` with `AlwaysOnePerLine` and `AlwaysRespectPrecedence`, and reuse the existing `MinChainLength` threshold in that context, making chains with at least `MinChainLength` operands always break onto separate lines regardless of `ColumnLimit`:
```yaml
BreakBeforeBinaryOperators: All
BreakBinaryOperations:
Default: RespectPrecedence
PerOperator:
- Operators: ['&&', '||']
Style: AlwaysOnePerLine
MinChainLength: 2
- Operators: ['|', '&']
Style: AlwaysRespectPrecedence
MinChainLength: 3
```
With the configuration above, even when well under `ColumnLimit`, you would then get:
```cpp
// input:
bool ok = has_header && is_valid && !is_expired;
uint32_t flags = flag_a | flab_b;
uint32_t mask = mask_a | mask_b | mask_c;
// formatted output:
bool ok = has_header
&& is_valid
&& !is_expired;
uint32_t flags = flag_a | flag_b; // chain length 2 < MinChainLength 3
uint32_t mask = mask_a
| mask_b
| mask_c; // chain length 3 >= MinChainLength 3
```
_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs