-
Notifications
You must be signed in to change notification settings - Fork 23
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
C headers treated as C++ #15
Comments
Not sure but it could be that you have the |
Thanks for the quick response! Do you mind elaborating on |
Haha, I'm sorry, I thought this issue was on another project of mine! 😄 Well, I assume it is not wrong that the header is C++. Regarding clang-tidy, I think the header file should not be checked, instead the main file should be checked. The header compilation database is more useful to text editors for things like completion I think. |
The command looks like this for the header: And its associated implementation file looks like this: And here's the command for one of the CPP files that includes the C header: Based on this one example, it appears that the commands for the CPP file overrode the ones for the header's implementation file. What do you think about giving precedence to the commands that are associated with the implementation file if it can be determined? As a first step, a naive implementation could just look for a file with the same name, but with a different file extension (i.e., We actually got benefit from running tidy over headers directly instead of just using the header filter. For one, it found some headers that were missing necessary includes because every implementation file it was included in had those missing includes. Also, we run tidy as part of our CI, but for efficiency, we only run it over files that have changed. When someone changed only a header, we previously weren't able to validate those changes. |
This is already done:
The last entry is just to show the prevalence of a file in the same directory with just a different extension.
A general rule to guard against this is to have the first include in the main file be the header, see https://llvm.org/docs/CodingStandards.html#include-style.
I think it would be more correct to check all the files this header is included-by (directly or transitively), as a change in a header file, might produce clang-tidy warnings in a file using it. |
I work in a code base where there is a mixture of C and C++. I noticed that C headers (files that are guarded by
extern "C"
) are being treated like C++ files, which causes tooling like Clang Tidy to apply C++ specific checks to these files. I believe the issue could happen specifically when C headers are included in C++ files.The text was updated successfully, but these errors were encountered: