r200840 - clang-format: Don't indent relative to unary operators.

Daniel Jasper djasper at google.com
Wed Feb 5 05:43:04 PST 2014


Author: djasper
Date: Wed Feb  5 07:43:04 2014
New Revision: 200840

URL: http://llvm.org/viewvc/llvm-project?rev=200840&view=rev
Log:
clang-format: Don't indent relative to unary operators.

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));

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=200840&r1=200839&r2=200840&view=diff
==============================================================================
--- cfe/trunk/lib/Format/ContinuationIndenter.cpp (original)
+++ cfe/trunk/lib/Format/ContinuationIndenter.cpp Wed Feb  5 07:43:04 2014
@@ -296,7 +296,6 @@ void ContinuationIndenter::addTokenOnCur
     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))

Modified: cfe/trunk/unittests/Format/FormatTest.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTest.cpp?rev=200840&r1=200839&r2=200840&view=diff
==============================================================================
--- cfe/trunk/unittests/Format/FormatTest.cpp (original)
+++ cfe/trunk/unittests/Format/FormatTest.cpp Wed Feb  5 07:43:04 2014
@@ -4219,14 +4219,12 @@ TEST_F(FormatTest, UnderstandsUnaryOpera
   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);");
 }





More information about the cfe-commits mailing list