summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Jasper <djasper@google.com>2013-05-15 13:46:48 +0000
committerDaniel Jasper <djasper@google.com>2013-05-15 13:46:48 +0000
commit5d823e3a00a3e21a0823288e6dee26a93758332b (patch)
treedb8ef07e165452b99b30d647f890662455049588
parent0ff5074f37a66bca244a9d5d0da050ff68693ce2 (diff)
downloadclang-5d823e3a00a3e21a0823288e6dee26a93758332b.tar.gz
clang-5d823e3a00a3e21a0823288e6dee26a93758332b.tar.bz2
clang-5d823e3a00a3e21a0823288e6dee26a93758332b.tar.xz
Improve recognition of template definitions.
In the long run, this will probably be better fixed by a proper expression parser.. Before: template <typename F> Matcher(const Matcher<F> & Other, typename enable_if_c < is_base_of<F, T>::value && !is_same<F, T>::value > ::type * = 0) : Implementation(new ImplicitCastMatcher<F>(Other)) {} After: template <typename F> Matcher(const Matcher<F> & Other, typename enable_if_c<is_base_of<F, T>::value && !is_same<F, T>::value>::type * = 0) : Implementation(new ImplicitCastMatcher<F>(Other)) {} git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@181884 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--lib/Format/TokenAnnotator.cpp6
-rw-r--r--unittests/Format/FormatTest.cpp7
2 files changed, 11 insertions, 2 deletions
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 <typename F>\n"
+ "Matcher(const Matcher<F> &Other,\n"
+ " typename enable_if_c<is_base_of<F, T>::value &&\n"
+ " !is_same<F, T>::value>::type * = 0)\n"
+ " : 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> {\n};");