Getting clang-tidy to fix header files

I am in the process of moving a project that is now compiled with gcc to clang and have a bunch of warnings that gcc did not generate ( -Winconsistent-missing-override ). clang-tidy works to fix these errors in *.cpp files, however it does not apply to hpp files because the compilation command was not found in the database (as you would expect).

I use ninja to create a project and ninja -t compdb cc cxx > .build/compile_commands.json to create a compilation database. I tried to work:

 clang-tidy-3.6 -p .build/ \ $(find src/ -name *.cpp) \ $(find src/ -name *.hpp) \ --checks=misc-use-override --fix 

to fix errors. He refuses to touch the header files complaining:

 Skipping .../src/header/file.hpp. Compile command not found. 
+10
c ++ clang ++ llvm-clang automated-refactoring clang-tidy
source share
2 answers

I got it by specifying the option --header-filter=src/ . Interesting fixes were eventually applied several times, causing the output as follows:

 void f() override override override override override; 

I worked on this by running clang-tidy in each source file separately. Also note that the <build-path> specified with -p must also contain the .clang-format configuration for styling to be applied.

This is my current iteration of the command:

 find src/ -name '*.cpp' -exec \ clang-tidy-3.6 -p . --header-filter=src/ {} --checks=misc-use-override --fix 
+10
source share

Be careful when using the "-header-filter" correctly. There are no two minus signs in front of the heading! Unlike the answer in nishantjr.

As shown here: http://releases.llvm.org/3.9.0/tools/clang/tools/extra/docs/clang-tidy/index.html

This is still true in Clang-Tidy 9.0.

0
source share

All Articles