Skip to content

Commit df935ff

Browse files
authored
[clang-format] Fix regression with BlockIndent of Braced Initializers (#108717)
Fixes #73584.
1 parent 53266f7 commit df935ff

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

clang/lib/Format/ContinuationIndenter.cpp

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

351+
// Don't allow breaking before a closing brace of a block-indented braced list
352+
// initializer if there isn't already a break.
353+
if (Current.is(tok::r_brace) && Current.MatchingParen &&
354+
Current.isBlockIndentedInitRBrace(Style)) {
355+
return CurrentState.BreakBeforeClosingBrace;
356+
}
357+
351358
// If binary operators are moved to the next line (including commas for some
352359
// styles of constructor initializers), that's always ok.
353360
if (!Current.isOneOf(TT_BinaryOperator, tok::comma) &&

clang/unittests/Format/FormatTest.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9441,6 +9441,11 @@ TEST_F(FormatTest, AlignsAfterOpenBracket) {
94419441
" aaaaaaaaaaaaaaaa\n"
94429442
");",
94439443
Style);
9444+
verifyFormat("aaaaaaa<bbbbbbbb> const aaaaaaaaaa{\n"
9445+
" aaaaaaaaaaaaa(aaaaaaaaaaa, aaaaaaaaaaaaaaaa)\n"
9446+
"};",
9447+
Style);
9448+
94449449
verifyFormat("bool aaaaaaaaaaaaaaaaaaaaaaaaaaa(\n"
94459450
" const bool &aaaaaaaaa, const void *aaaaaaaaaa\n"
94469451
") const {\n"

0 commit comments

Comments
 (0)