[clang] [clang-format] Disable short blocks if brace is on the new line (PR #196021)

Gedare Bloom via cfe-commits cfe-commits at lists.llvm.org
Sun Jun 14 10:31:40 PDT 2026


================
@@ -895,6 +889,11 @@ class LineJoiner {
         Line.startsWithExportBlock()) {
       if (IsSplitBlock)
         return 0;
+      // The construct-specific options AllowShortIfStatementsOnASingleLine and
+      // AllowShortLoopsOnASingleLine take precedence over
+      // AllowShortBlocksOnASingleLine: a statement whose specific option
+      // disallows merging is not put on a single line even when short blocks
+      // are always allowed.
----------------
gedare wrote:

I think you can fix the regressions by adding `AllowShortBlocksOnASingleLine.Attached` configuration option. This still requires a style file change by users. 

An alternative would be to introduce `AllowShortBlocksOnASingleLine.Detached` (or `NotAttached`, or similar), and clarifying that `Always` is only when the block is attached to the same line preceding the block compound statement. Limiting `Always` in this way is a bit non-intuitive, but it matches the documentation and possibly the test cases better.

Personally, I would try adding the `NotAttached` option, and documenting the constraint on `Always`, assuming that it doesn't require modifying tests.

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


More information about the cfe-commits mailing list