[clang] [clang-format] allow short function body on a single line (PR #151428)
Lidong Yan via cfe-commits
cfe-commits at lists.llvm.org
Mon Aug 25 21:51:45 PDT 2025
================
@@ -510,27 +515,50 @@ class LineJoiner {
// Try to merge a function block with left brace wrapped.
if (NextLine.First->is(TT_FunctionLBrace) &&
- Style.BraceWrapping.AfterFunction) {
+ (Style.BraceWrapping.AfterFunction ||
+ Style.AllowShortBlocksOnASingleLine >= FormatStyle::SBS_Empty)) {
if (NextLine.Last->is(TT_LineComment))
return 0;
// Check for Limit <= 2 to account for the " {".
if (Limit <= 2 || (Style.ColumnLimit == 0 && containsMustBreak(TheLine)))
- return 0;
+ if (Style.BraceWrapping.AfterFunction)
+ return 0;
Limit -= 2;
unsigned MergedLines = 0;
+ const bool NextShortBlock = NextLine.First == NextLine.Last &&
+ I + 3 != E && I[3]->First->is(tok::r_brace);
----------------
brandb97 wrote:
I mean these three failed tests in [CI Checks / Build and Test Linux (pull_request)]
lldb-api:
- lldb-api.functionalities/data-formatter/data-formatter-stl/generic/forward_list/TestDataFormatterGenericForwardList.py
- lldb-api.functionalities/data-formatter/data-formatter-stl/generic/list/TestDataFormatterGenericList.py
- lldb-api.functionalities/data-formatter/data-formatter-stl/generic/list/loop/TestDataFormatterGenericListLoop.py
But since I need to rewrite some code again, maybe these failed tests would disappear in next commit.
https://github.com/llvm/llvm-project/pull/151428
More information about the cfe-commits
mailing list