r291974 - clang-format: Fix bug in making line break decisions.
Daniel Jasper via cfe-commits
cfe-commits at lists.llvm.org
Fri Jan 13 15:18:16 PST 2017
Author: djasper
Date: Fri Jan 13 17:18:16 2017
New Revision: 291974
URL: http://llvm.org/viewvc/llvm-project?rev=291974&view=rev
Log:
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;
Modified:
cfe/trunk/lib/Format/ContinuationIndenter.cpp
cfe/trunk/unittests/Format/FormatTest.cpp
Modified: cfe/trunk/lib/Format/ContinuationIndenter.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/ContinuationIndenter.cpp?rev=291974&r1=291973&r2=291974&view=diff
==============================================================================
--- cfe/trunk/lib/Format/ContinuationIndenter.cpp (original)
+++ cfe/trunk/lib/Format/ContinuationIndenter.cpp Fri Jan 13 17:18:16 2017
@@ -191,6 +191,11 @@ bool ContinuationIndenter::mustBreak(con
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(con
!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.
Modified: cfe/trunk/unittests/Format/FormatTest.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTest.cpp?rev=291974&r1=291973&r2=291974&view=diff
==============================================================================
--- cfe/trunk/unittests/Format/FormatTest.cpp (original)
+++ cfe/trunk/unittests/Format/FormatTest.cpp Fri Jan 13 17:18:16 2017
@@ -3438,6 +3438,12 @@ TEST_F(FormatTest, LineBreakingInBinaryE
" 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) {
More information about the cfe-commits
mailing list