[clang] c41ef75 - [clang-format] Treat lambda in braced init as inline (#135520)
via cfe-commits
cfe-commits at lists.llvm.org
Sun Apr 13 09:02:49 PDT 2025
Author: Owen Pan
Date: 2025-04-13T09:02:46-07:00
New Revision: c41ef751f85ee42f40380d064f44cfd347fb6215
URL: https://github.com/llvm/llvm-project/commit/c41ef751f85ee42f40380d064f44cfd347fb6215
DIFF: https://github.com/llvm/llvm-project/commit/c41ef751f85ee42f40380d064f44cfd347fb6215.diff
LOG: [clang-format] Treat lambda in braced init as inline (#135520)
Fix #125430
Added:
Modified:
clang/lib/Format/TokenAnnotator.cpp
clang/unittests/Format/FormatTest.cpp
Removed:
################################################################################
diff --git a/clang/lib/Format/TokenAnnotator.cpp b/clang/lib/Format/TokenAnnotator.cpp
index 82dc403538c45..ef5f07e2c62ee 100644
--- a/clang/lib/Format/TokenAnnotator.cpp
+++ b/clang/lib/Format/TokenAnnotator.cpp
@@ -5569,7 +5569,8 @@ static bool isAllmanBrace(const FormatToken &Tok) {
// Returns 'true' if 'Tok' is a function argument.
static bool IsFunctionArgument(const FormatToken &Tok) {
return Tok.MatchingParen && Tok.MatchingParen->Next &&
- Tok.MatchingParen->Next->isOneOf(tok::comma, tok::r_paren);
+ Tok.MatchingParen->Next->isOneOf(tok::comma, tok::r_paren,
+ tok::r_brace);
}
static bool
diff --git a/clang/unittests/Format/FormatTest.cpp b/clang/unittests/Format/FormatTest.cpp
index f5c5a9ea4a1fa..b62d49e17c83f 100644
--- a/clang/unittests/Format/FormatTest.cpp
+++ b/clang/unittests/Format/FormatTest.cpp
@@ -23722,6 +23722,7 @@ TEST_F(FormatTest, FormatsLambdas) {
verifyFormat("function([]() { return b; })", MergeInline);
verifyFormat("function([]() { return b; }, a)", MergeInline);
verifyFormat("function(a, []() { return b; })", MergeInline);
+ verifyFormat("auto guard = foo{[&] { exit_status = true; }};", MergeInline);
// Check option "BraceWrapping.BeforeLambdaBody" and
diff erent state of
// AllowShortLambdasOnASingleLine
More information about the cfe-commits
mailing list