Fix formatting of expressions containing ">>".

This gets turned into two ">" operators at the beginning in order to
simplify template parameter handling. Thus, we need a special case to
handle those two binary operators correctly.

With this patch, clang-format can now correctly handle cases like:
aaaaaa = aaaaaaa(aaaaaaa, // break
                 aaaaaa) >>
         bbbbbb;

llvm-svn: 182754
This commit is contained in:
Daniel Jasper 2013-05-28 07:42:44 +00:00
parent 02dc6a1451
commit 9f82df295e
2 changed files with 4 additions and 0 deletions

View File

@ -1040,6 +1040,7 @@ private:
// If we need to break somewhere inside the LHS of a binary expression, we
// should also break after the operator.
if (Previous.Type == TT_BinaryOperator &&
Current.Type != TT_BinaryOperator && // Special case for ">>".
!Previous.isOneOf(tok::lessless, tok::question) &&
getPrecedence(Previous) != prec::Assignment &&
State.Stack.back().BreakBeforeParameter)

View File

@ -1921,6 +1921,9 @@ TEST_F(FormatTest, LineBreakingInBinaryExpressions) {
verifyFormat("aaaaaa = aaaaaaa(aaaaaaa, // break\n"
" aaaaaa) &&\n"
" bbbbbb && cccccc;");
verifyFormat("aaaaaa = aaaaaaa(aaaaaaa, // break\n"
" aaaaaa) >>\n"
" bbbbbb;");
verifyFormat("Whitespaces.addUntouchableComment(\n"
" SourceMgr.getSpellingColumnNumber(\n"
" TheLine.Last->FormatTok.Tok.getLocation()) -\n"