From: Daniel Jasper Date: Tue, 30 Jul 2013 22:37:19 +0000 (+0000) Subject: clang-format: Improve detection of templates. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=0236dd09c040f2e6124654d620dde94a595c5ab0;p=clang clang-format: Improve detection of templates. Before: template typename enable_if < 0::type Foo() {} After: template typename enable_if<0 < sizeof...(Types)>::type Foo() {} git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@187458 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Format/TokenAnnotator.cpp b/lib/Format/TokenAnnotator.cpp index a7fa3ec239..b9d26ca521 100644 --- a/lib/Format/TokenAnnotator.cpp +++ b/lib/Format/TokenAnnotator.cpp @@ -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; diff --git a/unittests/Format/FormatTest.cpp b/unittests/Format/FormatTest.cpp index ebb7722a64..4a28cca222 100644 --- a/unittests/Format/FormatTest.cpp +++ b/unittests/Format/FormatTest.cpp @@ -3372,6 +3372,8 @@ TEST_F(FormatTest, UnderstandsTemplateParameters) { " while (a < b && c > d) {\n" " }\n" "}"); + verifyFormat("template \n" + "typename enable_if<0 < sizeof...(Types)>::type Foo() {}"); } TEST_F(FormatTest, UnderstandsBinaryOperators) { @@ -4107,7 +4109,7 @@ TEST_F(FormatTest, UnderstandContextOfRecordTypeKeywords) { " : Implementation(new ImplicitCastMatcher(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.