r195418 - clang-format: Fix bug in alignment of complex template parameters.

Daniel Jasper djasper at google.com
Thu Nov 21 23:48:15 PST 2013


Author: djasper
Date: Fri Nov 22 01:48:15 2013
New Revision: 195418

URL: http://llvm.org/viewvc/llvm-project?rev=195418&view=rev
Log:
clang-format: Fix bug in alignment of complex template parameters.

Before:
  template <typename aaaaaaaaaaa, typename bbbbbbbbbbbbb, template <typename>
            class cccccccccccccccccccccc, typename ddddddddddddd>
  class C {};

After:
  template <typename aaaaaaaaaaa, typename bbbbbbbbbbbbb,
            template <typename> class cccccccccccccccccccccc,
            typename ddddddddddddd>
  class C {};

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=195418&r1=195417&r2=195418&view=diff
==============================================================================
--- cfe/trunk/lib/Format/ContinuationIndenter.cpp (original)
+++ cfe/trunk/lib/Format/ContinuationIndenter.cpp Fri Nov 22 01:48:15 2013
@@ -375,7 +375,8 @@ unsigned ContinuationIndenter::addTokenO
               State.ParenLevel == 0 &&
               (!Style.IndentFunctionDeclarationAfterType ||
                State.Line->StartsDefinition))) {
-    State.Column = State.Stack.back().Indent;
+    State.Column =
+        std::max(State.Stack.back().LastSpace, State.Stack.back().Indent);
   } else if (Current.Type == TT_ObjCSelectorName) {
     if (State.Stack.back().ColonPos == 0) {
       State.Stack.back().ColonPos =

Modified: cfe/trunk/unittests/Format/FormatTest.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTest.cpp?rev=195418&r1=195417&r2=195418&view=diff
==============================================================================
--- cfe/trunk/unittests/Format/FormatTest.cpp (original)
+++ cfe/trunk/unittests/Format/FormatTest.cpp Fri Nov 22 01:48:15 2013
@@ -3882,6 +3882,10 @@ TEST_F(FormatTest, WrapsTemplateDeclarat
       "template <typename T1, typename T2 = char, typename T3 = char,\n"
       "          typename T4 = char>\n"
       "void f();");
+  verifyFormat("template <typename aaaaaaaaaaa, typename bbbbbbbbbbbbb,\n"
+               "          template <typename> class cccccccccccccccccccccc,\n"
+               "          typename ddddddddddddd>\n"
+               "class C {};");
   verifyFormat(
       "aaaaaaaaaaaaaaaaaaaaaaaa<aaaaaaaaaaaaaaaaa, aaaaaaaaaaaaaaaaa>(\n"
       "    aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa);");





More information about the cfe-commits mailing list