Skip to content
Snippets Groups Projects
Commit 2f0a020d authored by Daniel Jasper's avatar Daniel Jasper
Browse files

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.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@190126 91177308-0d34-0410-b5e6-96231b3b80d8
parent 1ae74842
No related branches found
No related tags found
No related merge requests found
...@@ -520,7 +520,7 @@ private: ...@@ -520,7 +520,7 @@ private:
LBrace.Children.size() == 0) LBrace.Children.size() == 0)
// The previous token does not open a block. Nothing to do. We don't // 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. // assert so that we can simply call this function for all tokens.
return true; return true;
if (NewLine) { if (NewLine) {
unsigned ParentIndent = State.Stack.back().Indent; unsigned ParentIndent = State.Stack.back().Indent;
...@@ -624,7 +624,7 @@ private: ...@@ -624,7 +624,7 @@ private:
++FormatTok->NewlinesBefore; ++FormatTok->NewlinesBefore;
// FIXME: This is technically incorrect, as it could also // FIXME: This is technically incorrect, as it could also
// be a literal backslash at the end of the line. // 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->HasUnescapedNewline = true;
FormatTok->LastNewlineOffset = WhitespaceLength + i + 1; FormatTok->LastNewlineOffset = WhitespaceLength + i + 1;
Column = 0; Column = 0;
......
...@@ -1137,7 +1137,8 @@ unsigned TokenAnnotator::splitPenalty(const AnnotatedLine &Line, ...@@ -1137,7 +1137,8 @@ unsigned TokenAnnotator::splitPenalty(const AnnotatedLine &Line,
return 2; return 2;
if (Right.isMemberAccess()) { 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 20; // Should be smaller than breaking at a nested comma.
return 150; return 150;
} }
......
...@@ -2970,6 +2970,10 @@ TEST_F(FormatTest, FormatsBuilderPattern) { ...@@ -2970,6 +2970,10 @@ TEST_F(FormatTest, FormatsBuilderPattern) {
verifyFormat("aaaaaaaaaaaaa->aaaaaaaaaaaaaaaaaaaaaaaa()\n" verifyFormat("aaaaaaaaaaaaa->aaaaaaaaaaaaaaaaaaaaaaaa()\n"
" ->aaaaaaaaaaaaaae(0)\n" " ->aaaaaaaaaaaaaae(0)\n"
" ->aaaaaaaaaaaaaaa();"); " ->aaaaaaaaaaaaaaa();");
// Prefer not to break after empty parentheses.
verifyFormat("FirstToken->WhitespaceRange.getBegin().getLocWithOffset(\n"
" First->LastNewlineOffset);");
} }
TEST_F(FormatTest, BreaksAccordingToOperatorPrecedence) { TEST_F(FormatTest, BreaksAccordingToOperatorPrecedence) {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment