diff options
| -rw-r--r-- | clang/lib/Format/TokenAnnotator.cpp | 3 | ||||
| -rw-r--r-- | clang/unittests/Format/FormatTest.cpp | 3 |
2 files changed, 6 insertions, 0 deletions
diff --git a/clang/lib/Format/TokenAnnotator.cpp b/clang/lib/Format/TokenAnnotator.cpp index 6cf3f1d5230..777de9bf1e3 100644 --- a/clang/lib/Format/TokenAnnotator.cpp +++ b/clang/lib/Format/TokenAnnotator.cpp @@ -1593,6 +1593,9 @@ unsigned TokenAnnotator::splitPenalty(const AnnotatedLine &Line, if (Right.is(tok::l_square)) { if (Style.Language == FormatStyle::LK_Proto) return 1; + // Slightly prefer formatting local lambda definitions like functions. + if (Right.is(TT_LambdaLSquare) && Left.is(tok::equal)) + return 50; if (!Right.isOneOf(TT_ObjCMethodExpr, TT_LambdaLSquare)) return 500; } diff --git a/clang/unittests/Format/FormatTest.cpp b/clang/unittests/Format/FormatTest.cpp index 371fa0f3d22..ecd78b24d09 100644 --- a/clang/unittests/Format/FormatTest.cpp +++ b/clang/unittests/Format/FormatTest.cpp @@ -9967,6 +9967,9 @@ TEST_F(FormatTest, FormatsLambdas) { " : Field([] { // comment\n" " int i;\n" " }) {}"); + verifyFormat("auto my_lambda = [](const string &some_parameter) {\n" + " return some_parameter.size();\n" + "};"); // Lambdas with return types. verifyFormat("int c = []() -> int { return 2; }();\n"); |

