[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
Fri Jun 12 11:04:17 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 don't know that this entirely makes sense. As it currently works:

`$ echo "while (foo > 0) { --foo; }" | clang-format --style="{BasedOnStyle: LLVM, BreakBeforeBraces: Custom, BraceWrapping: {AfterControlStatement: true}, AllowShortLoopsOnASingleLine: false, AllowShortBlocksOnASingleLine: true, ColumnLimit: 20}"`
```
while (foo > 0)
{ --foo; }
```

I think this is intended, and the changes here will cause more regressions. I don't currently have an older clang-format to check with, but it seems (based on the test case changes) that there are going to be a lot of changes here and it's not clear how to support users through a transition.





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


More information about the cfe-commits mailing list