r187458 - clang-format: Improve detection of templates.

Daniel Jasper djasper at google.com
Tue Jul 30 15:37:19 PDT 2013


Author: djasper
Date: Tue Jul 30 17:37:19 2013
New Revision: 187458

URL: http://llvm.org/viewvc/llvm-project?rev=187458&view=rev
Log:
clang-format: Improve detection of templates.

Before:
  template <typename... Types>
        typename enable_if < 0<sizeof...(Types)>::type Foo() {}
After:
  template <typename... Types>
  typename enable_if<0 < sizeof...(Types)>::type Foo() {}

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=187458&r1=187457&r2=187458&view=diff
==============================================================================
--- cfe/trunk/lib/Format/TokenAnnotator.cpp (original)
+++ cfe/trunk/lib/Format/TokenAnnotator.cpp Tue Jul 30 17:37:19 2013
@@ -360,7 +360,7 @@ private:
         return false;
       break;
     case tok::less:
-      if (parseAngle())
+      if (Tok->Previous && !Tok->Previous->Tok.isLiteral() && parseAngle())
         Tok->Type = TT_TemplateOpener;
       else {
         Tok->Type = TT_BinaryOperator;

Modified: cfe/trunk/unittests/Format/FormatTest.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTest.cpp?rev=187458&r1=187457&r2=187458&view=diff
==============================================================================
--- cfe/trunk/unittests/Format/FormatTest.cpp (original)
+++ cfe/trunk/unittests/Format/FormatTest.cpp Tue Jul 30 17:37:19 2013
@@ -3372,6 +3372,8 @@ TEST_F(FormatTest, UnderstandsTemplatePa
                "  while (a < b && c > d) {\n"
                "  }\n"
                "}");
+  verifyFormat("template <typename... Types>\n"
+               "typename enable_if<0 < sizeof...(Types)>::type Foo() {}");
 }
 
 TEST_F(FormatTest, UnderstandsBinaryOperators) {
@@ -4107,7 +4109,7 @@ TEST_F(FormatTest, UnderstandContextOfRe
       "    : Implementation(new ImplicitCastMatcher<F>(Other)) {}");
 
   // FIXME: This is still incorrectly handled at the formatter side.
-  verifyFormat("template <> struct X < 15, i < 3 && 42 < 50 && 33<28> {};");
+  verifyFormat("template <> struct X < 15, i<3 && 42 < 50 && 33 < 28> {};");
 
   // FIXME:
   // This now gets parsed incorrectly as class definition.





More information about the cfe-commits mailing list