r256739 - clang-format: Fix corner case for lambda assignments.
Daniel Jasper via cfe-commits
cfe-commits at lists.llvm.org
Sun Jan 3 23:29:40 PST 2016
Author: djasper
Date: Mon Jan 4 01:29:40 2016
New Revision: 256739
URL: http://llvm.org/viewvc/llvm-project?rev=256739&view=rev
Log:
clang-format: Fix corner case for lambda assignments.
Before:
std::function<std::string(const std::string &)> my_lambda = [](
const string &s) { return s; };
After:
std::function<std::string(const std::string &)> my_lambda =
[](const string &s) { return s; };
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=256739&r1=256738&r2=256739&view=diff
==============================================================================
--- cfe/trunk/lib/Format/TokenAnnotator.cpp (original)
+++ cfe/trunk/lib/Format/TokenAnnotator.cpp Mon Jan 4 01:29:40 2016
@@ -1722,7 +1722,7 @@ unsigned TokenAnnotator::splitPenalty(co
return 25;
// Slightly prefer formatting local lambda definitions like functions.
if (Right.is(TT_LambdaLSquare) && Left.is(tok::equal))
- return 50;
+ return 35;
if (!Right.isOneOf(TT_ObjCMethodExpr, TT_LambdaLSquare,
TT_ArrayInitializerLSquare))
return 500;
Modified: cfe/trunk/unittests/Format/FormatTest.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTest.cpp?rev=256739&r1=256738&r2=256739&view=diff
==============================================================================
--- cfe/trunk/unittests/Format/FormatTest.cpp (original)
+++ cfe/trunk/unittests/Format/FormatTest.cpp Mon Jan 4 01:29:40 2016
@@ -10512,6 +10512,8 @@ TEST_F(FormatTest, FormatsLambdas) {
verifyFormat("auto my_lambda = [](const string &some_parameter) {\n"
" return some_parameter.size();\n"
"};");
+ verifyFormat("std::function<std::string(const std::string &)> my_lambda =\n"
+ " [](const string &s) { return s; };");
verifyFormat("int i = aaaaaa ? 1 //\n"
" : [] {\n"
" return 2; //\n"
More information about the cfe-commits
mailing list