diff options
author | Daniel Jasper <djasper@google.com> | 2017-02-01 09:23:39 +0000 |
---|---|---|
committer | Daniel Jasper <djasper@google.com> | 2017-02-01 09:23:39 +0000 |
commit | 21f7dea5f568c1a78962be09df49b375f0ec03d1 (patch) | |
tree | d2dc498fdc63d1c53f5e7880a6116b3753d8e90d /clang/lib/Format/ContinuationIndenter.cpp | |
parent | 697507556a2f539b5fbb758441f7e3f177ee7cec (diff) | |
download | bcm5719-llvm-21f7dea5f568c1a78962be09df49b375f0ec03d1.tar.gz bcm5719-llvm-21f7dea5f568c1a78962be09df49b375f0ec03d1.zip |
clang-format: Don't force-wrap multiline RHSs for 2-operand experssions.
This rows back on r288120, r291801 and r292110. I apologize in advance
for the churn. All of those revisions where meant to make the wrapping
of RHS expressions more consistent. However, now that they are
consistent, we seem to be a bit too eager.
The reasoning here is that I think it is generally correct that we want
to line-wrap before multiline RHS expressions (or multiline arguments to
a function call). However, if there are only two of such operands or
arguments, there is always a clear vertical separation between them and
the additional line break seems much less desirable.
Somewhat good examples are expressions like:
EXPECT_EQ(2, someLongExpression(
orCall));
llvm-svn: 293752
Diffstat (limited to 'clang/lib/Format/ContinuationIndenter.cpp')
-rw-r--r-- | clang/lib/Format/ContinuationIndenter.cpp | 7 |
1 files changed, 6 insertions, 1 deletions
diff --git a/clang/lib/Format/ContinuationIndenter.cpp b/clang/lib/Format/ContinuationIndenter.cpp index 995ff06b540..176f4674aab 100644 --- a/clang/lib/Format/ContinuationIndenter.cpp +++ b/clang/lib/Format/ContinuationIndenter.cpp @@ -424,7 +424,12 @@ void ContinuationIndenter::addTokenOnCurrentLine(LineState &State, bool DryRun, (P->is(TT_BinaryOperator) && Style.BreakBeforeBinaryOperators != FormatStyle::BOS_None) || (P->is(TT_ConditionalExpr) && Style.BreakBeforeTernaryOperators); - if (!BreakBeforeOperator || + // Don't do this if there are only two operands. In these cases, there is + // always a nice vertical separation between them and the extra line break + // does not help. + bool HasTwoOperands = + P->OperatorIndex == 0 && !P->NextOperator && !P->is(TT_ConditionalExpr); + if ((!BreakBeforeOperator && !HasTwoOperands) || (!State.Stack.back().LastOperatorWrapped && BreakBeforeOperator)) State.Stack.back().NoLineBreakInOperand = true; } |