Index: lib/Format/ContinuationIndenter.cpp =================================================================== --- lib/Format/ContinuationIndenter.cpp +++ lib/Format/ContinuationIndenter.cpp @@ -1000,8 +1000,7 @@ Current.MatchingParen->Previous && Current.MatchingParen->Previous->is(tok::comma); AvoidBinPacking = - (Current.is(TT_ArrayInitializerLSquare) && EndsInComma) || - Current.is(TT_DictLiteral) || + EndsInComma || 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 @@ -5617,6 +5617,17 @@ "};"); verifyFormat("#define A {a, a},"); + // Binpacking only if there is no trailing comma + verifyFormat("const Aaaaaa aaaaa = {aaaaaaaaaa, bbbbbbbbbb,\n" + " cccccccccc, dddddddddd};", + getLLVMStyleWithColumns(50)); + verifyFormat("const Aaaaaa aaaaa = {\n" + " aaaaaaaaaaa,\n" + " bbbbbbbbbbb,\n" + " ccccccccccc,\n" + " ddddddddddd,\n" + "};", getLLVMStyleWithColumns(50)); + // Cases where distinguising braced lists and blocks is hard. verifyFormat("vector v{12} GUARDED_BY(mutex);"); verifyFormat("void f() {\n" @@ -5696,10 +5707,12 @@ " // Second element:\n" " 2};", getLLVMStyleWithColumns(30))); - // A trailing comma should still lead to an enforced line break. + // A trailing comma should still lead to an enforced line break and no + // binpacking. EXPECT_EQ("vector SomeVector = {\n" " // aaa\n" - " 1, 2,\n" + " 1,\n" + " 2,\n" "};", format("vector SomeVector = { // aaa\n" " 1, 2, };")); @@ -5784,7 +5797,7 @@ " 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" + " 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[] = {\n" @@ -5863,8 +5876,8 @@ " aaaaaaaaaaaa, a, aaaaaaaaaa, aaaaaaaaa, aaa}};"); // No column layout should be used here. - verifyFormat("aaaaaaaaaaaaaaa = {aaaaaaaaaaaaaaaaaaaaaaaaaaa, 0, 0,\n" - " bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb};"); + verifyFormat("aaaaaaaaaaaaaaa = {aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa, 0, 0,\n" + " bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb};"); verifyNoCrash("a<,");