[clang] [clang-format] allow short function body on a single line (PR #151428)
Lidong Yan via cfe-commits
cfe-commits at lists.llvm.org
Tue Aug 26 16:09:28 PDT 2025
================
@@ -251,10 +251,15 @@ class LineJoiner {
: Limit - TheLine->Last->TotalLength;
if (TheLine->Last->is(TT_FunctionLBrace) &&
- TheLine->First == TheLine->Last &&
- !Style.BraceWrapping.SplitEmptyFunction &&
- NextLine.First->is(tok::r_brace)) {
- return tryMergeSimpleBlock(I, E, Limit);
+ TheLine->First == TheLine->Last) {
+ const bool EmptyFunctionBody = NextLine.First->is(tok::r_brace);
+ const bool ShortFunctionBody =
+ !EmptyFunctionBody && I + 2 != E && I[2]->First->is(tok::r_brace);
+ if ((EmptyFunctionBody && !Style.BraceWrapping.SplitEmptyFunction) ||
+ (ShortFunctionBody &&
----------------
brandb97 wrote:
I see, tryMergeSimpleBlock() will check "Simple Block" anyway. No need to put ShortFunctionBody-check here.
https://github.com/llvm/llvm-project/pull/151428
More information about the cfe-commits
mailing list