Brief introduction
Clang Tidy is a Clang based "linter" tool which goal is to help
fixing typical programming errors.
It is run as a separate compile step of every file, which slows
compilation down but allows to fully analyze the file the same
way as compiler does and catch non-trivial bugprone cases.
About this patch
This change includes:
- CMake option called WITH_CLANG_TIDY which enables Clang Tidy linter tool on all source in the source/ directory.
- CMake module which is aimed to find latest available Clang Tidy.
- Set of rules which allows to have Blender fully compiled without extra issues.
The goal of this change is to provide a base ground so that solving
all the warnings can happen later on, as a team effort.
Technical notes
Personally I was able to use Clang Tidy side-by-side with both
Clang and GCC compilers. With Blender's make developer I run
into some compiler arguments incompatibilities where G++ specific
arguments are passed to clang-tidy. I am not aware of a way to
separate those command line arguments, so either we need to have
some separate configuration for GCC + Clang Tidy so the arguments
do not conflict, or limit Clang Tidy to use with Clang compiler
only.
Currently there is no official way of getting Clang Tidy on macOS.
On Windows, as far as I remember, there is clang-tidy distributed
together with LLVM package. It might work to pass the executable
to CMake via CLANG_TIDY_EXECUTABLE CMake argument, but I did not
test this.
Plan of action
Step 1: Get this ground work refined and put to master branch.
Step 2: Have a team effort to address warnings.
Step 3: Profit.
Step 1 is quite technical and we can easily do it.
Step 2 can be done as Quality Friday team work.
About the warnings
In the configuration files the warnings are split into separate
categories. Here is brief explanation (as I am not sure how to
mic string with comments in YAML).
Readability group.
- readability-uppercase-literal-suffix: think we follow lowercase.
- readability-magic-numbers: sounds very useful, but isn't that smart and often is a false-positive.
- readability-isolate-declaration: we do not follow single declaration per line.
- convert-member-functions-to-static: sometimes class is more readable to be used as namespace.
- implicit-bool-conversion: might consider enabling the warning, but a decision is to be agreed on.
- avoid-const-params-in-decls: this is where some more research is needed. It is rather helpful to have const qualifier in the definition, but not sure it's nice idea to have different const qualifiers for scalars in declaration and definition.
- readability-simplify-boolean-expr: seemed too noisy, but can be a candidate to be enabled.
- readability-make-member-function-const: didn't check how it works with inheritance, and how annoying it could be during development.
- readability-misleading-indentation: seems to be conflicting with our placement of else.
The rest of the warnings are suppressed for the transition period,
I think they all should be resolved from the code
Bugprone group.
- bugprone-narrowing-conversions: is rather annoying to do indexed based loops using vector.size() as an upper boundary.
- bugprone-unhandled-self-assignment: had some false-positives with an older version of clang-tidy. Need to be checked against the latest one.
- bugprone-branch-clone: in some cases duplicate switch cases are less bugprone.
- bugprone-macro-parentheses: we should probably enable it, but I had some false-positives in the past and is quite a noisy change.
Again, the rest of the warnings I consider to be addressed from code
as part of Friday cleanup.