diff --git a/lib/Format/Format.cpp b/lib/Format/Format.cpp index 7d4048f10498224cce2abef3edc49472afb1342e..d408b3862b1efc5b48d49789a90b143039f1195b 100644 --- a/lib/Format/Format.cpp +++ b/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/lib/Format/TokenAnnotator.cpp b/lib/Format/TokenAnnotator.cpp index c725f5097e21325042213b15b1a091f405e7abf6..e3cd2105e63756470b17f699cec2748233aa525a 100644 --- a/lib/Format/TokenAnnotator.cpp +++ b/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/unittests/Format/FormatTest.cpp b/unittests/Format/FormatTest.cpp index 6e9516da252ba99628a7f4e74fc9191d10002bfc..0f4600305872f5d92511686ed1a0cdbde314dff2 100644 --- a/unittests/Format/FormatTest.cpp +++ b/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) {