From: Daniel Jasper Date: Thu, 8 Jan 2015 08:48:21 +0000 (+0000) Subject: clang-format: Improve template parameter detection. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=f64def2baa796369c519a1e63e33916b44b655ca;p=clang clang-format: Improve template parameter detection. Before: struct A < std::enable_if::type>; After: struct A::type>; git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@225435 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Format/TokenAnnotator.cpp b/lib/Format/TokenAnnotator.cpp index 8966ab2484..23c1fcd212 100644 --- a/lib/Format/TokenAnnotator.cpp +++ b/lib/Format/TokenAnnotator.cpp @@ -470,9 +470,12 @@ private: return false; break; case tok::less: - if ((!Tok->Previous || !Tok->Previous->Tok.isLiteral()) && parseAngle()) + if ((!Tok->Previous || + (!Tok->Previous->Tok.isLiteral() && + !(Tok->Previous->is(tok::r_paren) && Contexts.size() > 1))) && + parseAngle()) { Tok->Type = TT_TemplateOpener; - else { + } else { Tok->Type = TT_BinaryOperator; CurrentToken = Tok; next(); diff --git a/unittests/Format/FormatTest.cpp b/unittests/Format/FormatTest.cpp index fc49bde714..1ecaf090e2 100644 --- a/unittests/Format/FormatTest.cpp +++ b/unittests/Format/FormatTest.cpp @@ -4939,6 +4939,7 @@ TEST_F(FormatTest, UnderstandsTemplateParameters) { verifyFormat("f();"); verifyFormat("template void f() {}"); + verifyFormat("struct A::type>;"); // Not template parameters. verifyFormat("return a < b && c > d;");