]> granicus.if.org Git - clang/commitdiff
clang-format: Fix bug in making line break decisions.
authorDaniel Jasper <djasper@google.com>
Fri, 13 Jan 2017 23:18:16 +0000 (23:18 +0000)
committerDaniel Jasper <djasper@google.com>
Fri, 13 Jan 2017 23:18:16 +0000 (23:18 +0000)
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

lib/Format/ContinuationIndenter.cpp
unittests/Format/FormatTest.cpp

index 6bb6fb3060352f7ab16ad8d4bba40f3f8179261c..45522a8232270235d1ead782fa6d0128afcd876a 100644 (file)
@@ -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.
index b402b5c4a54c264bfa251de0743762b01aac56ce..150f6077f2149270ea69bda224afd565a718fde5 100644 (file)
@@ -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) {