From cec65c0c874c5bea71c397b1b85949a301524125 Mon Sep 17 00:00:00 2001 From: Larry Gritz Date: Sun, 23 Aug 2026 17:11:40 -0700 Subject: [PATCH] style: Raise our clang-format standard to clang-format 22 Since we are very close to branching for 3.2, it's finally time to bump our clang-format standard from 17 to 22. We do this only every couple years or so (to avoid constant churn with every new clang release), and time it for right before a relase, so we are simultaneously doing it in main and in what is imminently the next release family. (Diverging at any other time then simultaneously with branching would make backports of other PRs through the year unnecessarily complicated with divergence.) This PR is EXPECTED to fail the clang-format test, because we're bumping the clang-format version without fixing anything that subsequently needs reformatting in the code. This is ON PURPOSE. First, we merge the clang-format version bump. Then we will have a separate PR that makes the code conform to the new rules, after which we will pass the CI clang-format test again. This split into two commits serves two purposes: 1. It isolates the code reformatting into its own PR whose commit SHA can be added to .git-blame-ignore-revs, marking that change as not counting for git blame queries (in other words, to prevent me from being misattributed as the author of the lines whose formatting changes). 2. It lets the .clang-format rule change be backported or cherry-picked into the topic branches of the many PRs in flight, or even into release branches, without pulling all the other code changes with it. I expect that the way to proceed with PRs currently in flight is (a) cherry-pick this PR (.clang-format change) into the patch's branch, (b) run clang-format on just the changed code of the PR to make the patch's changed code conform to the clang-format 22 rules, (c) rebase the PR on main, and hopefully have no merge conflicts. Signed-off-by: Larry Gritz --- .clang-format | 23 +++++++++++++++-------- .github/workflows/ci.yml | 6 +++--- src/cmake/compiler.cmake | 2 +- 3 files changed, 19 insertions(+), 12 deletions(-) diff --git a/.clang-format b/.clang-format index eb3621f5c0..013502522c 100644 --- a/.clang-format +++ b/.clang-format @@ -2,7 +2,7 @@ Language: Cpp BasedOnStyle: WebKit AccessModifierOffset: -4 -AlignAfterOpenBracket: Align +AlignAfterOpenBracket: true AlignConsecutiveAssignments: true #AlignConsecutiveAssignments: Consecutive #AlignConsecutiveBitFields: Consecutive @@ -14,14 +14,14 @@ AlignTrailingComments: true AllowAllArgumentsOnNextLine: true AllowAllConstructorInitializersOnNextLine: true AllowAllParametersOfDeclarationOnNextLine: false -AllowShortBlocksOnASingleLine: true +AllowShortBlocksOnASingleLine: Never AllowShortCaseLabelsOnASingleLine: true -AllowShortFunctionsOnASingleLine: All +AllowShortFunctionsOnASingleLine: InlineOnly AllowShortLambdasOnASingleLine: All AllowShortIfStatementsOnASingleLine: Never AllowShortLoopsOnASingleLine: false -AlwaysBreakAfterDefinitionReturnType: None -AlwaysBreakAfterReturnType: TopLevel +AllowShortNamespacesOnASingleLine: false +BreakAfterReturnType: TopLevelDefinitions AlwaysBreakBeforeMultilineStrings: false AlwaysBreakTemplateDeclarations: MultiLine BinPackArguments: true @@ -83,7 +83,10 @@ IndentWidth: 4 IndentWrappedFunctionNames: false JavaScriptQuotes: Leave JavaScriptWrapImports: true -KeepEmptyLinesAtTheStartOfBlocks: false +KeepEmptyLines: + AtEndOfFile: false + AtStartOfBlock: false + AtStartOfFile: false MacroBlockBegin: '' MacroBlockEnd: '' MaxEmptyLinesToKeep: 3 @@ -92,7 +95,7 @@ ObjCBinPackProtocolList: Auto ObjCBlockIndentWidth: 4 ObjCSpaceAfterProperty: true ObjCSpaceBeforeProtocolList: true -PenaltyBreakAssignment: 40 +PenaltyBreakAssignment: 50 PenaltyBreakBeforeFirstCallParameter: 100 PenaltyBreakComment: 300 PenaltyBreakFirstLessLess: 120 @@ -102,6 +105,8 @@ PenaltyExcessCharacter: 75 PenaltyReturnTypeOnItsOwnLine: 50 PointerAlignment: Left ReflowComments: false +RemoveEmptyLinesInUnwrappedLines: true +SkipMacroDefinitionBody: true SortIncludes: true SortUsingDeclarations: true SpaceAfterCStyleCast: false @@ -113,7 +118,7 @@ SpaceBeforeCtorInitializerColon: true SpaceBeforeInheritanceColon: true SpaceBeforeParens: ControlStatements SpaceBeforeRangeBasedForLoopColon: true -SpaceInEmptyBlock: false +SpaceInEmptyBraces: Never SpaceInEmptyParentheses: false SpacesBeforeTrailingComments: 2 SpacesInAngles: false @@ -126,6 +131,8 @@ StatementMacros: - Q_UNUSED - QT_REQUIRE_VERSION TabWidth: 8 +#TemplateNames: +#TypeNames: UseTab: Never #... diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 65c2ffcd18..8a4cf3c142 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -308,7 +308,7 @@ jobs: # the console output). - desc: "clang-format" nametag: clang-format - runner: ubuntu-24.04 + runner: ubuntu-26.04 cxx_std: 17 extra_artifacts: "src/*.*" python_ver: "3.10" @@ -318,8 +318,8 @@ jobs: skip_tests: 1 setenvs: export SKIP_SYSTEM_DEPS_INSTALL=1 SKIP_APT_GET_UPDATE=1 INSTALL_OPENCV=0 QT_VERSION=0 USE_LIBHEIF=0 - EXTRA_DEP_PACKAGES="clang-format-17" - CLANG_FORMAT_EXE=clang-format-17 + CLANG_FORMAT_EXE=clang-format-22 + EXTRA_DEP_PACKAGES="clang-format-22" - desc: latest releases gcc15 C++23 py3.12 avx2 exr3.4 ocio2.4 nametag: linux-latest-releases diff --git a/src/cmake/compiler.cmake b/src/cmake/compiler.cmake index 6ec98ee70e..971830b049 100644 --- a/src/cmake/compiler.cmake +++ b/src/cmake/compiler.cmake @@ -613,7 +613,7 @@ endif () # Note: skip all of this checking, setup, and cmake-format target if this # is being built as a subproject. if (PROJECT_IS_TOP_LEVEL) - set (CLANG_FORMAT_EXE_HINT "" CACHE PATH "clang-format executable's directory (will search if not specified") + set_cache (CLANG_FORMAT_EXE_HINT "" "clang-format executable's directory (will search if not specified") set (CLANG_FORMAT_INCLUDES "src/*.h" "src/*.cpp" "testsuite/*.cpp" "testsuite/*.h" CACHE STRING "Glob patterns to include for clang-format") set (CLANG_FORMAT_EXCLUDES "*pugixml*" "*SHA1*" "*/farmhash.cpp"