Make continuations in constructor initializers consistent.
authorDaniel Jasper <djasper@google.com>
Mon, 28 Jan 2013 13:31:35 +0000 (13:31 +0000)
committerDaniel Jasper <djasper@google.com>
Mon, 28 Jan 2013 13:31:35 +0000 (13:31 +0000)
Before:
Constructor
    : LooooooooooooooooooooongVariable(
        LooooooooooooooooooooongValue) {}

After:
Constructor
    : LooooooooooooooooooooongVariable(
          LooooooooooooooooooooongValue) {}

llvm-svn: 173685

clang/lib/Format/Format.cpp
clang/unittests/Format/FormatTest.cpp

index a6a53f4..27d4710 100644 (file)
@@ -625,7 +625,8 @@ private:
         // Top-level spaces are exempt as that mostly leads to better results.
         State.Stack.back().LastSpace = State.Column;
       else if ((Previous.Type == TT_BinaryOperator ||
-                Previous.Type == TT_ConditionalExpr) &&
+                Previous.Type == TT_ConditionalExpr ||
+                Previous.Type == TT_CtorInitializerColon) &&
                getPrecedence(Previous) != prec::Assignment)
         State.Stack.back().LastSpace = State.Column;
       else if (Previous.ParameterCount > 1 &&
index c143019..417dc9e 100644 (file)
@@ -924,6 +924,10 @@ TEST_F(FormatTest, ConstructorInitializers) {
                "                               aaaaaaaaaaaaaaaaaaaaaaaaaaa),\n"
                "      aaaaaaaaaaaaaaaaaaaaaaa() {\n}");
 
+  verifyFormat("Constructor()\n"
+               "    : aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa(\n"
+               "          aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa) {\n}");
+
   // Here a line could be saved by splitting the second initializer onto two
   // lines, but that is not desireable.
   verifyFormat(