r182754 - Fix formatting of expressions containing ">>".

Daniel Jasper djasper at google.com
Tue May 28 00:42:45 PDT 2013


Author: djasper
Date: Tue May 28 02:42:44 2013
New Revision: 182754

URL: http://llvm.org/viewvc/llvm-project?rev=182754&view=rev
Log:
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;

Modified:
    cfe/trunk/lib/Format/Format.cpp
    cfe/trunk/unittests/Format/FormatTest.cpp

Modified: cfe/trunk/lib/Format/Format.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/Format.cpp?rev=182754&r1=182753&r2=182754&view=diff
==============================================================================
--- cfe/trunk/lib/Format/Format.cpp (original)
+++ cfe/trunk/lib/Format/Format.cpp Tue May 28 02:42:44 2013
@@ -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)

Modified: cfe/trunk/unittests/Format/FormatTest.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTest.cpp?rev=182754&r1=182753&r2=182754&view=diff
==============================================================================
--- cfe/trunk/unittests/Format/FormatTest.cpp (original)
+++ cfe/trunk/unittests/Format/FormatTest.cpp Tue May 28 02:42:44 2013
@@ -1921,6 +1921,9 @@ TEST_F(FormatTest, LineBreakingInBinaryE
   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"





More information about the cfe-commits mailing list