Skip to content

Commit e7ae553

Browse files
gedaretstellar
authored andcommitted
[clang-format] Fix mismatched break in BlockIndent (llvm#124998)
Near the ColumnLimit a break could be inserted before a right parens with BlockIndent without a break after the matching left parens. Avoid these hanging right parens by disallowing breaks before right parens unless there was a break after the left parens. Fixes llvm#103306 (cherry picked from commit b873479)
1 parent 8f288eb commit e7ae553

File tree

2 files changed

+11
-0
lines changed

2 files changed

+11
-0
lines changed

clang/lib/Format/ContinuationIndenter.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -349,6 +349,13 @@ bool ContinuationIndenter::canBreak(const LineState &State) {
349349
}
350350
}
351351

352+
// Allow breaking before the right parens with block indentation if there was
353+
// a break after the left parens, which is tracked by BreakBeforeClosingParen.
354+
if (Style.AlignAfterOpenBracket == FormatStyle::BAS_BlockIndent &&
355+
Current.is(tok::r_paren)) {
356+
return CurrentState.BreakBeforeClosingParen;
357+
}
358+
352359
// Don't allow breaking before a closing brace of a block-indented braced list
353360
// initializer if there isn't already a break.
354361
if (Current.is(tok::r_brace) && Current.MatchingParen &&

clang/unittests/Format/FormatTest.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9614,6 +9614,10 @@ TEST_F(FormatTest, AlignsAfterOpenBracket) {
96149614
" auto aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\n"
96159615
" ) {};",
96169616
Style);
9617+
verifyFormat("aaaaaaaaaaaaaaaaaaaaaaaa(\n"
9618+
" &bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb\n"
9619+
");",
9620+
Style);
96179621
}
96189622

96199623
TEST_F(FormatTest, ParenthesesAndOperandAlignment) {

0 commit comments

Comments
 (0)