summaryrefslogtreecommitdiffstats
path: root/clang
diff options
context:
space:
mode:
authorDaniel Jasper <djasper@google.com>2013-05-28 07:42:44 +0000
committerDaniel Jasper <djasper@google.com>2013-05-28 07:42:44 +0000
commit9f82df295e59bcdef10b93e541b164ebccfe6bb2 (patch)
treee72dc64cf5b50e66119e442bc52a28c250b113a5 /clang
parent02dc6a1451a44fb11722fbc633237f8f18063792 (diff)
downloadbcm5719-llvm-9f82df295e59bcdef10b93e541b164ebccfe6bb2.tar.gz
bcm5719-llvm-9f82df295e59bcdef10b93e541b164ebccfe6bb2.zip
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
Diffstat (limited to 'clang')
-rw-r--r--clang/lib/Format/Format.cpp1
-rw-r--r--clang/unittests/Format/FormatTest.cpp3
2 files changed, 4 insertions, 0 deletions
diff --git a/clang/lib/Format/Format.cpp b/clang/lib/Format/Format.cpp
index ea8a0f9f7d1..f244792e521 100644
--- a/clang/lib/Format/Format.cpp
+++ b/clang/lib/Format/Format.cpp
@@ -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)
diff --git a/clang/unittests/Format/FormatTest.cpp b/clang/unittests/Format/FormatTest.cpp
index fd9678c3527..d39a8a40934 100644
--- a/clang/unittests/Format/FormatTest.cpp
+++ b/clang/unittests/Format/FormatTest.cpp
@@ -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"
OpenPOWER on IntegriCloud