From: Daniel Jasper Date: Tue, 11 Mar 2014 11:03:26 +0000 (+0000) Subject: clang-format: Avoid unnecessary break before lambda return type. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=ff4bb588943f0bf05c17415b7e440a81f73bbce7;p=clang clang-format: Avoid unnecessary break before lambda return type. Before: auto aaaaaaaa = [](int i, // break int j) -> int { return fffffffffffffffffffffffffffffffffffffff(i * j); }; After: auto aaaaaaaa = [](int i, // break int j) -> int { return fffffffffffffffffffffffffffffffffffffff(i * j); }; git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@203562 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Format/ContinuationIndenter.cpp b/lib/Format/ContinuationIndenter.cpp index ed5ce4a21e..a96f1680db 100644 --- a/lib/Format/ContinuationIndenter.cpp +++ b/lib/Format/ContinuationIndenter.cpp @@ -108,7 +108,8 @@ bool ContinuationIndenter::canBreak(const LineState &State) { // SomeParameter, OtherParameter).DoSomething( // ... // As they hide "DoSomething" and are generally bad for readability. - if (Previous.opensScope() && State.LowestLevelOnLine < State.StartOfLineLevel) + if (Previous.opensScope() && Previous.isNot(tok::l_brace) && + State.LowestLevelOnLine < State.StartOfLineLevel) return false; if (Current.isMemberAccess() && State.Stack.back().ContainsUnwrappedBuilder) return false; diff --git a/unittests/Format/FormatTest.cpp b/unittests/Format/FormatTest.cpp index c6968bcef9..78aa3ce7c8 100644 --- a/unittests/Format/FormatTest.cpp +++ b/unittests/Format/FormatTest.cpp @@ -7974,6 +7974,10 @@ TEST_F(FormatTest, FormatsLambdas) { verifyFormat("int c = []() -> int { return 2; }();\n"); verifyFormat("int c = []() -> vector { return {2}; }();\n"); verifyFormat("Foo([]() -> std::vector { return {2}; }());"); + verifyFormat("auto aaaaaaaa = [](int i, // break for some reason\n" + " int j) -> int {\n" + " return fffffffffffffffffffffffffffffffffffffff(i * j);\n" + "};"); // Not lambdas. verifyFormat("constexpr char hello[]{\"hello\"};");