[clang] [clang-format] Fix BreakAfterOpenBracket options being ignored with larger continuation indents (PR #228085)

Hadong Lee via cfe-commits cfe-commits at lists.llvm.org
Fri Oct 2 02:51:35 PDT 2026


================
@@ -996,7 +996,13 @@ void ContinuationIndenter::addTokenOnCurrentLine(LineState &State, bool DryRun,
            Next->is(TT_FunctionDeclarationLParen) || IsFunctionCallParen(*Next);
   };
   if (IsOpeningBracket(Previous) &&
-      State.Column > getNewLineColumn(State).Total &&
+      (State.Column > getNewLineColumn(State).Total ||
+       // IsOpeningBracket checks BreakAfterOpenBracketBracedList before its
+       // (!Tok.Previous) shortcut. All other true returns with a preceding
+       // token require a BreakAfterOpenBracket* option.
+       // Only forbid later breaks if a break here is possible to prevent
+       // alternatives from being blocked.
+       ((Previous.Previous || Previous.is(tok::l_brace)) && canBreak(State))) &&
----------------
ChrisLee02 wrote:

`Previous.Previous` is used to distinguish cases where `IsOpeningBracket(Previous)` returns `true` for an opening bracket with an actual preceding token.

`IsOpeningBracket()` can return `true` either because:
- the preceding context and a `BreakAfterOpenBracket*` option make the bracket relevant, or
- `Tok.Previous == nullptr`.

Only the former case is relevant here, so `Previous.Previous` serves to select that path. `{` is handled separately because `BreakAfterOpenBracketBracedList` is checked in a different order.

Would a local `ShouldBreakAfterOpeningBracket` lambda make this intent clearer?

https://github.com/llvm/llvm-project/pull/228085


More information about the cfe-commits mailing list