| Issue |
63865
|
| Summary |
ClangFormat C++11 brace initialization aligns arguments in columns
|
| Labels |
|
| Assignees |
|
| Reporter |
yuriisk
|
The bug can be reproduced with default ClangFormat config.
The code gets formatted in columns as follows
```cpp
MyData some_variable{long_parameter, very_very_long_parameter, short_param,
another_param, something_else, 10};
```
Expected formatting is
```cpp
MyData some_variable{long_parameter, very_very_long_parameter, short_param,
another_param, something_else, 10};
```
I think the behavior can be fixed in `clang/lib/Format/FormatToken.cpp`:
```diff
--- a/clang/lib/Format/FormatToken.cpp
+++ b/clang/lib/Format/FormatToken.cpp
@@ -194,10 +194,10 @@
}
// In C++11 braced list style, we should not format in columns unless they
- // have many items (20 or more) or we allow bin-packing of function call
+ // have many items (20 or more) and we allow bin-packing of function call
// arguments.
- if (Style.Cpp11BracedListStyle && !Style.BinPackArguments &&
- Commas.size() < 19) {
+ if (Style.Cpp11BracedListStyle && (!Style.BinPackArguments ||
+ Commas.size() < 20)) {
return;
}
```
Per my understanding, the code shouldn't be formatted in columns if either (1) bin-packing is disabled or (2) the number of items is less than 20.
I'm using clang-format version 16.0.6
_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs