r237235 - clang-format: Prefer formatting local lambdas like functions.
Daniel Jasper
djasper at google.com
Wed May 13 01:47:16 PDT 2015
Author: djasper
Date: Wed May 13 03:47:16 2015
New Revision: 237235
URL: http://llvm.org/viewvc/llvm-project?rev=237235&view=rev
Log:
clang-format: Prefer formatting local lambdas like functions.
Before:
auto my_lambda =
[](const string &some_parameter) { return some_parameter.size(); };
After:
auto my_lambda = [](const string &some_parameter) {
return some_parameter.size();
};
Modified:
cfe/trunk/lib/Format/TokenAnnotator.cpp
cfe/trunk/unittests/Format/FormatTest.cpp
Modified: cfe/trunk/lib/Format/TokenAnnotator.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/TokenAnnotator.cpp?rev=237235&r1=237234&r2=237235&view=diff
==============================================================================
--- cfe/trunk/lib/Format/TokenAnnotator.cpp (original)
+++ cfe/trunk/lib/Format/TokenAnnotator.cpp Wed May 13 03:47:16 2015
@@ -1593,6 +1593,9 @@ unsigned TokenAnnotator::splitPenalty(co
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;
}
Modified: cfe/trunk/unittests/Format/FormatTest.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTest.cpp?rev=237235&r1=237234&r2=237235&view=diff
==============================================================================
--- cfe/trunk/unittests/Format/FormatTest.cpp (original)
+++ cfe/trunk/unittests/Format/FormatTest.cpp Wed May 13 03:47:16 2015
@@ -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");
More information about the cfe-commits
mailing list