Index: lib/Format/ContinuationIndenter.cpp =================================================================== --- lib/Format/ContinuationIndenter.cpp +++ lib/Format/ContinuationIndenter.cpp @@ -999,9 +999,13 @@ bool EndsInComma = Current.MatchingParen && Current.MatchingParen->Previous && Current.MatchingParen->Previous->is(tok::comma); + const FormatToken *PreviousNoComment = Current.getPreviousNonComment(); + bool IsAfterAssignment = PreviousNoComment && + PreviousNoComment->getPrecedence() == + prec::Assignment; AvoidBinPacking = - (Current.is(TT_ArrayInitializerLSquare) && EndsInComma) || - Current.is(TT_DictLiteral) || + (/*Current.is(TT_ArrayInitializerLSquare) && */EndsInComma) || + IsAfterAssignment || Current.is(TT_DictLiteral) || Style.Language == FormatStyle::LK_Proto || !Style.BinPackArguments || (NextNoComment && NextNoComment->is(TT_DesignatedInitializerPeriod)); if (Current.ParameterCount > 1) Index: unittests/Format/FormatTest.cpp =================================================================== --- unittests/Format/FormatTest.cpp +++ unittests/Format/FormatTest.cpp @@ -5699,7 +5699,8 @@ // A trailing comma should still lead to an enforced line break. EXPECT_EQ("vector SomeVector = {\n" " // aaa\n" - " 1, 2,\n" + " 1,\n" + " 2,\n" "};", format("vector SomeVector = { // aaa\n" " 1, 2, };")); @@ -5783,10 +5784,17 @@ verifyFormat("static const uint16_t CallerSavedRegs64Bittttt[] = {\n" " X86::RAX, X86::RDX, X86::RCX, X86::RSI, X86::RDI,\n" " X86::R8, X86::R9, X86::R10, X86::R11, 0};"); - verifyFormat("static const uint16_t CallerSavedRegs64Bittttt[] = {\n" - " X86::RAX, X86::RDX, X86::RCX, X86::RSI, X86::RDI,\n" - " // Separating comment.\n" - " X86::R8, X86::R9, X86::R10, X86::R11, 0};"); + verifyFormat("static const uint16_t CallerSavedRegs64Bittttt[] = {X86::RAX,\n" + " X86::RDX,\n" + " X86::RCX,\n" + " X86::RSI,\n" + " X86::RDI,\n" + " // Separating comment.\n" + " X86::R8,\n" + " X86::R9,\n" + " X86::R10,\n" + " X86::R11,\n" + " 0};"); verifyFormat("static const uint16_t CallerSavedRegs64Bittttt[] = {\n" " // Leading comment\n" " X86::RAX, X86::RDX, X86::RCX, X86::RSI, X86::RDI,\n" @@ -5863,8 +5871,10 @@ " aaaaaaaaaaaa, a, aaaaaaaaaa, aaaaaaaaa, aaa}};"); // No column layout should be used here. - verifyFormat("aaaaaaaaaaaaaaa = {aaaaaaaaaaaaaaaaaaaaaaaaaaa, 0, 0,\n" - " bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb};"); + verifyFormat("aaaaaaaaaaaaaaa = {aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa,\n" + " 00000000,\n" + " 00000000,\n" + " bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb};"); verifyNoCrash("a<,"); Index: unittests/Format/FormatTestComments.cpp =================================================================== --- unittests/Format/FormatTestComments.cpp +++ unittests/Format/FormatTestComments.cpp @@ -1032,16 +1032,31 @@ " aaaaaaaaaaaaaaaaaaaa , // comment\n" " aaaaaaaaaaaaaaaaaaaa };")); verifyFormat("static SomeType type = {aaaaaaaaaaa, // comment for aa...\n" - " bbbbbbbbbbb, ccccccccccc};"); + " bbbbbbbbbbb,\n" + " ccccccccccc};"); + verifyFormat("static SomeType type{aaaaaaaaaaa, // comment for aa...\n" + " bbbbbbbbbbb, ccccccccccc};"); verifyFormat("static SomeType type = {aaaaaaaaaaa,\n" " // comment for bb....\n" - " bbbbbbbbbbb, ccccccccccc};"); + " bbbbbbbbbbb,\n" + " ccccccccccc};"); + verifyFormat("static SomeType type{aaaaaaaaaaa,\n" + " // comment for bb....\n" + " bbbbbbbbbbb, ccccccccccc};"); verifyGoogleFormat( "static SomeType type = {aaaaaaaaaaa, // comment for aa...\n" - " bbbbbbbbbbb, ccccccccccc};"); + " bbbbbbbbbbb,\n" + " ccccccccccc};"); + verifyGoogleFormat( + "static SomeType type{aaaaaaaaaaa, // comment for aa...\n" + " bbbbbbbbbbb, ccccccccccc};"); verifyGoogleFormat("static SomeType type = {aaaaaaaaaaa,\n" " // comment for bb....\n" - " bbbbbbbbbbb, ccccccccccc};"); + " bbbbbbbbbbb,\n" + " ccccccccccc};"); + verifyGoogleFormat("static SomeType type{aaaaaaaaaaa,\n" + " // comment for bb....\n" + " bbbbbbbbbbb, ccccccccccc};"); verifyFormat("S s = {{a, b, c}, // Group #1\n" " {d, e, f}, // Group #2\n"