From: Daniel Jasper Date: Tue, 2 Feb 2016 10:28:11 +0000 (+0000) Subject: clang-format: Make AlignAfterOpenBracket also affect angle brackets. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=2b9f6f3342bd454ccf0918a2c8c11d28f27ca42e;p=clang clang-format: Make AlignAfterOpenBracket also affect angle brackets. Patch by Matthew Whitehead, thank you. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@259487 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Format/ContinuationIndenter.cpp b/lib/Format/ContinuationIndenter.cpp index 76a458db9b..fa51f05543 100644 --- a/lib/Format/ContinuationIndenter.cpp +++ b/lib/Format/ContinuationIndenter.cpp @@ -353,7 +353,8 @@ void ContinuationIndenter::addTokenOnCurrentLine(LineState &State, bool DryRun, // 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.is(tok::l_paren) && State.Column > getNewLineColumn(State) && + Previous.isOneOf(tok::l_paren, TT_TemplateOpener, tok::l_square) && + State.Column > getNewLineColumn(State) && (!Previous.Previous || !Previous.Previous->isOneOf(tok::kw_for, tok::kw_while, tok::kw_switch))) State.Stack.back().NoLineBreak = true; diff --git a/unittests/Format/FormatTest.cpp b/unittests/Format/FormatTest.cpp index ad35539850..6ffeb65280 100644 --- a/unittests/Format/FormatTest.cpp +++ b/unittests/Format/FormatTest.cpp @@ -10325,6 +10325,15 @@ TEST_F(FormatTest, ConstructorInitializerIndentWidth) { ": aaaaaaaaaaaaa(aaaaaaaaaaaaaa), aaaaaaaaaaaaa(aaaaaaaaaaaaaa),\n" " aaaaaaaaaaaaa(aaaaaaaaaaaaaa) {}", Style); + Style.AlignAfterOpenBracket = FormatStyle::BAS_AlwaysBreak; + verifyFormat( + "SomeLongTemplateVariableName<\n" + " aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa, aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa>", + Style); + verifyFormat( + "bool smaller = 1 < bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb(\n" + " aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa);", + Style); } TEST_F(FormatTest, BreakConstructorInitializersBeforeComma) {