[clang] Remove control statement check ensuring line breaks shifts newline left (PR #182298)
via cfe-commits
cfe-commits at lists.llvm.org
Thu Feb 19 07:13:09 PST 2026
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-clang-format
Author: John Mitchell (fauxprogrammer)
<details>
<summary>Changes</summary>
Method ContinuationIndenter::addTokenOnCurrentLine contains a check "State.Column > getNewLineColumn(State).Total" (file line 954) whose purpose seems to validate that a control flow line break will result in leftward movement of the conditional check. If breaking control flow into multiple lines does not result in leftward movement then no line break is performed. This seems to be aberrant behavior and these four configuration settings should result in line breaks when enabled.
E.g even with BreakAfterOpenBracketIf / BreakBeforeCloseBracketIf set to true the result will be as follows:
```c
int
function1(int parameter1, int parameter2, int parameter3) {
if (parameter1 < parameter2 || (parameter1 > parameter3 && parameter1 != null)
|| parameter1 == 500) {
return 1;
}
return 0;
}
```
Expected result is:
```c
int
function1(int parameter1, int parameter2, int parameter3) {
if (
parameter1 < parameter2 || (parameter1 > parameter3 && parameter1 != null)
|| parameter1 == 500
) {
return 1;
}
return 0;
}
```
Fixes llvm#<!-- -->181293, llvm#<!-- -->181591
---
Full diff: https://github.com/llvm/llvm-project/pull/182298.diff
1 Files Affected:
- (modified) clang/lib/Format/ContinuationIndenter.cpp (-1)
``````````diff
diff --git a/clang/lib/Format/ContinuationIndenter.cpp b/clang/lib/Format/ContinuationIndenter.cpp
index f1edd71df73fa..2abf155a29b97 100644
--- a/clang/lib/Format/ContinuationIndenter.cpp
+++ b/clang/lib/Format/ContinuationIndenter.cpp
@@ -952,7 +952,6 @@ void ContinuationIndenter::addTokenOnCurrentLine(LineState &State, bool DryRun,
Next->is(TT_FunctionDeclarationLParen) || IsFunctionCallParen(*Next);
};
if (IsOpeningBracket(Previous) &&
- State.Column > getNewLineColumn(State).Total &&
// Don't do this for simple (no expressions) one-argument function calls
// as that feels like needlessly wasting whitespace, e.g.:
//
``````````
</details>
https://github.com/llvm/llvm-project/pull/182298
More information about the cfe-commits
mailing list