[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
Mon Jun 15 08:44:29 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 see. That appears to be different than the open issues that your PR is solving though. I'm not sure this was an explicitly supported format, but I guess it appears to have been working. Can you point to a format style guide that documents this style to help [justify additional style options](https://clang.llvm.org/docs/ClangFormatStyleOptions.html#adding-additional-style-options)?
This style requires the brace wrapping to be overridden in some cases, but not in others. I could see making an argument that `AllowShortXyzOnASingleLine` could be made to override the BraceWrapping, as suggested also by owenca, but there are also strange interactions such as with `BraceWrapping.SplitEmptyFunction`. You could instead propose a new option to `BraceWrapping` that prevents wrapping the brace if the function is empty. This, along with the `AllowShortBlocksOnASingleLine.Attached` (and `NotAttached`) should be able to satisfy your requirements.
The preference for fixing the open issues as regressions would be to have a minimal change to existing style files. Thus my recommended route of deprecating `Always` in favor of explicit `Attached` and `NotAttached` options, since `Always` did not really mean always.
Another possibility could be to have `AllowShortBlocksonASingleLine` to "inherit" from the `AllowShortXyzOnASingleLine` when the brace is attached.
https://github.com/llvm/llvm-project/pull/196021
More information about the cfe-commits
mailing list