[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
Sun Jun 14 00:52:39 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:
I am a bit confused now since you say:
> the Loop/If option should control the behavior everything up to the first `{`
> Somehow the initial options for the Loop/If appeared to assume these were just for braceless one-liners, which makes some sense. However, as the scope has expanded to include braces, the need to treat the cases of bracless, with braces, braces on same/next line, and ability to fit entire braced expression on one line, have all become necessary to handle simultaneously.
The first statement implies that `AllowShortLoopsOnASingleLine` should be concerned with `while (...) `. The second statement says that scope has expanded so that entirety of the statement, including the braced block, needs to be considered simultaneously in order to decide the formatting.
I'm not sure how to continue from here.
https://github.com/llvm/llvm-project/pull/196021
More information about the cfe-commits
mailing list