From: Daniel Jasper Date: Mon, 3 Jun 2013 08:42:05 +0000 (+0000) Subject: Fix line-breaking problem caused by comment. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=5ef8aacd5f25767fc7bd1ec47c2b5f5fd1ac38eb;p=clang Fix line-breaking problem caused by comment. Before, clang-format would not find a solution for formatting: if ((aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa || bbbbbbbbbbbbbbbbbb) && // aaaaaaaaaaaaaaaa cccccc) { } git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@183096 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Format/Format.cpp b/lib/Format/Format.cpp index 3ae279216f..e0142db554 100644 --- a/lib/Format/Format.cpp +++ b/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/unittests/Format/FormatTest.cpp b/unittests/Format/FormatTest.cpp index 24e4769274..98a6e07ab2 100644 --- a/unittests/Format/FormatTest.cpp +++ b/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(