Index: lib/Format/TokenAnnotator.cpp =================================================================== --- lib/Format/TokenAnnotator.cpp +++ lib/Format/TokenAnnotator.cpp @@ -2180,6 +2180,9 @@ if (Left.opensScope()) { if (Style.AlignAfterOpenBracket == FormatStyle::BAS_DontAlign) return 0; + if (Left.Previous && Left.Previous->is(tok::equal) && + !Style.Cpp11BracedListStyle) + return 19; return Left.ParameterCount > 1 ? Style.PenaltyBreakBeforeFirstCallParameter : 19; } @@ -2863,6 +2866,9 @@ if (Left.is(tok::equal) && !Right.isOneOf(tok::kw_default, tok::kw_delete) && Line.Type == LT_VirtualFunctionDecl && Left.NestingLevel == 0) return false; + if (Left.is(tok::equal) && Right.is(tok::l_brace) && + !Style.Cpp11BracedListStyle) + return false; if (Left.is(tok::l_paren) && Left.is(TT_AttributeParen)) return false; if (Left.is(tok::l_paren) && Left.Previous && Index: unittests/Format/FormatTest.cpp =================================================================== --- unittests/Format/FormatTest.cpp +++ unittests/Format/FormatTest.cpp @@ -6650,6 +6650,15 @@ "};"); verifyFormat("#define A {a, a},"); + // Avoid breaking between equal sign and opening brace + FormatStyle AvoidBreakingFirstArgument = getLLVMStyle(); + AvoidBreakingFirstArgument.PenaltyBreakBeforeFirstCallParameter = 200; + verifyFormat("const std::unordered_map MyHashTable =\n" + " {{\"aaaaaaaaaaaaaaaaaaaaa\", 0},\n" + " {\"bbbbbbbbbbbbbbbbbbbbb\", 1},\n" + " {\"ccccccccccccccccccccc\", 2}};", + AvoidBreakingFirstArgument); + // Binpacking only if there is no trailing comma verifyFormat("const Aaaaaa aaaaa = {aaaaaaaaaa, bbbbbbbbbb,\n" " cccccccccc, dddddddddd};", @@ -6806,6 +6815,15 @@ verifyFormat("vector foo = { ::SomeGlobalFunction() };", ExtraSpaces); verifyFormat("const struct A a = { .a = 1, .b = 2 };", ExtraSpaces); verifyFormat("const struct A a = { [0] = 1, [1] = 2 };", ExtraSpaces); + + // Avoid breaking between equal sign and opening brace + ExtraSpaces.PenaltyBreakBeforeFirstCallParameter = 200; + verifyFormat("const std::unordered_map MyHashTable = {\n" + " { \"aaaaaaaaaaaaaaaaaaaaa\", 0 },\n" + " { \"bbbbbbbbbbbbbbbbbbbbb\", 1 },\n" + " { \"ccccccccccccccccccccc\", 2 }\n" + "};", + ExtraSpaces); } TEST_F(FormatTest, FormatsBracedListsInColumnLayout) {