Skip to content

Commit a95b990

Browse files
committed
[clang-format] Fix regression with BlockIndent of Braced Initializers
Fixes llvm#73584.
1 parent acf90fd commit a95b990

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-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 right brace of a block-indented
352+
// braced list initializer if there was not 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: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9336,6 +9336,9 @@ TEST_F(FormatTest, AlignsAfterOpenBracket) {
93369336
" ccccccc(aaaaaaaaaaaaaaaaa, //\n"
93379337
" b));",
93389338
Style);
9339+
verifyFormat("aaaaaaa<bbbbbbbb> const aaaaaaaaaa{\n"
9340+
" aaaaaaaaaaaaa(aaaaaaaaaaa, aaaaaaaaaaaaaaaa)};",
9341+
Style);
93399342

93409343
Style.ColumnLimit = 30;
93419344
verifyFormat("for (int foo = 0; foo < FOO;\n"
@@ -9395,6 +9398,9 @@ TEST_F(FormatTest, AlignsAfterOpenBracket) {
93959398
"fooooooooooo(new FOO::BARRRR(\n"
93969399
" XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXZZZZZZZZZZZZZZZZZZZZZZZZZ()));",
93979400
Style);
9401+
verifyFormat("aaaaaaa<bbbbbbbb> const aaaaaaaaaa{\n"
9402+
" aaaaaaaaaaaaa(aaaaaaaaaaa, aaaaaaaaaaaaaaaa)};",
9403+
Style);
93989404

93999405
Style.AlignAfterOpenBracket = FormatStyle::BAS_BlockIndent;
94009406
Style.BinPackArguments = false;
@@ -9441,6 +9447,11 @@ TEST_F(FormatTest, AlignsAfterOpenBracket) {
94419447
" aaaaaaaaaaaaaaaa\n"
94429448
");",
94439449
Style);
9450+
verifyFormat("aaaaaaa<bbbbbbbb> const aaaaaaaaaa{\n"
9451+
" aaaaaaaaaaaaa(aaaaaaaaaaa, aaaaaaaaaaaaaaaa)\n"
9452+
"};",
9453+
Style);
9454+
94449455
verifyFormat("bool aaaaaaaaaaaaaaaaaaaaaaaaaaa(\n"
94459456
" const bool &aaaaaaaaa, const void *aaaaaaaaaa\n"
94469457
") const {\n"

0 commit comments

Comments
 (0)