From: Daniel Jasper Date: Fri, 13 Jan 2017 23:18:16 +0000 (+0000) Subject: clang-format: Fix bug in making line break decisions. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=3afc8a364ef241d20e839698fa852202f7b1cb2f;p=clang clang-format: Fix bug in making line break decisions. Here, the optimization to not line wrap when it would not lead to a reduction in columns was overwriting and enforced break that we want to do no matter what. Before: int i = someFunction( aaaaaaa, 0).aaa(aaaaaaaaaaaaa) * aaaaaaa + aaaaaaa; After: int i = someFunction(aaaaaaa, 0) .aaa(aaaaaaaaaaaaa) * aaaaaaa + aaaaaaa; git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@291974 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Format/ContinuationIndenter.cpp b/lib/Format/ContinuationIndenter.cpp index 6bb6fb3060..45522a8232 100644 --- a/lib/Format/ContinuationIndenter.cpp +++ b/lib/Format/ContinuationIndenter.cpp @@ -191,6 +191,11 @@ bool ContinuationIndenter::mustBreak(const LineState &State) { Current.NestingLevel < State.StartOfLineLevel)) return true; + if (startsSegmentOfBuilderTypeCall(Current) && + (State.Stack.back().CallContinuation != 0 || + State.Stack.back().BreakBeforeParameter)) + return true; + if (State.Column <= NewLineColumn) return false; @@ -255,11 +260,6 @@ bool ContinuationIndenter::mustBreak(const LineState &State) { !Previous.is(tok::kw_template) && State.Stack.back().BreakBeforeParameter) return true; - if (startsSegmentOfBuilderTypeCall(Current) && - (State.Stack.back().CallContinuation != 0 || - State.Stack.back().BreakBeforeParameter)) - return true; - // The following could be precomputed as they do not depend on the state. // However, as they should take effect only if the UnwrappedLine does not fit // into the ColumnLimit, they are checked here in the ContinuationIndenter. diff --git a/unittests/Format/FormatTest.cpp b/unittests/Format/FormatTest.cpp index b402b5c4a5..150f6077f2 100644 --- a/unittests/Format/FormatTest.cpp +++ b/unittests/Format/FormatTest.cpp @@ -3438,6 +3438,12 @@ TEST_F(FormatTest, LineBreakingInBinaryExpressions) { " aaaaaaaaaaaaaaaaaaaaaaaaaaaa || aaaaaaaaaaaaaaaaaaaaaaaaaaaa ||\n" " aaaaaaaaaaaaaaaaaaaaaaaaaaaa) {\n}", OnePerLine); + + verifyFormat("int i = someFunction(aaaaaaa, 0)\n" + " .aaa(aaaaaaaaaaaaa) *\n" + " aaaaaaa +\n" + " aaaaaaa;", + getLLVMStyleWithColumns(40)); } TEST_F(FormatTest, ExpressionIndentation) {