diff --git a/clang/lib/Format/TokenAnnotator.cpp b/clang/lib/Format/TokenAnnotator.cpp index 75b173ef4f46..12031166e234 100644 --- a/clang/lib/Format/TokenAnnotator.cpp +++ b/clang/lib/Format/TokenAnnotator.cpp @@ -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(); diff --git a/clang/lib/Format/TokenAnnotator.h b/clang/lib/Format/TokenAnnotator.h index a2080b5b6f30..5ea30159a2a0 100644 --- a/clang/lib/Format/TokenAnnotator.h +++ b/clang/lib/Format/TokenAnnotator.h @@ -45,6 +45,7 @@ enum TokenType { TT_ObjCMethodSpecifier, TT_ObjCProperty, TT_ObjCSelectorName, + TT_OverloadedOperator, TT_OverloadedOperatorLParen, TT_PointerOrReference, TT_PureVirtualSpecifier, diff --git a/clang/unittests/Format/FormatTest.cpp b/clang/unittests/Format/FormatTest.cpp index 9e6a60961bce..30fea1c06791 100644 --- a/clang/unittests/Format/FormatTest.cpp +++ b/clang/unittests/Format/FormatTest.cpp @@ -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 \n" + "AAAAAAA operator/(const AAAAAAA &a, BBBBBBB &b);"); verifyFormat( "ostream &operator<<(ostream &OutputStream,\n"