| Issue |
181591
|
| Summary |
clang-format: Inconsistent formatting with BreakAfterOpenBracketIf / BreakBeforeCloseBracketIf depending on ContinuationIndentWidth
|
| Labels |
clang-format
|
| Assignees |
|
| Reporter |
JWTheDBA
|
I'm having trouble with BreakAfterOpenBracketIf and BreakBeforeCloseBracketIf. When both are set, and I use a ContinuationIndentWidth of 0, 1, 2, or 3 I get this layout.
```c
int
function1(int parameter1, int parameter2, int parameter3) {
if (
parameter1 < parameter2 || (parameter1 > parameter3 && parameter1 != null)
|| parameter1 == 500
) {
return 1;
}
return 0;
}
```
The conditionals are on their own lines between the open and close 'if' parens. This is what I'm wanting to archive. But I'd like to achieve it with a ContinuationIndentWidth of 4. When ContinuationIndentWidth is set >=4 the formatting changes to the following:
```c
int
function1(int parameter1, int parameter2, int parameter3) {
if (parameter1 < parameter2 || (parameter1 > parameter3 && parameter1 != null)
|| parameter1 == 500) {
return 1;
}
return 0;
}
```
Notice how some of the conditionals have moved back up to be on the same line as the 'if' keyword.
As best I can tell from looking at the code within clang/lib/Format/ContinuationIndenter.cpp this is by design. Within method ContinuationIndenter::addTokenOnCurrentLine there is a check "State.Column > getNewLineColumn(State).Total" (file line 954) whose purpose seems to validate that a line break will result in a leftward move of the new line. And if not then no break is performed. I've confirmed this suspicion by rebuilding clang-format with this line commented out and formatting worked as expected.
Not sure what prompted this check to be added but for my use cases of BreakAfterOpenBracketIf and BreakBeforeCloseBracketIf it breaks the expected formatting. Even if there is no left movement of the new line, in my opinion, it makes the control statement block easier to read.
Is this working as expected? Seems like a bug that the line breaks would only work for continuation indents less than 4.
_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs