Skip to content
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 can mistakenly be recognized as C++ #78

Open
yuyawk opened this issue Oct 14, 2024 · 4 comments · May be fixed by #81
Open

C headers can mistakenly be recognized as C++ #78

yuyawk opened this issue Oct 14, 2024 · 4 comments · May be fixed by #81

Comments

@yuyawk
Copy link
Contributor

yuyawk commented Oct 14, 2024

Hi.

While I'm using bazel_clang_tidy at a01e5e2, I noticed my C header with the extension ".h" is mistakenly recognized as C++.

The cause of this issue is this line. When I changed its condition to src.extension in ["c", "h"], the header was correctly recognized as C.

I'd like to suggest changing that line so that the tool can correctly recognize C/C++, also taking other extensions (e.g. ".C") into account.

Any opinions?

@erenon
Copy link
Owner

erenon commented Oct 14, 2024

I'm not sure :(
I fear that projects use .h files in their C++ programs, and expect those to be considered C++, making this a breaking change.
Unfortunately, the official rules_cc (https://bazel.build/reference/be/c-cpp) does not really make a difference between C and C++ headers, as far as I can tell. Can you think of a solution that is backward compatible? what's your use-case?

@yuyawk
Copy link
Contributor Author

yuyawk commented Oct 14, 2024

I fear that projects use .h files in their C++ programs, and expect those to be considered C++, making this a breaking change.

Yeah that's exactly the pain point. Indeed some people prefer to use ".h" also for C++, as ISO C++ core guideline implies...

Can you think of a solution that is backward compatible?

My idea is to add a command-line option to overwrite the list of the extensions for C. When the command-line option is not set, the behavior will be the same.

what's your use-case?

In my use case, C and C++ files can coexist in a project, but they have separate extensions. That is, ".c" and ".h" for C, and ".cpp" and ".hpp" for C++.

@erenon
Copy link
Owner

erenon commented Oct 14, 2024

This'd still break for larger projects, where the two conventions are mixed. What about a tag on each such target? Would that work for you?

@yuyawk
Copy link
Contributor Author

yuyawk commented Oct 14, 2024

What about a tag on each such target? Would that work for you?

I guess the use of tags will also be fine for my use case.

@yuyawk yuyawk linked a pull request Nov 28, 2024 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants