diff options
| author | Daniel Jasper <djasper@google.com> | 2014-04-03 12:00:33 +0000 |
|---|---|---|
| committer | Daniel Jasper <djasper@google.com> | 2014-04-03 12:00:33 +0000 |
| commit | 5c33265c9e85bb9ce7d37be40c6ac870be720c5f (patch) | |
| tree | 0f8a42c4927cf9835f87ee1b4af7899315344b52 /clang | |
| parent | 2b7556ec1632eb587c9dc7a7d40a4eae8703083a (diff) | |
| download | bcm5719-llvm-5c33265c9e85bb9ce7d37be40c6ac870be720c5f.tar.gz bcm5719-llvm-5c33265c9e85bb9ce7d37be40c6ac870be720c5f.zip | |
clang-format: Prefer an additional line-break over hanging indent.
Don't allow the RHS of an operator to be split over multiple
lines unless there is a line-break right after the operator.
Before:
if (aaaa && bbbbb || // break
cccc) {
}
After:
if (aaaa &&
bbbbb || // break
cccc) {
}
In most cases, this seems to increase readability.
llvm-svn: 205527
Diffstat (limited to 'clang')
| -rw-r--r-- | clang/lib/Format/ContinuationIndenter.cpp | 12 | ||||
| -rw-r--r-- | clang/unittests/Format/FormatTest.cpp | 5 |
2 files changed, 15 insertions, 2 deletions
diff --git a/clang/lib/Format/ContinuationIndenter.cpp b/clang/lib/Format/ContinuationIndenter.cpp index 38086379fe7..5a3dee63870 100644 --- a/clang/lib/Format/ContinuationIndenter.cpp +++ b/clang/lib/Format/ContinuationIndenter.cpp @@ -609,6 +609,18 @@ unsigned ContinuationIndenter::moveStateToNextToken(LineState &State, std::max(std::max(State.Column, NewParenState.Indent), State.Stack.back().LastSpace); + // Don't allow the RHS of an operator to be split over multiple lines unless + // there is a line-break right after the operator. + // Exclude relational operators, as there, it is always more desirable to + // have the LHS 'left' of the RHS. + // FIXME: Implement this for '<<' and BreakBeforeBinaryOperators. + if (!Newline && Previous && Previous->Type == TT_BinaryOperator && + !Previous->isOneOf(tok::lessless, tok::question, tok::colon) && + Previous->getPrecedence() > prec::Assignment && + Previous->getPrecedence() != prec::Relational && + !Style.BreakBeforeBinaryOperators) + NewParenState.NoLineBreak = true; + // Do not indent relative to the fake parentheses inserted for "." or "->". // This is a special case to make the following to statements consistent: // OuterFunction(InnerFunctionCall( // break diff --git a/clang/unittests/Format/FormatTest.cpp b/clang/unittests/Format/FormatTest.cpp index 5395fd98923..76062605f70 100644 --- a/clang/unittests/Format/FormatTest.cpp +++ b/clang/unittests/Format/FormatTest.cpp @@ -2889,8 +2889,9 @@ TEST_F(FormatTest, ExpressionIndentation) { " aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa +\n" " bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb) {\n}"); verifyFormat("if () {\n" - "} else if (aaaaa && bbbbb > // break\n" - " ccccc) {\n" + "} else if (aaaaa &&\n" + " bbbbb > // break\n" + " ccccc) {\n" "}"); // Presence of a trailing comment used to change indentation of b. |

