From 62c0ac0acfbd59b60b5c648b4af09601dc4dff3d Mon Sep 17 00:00:00 2001 From: Daniel Jasper Date: Tue, 30 Jul 2013 22:37:19 +0000 Subject: [PATCH] clang-format: Improve detection of templates. Before: template typename enable_if < 0::type Foo() {} After: template typename enable_if<0 < sizeof...(Types)>::type Foo() {} llvm-svn: 187458 --- clang/lib/Format/TokenAnnotator.cpp | 2 +- clang/unittests/Format/FormatTest.cpp | 4 +++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/clang/lib/Format/TokenAnnotator.cpp b/clang/lib/Format/TokenAnnotator.cpp index a7fa3ec..b9d26ca 100644 --- a/clang/lib/Format/TokenAnnotator.cpp +++ b/clang/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/clang/unittests/Format/FormatTest.cpp b/clang/unittests/Format/FormatTest.cpp index ebb7722..4a28cca2 100644 --- a/clang/unittests/Format/FormatTest.cpp +++ b/clang/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. -- 2.7.4