r188665 - clang-format: Fix return type line break decision.

Daniel Jasper djasper at google.com
Mon Aug 19 03:16:18 PDT 2013


Author: djasper
Date: Mon Aug 19 05:16:18 2013
New Revision: 188665

URL: http://llvm.org/viewvc/llvm-project?rev=188665&view=rev
Log:
clang-format: Fix return type line break decision.

This accidentally introduced by r186077, as function names were not
correctly recognized in templated declarations.

Before:
  template <class TemplateIt>
  SomeReturnType
  SomeFunction(TemplateIt begin, TemplateIt end, TemplateIt* stop) {}

After:
  template <class TemplateIt>
  SomeReturnType SomeFunction(TemplateIt begin, TemplateIt end,
                              TemplateIt* stop) {}

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

Modified: cfe/trunk/lib/Format/TokenAnnotator.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/TokenAnnotator.cpp?rev=188665&r1=188664&r2=188665&view=diff
==============================================================================
--- cfe/trunk/lib/Format/TokenAnnotator.cpp (original)
+++ cfe/trunk/lib/Format/TokenAnnotator.cpp Mon Aug 19 05:16:18 2013
@@ -717,9 +717,13 @@ private:
                        PreviousNotConst->Previous &&
                        PreviousNotConst->Previous->is(tok::hash);
 
+    if (PreviousNotConst->Type == TT_TemplateCloser)
+      return PreviousNotConst && PreviousNotConst->MatchingParen &&
+             PreviousNotConst->MatchingParen->Previous &&
+             PreviousNotConst->MatchingParen->Previous->isNot(tok::kw_template);
+
     return (!IsPPKeyword && PreviousNotConst->is(tok::identifier)) ||
            PreviousNotConst->Type == TT_PointerOrReference ||
-           PreviousNotConst->Type == TT_TemplateCloser ||
            isSimpleTypeSpecifier(*PreviousNotConst);
   }
 
@@ -1041,11 +1045,10 @@ unsigned TokenAnnotator::splitPenalty(co
       return 3;
     if (Left.Type == TT_StartOfName)
       return 20;
-    else if (Line.MightBeFunctionDecl && Right.BindingStrength == 1)
+    if (Line.MightBeFunctionDecl && Right.BindingStrength == 1)
       // FIXME: Clean up hack of using BindingStrength to find top-level names.
       return Style.PenaltyReturnTypeOnItsOwnLine;
-    else
-      return 200;
+    return 200;
   }
   if (Left.is(tok::equal) && Right.is(tok::l_brace))
     return 150;

Modified: cfe/trunk/unittests/Format/FormatTest.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTest.cpp?rev=188665&r1=188664&r2=188665&view=diff
==============================================================================
--- cfe/trunk/unittests/Format/FormatTest.cpp (original)
+++ cfe/trunk/unittests/Format/FormatTest.cpp Mon Aug 19 05:16:18 2013
@@ -2523,6 +2523,10 @@ TEST_F(FormatTest, BreaksFunctionDeclara
   // 1) break amongst arguments.
   verifyFormat("Aaaaaaaaaaaaaa bbbbbbbbbbbbbb(Cccccccccccccc cccccccccccccc,\n"
                "                              Cccccccccccccc cccccccccccccc);");
+  verifyFormat(
+      "template <class TemplateIt>\n"
+      "SomeReturnType SomeFunction(TemplateIt begin, TemplateIt end,\n"
+      "                            TemplateIt *stop) {}");
 
   // 2) break after return type.
   verifyFormat(
@@ -3859,12 +3863,11 @@ TEST_F(FormatTest, BreaksLongDeclaration
                "SomeLoooooooooooooooooooooongType<\n"
                "    typename some_namespace::SomeOtherType<A>::Type>\n"
                "Function() {}");
-  verifyFormat(
-      "aaaaaaaaaaaaaaaa::aaaaaaaaaaaaaaaa<aaaaaaaaaaaaa, aaaaaaaaaaaa>\n"
-      "    aaaaaaaaaaaaaaaaaaaaaaa;",
-      getGoogleStyle());
 
   verifyGoogleFormat(
+      "aaaaaaaaaaaaaaaa::aaaaaaaaaaaaaaaa<aaaaaaaaaaaaa, aaaaaaaaaaaa>\n"
+      "    aaaaaaaaaaaaaaaaaaaaaaa;");
+  verifyGoogleFormat(
       "TypeSpecDecl* TypeSpecDecl::Create(ASTContext& C, DeclContext* DC,\n"
       "                                   SourceLocation L) {}");
   verifyGoogleFormat(





More information about the cfe-commits mailing list