diff options
author | Daniel Jasper <djasper@google.com> | 2013-09-06 08:54:24 +0000 |
---|---|---|
committer | Daniel Jasper <djasper@google.com> | 2013-09-06 08:54:24 +0000 |
commit | 36c28ce38d98ac0bf8657d94ae3c477a158b33c7 (patch) | |
tree | 16b6162633ddce6e3eaf7069e90100b60f70a01d /clang | |
parent | 921e7650d42ba46a706f2eb2516cddf6ea5a5b81 (diff) | |
download | bcm5719-llvm-36c28ce38d98ac0bf8657d94ae3c477a158b33c7.tar.gz bcm5719-llvm-36c28ce38d98ac0bf8657d94ae3c477a158b33c7.zip |
clang-format: Fix regression introduced by r189353.
Before:
FirstToken->WhitespaceRange.getBegin()
.getLocWithOffset(First->LastNewlineOffset);
After:
FirstToken->WhitespaceRange.getBegin().getLocWithOffset(
First->LastNewlineOffset);
Re-add logic to prevent breaking after an empty set of parentheses.
Basically it seems that calling a function without parameters is more
like navigating along the same object than it is a separate step of a
builder-type call.
We might need to extends this in future to allow "short" parameters that
e.g. are an index accessing a specific element.
llvm-svn: 190126
Diffstat (limited to 'clang')
-rw-r--r-- | clang/lib/Format/Format.cpp | 4 | ||||
-rw-r--r-- | clang/lib/Format/TokenAnnotator.cpp | 3 | ||||
-rw-r--r-- | clang/unittests/Format/FormatTest.cpp | 4 |
3 files changed, 8 insertions, 3 deletions
diff --git a/clang/lib/Format/Format.cpp b/clang/lib/Format/Format.cpp index 7d4048f1049..d408b3862b1 100644 --- a/clang/lib/Format/Format.cpp +++ b/clang/lib/Format/Format.cpp @@ -520,7 +520,7 @@ private: LBrace.Children.size() == 0) // The previous token does not open a block. Nothing to do. We don't // assert so that we can simply call this function for all tokens. - return true; + return true; if (NewLine) { unsigned ParentIndent = State.Stack.back().Indent; @@ -624,7 +624,7 @@ private: ++FormatTok->NewlinesBefore; // FIXME: This is technically incorrect, as it could also // be a literal backslash at the end of the line. - if (i == 0 || FormatTok->TokenText[i-1] != '\\') + if (i == 0 || FormatTok->TokenText[i - 1] != '\\') FormatTok->HasUnescapedNewline = true; FormatTok->LastNewlineOffset = WhitespaceLength + i + 1; Column = 0; diff --git a/clang/lib/Format/TokenAnnotator.cpp b/clang/lib/Format/TokenAnnotator.cpp index c725f5097e2..e3cd2105e63 100644 --- a/clang/lib/Format/TokenAnnotator.cpp +++ b/clang/lib/Format/TokenAnnotator.cpp @@ -1137,7 +1137,8 @@ unsigned TokenAnnotator::splitPenalty(const AnnotatedLine &Line, return 2; if (Right.isMemberAccess()) { - if (Left.isOneOf(tok::r_paren, tok::r_square)) + if (Left.isOneOf(tok::r_paren, tok::r_square) && Left.MatchingParen && + Left.MatchingParen->ParameterCount > 0) return 20; // Should be smaller than breaking at a nested comma. return 150; } diff --git a/clang/unittests/Format/FormatTest.cpp b/clang/unittests/Format/FormatTest.cpp index 6e9516da252..0f460030587 100644 --- a/clang/unittests/Format/FormatTest.cpp +++ b/clang/unittests/Format/FormatTest.cpp @@ -2970,6 +2970,10 @@ TEST_F(FormatTest, FormatsBuilderPattern) { verifyFormat("aaaaaaaaaaaaa->aaaaaaaaaaaaaaaaaaaaaaaa()\n" " ->aaaaaaaaaaaaaae(0)\n" " ->aaaaaaaaaaaaaaa();"); + + // Prefer not to break after empty parentheses. + verifyFormat("FirstToken->WhitespaceRange.getBegin().getLocWithOffset(\n" + " First->LastNewlineOffset);"); } TEST_F(FormatTest, BreaksAccordingToOperatorPrecedence) { |