CXX-2139 update clang-tidy configuration with WarningsAsErrors #1496
+139 −45
Add this suggestion to a batch that can be applied as a single commit. This suggestion is invalid because no changes were made to the code. Suggestions cannot be applied while the pull request is closed. Suggestions cannot be applied while viewing a subset of changes. Only one suggestion per line can be applied in a batch. Add this suggestion to a batch that can be applied as a single commit. Applying suggestions on deleted lines is not supported. You must change the existing code in this line in order to create a valid suggestion. Outdated suggestions cannot be applied. This suggestion has been applied or marked resolved. Suggestions cannot be applied from pending reviews. Suggestions cannot be applied on multi-line comments. Suggestions cannot be applied while the pull request is queued to merge. Suggestion cannot be applied right now. Please check back later.
Resolves CXX-2139. Followup to #1495 upon realising the clang-tidy EVG task has been providing minimal value due to the absence of
WarningsAsErrorschecks (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 (onrhel9-latest) and the initial set ofWarningsAsErrorschecks to be enabled going forward.The set of clang-tidy warnings emitted by the
clang-tidytask with currently proposed changes are visible in this patch build.The
.clang-tidyconfiguration file has been updated with the dump of the default configuration for clang-tidy 21.1.1 (the version onrhel9-latestwhere 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 ofWarningsAsErrorsdiagnostics (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 theclang-tidytask on error.Important
Adding checks to
WarningsAsErrorsis necessary to determine when theclang-tidyEVG 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 ofWarningsAsErrorsdiagnostics to enable. The current filter list includes 219 source files:The
--header-filterflag 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-tidyconfiguration options to avoid pessimizing the local development experience. The.clang-tidyconfiguration only excludesconfig,_depsandenumsheaders.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/nullthat 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:
cppcoreguidelines-pro-type-union-access: 87 warningscppcoreguidelines-pro-bounds-array-to-pointer-decay: 34 warningscppcoreguidelines-init-variables: 20 warningscppcoreguidelines-pro-type-reinterpret-cast: 19 warningscppcoreguidelines-avoid-magic-numbers: 17 warningscppcoreguidelines-pro-bounds-pointer-arithmetic: 17 warningscppcoreguidelines-pro-type-const-cast: 12 warningscppcoreguidelines-pro-type-member-init: 12 warningscert-oop54-cpp: 11 warningscppcoreguidelines-avoid-c-arrays: 9 warningscppcoreguidelines-rvalue-reference-param-not-moved: 5 warningscppcoreguidelines-use-enum-class: 5 warningscppcoreguidelines-use-default-member-init: 4 warningscppcoreguidelines-owning-memory: 3 warningscppcoreguidelines-prefer-member-initializer: 3 warningscppcoreguidelines-avoid-non-const-global-variables: 2 warningscppcoreguidelines-pro-bounds-constant-array-index: 2 warningscert-err58-cpp: 1 warningcppcoreguidelines-avoid-do-while: 1 warningcppcoreguidelines-pro-type-static-cast-downcast: 1 warningcppcoreguidelines-pro-type-vararg: 1 warningTip
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):