From a2fb50f9b3eefae4146d001365a29d4a86c41fbe Mon Sep 17 00:00:00 2001 From: Daniel Jasper Date: Tue, 24 Jun 2014 09:15:49 +0000 Subject: [PATCH] clang-format: Understand that breaking before lambdas is fine. Before: aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa([]( const aaaaaaaaaa &a) { return a; }); After: aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa( [](const aaaaaaaaaa &a) { return a; }); llvm-svn: 211575 --- clang/lib/Format/TokenAnnotator.cpp | 2 +- clang/unittests/Format/FormatTest.cpp | 4 +++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/clang/lib/Format/TokenAnnotator.cpp b/clang/lib/Format/TokenAnnotator.cpp index 3793fe0..0760f35 100644 --- a/clang/lib/Format/TokenAnnotator.cpp +++ b/clang/lib/Format/TokenAnnotator.cpp @@ -1315,7 +1315,7 @@ unsigned TokenAnnotator::splitPenalty(const AnnotatedLine &Line, if (Right.is(tok::l_square)) { if (Style.Language == FormatStyle::LK_Proto) return 1; - if (Right.Type != TT_ObjCMethodExpr) + if (Right.Type != TT_ObjCMethodExpr && Right.Type != TT_LambdaLSquare) return 500; } if (Right.Type == TT_StartOfName || Right.is(tok::kw_operator)) { diff --git a/clang/unittests/Format/FormatTest.cpp b/clang/unittests/Format/FormatTest.cpp index 968e13b..11a42a51 100644 --- a/clang/unittests/Format/FormatTest.cpp +++ b/clang/unittests/Format/FormatTest.cpp @@ -8721,6 +8721,8 @@ TEST_F(FormatTest, FormatsLambdas) { verifyFormat("void f() {\n" " SomeFunction([](decltype(x), A *a) {});\n" "}"); + verifyFormat("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa(\n" + " [](const aaaaaaaaaa &a) { return a; });"); // Lambdas with return types. verifyFormat("int c = []() -> int { return 2; }();\n"); @@ -8728,7 +8730,7 @@ TEST_F(FormatTest, FormatsLambdas) { 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" + " return ffffffffffffffffffffffffffffffffffffffffffff(i * j);\n" "};"); // Multiple lambdas in the same parentheses change indentation rules. -- 2.7.4