]> granicus.if.org Git - clang/commitdiff
Fix bug when formatting overloaded operators.
authorDaniel Jasper <djasper@google.com>
Fri, 10 May 2013 07:59:58 +0000 (07:59 +0000)
committerDaniel Jasper <djasper@google.com>
Fri, 10 May 2013 07:59:58 +0000 (07:59 +0000)
Before, the actual operator of an overloaded operator declaration was
handled as a binary operator an thus, clang-format could not find valid
formattings for many examples, e.g.:

template <typename AAAAAAA, typename BBBBBBB>
AAAAAAA operator/(const AAAAAAA &a, BBBBBBB &b);

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

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

index 75b173ef4f464f9d0385e081143f7f874bd3275c..12031166e234ef9939a871c2188c8bc463b0abae 100644 (file)
@@ -390,8 +390,11 @@ private:
           CurrentToken->Type = TT_PointerOrReference;
         consumeToken();
       }
-      if (CurrentToken)
+      if (CurrentToken) {
         CurrentToken->Type = TT_OverloadedOperatorLParen;
+        if (CurrentToken->Parent->Type == TT_BinaryOperator)
+          CurrentToken->Parent->Type = TT_OverloadedOperator;
+      }
       break;
     case tok::question:
       parseConditional();
index a2080b5b6f3028c02122aeb30d80694549483e45..5ea30159a2a0d3b8b484800776c23055886393fe 100644 (file)
@@ -45,6 +45,7 @@ enum TokenType {
   TT_ObjCMethodSpecifier,
   TT_ObjCProperty,
   TT_ObjCSelectorName,
+  TT_OverloadedOperator,
   TT_OverloadedOperatorLParen,
   TT_PointerOrReference,
   TT_PureVirtualSpecifier,
index 9e6a60961bce7104636a054efa8f3e13327bebad..30fea1c0679185b498b35712fdec17e323e8f991 100644 (file)
@@ -2490,6 +2490,8 @@ TEST_F(FormatTest, UndestandsOverloadedOperators) {
   verifyFormat("void *operator new[](std::size_t size);");
   verifyFormat("void operator delete(void *ptr);");
   verifyFormat("void operator delete[](void *ptr);");
+  verifyFormat("template <typename AAAAAAA, typename BBBBBBB>\n"
+               "AAAAAAA operator/(const AAAAAAA &a, BBBBBBB &b);");
 
   verifyFormat(
       "ostream &operator<<(ostream &OutputStream,\n"