]> granicus.if.org Git - clang/commitdiff
Fix formatting of expressions containing ">>".
authorDaniel Jasper <djasper@google.com>
Tue, 28 May 2013 07:42:44 +0000 (07:42 +0000)
committerDaniel Jasper <djasper@google.com>
Tue, 28 May 2013 07:42:44 +0000 (07:42 +0000)
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;

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@182754 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Format/Format.cpp
unittests/Format/FormatTest.cpp

index ea8a0f9f7d10386f1ad3e67a76d93483026c758c..f244792e521f13864082b9312b8da94c280abfdf 100644 (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)
index fd9678c3527c7fabd86b007576f75b054a7fc6cb..d39a8a4093416621dbc59240657e6fd27d08cbc9 100644 (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"