From: Daniel Jasper Date: Wed, 28 Aug 2013 07:27:35 +0000 (+0000) Subject: clang-format: Fix corner case in overloaded operator definitions. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=c476ea976badd316e3afd0f34afe1f030a710117;p=clang clang-format: Fix corner case in overloaded operator definitions. Before: SomeLoooooooooooooooooooooooooogType operator> >(const SomeLooooooooooooooooooooooooogType &other); SomeLoooooooooooooooooooooooooogType // break operator>>(const SomeLooooooooooooooooooooooooogType &other); After: SomeLoooooooooooooooooooooooooogType operator>>(const SomeLooooooooooooooooooooooooogType &other); SomeLoooooooooooooooooooooooooogType // break operator>>(const SomeLooooooooooooooooooooooooogType &other); This fixes llvm.org/PR16328. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@189450 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Format/TokenAnnotator.cpp b/lib/Format/TokenAnnotator.cpp index ee476b952e..bec589d572 100644 --- a/lib/Format/TokenAnnotator.cpp +++ b/lib/Format/TokenAnnotator.cpp @@ -393,6 +393,8 @@ private: if (CurrentToken->isOneOf(tok::star, tok::amp)) CurrentToken->Type = TT_PointerOrReference; consumeToken(); + if (CurrentToken->Previous->Type == TT_BinaryOperator) + CurrentToken->Previous->Type = TT_OverloadedOperator; } if (CurrentToken) { CurrentToken->Type = TT_OverloadedOperatorLParen; @@ -1319,7 +1321,8 @@ bool TokenAnnotator::canBreakBefore(const AnnotatedLine &Line, Right.is(tok::question)) return true; if (Right.Type == TT_RangeBasedForLoopColon || - Right.Type == TT_OverloadedOperatorLParen) + Right.Type == TT_OverloadedOperatorLParen || + Right.Type == TT_OverloadedOperator) return false; if (Left.Type == TT_RangeBasedForLoopColon) return true; diff --git a/unittests/Format/FormatTest.cpp b/unittests/Format/FormatTest.cpp index 5002c9ce80..51ada26a20 100644 --- a/unittests/Format/FormatTest.cpp +++ b/unittests/Format/FormatTest.cpp @@ -2610,6 +2610,8 @@ TEST_F(FormatTest, BreaksFunctionDeclarations) { // Treat overloaded operators like other functions. verifyFormat("SomeLoooooooooooooooooooooooooogType\n" "operator>(const SomeLoooooooooooooooooooooooooogType &other);"); + verifyFormat("SomeLoooooooooooooooooooooooooogType\n" + "operator>>(const SomeLooooooooooooooooooooooooogType &other);"); verifyGoogleFormat( "SomeLoooooooooooooooooooooooooooooogType operator<<(\n" " const SomeLooooooooogType &a, const SomeLooooooooogType &b);");