From: Daniel Jasper Date: Wed, 15 May 2013 13:46:48 +0000 (+0000) Subject: Improve recognition of template definitions. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=5d823e3a00a3e21a0823288e6dee26a93758332b;p=clang Improve recognition of template definitions. In the long run, this will probably be better fixed by a proper expression parser.. Before: template Matcher(const Matcher & Other, typename enable_if_c < is_base_of::value && !is_same::value > ::type * = 0) : Implementation(new ImplicitCastMatcher(Other)) {} After: template Matcher(const Matcher & Other, typename enable_if_c::value && !is_same::value>::type * = 0) : Implementation(new ImplicitCastMatcher(Other)) {} git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@181884 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Format/TokenAnnotator.cpp b/lib/Format/TokenAnnotator.cpp index e0552de01d..21518c6824 100644 --- a/lib/Format/TokenAnnotator.cpp +++ b/lib/Format/TokenAnnotator.cpp @@ -101,8 +101,10 @@ private: return true; } if (CurrentToken->isOneOf(tok::r_paren, tok::r_square, tok::r_brace, - tok::pipepipe, tok::ampamp, tok::question, - tok::colon)) + tok::question, tok::colon)) + return false; + if (CurrentToken->isOneOf(tok::pipepipe, tok::ampamp) && + Line.First.isNot(tok::kw_template)) return false; updateParameterCount(Left, CurrentToken); if (!consumeToken()) diff --git a/unittests/Format/FormatTest.cpp b/unittests/Format/FormatTest.cpp index 20a32e740e..499388e6ba 100644 --- a/unittests/Format/FormatTest.cpp +++ b/unittests/Format/FormatTest.cpp @@ -3077,6 +3077,13 @@ TEST_F(FormatTest, UnderstandContextOfRecordTypeKeywords) { verifyFormat("class A::B::C {\n} n;"); // Template definitions. + verifyFormat( + "template \n" + "Matcher(const Matcher &Other,\n" + " typename enable_if_c::value &&\n" + " !is_same::value>::type * = 0)\n" + " : 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> {\n};");