clang-format: Fix overloaded operator edge case.
authorDaniel Jasper <djasper@google.com>
Mon, 20 Oct 2014 13:56:30 +0000 (13:56 +0000)
committerDaniel Jasper <djasper@google.com>
Mon, 20 Oct 2014 13:56:30 +0000 (13:56 +0000)
Before:
  template <class F>
  void Call(F f) {
    f.template operator() <int>();
  }

After:
  template <class F>
  void Call(F f) {
    f.template operator()<int>();
  }

llvm-svn: 220202

clang/lib/Format/TokenAnnotator.cpp
clang/unittests/Format/FormatTest.cpp

index 33627e5..76de388 100644 (file)
@@ -1698,6 +1698,10 @@ bool TokenAnnotator::spaceRequiredBefore(const AnnotatedLine &Line,
     return true;
   if (Tok.Previous->Type == TT_TemplateCloser && Tok.is(tok::l_paren))
     return Style.SpaceBeforeParens == FormatStyle::SBPO_Always;
+  if (Tok.Type == TT_TemplateOpener && Tok.Previous->is(tok::r_paren) &&
+      Tok.Previous->MatchingParen &&
+      Tok.Previous->MatchingParen->Type == TT_OverloadedOperatorLParen)
+    return false;
   if (Tok.is(tok::less) && Tok.Previous->isNot(tok::l_paren) &&
       Line.First->is(tok::hash))
     return true;
index a16ee2c..79e5ab1 100644 (file)
@@ -4844,6 +4844,7 @@ TEST_F(FormatTest, UnderstandsOverloadedOperators) {
                "  return left.group < right.group;\n"
                "}");
   verifyFormat("SomeType &operator=(const SomeType &S);");
+  verifyFormat("f.template operator()<int>();");
 
   verifyGoogleFormat("operator void*();");
   verifyGoogleFormat("operator SomeType<SomeType<int>>();");