summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDaniel Jasper <djasper@google.com>2013-06-03 08:42:05 +0000
committerDaniel Jasper <djasper@google.com>2013-06-03 08:42:05 +0000
commit68d888cfed6e6029d09c1b36a1013eca7d0c1094 (patch)
tree653fbfe6253bb411a4d7ce7a19910159a02f03ed
parent2d18790b3a201119cd0ca83813be70e3838f3c6d (diff)
downloadbcm5719-llvm-68d888cfed6e6029d09c1b36a1013eca7d0c1094.tar.gz
bcm5719-llvm-68d888cfed6e6029d09c1b36a1013eca7d0c1094.zip
Fix line-breaking problem caused by comment.
Before, clang-format would not find a solution for formatting: if ((aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa || bbbbbbbbbbbbbbbbbb) && // aaaaaaaaaaaaaaaa cccccc) { } llvm-svn: 183096
-rw-r--r--clang/lib/Format/Format.cpp1
-rw-r--r--clang/unittests/Format/FormatTest.cpp4
2 files changed, 5 insertions, 0 deletions
diff --git a/clang/lib/Format/Format.cpp b/clang/lib/Format/Format.cpp
index 3ae279216f8..e0142db554b 100644
--- a/clang/lib/Format/Format.cpp
+++ b/clang/lib/Format/Format.cpp
@@ -1040,6 +1040,7 @@ private:
// should also break after the operator.
if (Previous.Type == TT_BinaryOperator &&
Current.Type != TT_BinaryOperator && // Special case for ">>".
+ !Current.isTrailingComment() &&
!Previous.isOneOf(tok::lessless, tok::question) &&
Previous.getPrecedence() != prec::Assignment &&
State.Stack.back().BreakBeforeParameter)
diff --git a/clang/unittests/Format/FormatTest.cpp b/clang/unittests/Format/FormatTest.cpp
index 24e4769274f..98a6e07ab28 100644
--- a/clang/unittests/Format/FormatTest.cpp
+++ b/clang/unittests/Format/FormatTest.cpp
@@ -1991,6 +1991,10 @@ TEST_F(FormatTest, LineBreakingInBinaryExpressions) {
" TheLine.Last->FormatTok.Tok.getLocation()) -\n"
" 1);");
+ verifyFormat("if ((aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa ||\n"
+ " bbbbbbbbbbbbbbbbbb) && // aaaaaaaaaaaaaaaa\n"
+ " cccccc) {\n}");
+
FormatStyle OnePerLine = getLLVMStyle();
OnePerLine.BinPackParameters = false;
verifyFormat(
OpenPOWER on IntegriCloud