clang-tidy checks and fixing remaining checks

clang-tidy is now being run on master for SMTK and CMB. The CI build will fail if any warnings are made from it.

You can run it locally by doing -DCMAKE_{C,CXX}_CLANG_TIDY=$(which clang-tidy) on the command line to tell CMake to build your code with clang-tidy as well. Note that third party code is masked from this, so it will not use clang-tidy (you can unmask it by removing the lines in thirdparty/CMakeLists.txt if you’re interested). If you’d like to fix things locally, I recommend uncommenting the WarningsAsErrors line in the .clang-tidy file in the source tree, remove the masking check in the list and then build until it is clean. Without the WarningsAsErrors line, you’ll need to make clean to get the clang-tidy output again (since the .clang-tidy file changing doesn’t trigger a rebuild). Adding ;-fix to the value will have clang-tidy edit your code when it builds it (not everything is automatically fixable though).

The list of checks currently masked are:

Should investigate and fix or add a NOLINT comment:

  • bugprone-branch-clone
  • bugprone-exception-escape
  • bugprone-inaccurate-erase
  • bugprone-incorrect-roundings
  • bugprone-integer-division
  • bugprone-misplaced-widening-cast
  • bugprone-narrowing-conversions
  • bugprone-sizeof-expression
  • bugprone-string-integer-assignment
  • bugprone-unhandled-self-assignment
  • clang-analyzer-deadcode.DeadStores
  • clang-analyzer-optin.cplusplus.VirtualCall
  • clang-analyzer-security.FloatLoopCounter
  • clang-analyzer-security.insecureAPI.strcpy
  • misc-redundant-expression
  • misc-throw-by-value-catch-by-reference
  • modernize-avoid-c-arrays
  • modernize-loop-convert
  • modernize-raw-string-literal
  • modernize-return-braced-init-list
  • modernize-use-auto
  • modernize-use-using
  • performance-inefficient-string-concatenation
  • performance-move-const-arg
  • readability-braces-around-statements
  • readability-else-after-return
  • readability-inconsistent-declaration-parameter-name
  • readability-isolate-declaration
  • readability-redundant-control-flow

Probably affects APIs:

  • misc-non-private-member-variables-in-classes
  • modernize-pass-by-value
  • performance-unnecessary-value-param
  • readability-const-return-type
  • readability-convert-member-functions-to-static
  • readability-non-const-parameter

Of interest, but probably not largely of interest to SMTK/CMB code:

  • performance-type-promotion-in-math-fn
  • readability-implicit-bool-conversion
  • readability-magic-numbers
  • readability-uppercase-literal-suffix

Should be fixed, but may be hard (needs more detailed analysis):

  • clang-analyzer-core.CallAndMessage
  • clang-analyzer-core.DivideZero
  • clang-analyzer-core.NonNullParamChecker
  • clang-analyzer-core.NullDereference
  • clang-analyzer-core.UndefinedBinaryOperatorResult
  • clang-analyzer-core.uninitialized.Assign
  • clang-analyzer-core.uninitialized.Branch
  • clang-analyzer-cplusplus.NewDelete
  • clang-analyzer-cplusplus.NewDeleteLeaks
  • clang-analyzer-optin.cplusplus.UninitializedObject

Unlikely to ever be fixed, but may be of interest:

  • cert-*
  • cppcoreguidelines-*
  • google-readability-casting
  • hicpp-*
  • modernize-use-trailing-return-type

Masked due to generated code (updating VTK and/or ParaView necessary to unmask these):

  • readability-named-parameter