r181585 - Fix bug when formatting overloaded operators.
Daniel Jasper
djasper at google.com
Fri May 10 00:59:58 PDT 2013
Author: djasper
Date: Fri May 10 02:59:58 2013
New Revision: 181585
URL: http://llvm.org/viewvc/llvm-project?rev=181585&view=rev
Log:
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);
Modified:
cfe/trunk/lib/Format/TokenAnnotator.cpp
cfe/trunk/lib/Format/TokenAnnotator.h
cfe/trunk/unittests/Format/FormatTest.cpp
Modified: cfe/trunk/lib/Format/TokenAnnotator.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/TokenAnnotator.cpp?rev=181585&r1=181584&r2=181585&view=diff
==============================================================================
--- cfe/trunk/lib/Format/TokenAnnotator.cpp (original)
+++ cfe/trunk/lib/Format/TokenAnnotator.cpp Fri May 10 02:59:58 2013
@@ -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();
Modified: cfe/trunk/lib/Format/TokenAnnotator.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/TokenAnnotator.h?rev=181585&r1=181584&r2=181585&view=diff
==============================================================================
--- cfe/trunk/lib/Format/TokenAnnotator.h (original)
+++ cfe/trunk/lib/Format/TokenAnnotator.h Fri May 10 02:59:58 2013
@@ -45,6 +45,7 @@ enum TokenType {
TT_ObjCMethodSpecifier,
TT_ObjCProperty,
TT_ObjCSelectorName,
+ TT_OverloadedOperator,
TT_OverloadedOperatorLParen,
TT_PointerOrReference,
TT_PureVirtualSpecifier,
Modified: cfe/trunk/unittests/Format/FormatTest.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTest.cpp?rev=181585&r1=181584&r2=181585&view=diff
==============================================================================
--- cfe/trunk/unittests/Format/FormatTest.cpp (original)
+++ cfe/trunk/unittests/Format/FormatTest.cpp Fri May 10 02:59:58 2013
@@ -2490,6 +2490,8 @@ TEST_F(FormatTest, UndestandsOverloadedO
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"
More information about the cfe-commits
mailing list