]> granicus.if.org Git - clang/commitdiff
clang-format: Do not use two-argument/operand special case with no alignment
authorDaniel Jasper <djasper@google.com>
Thu, 2 Feb 2017 08:30:21 +0000 (08:30 +0000)
committerDaniel Jasper <djasper@google.com>
Thu, 2 Feb 2017 08:30:21 +0000 (08:30 +0000)
Without alignment, there is no clean separation between the arguments, even if
there are only two.

Before:
  aaaaaaaaaaaaaa(
      aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa +
          aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa);

After:
  aaaaaaaaaaaaaa(aaaaaaaaaaaa,
                 aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa +
                     aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa);

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@293875 91177308-0d34-0410-b5e6-96231b3b80d8

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

index a7eb82ad56fde392f05939c0490f4423ed3430b5..3a100651cababdc04154705401b6752f4a586eaf 100644 (file)
@@ -429,7 +429,7 @@ void ContinuationIndenter::addTokenOnCurrentLine(LineState &State, bool DryRun,
     // does not help.
     bool HasTwoOperands =
         P->OperatorIndex == 0 && !P->NextOperator && !P->is(TT_ConditionalExpr);
-    if ((!BreakBeforeOperator && !HasTwoOperands) ||
+    if ((!BreakBeforeOperator && !(HasTwoOperands && Style.AlignOperands)) ||
         (!State.Stack.back().LastOperatorWrapped && BreakBeforeOperator))
       State.Stack.back().NoLineBreakInOperand = true;
   }
index cb0d7b32972b364d6ea2ca03e962702103591561..1a11425be21e0b1c5abe44abb5c0b37d99e2993a 100644 (file)
@@ -4163,6 +4163,10 @@ TEST_F(FormatTest, EnforcedOperatorWraps) {
 TEST_F(FormatTest, NoOperandAlignment) {
   FormatStyle Style = getLLVMStyle();
   Style.AlignOperands = false;
+  verifyFormat("aaaaaaaaaaaaaa(aaaaaaaaaaaa,\n"
+               "               aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa +\n"
+               "                   aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa);",
+               Style);
   Style.BreakBeforeBinaryOperators = FormatStyle::BOS_NonAssignment;
   verifyFormat("bool value = aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\n"
                "            + aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\n"