Skip to content
This repository was archived by the owner on Nov 1, 2021. It is now read-only.

Commit 3afc8a3

Browse files
committed
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
1 parent b0e39fe commit 3afc8a3

File tree

2 files changed

+11
-5
lines changed

2 files changed

+11
-5
lines changed

Diff for: lib/Format/ContinuationIndenter.cpp

+5-5
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,11 @@ bool ContinuationIndenter::mustBreak(const LineState &State) {
191191
Current.NestingLevel < State.StartOfLineLevel))
192192
return true;
193193

194+
if (startsSegmentOfBuilderTypeCall(Current) &&
195+
(State.Stack.back().CallContinuation != 0 ||
196+
State.Stack.back().BreakBeforeParameter))
197+
return true;
198+
194199
if (State.Column <= NewLineColumn)
195200
return false;
196201

@@ -255,11 +260,6 @@ bool ContinuationIndenter::mustBreak(const LineState &State) {
255260
!Previous.is(tok::kw_template) && State.Stack.back().BreakBeforeParameter)
256261
return true;
257262

258-
if (startsSegmentOfBuilderTypeCall(Current) &&
259-
(State.Stack.back().CallContinuation != 0 ||
260-
State.Stack.back().BreakBeforeParameter))
261-
return true;
262-
263263
// The following could be precomputed as they do not depend on the state.
264264
// However, as they should take effect only if the UnwrappedLine does not fit
265265
// into the ColumnLimit, they are checked here in the ContinuationIndenter.

Diff for: unittests/Format/FormatTest.cpp

+6
Original file line numberDiff line numberDiff line change
@@ -3438,6 +3438,12 @@ TEST_F(FormatTest, LineBreakingInBinaryExpressions) {
34383438
" aaaaaaaaaaaaaaaaaaaaaaaaaaaa || aaaaaaaaaaaaaaaaaaaaaaaaaaaa ||\n"
34393439
" aaaaaaaaaaaaaaaaaaaaaaaaaaaa) {\n}",
34403440
OnePerLine);
3441+
3442+
verifyFormat("int i = someFunction(aaaaaaa, 0)\n"
3443+
" .aaa(aaaaaaaaaaaaa) *\n"
3444+
" aaaaaaa +\n"
3445+
" aaaaaaa;",
3446+
getLLVMStyleWithColumns(40));
34413447
}
34423448

34433449
TEST_F(FormatTest, ExpressionIndentation) {

0 commit comments

Comments
 (0)