summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDaniel Jasper <djasper@google.com>2015-01-08 08:48:21 +0000
committerDaniel Jasper <djasper@google.com>2015-01-08 08:48:21 +0000
commitb13135bc08df6b3ccf82ce8f0240508625a86d88 (patch)
treed6b5672a8ceaae19fcf0dc37668e17f880d88c9a
parent0c4d51b7790682bc45f8e9d4691da421e7d542ef (diff)
downloadbcm5719-llvm-b13135bc08df6b3ccf82ce8f0240508625a86d88.tar.gz
bcm5719-llvm-b13135bc08df6b3ccf82ce8f0240508625a86d88.zip
clang-format: Improve template parameter detection.
Before: struct A < std::enable_if<sizeof(T2) <sizeof(int32)>::type>; After: struct A<std::enable_if<sizeof(T2) < sizeof(int32)>::type>; llvm-svn: 225435
-rw-r--r--clang/lib/Format/TokenAnnotator.cpp7
-rw-r--r--clang/unittests/Format/FormatTest.cpp1
2 files changed, 6 insertions, 2 deletions
diff --git a/clang/lib/Format/TokenAnnotator.cpp b/clang/lib/Format/TokenAnnotator.cpp
index 8966ab2484b..23c1fcd2129 100644
--- a/clang/lib/Format/TokenAnnotator.cpp
+++ b/clang/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/clang/unittests/Format/FormatTest.cpp b/clang/unittests/Format/FormatTest.cpp
index fc49bde7140..1ecaf090e2e 100644
--- a/clang/unittests/Format/FormatTest.cpp
+++ b/clang/unittests/Format/FormatTest.cpp
@@ -4939,6 +4939,7 @@ TEST_F(FormatTest, UnderstandsTemplateParameters) {
verifyFormat("f<int>();");
verifyFormat("template <typename T> void f() {}");
+ verifyFormat("struct A<std::enable_if<sizeof(T2) < sizeof(int32)>::type>;");
// Not template parameters.
verifyFormat("return a < b && c > d;");
OpenPOWER on IntegriCloud