Code Yarns ‍👨‍💻
Tech BlogPersonal Blog

How to use clang-tidy

📅 2019-Jan-28 ⬩ ✍️ Ashwin Nanjappa ⬩ 🏷️ clang-tidy, llvm, static checker ⬩ 📚 Archive

clang-tidy is a LLVM tool that can be used as a static checker on your C++ codebase and to fix errors it finds. A full list of current checks and their descriptions can be found here. The number of checks available to you will depend on the clang-tidy version you are using.

$ sudo apt install clang-tidy

This typically installs a stable but older version of the tool with less number of checks. It is recommended the latest version if you like a larger number of checks to use.

$ clang-tidy -list-checks

On my computer I found it had 80 checks enabled by default.

$ clang-tidy -list-checks -checks="*"

On my computer I found that it had a total of 292 checks.

$ clang-tidy foobar.cpp
$ clang-tidy -fix foobar.cpp
$ clang-tidy -fix-errors foobar.cpp
$ clang-tidy -checks="-*,modernize-use-nullptr" foobar.cpp
$ clang-tidy -dump-config

Tried with: clang-tidy 6.0.0 and Ubuntu 18.04