Skip to content

Commit f041f9c

Browse files
committed
[clang-format] Wrap and indent lambda braces in GNU style
Fix #133135
1 parent 72540db commit f041f9c

File tree

3 files changed

+15
-1
lines changed

3 files changed

+15
-1
lines changed

clang/lib/Format/ContinuationIndenter.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1334,6 +1334,11 @@ unsigned ContinuationIndenter::getNewLineColumn(const LineState &State) {
13341334
Style.IndentWidth;
13351335
}
13361336

1337+
if (Style.BraceWrapping.BeforeLambdaBody &&
1338+
Style.BraceWrapping.IndentBraces && Current.is(TT_LambdaLBrace)) {
1339+
return CurrentState.Indent + Style.IndentWidth;
1340+
}
1341+
13371342
if ((NextNonComment->is(tok::l_brace) && NextNonComment->is(BK_Block)) ||
13381343
(Style.isVerilog() && Keywords.isVerilogBegin(*NextNonComment))) {
13391344
if (Current.NestingLevel == 0 ||

clang/lib/Format/Format.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1435,7 +1435,7 @@ static void expandPresetsBraceWrapping(FormatStyle &Expanded) {
14351435
/*AfterExternBlock=*/true,
14361436
/*BeforeCatch=*/true,
14371437
/*BeforeElse=*/true,
1438-
/*BeforeLambdaBody=*/false,
1438+
/*BeforeLambdaBody=*/true,
14391439
/*BeforeWhile=*/true,
14401440
/*IndentBraces=*/true,
14411441
/*SplitEmptyFunction=*/true,

clang/unittests/Format/FormatTest.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24268,6 +24268,15 @@ TEST_F(FormatTest, EmptyLinesInLambdas) {
2426824268
"};");
2426924269
}
2427024270

24271+
TEST_F(FormatTest, LambdaBracesInGNU) {
24272+
verifyFormat("auto x = [&] ()\n"
24273+
" {\n"
24274+
" for (int i = 0; i < y; ++i)\n"
24275+
" return 97;\n"
24276+
" };",
24277+
getGNUStyle());
24278+
}
24279+
2427124280
TEST_F(FormatTest, FormatsBlocks) {
2427224281
FormatStyle ShortBlocks = getLLVMStyle();
2427324282
ShortBlocks.AllowShortBlocksOnASingleLine = FormatStyle::SBS_Always;

0 commit comments

Comments
 (0)