[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 05:07:37 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 didn't quite understand why the LLDB formatter failed. Could you help me analyze the possible reasons for the error? Thank you very much!
https://github.com/llvm/llvm-project/pull/151428
More information about the cfe-commits
mailing list