In-depth study Clang (thirteen) clang-tidy Profile

In recent days, attention clang-tidy, there is some experience, do some simple notes. Share to interested friends, but also for yourself in the future.

1, clang-tidy-based AST static checking tool. Because it is based AST, based on static checking tool so than regular expressions more precise, but the drawback is that than to bring static checking tool based on regular expressions slowly. AST also because it is based on, so when the clang-tidy need to know to run the compiler command.

2, clang-tidy can not only do static checking, you can also do some repair work.

3, clang-tidy-based LibTooling tool. And LibTooling is a library that is mainly based on Clang to write a separate tool. clang clang-tidy part of the extra tools, and the clang of tools at different levels in the source directory, is the difference clang / tools and clang / tools / extra's.

4, clang-tidy added by adding check inspection rules, there are already a series of check: Extra Clang 10 Tools Documentation  by clang-tidy -list-checks will be enabled by default listed in the check, clang-tidy-tidy -list- checks -checks = * will list all of the check.

5, clang-tidy once for each TU, that is, a single cpp file and can not cross the TU. However, you can use run-clang-tidy.py under the clang-tidy / tool / source directory to check the batch file.

6、clang-tidy还可以调用clang static analyzer的check.(clang-tidy has its own checks and can also run Clang static analyzer checks.)

7, clang-tidy because the compiler needs to know the command, you must get the compiler command compile_commands.json, or by the clang-tidy by - adding compile options. Which, compile_commands.json generation can refer to the documentation LibTooling , it can be understood as based on the need to generate the file LibTooling of. compile_commands.json mainly comprising compiling each directory command, it generates a system built by cmake -DCMAKE_EXPORT_COMPILE_COMMANDS = ON; build system which can be generated by Makefile compiledb . I tried other building systems gn and ninja, gn can. --Export-compile-commands generate json file this form by gn gen, ninja can> compile_commands.json this form json file generated by ninja -t compdb cxx cc. Currently it has been summed up more of use, reference may be MaskRay / ccls  and  Compilation database these two articles.

8, the system can be run after clang-tidy, run-clang-tidy.py direct copy can be tested using the directory.

9, clang-tidy-based C ++ development.

发布了195 篇原创文章 · 获赞 557 · 访问量 111万+

Guess you like

Origin blog.csdn.net/snsn1984/article/details/103935196