[clang] [clang-format] Disable short blocks if brace is on the new line (PR #196021)
Rudolf Lovrenčić via cfe-commits
cfe-commits at lists.llvm.org
Mon Jun 15 01:03:33 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.
----------------
rudolflovrencic wrote:
Seems like a good suggestion but I do not think I can achieve the following with that approach:
```c++
void f() {} // Empty function blocks are formatted on a single line.
void g(int x)
{
if (x == 42) { throw "error"; } // Short loop/if blocks are formatted on a single line.
}
```
This formatting was possible in `v21`.
https://github.com/llvm/llvm-project/pull/196021
More information about the cfe-commits
mailing list