From: Alexander Kornienko Date: Thu, 6 Mar 2014 15:13:08 +0000 (+0000) Subject: Fix operator<< recognition (PR19064). X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=a2d482a94385a3ca8ca2f736723b9ba7711af634;p=clang Fix operator<< recognition (PR19064). git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@203123 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Format/ContinuationIndenter.cpp b/lib/Format/ContinuationIndenter.cpp index 5ea2488395..b82726a6b8 100644 --- a/lib/Format/ContinuationIndenter.cpp +++ b/lib/Format/ContinuationIndenter.cpp @@ -174,7 +174,8 @@ bool ContinuationIndenter::mustBreak(const LineState &State) { } // Same as above, but for the first "<<" operator. - if (Current.is(tok::lessless) && State.Stack.back().BreakBeforeParameter && + if (Current.is(tok::lessless) && Current.Type != TT_OverloadedOperator && + State.Stack.back().BreakBeforeParameter && State.Stack.back().FirstLessLess == 0) return true; @@ -515,7 +516,8 @@ unsigned ContinuationIndenter::moveStateToNextToken(LineState &State, if (Current.Type == TT_InheritanceColon) State.Stack.back().AvoidBinPacking = true; - if (Current.is(tok::lessless) && State.Stack.back().FirstLessLess == 0) + if (Current.is(tok::lessless) && Current.Type != TT_OverloadedOperator && + State.Stack.back().FirstLessLess == 0) State.Stack.back().FirstLessLess = State.Column; if (Current.Type == TT_ArraySubscriptLSquare && State.Stack.back().StartOfArraySubscripts == 0) diff --git a/unittests/Format/FormatTest.cpp b/unittests/Format/FormatTest.cpp index a86776cff9..341fb3589a 100644 --- a/unittests/Format/FormatTest.cpp +++ b/unittests/Format/FormatTest.cpp @@ -3077,6 +3077,11 @@ TEST_F(FormatTest, BreaksFunctionDeclarations) { "operator>(const SomeLoooooooooooooooooooooooooogType &other);"); verifyFormat("SomeLoooooooooooooooooooooooooogType\n" "operator>>(const SomeLooooooooooooooooooooooooogType &other);"); + verifyFormat("SomeLoooooooooooooooooooooooooogType\n" + "operator<<(const SomeLooooooooooooooooooooooooogType &other);"); + verifyGoogleFormat( + "SomeLoooooooooooooooooooooooooooooogType operator>>(\n" + " const SomeLooooooooogType &a, const SomeLooooooooogType &b);"); verifyGoogleFormat( "SomeLoooooooooooooooooooooooooooooogType operator<<(\n" " const SomeLooooooooogType &a, const SomeLooooooooogType &b);");