[cfe-commits] r171966 - in /cfe/trunk: lib/Format/Format.cpp unittests/Format/FormatTest.cpp

Daniel Jasper djasper at google.com
Wed Jan 9 02:40:24 PST 2013


Author: djasper
Date: Wed Jan  9 04:40:23 2013
New Revision: 171966

URL: http://llvm.org/viewvc/llvm-project?rev=171966&view=rev
Log:
Only align after assignments on the top level.

This fixes llvm.org/PR14870 and we no longer mess up:
template <typename T1, typename T2 = char, typename T3 = char,
          typename T4 = char>
void f();

It removes the nice aligment for assignments inside other expressions,
but I am not sure those are actually practically relevant. If so, we can
fix those later.

Modified:
    cfe/trunk/lib/Format/Format.cpp
    cfe/trunk/unittests/Format/FormatTest.cpp

Modified: cfe/trunk/lib/Format/Format.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/Format.cpp?rev=171966&r1=171965&r2=171966&view=diff
==============================================================================
--- cfe/trunk/lib/Format/Format.cpp (original)
+++ cfe/trunk/lib/Format/Format.cpp Wed Jan  9 04:40:23 2013
@@ -333,7 +333,9 @@
       if (!DryRun)
         replaceWhitespace(Current, 0, Spaces);
 
-      if (RootToken.isNot(tok::kw_for) &&
+      // FIXME: Do we need to do this for assignments nested in other
+      // expressions?
+      if (RootToken.isNot(tok::kw_for) && ParenLevel == 0 &&
           (getPrecedence(Previous) == prec::Assignment ||
            Previous.is(tok::kw_return)))
         State.Indent[ParenLevel] = State.Column + Spaces;

Modified: cfe/trunk/unittests/Format/FormatTest.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTest.cpp?rev=171966&r1=171965&r2=171966&view=diff
==============================================================================
--- cfe/trunk/unittests/Format/FormatTest.cpp (original)
+++ cfe/trunk/unittests/Format/FormatTest.cpp Wed Jan  9 04:40:23 2013
@@ -816,8 +816,9 @@
       "}");
 
   verifyFormat(
+      // FIXME: Does an expression like this ever make sense? If yes, fix.
       "if (int aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa = 100000000 +\n"
-      "                                                           10000000) {\n"
+      "    10000000) {\n"
       "}");
 }
 
@@ -872,7 +873,10 @@
   verifyFormat("template <typename T>\n"
                "void aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa(\n"
                "    int aaaaaaaaaaaaaaaaa);");
-
+  verifyFormat(
+      "template <typename T1, typename T2 = char, typename T3 = char,\n"
+      "          typename T4 = char>\n"
+      "void f();");
 }
 
 TEST_F(FormatTest, UnderstandsTemplateParameters) {





More information about the cfe-commits mailing list