Fix bug when formatting overloaded operators.
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
diff --git a/lib/Format/TokenAnnotator.cpp b/lib/Format/TokenAnnotator.cpp
index 75b173e..1203116 100644
--- a/lib/Format/TokenAnnotator.cpp
+++ b/lib/Format/TokenAnnotator.cpp
@@ -390,8 +390,11 @@
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();
diff --git a/lib/Format/TokenAnnotator.h b/lib/Format/TokenAnnotator.h
index a2080b5..5ea3015 100644
--- a/lib/Format/TokenAnnotator.h
+++ b/lib/Format/TokenAnnotator.h
@@ -45,6 +45,7 @@
TT_ObjCMethodSpecifier,
TT_ObjCProperty,
TT_ObjCSelectorName,
+ TT_OverloadedOperator,
TT_OverloadedOperatorLParen,
TT_PointerOrReference,
TT_PureVirtualSpecifier,
diff --git a/unittests/Format/FormatTest.cpp b/unittests/Format/FormatTest.cpp
index 9e6a609..30fea1c 100644
--- a/unittests/Format/FormatTest.cpp
+++ b/unittests/Format/FormatTest.cpp
@@ -2490,6 +2490,8 @@
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"