Skip to content

Bump clang-format from 17.0.6 to 20.1.0 #2046

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Jun 26, 2025

Conversation

eramongodb
Copy link
Contributor

@eramongodb eramongodb commented Jun 26, 2025

Raises the ClangFormat version used to format our codebase from 17.0.6 to 20.1.0 for better compatibility with recent versions of clangd (which embeds its own clang-format). See ClangFormat 20.1 docs for reference.


The most significant change due to this upgrade is the formatting of list initializers, such as for compound literals, which does not seem to have a related configuration option (hence pre-ClangFormat 19 compatibility pains; it is not SpaceAfterCStyleCast or SpaceBeforeCpp11BracedList):

// Before
(type){ ... }

// After
(type) { ... }

This upgrade also seems to insert a space after some (paren) which it may be (mis-)interpreting as as C-style cast. These changes are left as-is due to relatively minor impact (especially compared to the compound literal changes mentioned above).

// Before
MONGOC_RPC_CONSUME (uint8_t, uint8_t, (uint8_t))

// After
MONGOC_RPC_CONSUME (uint8_t, uint8_t, (uint8_t) )

The last notable changes to mention are better handling of preprocessor macro definitions (e.g. applying existing rules, abbreviating to a single line, etc.). These changes are also left as-is due to relatively minor impact.

// Before
#define BSON_INITIALIZER \
   {                     \
      3, 5,              \
      {                  \
         5               \
      }                  \
   }

// After
#define BSON_INITIALIZER {3, 5, {5}}

There is also this one particular change which confuses me, but I do not think it is worth going out of our way to address/prevent .

// Before
typedef future_t *(func_with_opts_t) (func_ctx_t *ctx, bson_t *cmd);

// After (why?)
typedef future_t *(func_with_opts_t) (func_ctx_t * ctx, bson_t *cmd);

The ClangFormat configuration file is regenerated (via --dump-config) to explicitly address all new/changed/removed options. Notable changes (relative to the old ClangFormat 17 config or relative to ClangFormat 20 defaults) include:

  • AlwaysBreakAfterReturnType: All is renamed to BreakAfterReturnType: All
  • AlwaysBreakTemplateDeclarations: Multiline renamed to BreakTemplateDeclarations: Multiline
  • BinPackParameters is set to OnePerLine (equivalent to former value of false).
  • IndentExportBlock is set to false for consistency with other Indent* options (default is true).
  • KeepEmptyLinesAtTheStartOfBlocks: false renamed to KeepEmptyLines.AtStartOfBlock: false.
  • KeepEmptyLinesAtEOF: false is renamed to KeepEmptyLines.AtEndOfFile: false.
  • KeepEmptyLines.AtStartOfFile is set to false for consistency with other KeepEmptyLines options (default is true).
    • Setting this new option modified a few files which had empty newlines at the start of the file.
  • MainIncludeChar is set to Any (default is Quote).

All other options are left as their default values.

@eramongodb eramongodb self-assigned this Jun 26, 2025
@eramongodb eramongodb requested a review from a team as a code owner June 26, 2025 17:06
Copy link
Collaborator

@kevinAlbs kevinAlbs left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM and thank you.

Copy link
Contributor

@vector-of-bool vector-of-bool left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@eramongodb eramongodb merged commit 30ac9bf into mongodb:master Jun 26, 2025
37 of 39 checks passed
@eramongodb eramongodb deleted the cdriver-format branch June 26, 2025 17:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants