]> granicus.if.org Git - clang/commitdiff
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>();
  }

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@220202 91177308-0d34-0410-b5e6-96231b3b80d8

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

index 33627e5a95a150dc7f900c05db1b47015fdc6cb4..76de3884a9013a4545a23c6ddd7b928ec9a7719b 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 a16ee2cb2f5b85f5913fa50542ac06adf1048129..79e5ab1182659702ffec8fd6ecdf74dceb1138b3 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>>();");