From 6ea933c7e8f6988d5647af4a0eafd393a4c3685a Mon Sep 17 00:00:00 2001 From: Daniel Jasper Date: Fri, 10 May 2013 07:59:58 +0000 Subject: [PATCH] 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 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 | 5 ++++- lib/Format/TokenAnnotator.h | 1 + unittests/Format/FormatTest.cpp | 2 ++ 3 files changed, 7 insertions(+), 1 deletion(-) diff --git a/lib/Format/TokenAnnotator.cpp b/lib/Format/TokenAnnotator.cpp index 75b173ef4f..12031166e2 100644 --- a/lib/Format/TokenAnnotator.cpp +++ b/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/lib/Format/TokenAnnotator.h b/lib/Format/TokenAnnotator.h index a2080b5b6f..5ea30159a2 100644 --- a/lib/Format/TokenAnnotator.h +++ b/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/unittests/Format/FormatTest.cpp b/unittests/Format/FormatTest.cpp index 9e6a60961b..30fea1c067 100644 --- a/unittests/Format/FormatTest.cpp +++ b/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" -- 2.40.0