Skip to content
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

Add clang-tidy to the C++ static code analysis #492

Closed
fklebert opened this issue Mar 20, 2023 · 2 comments
Closed

Add clang-tidy to the C++ static code analysis #492

fklebert opened this issue Mar 20, 2023 · 2 comments
Assignees
Labels
c++ C++ language generator
Milestone

Comments

@fklebert
Copy link
Contributor

In addition to cppcheck, add clang-tidy to the CI and refactor runtime code so that we have no issues reported.
Provide report along with the release assets.

The following checks should be run and report no errors:

---
#
# This configuration file defines a list of activated
# clang-tidy checks for zserio

Checks: "-*,\
  bugprone-bool-pointer-implicit-conversion,\
  bugprone-copy-constructor-init,\
  bugprone-dangling-handle,\
  bugprone-exception-escape,\
  bugprone-fold-init-type,\
  bugprone-forwarding-reference-overload,\
  bugprone-inaccurate-erase,\
  bugprone-incorrect-roundings,\
  bugprone-infinite-loop,\
  bugprone-integer-division,\
  bugprone-macro-repeated-side-effects,\
  bugprone-misplaced-operator-in-strlen-in-alloc,\
  bugprone-misplaced-pointer-arithmetic-in-alloc,\
  bugprone-misplaced-widening-cast,\
  bugprone-move-forwarding-reference,\
  bugprone-multiple-statement-macro,\
  bugprone-not-null-terminated-result,\
  bugprone-parent-virtual-call,\
  bugprone-posix-return,\
  bugprone-reserved-identifier,\
  bugprone-signed-char-misuse,\
  bugprone-sizeof-expression,\
  bugprone-spuriously-wake-up-functions,\
  bugprone-string-constructor,\
  bugprone-suspicious-enum-usage,\
  bugprone-suspicious-include,\
  bugprone-suspicious-memset-usage,\
  bugprone-suspicious-missing-comma,\
  bugprone-suspicious-semicolon,\
  bugprone-suspicious-string-compare,\
  bugprone-swapped-arguments,\
  bugprone-terminating-continue,\
  bugprone-too-small-loop-variable,\
  bugprone-undefined-memory-manipulation,\
  bugprone-unhandled-self-assignment,\
  bugprone-unused-raii,\
  bugprone-unused-return-value,\
  bugprone-use-after-move,\
  bugprone-virtual-near-miss,\
  cert-dcl50-cpp,\
  cert-dcl58-cpp,\
  cert-env33-c,\
  cert-err52-cpp,\
  cert-err58-cpp,\
  cert-flp30-c,\
  cert-mem57-cpp,\
  cert-msc50-cpp,\
  cert-oop57-cpp,\
  cert-oop58-cpp,\
  cppcoreguidelines-avoid-c-arrays,\
  cppcoreguidelines-avoid-goto,\
  cppcoreguidelines-avoid-non-const-global-variables,\
  cppcoreguidelines-init-variables,\
  cppcoreguidelines-interfaces-global-init,\
  cppcoreguidelines-macro-usage,\
  cppcoreguidelines-narrowing-conversions,\
  cppcoreguidelines-no-malloc,\
  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-slicing,\
  cppcoreguidelines-special-member-functions,\
  fuchsia-multiple-inheritance,\
  google-build-explicit-make-pair,\
  google-build-namespaces,\
  google-build-using-namespace,\
  google-default-arguments,\
  google-explicit-constructor,\
  google-global-names-in-headers,\
  google-readability-casting,\
  google-runtime-int,\
  google-runtime-operator,\
  google-upgrade-googletest-case,\
  hicpp-multiway-paths-covered,\
  hicpp-no-assembler,\
  hicpp-signed-bitwise,\
  misc-definitions-in-headers,\
  misc-misplaced-const,\
  misc-new-delete-overloads,\
  misc-no-recursion,\
  misc-non-copyable-objects,\
  misc-redundant-expression,\
  misc-throw-by-value-catch-by-reference,\
  misc-unconventional-assign-operator,\
  misc-unused-parameters,\
  modernize-avoid-bind,\
  modernize-deprecated-headers,\
  modernize-deprecated-ios-base-aliases,\
  modernize-loop-convert,\
  modernize-make-shared,\
  modernize-make-unique,\
  modernize-redundant-void-arg,\
  modernize-replace-auto-ptr,\
  modernize-replace-random-shuffle,\
  modernize-shrink-to-fit,\
  modernize-use-bool-literals,\
  modernize-use-equals-default,\
  modernize-use-equals-delete,\
  modernize-use-nullptr,\
  modernize-use-override,\
  modernize-use-using,\
  performance-faster-string-find,\
  performance-for-range-copy,\
  performance-implicit-conversion-in-loop,\
  performance-inefficient-algorithm,\
  performance-inefficient-string-concatenation,\
  performance-inefficient-vector-operation,\
  performance-move-const-arg,\
  performance-no-automatic-move,\
  performance-trivially-destructible,\
  performance-type-promotion-in-math-fn,\
  performance-unnecessary-value-param,\
  portability-simd-intrinsics,\
  readability-braces-around-statements,\
  readability-const-return-type,\
  readability-delete-null-pointer,\
  readability-deleted-default,\
  readability-identifier-naming,\
  readability-implicit-bool-conversion,\
  readability-inconsistent-declaration-parameter-name,\
  readability-isolate-declaration,\
  readability-make-member-function-const,\
  readability-misleading-indentation,\
  readability-misplaced-array-index,\
  readability-non-const-parameter,\
  readability-redundant-access-specifiers,\
  readability-redundant-control-flow,\
  readability-redundant-function-ptr-dereference,\
  readability-redundant-preprocessor,\
  readability-redundant-smartptr-get,\
  readability-simplify-boolean-expr,\
  readability-simplify-subscript-expr,\
  readability-static-definition-in-anonymous-namespace,\
  readability-string-compare,\
  readability-uniqueptr-delete-release,\
  readability-uppercase-literal-suffix,\
  readability-use-anyofallof,\
  "

CheckOptions:
  - key: IgnoredMacros
    value: "TEST,INSTANTIATE,BENCHMARK,MATCHER"
  - key: cppcoreguidelines-special-member-functions.AllowSoleDefaultDtor
    value: true
  - key: misc-non-private-member-variables-in-classes.IgnoreClassesWithAllMemberVariablesBeingPublic
    value: true
  - key: readability-inconsistent-declaration-parameter-name.Strict
    value: true
  - key: readability-identifier-naming.UnionCase
    value: CamelCase
@fklebert fklebert changed the title Add clang-tidy to the static code analysis Add clang-tidy to the C++ static code analysis Mar 20, 2023
@fklebert fklebert added this to the 2.11 milestone Mar 20, 2023
@mikir mikir added the c++ C++ language generator label Mar 21, 2023
@Mi-La Mi-La self-assigned this Mar 21, 2023
Mi-La added a commit that referenced this issue Mar 24, 2023
Mi-La added a commit that referenced this issue Mar 24, 2023
* clang-analyzer-cplusplus.NewDeleteLeaks
Mi-La added a commit that referenced this issue Mar 24, 2023
Mi-La added a commit that referenced this issue Mar 24, 2023
Mi-La added a commit that referenced this issue Mar 24, 2023
Mi-La added a commit that referenced this issue Mar 24, 2023
* clang-analyzer-cplusplus.NewDeleteLeaks
Mi-La added a commit that referenced this issue Mar 24, 2023
Mi-La added a commit that referenced this issue Mar 24, 2023
* clang-analyzer-cplusplus.NewDeleteLeaks
Mi-La added a commit that referenced this issue Mar 27, 2023
* and very similar clang-analyzer-cplusplus.Move
mikir added a commit that referenced this issue May 2, 2023
This improve hidden installation of coverage report as well.
Mi-La added a commit that referenced this issue May 3, 2023
@mikir
Copy link
Contributor

mikir commented May 10, 2023

We use the same clang-tidy config file as requested.

The complete clang-tidy report of C++ runtime library would be available in each release in zserio-version-runtime-libs.zip file in directory runtime_libs/cpp/zserio_doc/clang-tidy/.

Please note that not all rules can be fixed (e.g. cppcoreguidelines-pro-type-reinterpret-cast, we need reinterpret_cast for AnyHolder and OptionalHolder). This is because C++ runtime library is very low level (e.g. it mimics std::span or std::string_view standard abstractions from C++17).

In all cases, all clang-tidy findings which are currently reported have been carefully checked and filtered out using definitions in clang-tidy suppression file. This suppression file contains as well the brief reasoning why these findings are not fixed.

This solution with suppression file has been chosen not to pollute C++ runtime sources with // NOLINT comments and to
allow implementation of warnings-as-error feature. The clang-tidy suppression file is automatically used
during compilation using CMake.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
c++ C++ language generator
Projects
None yet
Development

No branches or pull requests

3 participants