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);

llvm-svn: 181585
This commit is contained in:
Daniel Jasper 2013-05-10 07:59:58 +00:00
parent 7500ab2464
commit 8f9624b3bc
3 changed files with 7 additions and 1 deletions

View 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();

View File

@ -45,6 +45,7 @@ enum TokenType {
TT_ObjCMethodSpecifier,
TT_ObjCProperty,
TT_ObjCSelectorName,
TT_OverloadedOperator,
TT_OverloadedOperatorLParen,
TT_PointerOrReference,
TT_PureVirtualSpecifier,

View 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"