Oh, joy, clang-format 22 has compounded an existing bug where AllowShortBlocksOnASingleLine: Empty didn't work by applying the AllowShortBlocksOnASingleLine setting to functions, meaning that there is no way for us to move to clang 22 without some formatting churn.

#llvm #ClangFormat

[clang-format] `AllowShortBlocksOnASingleLine: Empty` does not allow short blocks on single lines · Issue #62117 · llvm/llvm-project

clang-format version: 16.0.0 on Windows 10 AllowShortBlocksOnASingleLine: Empty behaves like AllowShortBlocksOnASingleLine: Never for empty blocks. Minimal Example: Config: --- BasedOnStyle: Chromi...

GitHub

@david_chisnall The formatting churn for clang-format is so horrible. In my C++ project where formatting is enforced with clang-format, I have the Makefile create a Python venv into which I pip install clang-format=18.1.8 (using pip as a cross-platform distributor of version-locked clang-format builds).

Contrast to Rust, where I just run `cargo fmt` on my laptop, my desktop and in CI and it's fine.

Formatting churn across versions in a code formatter should be considered a bug.

@david_chisnall https://github.com/llvm/llvm-project/blob/main/clang/tools/clang-format/git-clang-format would this help? IIUC it only formats what you changed.
If the 2 styles are too different from each other you'll end up with an inconsistent style in the file though.

If you do reformat the whole codebase then a merge driver could help [e.g. with outstanding PRs/branches) (it reformats all 3 sides of a merge, and is usually able to avoid conflicts most of the time that way) https://github.com/emilio/clang-format-merge.
(Or equivalently if you use `jj` there is a configuration option to autoformat each commit).
You can also define certain commits to be ignored by 'git blame', e.g. the reformatting commits.

I haven't tried this with clang-format, but the equivalent steps with `ocamlformat` work great (and we've done several repo wide reformats on version upgrades).

llvm-project/clang/tools/clang-format/git-clang-format at main · llvm/llvm-project

The LLVM Project is a collection of modular and reusable compiler and toolchain technologies. - llvm/llvm-project

GitHub