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
This commit is contained in:
Daniel Jasper 2015-01-08 08:48:21 +00:00
parent 0c4d51b779
commit b13135bc08
2 changed files with 6 additions and 2 deletions

View File

@ -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();

View File

@ -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;");