diff --git a/clang/lib/Format/WhitespaceManager.cpp b/clang/lib/Format/WhitespaceManager.cpp --- a/clang/lib/Format/WhitespaceManager.cpp +++ b/clang/lib/Format/WhitespaceManager.cpp @@ -371,6 +371,9 @@ return false; if (Changes[ScopeStart].NewlinesBefore > 0) return false; + if (Changes[i].Tok->is(tok::l_brace) && + Changes[i].Tok->is(BK_BracedInit)) + return true; return Style.BinPackArguments; } @@ -387,6 +390,15 @@ Changes[i].Tok->Previous->is(TT_ConditionalExpr)) return true; + // Continued direct-list-initialization using braced list. + if (ScopeStart > Start + 1 && + Changes[ScopeStart - 2].Tok->is(tok::identifier) && + Changes[ScopeStart - 1].Tok->is(tok::l_brace) && + Changes[i].Tok->is(tok::l_brace) && + Changes[i].Tok->is(BK_BracedInit)) { + return true; + } + // Continued braced list. if (ScopeStart > Start + 1 && Changes[ScopeStart - 2].Tok->isNot(tok::identifier) && diff --git a/clang/unittests/Format/FormatTest.cpp b/clang/unittests/Format/FormatTest.cpp --- a/clang/unittests/Format/FormatTest.cpp +++ b/clang/unittests/Format/FormatTest.cpp @@ -17280,6 +17280,46 @@ // " ccc ? aaaaa : bbbbb,\n" // " dddddddddddddddddddddddddd);", // Alignment); + + // Confirm proper handling of AlignConsecutiveAssignments with + // BinPackArguments. + Alignment = getLLVMStyleWithColumns(50); + Alignment.AlignConsecutiveAssignments.Enabled = true; + Alignment.BinPackArguments = false; + { + const char *Expected = "struct A {\n" + " int a;\n" + " int b;\n" + "};\n" + "struct B {\n" + " A a1;\n" + " A a2;\n" + "};\n" + "int a_longer_name_for_wrap = 1;\n" + "// comment to prevent alignment\n" + "int a_long_name = 1;\n" + "auto b = B({a_long_name, a_long_name},\n" + " {a_longer_name_for_wrap,\n" + " a_longer_name_for_wrap});"; + + const char *ToFormat = "struct A {\n" + "int a;\n" + "int b;\n" + "};\n" + "struct B{\n" + " A a1;\n" + " A a2;\n" + "};\n" + "int a_longer_name_for_wrap = 1;\n" + "// comment to prevent alignment\n" + "int a_long_name = 1;\n" + "auto b = B({a_long_name,\n" + " a_long_name},\n" + " {a_longer_name_for_wrap,\n" + "a_longer_name_for_wrap});"; + + verifyFormat(Expected, ToFormat, Alignment); + } } TEST_F(FormatTest, AlignConsecutiveBitFields) {