Index: lib/Format/ContinuationIndenter.cpp =================================================================== --- lib/Format/ContinuationIndenter.cpp +++ lib/Format/ContinuationIndenter.cpp @@ -607,7 +607,7 @@ // disallowing any further line breaks if there is no line break after the // opening parenthesis. Don't break if it doesn't conserve columns. if (Style.AlignAfterOpenBracket == FormatStyle::BAS_AlwaysBreak && - Previous.isOneOf(tok::l_paren, TT_TemplateOpener, tok::l_square) && + Previous.isOneOf(tok::l_paren, TT_TemplateOpener, tok::l_square, tok::l_brace) && State.Column > getNewLineColumn(State) && (!Previous.Previous || !Previous.Previous->isOneOf( tok::kw_for, tok::kw_while, tok::kw_switch)) && @@ -625,6 +625,7 @@ State.Stack.back().NoLineBreak = true; if (Style.AlignAfterOpenBracket != FormatStyle::BAS_DontAlign && + (!Style.isCpp() || Style.AlignAfterOpenBracket != FormatStyle::BAS_AlwaysBreak) && Previous.opensScope() && Previous.isNot(TT_ObjCMethodExpr) && (Current.isNot(TT_LineComment) || Previous.BlockKind == BK_BracedInit)) State.Stack.back().Indent = State.Column + Spaces; @@ -1217,12 +1218,14 @@ // Indent from 'LastSpace' unless these are fake parentheses encapsulating // a builder type call after 'return' or, if the alignment after opening // brackets is disabled. + const bool isAlignParametersMode = + Style.AlignAfterOpenBracket != FormatStyle::BAS_DontAlign && + Style.AlignAfterOpenBracket != FormatStyle::BAS_AlwaysBreak; if (!Current.isTrailingComment() && (Style.AlignOperands || *I < prec::Assignment) && (!Previous || Previous->isNot(tok::kw_return) || (Style.Language != FormatStyle::LK_Java && *I > 0)) && - (Style.AlignAfterOpenBracket != FormatStyle::BAS_DontAlign || - *I != prec::Comma || Current.NestingLevel == 0)) + (isAlignParametersMode || *I != prec::Comma || Current.NestingLevel == 0)) NewParenState.Indent = std::max(std::max(State.Column, NewParenState.Indent), State.Stack.back().LastSpace); Index: unittests/Format/FormatTest.cpp =================================================================== --- unittests/Format/FormatTest.cpp +++ unittests/Format/FormatTest.cpp @@ -7277,6 +7277,60 @@ verifyFormat("f({}, {{}, {}}, MyMap[{k, v}]);", SpaceBeforeBrace); } +TEST_F(FormatTest, Cpp11ListAlwaysBreakOrDontAlign) { + FormatStyle Style = getLLVMStyle(); + Style.AlignAfterOpenBracket = FormatStyle::BAS_AlwaysBreak; + Style.BinPackArguments = false; + Style.ColumnLimit = 40; + Style.Cpp11BracedListStyle = true; + + verifyFormat("type foobar_a{\n" + " aaaaaa,\n" + " bbbbbb,\n" + " cccccc,\n" + " dddddddddddddddddddddddddd,\n" + " eeeeeeeeeeeeeeeeeeeeeeeeee};", + Style); + + verifyFormat("type some_namespace::foobar_b{\n" + " a, abc, adbdef};", + Style); + + verifyFormat("type foobar_c{\n" + " an_int,\n" + " an_int,\n" + " an_int,\n" + " an_int,\n" + " an_int,\n" + " an_int,\n" + " an_int,\n" + " an_int};", + Style); + + Style.AlignAfterOpenBracket = FormatStyle::BAS_DontAlign; + + verifyFormat("type foobar_a{aaaaaa,\n" + " bbbbbb,\n" + " cccccc,\n" + " dddddddddddddddddddddddddd,\n" + " eeeeeeeeeeeeeeeeeeeeeeeeee};", + Style); + + verifyFormat("type some_namespace::foobar_b{\n" + " a, abc, adbdef};", + Style); + + verifyFormat("type foobar_c{an_int,\n" + " an_int,\n" + " an_int,\n" + " an_int,\n" + " an_int,\n" + " an_int,\n" + " an_int,\n" + " an_int};", + Style); +} + TEST_F(FormatTest, FormatsBracedListsInColumnLayout) { verifyFormat("vector x = {1, 22, 333, 4444, 55555, 666666, 7777777,\n" " 1, 22, 333, 4444, 55555, 666666, 7777777,\n"