From 4ff1e1c912f0ea30846e8b88270771ad8433d770 Mon Sep 17 00:00:00 2001 From: Daniel Jasper Date: Fri, 8 Aug 2014 12:00:13 +0000 Subject: [PATCH] clang-format: Prefer not to put lambdas on a single line. Before: string abc = SomeFunction(aaaaaaaaaaaaa, aaaaa, []() { SomeOtherFunctioooooooooooooooooooooooooon(); }); After: string abc = SomeFunction(aaaaaaaaaaaaa, aaaaa, []() { SomeOtherFunctioooooooooooooooooooooooooon(); }); git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@215197 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Format/TokenAnnotator.cpp | 2 ++ unittests/Format/FormatTest.cpp | 3 +++ 2 files changed, 5 insertions(+) diff --git a/lib/Format/TokenAnnotator.cpp b/lib/Format/TokenAnnotator.cpp index 54644ad768..f817224e19 100644 --- a/lib/Format/TokenAnnotator.cpp +++ b/lib/Format/TokenAnnotator.cpp @@ -1420,6 +1420,8 @@ unsigned TokenAnnotator::splitPenalty(const AnnotatedLine &Line, return 100; if (Left.is(tok::equal) && InFunctionDecl) return 110; + if (Right.is(tok::r_brace)) + return 1; if (Left.opensScope()) return Left.ParameterCount > 1 ? Style.PenaltyBreakBeforeFirstCallParameter : 19; diff --git a/unittests/Format/FormatTest.cpp b/unittests/Format/FormatTest.cpp index bd55c9ef21..a171066fa3 100644 --- a/unittests/Format/FormatTest.cpp +++ b/unittests/Format/FormatTest.cpp @@ -8819,6 +8819,9 @@ TEST_F(FormatTest, FormatsLambdas) { "}"); verifyFormat("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa(\n" " [](const aaaaaaaaaa &a) { return a; });"); + verifyFormat("string abc = SomeFunction(aaaaaaaaaaaaa, aaaaa, []() {\n" + " SomeOtherFunctioooooooooooooooooooooooooon();\n" + "});"); // Lambdas with return types. verifyFormat("int c = []() -> int { return 2; }();\n"); -- 2.40.0