[clang] [clang-format] Add option AllowShortRecordOnASingleLine (PR #154580)

Tomáš Slanina via cfe-commits cfe-commits at lists.llvm.org
Sat Mar 14 19:52:40 PDT 2026


================
@@ -957,15 +958,20 @@ static bool ShouldBreakBeforeBrace(const FormatStyle &Style,
   if (InitialToken.is(TT_NamespaceMacro))
     Kind = tok::kw_namespace;
 
+  const bool WrapRecordAllowed =
+      !IsEmptyBlock ||
+      Style.AllowShortRecordOnASingleLine < FormatStyle::SRS_Empty ||
+      Style.BraceWrapping.SplitEmptyRecord;
----------------
itzexpoexpo wrote:

If the block is empty, SRS is Empty or Always and SplitEmptyRecord is false we disable wrapping the left brace as it's in that case guaranteed that it will be merged onto a single line and avoids the complexity of trying to merge it in Formatter.
I found that the `IsEmptyBlock` condition wasn't checked in tests, removing it would cause a regression. It's covered in the latest commit.

https://github.com/llvm/llvm-project/pull/154580


More information about the cfe-commits mailing list