https://github.com/owenca created https://github.com/llvm/llvm-project/pull/135479
Fix #133135 >From f041f9c3eac94b8f1322ebaa9dfd60d4287840d7 Mon Sep 17 00:00:00 2001 From: Owen Pan <owenpi...@gmail.com> Date: Fri, 11 Apr 2025 23:36:37 -0700 Subject: [PATCH] [clang-format] Wrap and indent lambda braces in GNU style Fix #133135 --- clang/lib/Format/ContinuationIndenter.cpp | 5 +++++ clang/lib/Format/Format.cpp | 2 +- clang/unittests/Format/FormatTest.cpp | 9 +++++++++ 3 files changed, 15 insertions(+), 1 deletion(-) diff --git a/clang/lib/Format/ContinuationIndenter.cpp b/clang/lib/Format/ContinuationIndenter.cpp index 1969f4297b211..9bebac1bed5c6 100644 --- a/clang/lib/Format/ContinuationIndenter.cpp +++ b/clang/lib/Format/ContinuationIndenter.cpp @@ -1334,6 +1334,11 @@ unsigned ContinuationIndenter::getNewLineColumn(const LineState &State) { Style.IndentWidth; } + if (Style.BraceWrapping.BeforeLambdaBody && + Style.BraceWrapping.IndentBraces && Current.is(TT_LambdaLBrace)) { + return CurrentState.Indent + Style.IndentWidth; + } + if ((NextNonComment->is(tok::l_brace) && NextNonComment->is(BK_Block)) || (Style.isVerilog() && Keywords.isVerilogBegin(*NextNonComment))) { if (Current.NestingLevel == 0 || diff --git a/clang/lib/Format/Format.cpp b/clang/lib/Format/Format.cpp index b90bd8276e1e2..57175a0be1a6b 100644 --- a/clang/lib/Format/Format.cpp +++ b/clang/lib/Format/Format.cpp @@ -1435,7 +1435,7 @@ static void expandPresetsBraceWrapping(FormatStyle &Expanded) { /*AfterExternBlock=*/true, /*BeforeCatch=*/true, /*BeforeElse=*/true, - /*BeforeLambdaBody=*/false, + /*BeforeLambdaBody=*/true, /*BeforeWhile=*/true, /*IndentBraces=*/true, /*SplitEmptyFunction=*/true, diff --git a/clang/unittests/Format/FormatTest.cpp b/clang/unittests/Format/FormatTest.cpp index f0e67c604cc4b..108d5b90e31f8 100644 --- a/clang/unittests/Format/FormatTest.cpp +++ b/clang/unittests/Format/FormatTest.cpp @@ -24268,6 +24268,15 @@ TEST_F(FormatTest, EmptyLinesInLambdas) { "};"); } +TEST_F(FormatTest, LambdaBracesInGNU) { + verifyFormat("auto x = [&] ()\n" + " {\n" + " for (int i = 0; i < y; ++i)\n" + " return 97;\n" + " };", + getGNUStyle()); +} + TEST_F(FormatTest, FormatsBlocks) { FormatStyle ShortBlocks = getLLVMStyle(); ShortBlocks.AllowShortBlocksOnASingleLine = FormatStyle::SBS_Always; _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits