Skip to content

Conversation

@eramongodb
Copy link
Contributor

@eramongodb eramongodb commented Nov 12, 2025

Resolves CXX-2139. Followup to #1495 upon realising the clang-tidy EVG task has been providing minimal value due to the absence of WarningsAsErrors checks (most/all diagnostics except for hard compilation errors are emitted but otherwise ignored). #1049 implemented a "temporary" workaround clang-tidy configuration options document this absence of static analysis errors. This PR proposes taking this opportunity to codify the clang-tidy configuration options for Clang 21.1.1 (on rhel9-latest) and the initial set of WarningsAsErrors checks to be enabled going forward.

The set of clang-tidy warnings emitted by the clang-tidy task with currently proposed changes are visible in this patch build.


The .clang-tidy configuration file has been updated with the dump of the default configuration for clang-tidy 21.1.1 (the version on rhel9-latest where this task will now be executed). The default list of checks is preserved for now, including the disabling of all default checks with -* (with redundancy removed). The initial changes in this PR leave the set of WarningsAsErrors diagnostics (which unfortunately does not seem to support list syntax) empty: this PR is an opportunity to decide on an initially minimal-and-constrainted set of checks which will fail the clang-tidy task on error.

Important

Adding checks to WarningsAsErrors is necessary to determine when the clang-tidy EVG task fails due to static analysis diagnostics.

The initial set of files to be analyzed are library components only. Notably, the benchmark (requires C++17), config, _deps, docs, enums, test, directories and macro guard headers are excluded from analysis. We can consider extending analysis to one or more of these extra directories once we have decided the set of WarningsAsErrors diagnostics to enable. The current filter list includes 219 source files:

$ find src -type f \( -name *.cc -o -name *.cpp \) | perl -lne 'print if m$.*/(?:bsoncxx|mongocxx)/lib/.*$' | wc -l 219 

The --header-filter flag further limits analysis to library headers only so that diagnostics are not emitted for external headers.

Note

These filters and exclusions are deliberately not specified via .clang-tidy configuration options to avoid pessimizing the local development experience. The .clang-tidy configuration only excludes config, _deps and enums headers.

According to llvm/llvm-project#47042 (which is finally resolved by llvm/llvm-project#154012), the "N warnings generated" spam (which is what motivated the 2>/dev/null that masked the "command not found" error) should hopefully be in the next clang-tidy release. 👏 Until then, we'll need to continue using this workaround.

Given this configuration and filters, the current state of clang-tidy warnings is as follows:

  • Total warnings emitted: 266.
  • Warnings sorted from top to bottom by highest unique occurance count:
    • cppcoreguidelines-pro-type-union-access: 87 warnings
    • cppcoreguidelines-pro-bounds-array-to-pointer-decay: 34 warnings
    • cppcoreguidelines-init-variables: 20 warnings
    • cppcoreguidelines-pro-type-reinterpret-cast: 19 warnings
    • cppcoreguidelines-avoid-magic-numbers: 17 warnings
    • cppcoreguidelines-pro-bounds-pointer-arithmetic: 17 warnings
    • cppcoreguidelines-pro-type-const-cast: 12 warnings
    • cppcoreguidelines-pro-type-member-init: 12 warnings
    • cert-oop54-cpp: 11 warnings
    • cppcoreguidelines-avoid-c-arrays: 9 warnings
    • cppcoreguidelines-rvalue-reference-param-not-moved: 5 warnings
    • cppcoreguidelines-use-enum-class: 5 warnings
    • cppcoreguidelines-use-default-member-init: 4 warnings
    • cppcoreguidelines-owning-memory: 3 warnings
    • cppcoreguidelines-prefer-member-initializer: 3 warnings
    • cppcoreguidelines-avoid-non-const-global-variables: 2 warnings
    • cppcoreguidelines-pro-bounds-constant-array-index: 2 warnings
    • cert-err58-cpp: 1 warning
    • cppcoreguidelines-avoid-do-while: 1 warning
    • cppcoreguidelines-pro-type-static-cast-downcast: 1 warning
    • cppcoreguidelines-pro-type-vararg: 1 warning

Tip

See here for the list of all available checks with clang-tidy 21.1 and their descriptions.

All checks currently enabled by the default configuration are listed below (82 in total; 21 of these currently emit at least one a diagnostic):

cert-arr39-c cert-con36-c cert-con54-cpp cert-ctr56-cpp cert-dcl03-c cert-dcl16-c cert-dcl37-c cert-dcl50-cpp cert-dcl51-cpp cert-dcl54-cpp cert-dcl58-cpp cert-dcl59-cpp cert-env33-c cert-err09-cpp cert-err33-c cert-err34-c cert-err52-cpp cert-err58-cpp cert-err60-cpp cert-err61-cpp cert-exp42-c cert-fio38-c cert-flp30-c cert-flp37-c cert-int09-c cert-mem57-cpp cert-msc24-c cert-msc30-c cert-msc32-c cert-msc33-c cert-msc50-cpp cert-msc51-cpp cert-msc54-cpp cert-oop11-cpp cert-oop54-cpp cert-oop57-cpp cert-oop58-cpp cert-pos44-c cert-pos47-c cert-sig30-c cert-str34-c cppcoreguidelines-avoid-c-arrays cppcoreguidelines-avoid-capturing-lambda-coroutines cppcoreguidelines-avoid-const-or-ref-data-members cppcoreguidelines-avoid-do-while cppcoreguidelines-avoid-goto cppcoreguidelines-avoid-magic-numbers cppcoreguidelines-avoid-non-const-global-variables cppcoreguidelines-avoid-reference-coroutine-parameters cppcoreguidelines-c-copy-assignment-signature cppcoreguidelines-explicit-virtual-functions cppcoreguidelines-init-variables cppcoreguidelines-interfaces-global-init cppcoreguidelines-macro-to-enum cppcoreguidelines-macro-usage cppcoreguidelines-misleading-capture-default-by-value cppcoreguidelines-missing-std-forward cppcoreguidelines-narrowing-conversions cppcoreguidelines-no-malloc cppcoreguidelines-no-suspend-with-lock cppcoreguidelines-noexcept-destructor cppcoreguidelines-noexcept-move-operations cppcoreguidelines-noexcept-swap cppcoreguidelines-non-private-member-variables-in-classes cppcoreguidelines-owning-memory cppcoreguidelines-prefer-member-initializer cppcoreguidelines-pro-bounds-array-to-pointer-decay cppcoreguidelines-pro-bounds-constant-array-index cppcoreguidelines-pro-bounds-pointer-arithmetic cppcoreguidelines-pro-type-const-cast cppcoreguidelines-pro-type-cstyle-cast cppcoreguidelines-pro-type-member-init cppcoreguidelines-pro-type-reinterpret-cast cppcoreguidelines-pro-type-static-cast-downcast cppcoreguidelines-pro-type-union-access cppcoreguidelines-pro-type-vararg cppcoreguidelines-rvalue-reference-param-not-moved cppcoreguidelines-slicing cppcoreguidelines-special-member-functions cppcoreguidelines-use-default-member-init cppcoreguidelines-use-enum-class cppcoreguidelines-virtual-class-destructor 
@eramongodb eramongodb self-assigned this Nov 12, 2025
@eramongodb eramongodb requested a review from a team as a code owner November 12, 2025 15:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

1 participant