Clang-Tidy warnings not appearing in header files (Using Visual Studio Code)

Greetings,

I have been running clang-tidy tool check in a C++ project, but it only works in .cpp, not in header files.
1- Do I have to add an specific configuration in my .clang-tidy file to start working the checks in header files?
2- In Visual Studio Code, I tried to use header filter option, adding this line:
“C_Cpp.codeAnalysis.clangTidy.headerFilter”: “${workspaceFolder}” or
“C_Cpp.codeAnalysis.clangTidy.headerFilter”: “.*” but it still did not work.

I hope someone could support me on this issue! I wanted to my .clang-tidy file here, but as a new user, it is not possible.

Thank you in advance!

Hi!

Yes, you need to enable HeaderFilter: ".*" in your .clang-tidy file. In seems the VS Code settings should do the same, but I haven’t used that plugin so I can’t tell if there’s anything wrong. Putting this in the .clang-tidy file should work.

1 Like

Hi Carlos, thanks for the advice!

1- I took some time to test it in my project. Actually I included this HeaderFilter option in my .clang-tidy file, which is HeaderFilterRegex: “.*”, according to Clang-Tidy — Extra Clang Tools 19.0.0git documentation (llvm.org).
2- Diagnostics are now appearing in many header files. However, header files with interface classes or headers with some virtual (member) functions do not show any warnings. Could it be an issue of the Clang version I am currently working (version15)? An additional interesting fact: if I rename one of these “contains virtual” header files (which means separating it from the project), the warnings will appear!

I appreciate if you again (or anyone) could give me a feedback on this and once again, I thank you (all) in advance!

Update: after installing the add-on clangd - Visual Studio Marketplace, clang-tidy checks warnings works properly when opening header files that contains “any virtual content”. Using only C/C++ add-on is not sufficient, resulting the problem I mentioned in previous post, item 2.

Great that you solved it! Often times these issues stem from how the build system is configured. When in doubt, try first to run the raw clang-tidy binary on the header file directly. It that works, then the problem lies on the build system/plugin/etc.

1 Like