r183096 - Fix line-breaking problem caused by comment.
Daniel Jasper
djasper at google.com
Mon Jun 3 01:42:06 PDT 2013
Author: djasper
Date: Mon Jun 3 03:42:05 2013
New Revision: 183096
URL: http://llvm.org/viewvc/llvm-project?rev=183096&view=rev
Log:
Fix line-breaking problem caused by comment.
Before, clang-format would not find a solution for formatting:
if ((aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa ||
bbbbbbbbbbbbbbbbbb) && // aaaaaaaaaaaaaaaa
cccccc) {
}
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=183096&r1=183095&r2=183096&view=diff
==============================================================================
--- cfe/trunk/lib/Format/Format.cpp (original)
+++ cfe/trunk/lib/Format/Format.cpp Mon Jun 3 03:42:05 2013
@@ -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)
Modified: cfe/trunk/unittests/Format/FormatTest.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTest.cpp?rev=183096&r1=183095&r2=183096&view=diff
==============================================================================
--- cfe/trunk/unittests/Format/FormatTest.cpp (original)
+++ cfe/trunk/unittests/Format/FormatTest.cpp Mon Jun 3 03:42:05 2013
@@ -1991,6 +1991,10 @@ TEST_F(FormatTest, LineBreakingInBinaryE
" TheLine.Last->FormatTok.Tok.getLocation()) -\n"
" 1);");
+ verifyFormat("if ((aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa ||\n"
+ " bbbbbbbbbbbbbbbbbb) && // aaaaaaaaaaaaaaaa\n"
+ " cccccc) {\n}");
+
FormatStyle OnePerLine = getLLVMStyle();
OnePerLine.BinPackParameters = false;
verifyFormat(
More information about the cfe-commits
mailing list