diff --git a/lib/Format/UnwrappedLineParser.cpp b/lib/Format/UnwrappedLineParser.cpp index 6e18ad352af4b5c10edec5339399718fe1b180dd..dbd8d9dbc1b6dddfed6687cdca6a32f9ca51f4a3 100644 --- a/lib/Format/UnwrappedLineParser.cpp +++ b/lib/Format/UnwrappedLineParser.cpp @@ -641,9 +641,6 @@ void UnwrappedLineParser::parseStructuralElement() { case tok::kw_case: parseCaseLabel(); return; - case tok::kw_return: - parseReturn(); - return; case tok::kw_extern: nextToken(); if (FormatTok->Tok.is(tok::string_literal)) { @@ -890,40 +887,6 @@ bool UnwrappedLineParser::parseBracedList(bool ContinueOnSemicolons) { return false; } -void UnwrappedLineParser::parseReturn() { - nextToken(); - - do { - switch (FormatTok->Tok.getKind()) { - case tok::l_brace: - parseBracedList(); - if (FormatTok->Tok.isNot(tok::semi)) { - // Assume missing ';'. - addUnwrappedLine(); - return; - } - break; - case tok::l_paren: - parseParens(); - break; - case tok::r_brace: - // Assume missing ';'. - addUnwrappedLine(); - return; - case tok::semi: - nextToken(); - addUnwrappedLine(); - return; - case tok::l_square: - tryToParseLambda(); - break; - default: - nextToken(); - break; - } - } while (!eof()); -} - void UnwrappedLineParser::parseParens() { assert(FormatTok->Tok.is(tok::l_paren) && "'(' expected."); nextToken(); diff --git a/lib/Format/UnwrappedLineParser.h b/lib/Format/UnwrappedLineParser.h index a235960c7996bf1d9034e195964c94917ebe6511..ce48de2d4f5c7233bedc27d8fe7c210d337d971e 100644 --- a/lib/Format/UnwrappedLineParser.h +++ b/lib/Format/UnwrappedLineParser.h @@ -82,7 +82,6 @@ private: void parseStructuralElement(); bool tryToParseBracedList(); bool parseBracedList(bool ContinueOnSemicolons = false); - void parseReturn(); void parseParens(); void parseSquare(); void parseIfThenElse(); diff --git a/unittests/Format/FormatTest.cpp b/unittests/Format/FormatTest.cpp index 7b3ea6e2f81af2374750e407eeaa19cc9129e389..54a13b6e1a0b62897bdf71462a3f2cd8d42f7915 100644 --- a/unittests/Format/FormatTest.cpp +++ b/unittests/Format/FormatTest.cpp @@ -6479,14 +6479,18 @@ TEST_F(FormatTest, DoNotCreateUnreasonableUnwrappedLines) { verifyFormat("void f() {\n" " return g() {}\n" " void h() {}"); - verifyFormat("if (foo)\n" - " return { forgot_closing_brace();\n" - "test();"); verifyFormat("int a[] = { void forgot_closing_brace() { f();\n" "g();\n" "}"); } +TEST_F(FormatTest, DoNotPrematurelyEndUnwrappedLineForReturnStatements) { + verifyFormat( + "void f() {\n" + " return C{ param1, param2 }.SomeCall(param1, param2);\n" + "}\n"); +} + TEST_F(FormatTest, FormatsClosingBracesInEmptyNestedBlocks) { verifyFormat("class X {\n" " void f() {\n"