forked from OSchip/llvm-project
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(); }; llvm-svn: 237235
This commit is contained in:
parent
aba4a34ef2
commit
0ad2814c89
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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");
|
||||
|
|
Loading…
Reference in New Issue