-
Notifications
You must be signed in to change notification settings - Fork 248
How to use Clang Tidy to automatically correct code
Clang-Tidy is a tool developed and maintained by the Clang/LLVM community. The official documentation can be found at http://clang.llvm.org/extra/clang-tidy/. When running Linux, clang-tidy is usually easy to get via your distribution’s package manager. On Ubuntu Linux:
sudo apt-get install clang-tidy
Additionally you can download directly in the project page.
A typical invocation of the command-line tool looks like this:
clang-tidy test.cpp -- -Imy_project/include -DMY_DEFINES ...
Executing it like this, the tool will print a bunch of warnings and notes (if applicable), in exactly the same way Clang/GCC provide diagnostics, too.
The avalaible checkers avaible can be found with the following command:
clang-tidy --list-checks -checks='*' | grep "modernize"
modernize-avoid-bind
modernize-deprecated-headers
modernize-loop-convert
modernize-make-shared
modernize-make-unique
modernize-pass-by-value
modernize-raw-string-literal
modernize-redundant-void-arg
modernize-replace-auto-ptr
modernize-shrink-to-fit
modernize-use-auto
modernize-use-bool-literals
modernize-use-default
modernize-use-emplace
modernize-use-nullptr
modernize-use-override
modernize-use-using
To correct the code we can use the command -fix
(not all the avalaible checkers have the -fix
function). For example to add the missing overrides in the following code:
struct Base {
virtual void reimplementMe(int a) {}
};
struct Derived : public Base {
virtual void reimplementMe(int a) {}
};
We use the next command:
clang-tidy -checks='modernize-use-override' -fix test.cpp -- -std=c++11
The previous example will work just with a very simple example contained in one file. To correct the whole project we will need to create a json
file containing all the file in the project. For that we add the following line to ou configure.sh:
-DCMAKE_EXPORT_COMPILE_COMMANDS=ON \
This will create a file named compile_commands.json
that we will use with the following python script from the LLVM project).
Once we have the script and the json file we can check and fix the whole project by the following way:
run-clang-tidy.py -header-filter='.*' -checks='-*,modernize-use-override' -fix
You can run simmultaneously all the possible modernize commands using the following shell script.
sh modernize.sh
- Getting Kratos (Last compiled Release)
- Compiling Kratos
- Running an example from GiD
- Kratos input files and I/O
- Data management
- Solving strategies
- Manipulating solution values
- Multiphysics
- Video tutorials
- Style Guide
- Authorship of Kratos files
- Configure .gitignore
- How to configure clang-format
- How to use smart pointer in Kratos
- How to define adjoint elements and response functions
- Visibility and Exposure
- Namespaces and Static Classes
Kratos structure
Conventions
Solvers
Debugging, profiling and testing
- Compiling Kratos in debug mode
- Debugging Kratos using GDB
- Cross-debugging Kratos under Windows
- Debugging Kratos C++ under Windows
- Checking memory usage with Valgind
- Profiling Kratos with MAQAO
- Creating unitary tests
- Using ThreadSanitizer to detect OMP data race bugs
- Debugging Memory with ASAN
HOW TOs
- How to create applications
- Python Tutorials
- Kratos For Dummies (I)
- List of classes and variables accessible via python
- How to use Logger
- How to Create a New Application using cmake
- How to write a JSON configuration file
- How to Access DataBase
- How to use quaternions in Kratos
- How to do Mapping between nonmatching meshes
- How to use Clang-Tidy to automatically correct code
- How to use the Constitutive Law class
- How to use Serialization
- How to use GlobalPointerCommunicator
- How to use PointerMapCommunicator
- How to use the Geometry
- How to use processes for BCs
- How to use Parallel Utilities in futureproofing the code
- Porting to Pybind11 (LEGACY CODE)
- Porting to AMatrix
- How to use Cotire
- Applications: Python-modules
- How to run multiple cases using PyCOMPSs
- How to apply a function to a list of variables
- How to use Kratos Native sparse linear algebra
Utilities
Kratos API
Kratos Structural Mechanics API