Index: lib/Format/ContinuationIndenter.cpp =================================================================== --- lib/Format/ContinuationIndenter.cpp +++ lib/Format/ContinuationIndenter.cpp @@ -399,7 +399,9 @@ // }.bind(...)); // FIXME: We should find a more generic solution to this problem. !(State.Column <= NewLineColumn && - Style.Language == FormatStyle::LK_JavaScript)) + Style.Language == FormatStyle::LK_JavaScript) && + !(Previous.closesScopeAfterBlock() && + State.Column <= NewLineColumn)) return true; // If the template declaration spans multiple lines, force wrap before the Index: lib/Format/FormatToken.h =================================================================== --- lib/Format/FormatToken.h +++ lib/Format/FormatToken.h @@ -319,6 +319,14 @@ } template bool isNot(T Kind) const { return !is(Kind); } + bool closesScopeAfterBlock() const { + if(BlockKind == BK_Block) + return true; + if(closesScope()) + return Previous->closesScopeAfterBlock(); + return false; + } + /// \c true if this token starts a sequence with the given tokens in order, /// following the ``Next`` pointers, ignoring comments. template Index: unittests/Format/FormatTest.cpp =================================================================== --- unittests/Format/FormatTest.cpp +++ unittests/Format/FormatTest.cpp @@ -4416,6 +4416,71 @@ verifyFormat("aaaa.aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa(\n" " aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa)\n" " .aaaaaa(aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa);"); + + // Dont break if only closing statements before member call + verifyFormat("test() {\n" + " ([]() -> {\n" + " int b = 32;\n" + " return 3;\n" + " }).foo();\n" + "}"); + verifyFormat("test() {\n" + " (\n" + " []() -> {\n" + " int b = 32;\n" + " return 3;\n" + " },\n" + " foo, bar)\n" + " .foo();\n" + "}"); + verifyFormat("test() {\n" + " ([]() -> {\n" + " int b = 32;\n" + " return 3;\n" + " })\n" + " .foo()\n" + " .bar();\n" + "}"); + verifyFormat("test() {\n" + " ([]() -> {\n" + " int b = 32;\n" + " return 3;\n" + " })\n" + " .foo(\"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\"\n" + " \"bbbbbbbbbbbbbbbbbbbbbb\");\n" + "}"); + + verifyFormat("test() {\n" + " foo([]() -> {\n" + " int b = 32;\n" + " return 3;\n" + " }).foo();\n" + "}"); + verifyFormat("test() {\n" + " foo(\n" + " []() -> {\n" + " int b = 32;\n" + " return 3;\n" + " },\n" + " foo, bar)\n" + " .as();\n" + "}"); + verifyFormat("test() {\n" + " foo([]() -> {\n" + " int b = 32;\n" + " return 3;\n" + " })\n" + " .foo()\n" + " .bar();\n" + "}"); + verifyFormat("test() {\n" + " foo([]() -> {\n" + " int b = 32;\n" + " return 3;\n" + " })\n" + " .as(\"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\"\n" + " \"bbbbbbbbbbbbbbbbbbbbbb\");\n" + "}"); } TEST_F(FormatTest, BreaksAccordingToOperatorPrecedence) {