From: Daniel Jasper Date: Mon, 2 Mar 2015 10:35:13 +0000 (+0000) Subject: clang-format: Prefer wrapping a lambda's body over the lambda's return type. X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=e662316994ff7f90263c98e5213230fa7823e8d2;p=platform%2Fupstream%2Fllvm.git clang-format: Prefer wrapping a lambda's body over the lambda's return type. Before: aaaaaaaaaaaaaaaaaaaaaa( [](aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa &aaa) -> aaaaaaaaaaaaaaaaaaaaa { return aaaaaaaaaaaaaaaaa; }); After: aaaaaaaaaaaaaaaaaaaaaa( [](aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa &aaa) -> aaaaaaaaaaaaaaaaaaaaa { return aaaaaaaaaaaaaaaaa; }); llvm-svn: 230942 --- diff --git a/clang/lib/Format/TokenAnnotator.cpp b/clang/lib/Format/TokenAnnotator.cpp index 853a56b..1688568 100644 --- a/clang/lib/Format/TokenAnnotator.cpp +++ b/clang/lib/Format/TokenAnnotator.cpp @@ -1535,6 +1535,8 @@ unsigned TokenAnnotator::splitPenalty(const AnnotatedLine &Line, return Style.PenaltyReturnTypeOnItsOwnLine; return 200; } + if (Right.is(TT_TrailingReturnArrow)) + return 110; if (Left.is(tok::equal) && Right.is(tok::l_brace)) return 150; if (Left.is(TT_CastRParen)) diff --git a/clang/unittests/Format/FormatTest.cpp b/clang/unittests/Format/FormatTest.cpp index e763356..bfc601f 100644 --- a/clang/unittests/Format/FormatTest.cpp +++ b/clang/unittests/Format/FormatTest.cpp @@ -9537,6 +9537,12 @@ TEST_F(FormatTest, FormatsLambdas) { " int j) -> int {\n" " return ffffffffffffffffffffffffffffffffffffffffffff(i * j);\n" "};"); + verifyFormat( + "aaaaaaaaaaaaaaaaaaaaaa(\n" + " [](aaaaaaaaaaaaaaaaaaaaaaaaaaa &aaa) -> aaaaaaaaaaaaaaaa {\n" + " return aaaaaaaaaaaaaaaaa;\n" + " });", + getLLVMStyleWithColumns(70)); // Multiple lambdas in the same parentheses change indentation rules. verifyFormat("SomeFunction(\n"