]> granicus.if.org Git - clang/commitdiff
clang-format: Don't indent relative to unary operators.
authorDaniel Jasper <djasper@google.com>
Wed, 5 Feb 2014 13:43:04 +0000 (13:43 +0000)
committerDaniel Jasper <djasper@google.com>
Wed, 5 Feb 2014 13:43:04 +0000 (13:43 +0000)
It seems like most people see unary operators more like part of the
subsequent identifier and find relative indentation odd.

Before:
  aaaaaaaaaa(!aaaaaaaaaa( // break
                  aaaaa));
After:
  aaaaaaaaaa(!aaaaaaaaaa( // break
                 aaaaa));

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

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

index 6db3ca98240ee89d050d3b727511836595687f1e..95cb54df9a635e44d9b361c4ed569d2c495a4a7c 100644 (file)
@@ -296,7 +296,6 @@ void ContinuationIndenter::addTokenOnCurrentLine(LineState &State, bool DryRun,
     State.Stack.back().LastSpace = State.Column;
   else if ((Previous.Type == TT_BinaryOperator ||
             Previous.Type == TT_ConditionalExpr ||
-            Previous.Type == TT_UnaryOperator ||
             Previous.Type == TT_CtorInitializerColon) &&
            (Previous.getPrecedence() != prec::Assignment ||
             Current.StartsBinaryExpression))
index 5de15e3c2b9235675838b2a1d18d3b58f7e5e004..0f112a13f19196003bf018fac329555c9860f60e 100644 (file)
@@ -4219,14 +4219,12 @@ TEST_F(FormatTest, UnderstandsUnaryOperators) {
   verifyFormat("int a = i /* confusing comment */++;");
 }
 
-TEST_F(FormatTest, IndentsRelativeToUnaryOperators) {
+TEST_F(FormatTest, DoesNotIndentRelativeToUnaryOperators) {
   verifyFormat("if (!aaaaaaaaaa( // break\n"
-               "         aaaaa)) {\n"
+               "        aaaaa)) {\n"
                "}");
   verifyFormat("aaaaaaaaaa(!aaaaaaaaaa( // break\n"
-               "                aaaaa));");
-
-  // Only indent relative to unary operators if the expression is nested.
+               "               aaaaa));");
   verifyFormat("*aaa = aaaaaaa( // break\n"
                "    bbbbbb);");
 }