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

[clang-tidy] some clang-diagnostic checks are not available. #117264

Closed
hoyhoy opened this issue Nov 21, 2024 · 5 comments
Closed

[clang-tidy] some clang-diagnostic checks are not available. #117264

hoyhoy opened this issue Nov 21, 2024 · 5 comments
Labels
clang-tidy invalid Resolved as invalid, i.e. not a bug

Comments

@hoyhoy
Copy link

hoyhoy commented Nov 21, 2024

Possibly anything not included by -Wextra...

The clang-dianostic-strict-prototypes check can't be enabled by llvm 19.1.4's clang-tidy. Explicitly enabling it with clang-dianostic-strict-prototypes in a .clang-tidy file doesn't work. Is there some way to enable this manually? Seems like a bug.

This prevents VSCode from being able to auto-correct these issues.

@hoyhoy hoyhoy changed the title [clang-tidy] Some clang-diagnostic checks are no available. [clang-tidy] some clang-diagnostic checks are not available. Nov 21, 2024
@AaronBallman AaronBallman added the invalid Resolved as invalid, i.e. not a bug label Nov 22, 2024
@AaronBallman
Copy link
Collaborator

clang-tidy does not allow you to enable Clang warnings which are not enabled by the build system:

Clang diagnostics are treated in a similar way as check diagnostics. Clang diagnostics are displayed by clang-tidy and can be filtered out using the -checks= option. However, the -checks= option does not affect compilation arguments, so it cannot turn on Clang warnings which are not already turned on in the build configuration. The -warnings-as-errors= option upgrades any warnings emitted under the -checks= flag to errors (but it does not enable any checks itself).

Enabling the diagnostic in Clang will cause it to be displayed by clang-tidy: https://godbolt.org/z/WcrhWd8q7

Closing the issue as not a bug, but if you think this is incorrect, feel free to reopen with more information!

@AaronBallman AaronBallman closed this as not planned Won't fix, can't repro, duplicate, stale Nov 22, 2024
@hoyhoy
Copy link
Author

hoyhoy commented Nov 22, 2024

Yeah, I know I can enable it with -Wstrict-prototypes, but VSCode doesn't flag it as a "problem" unless clang-tidy emits the warning.

I have -Wstrict-prototypes enabled and I'm pointing clang-tidy to my compile_commands.json, but clang-tidy doesn't emit it. Do these all have to be enabled with --extra-arg?

@AaronBallman
Copy link
Collaborator

Yeah, I know I can enable it with -Wstrict-prototypes, but VSCode doesn't flag it as a "problem" unless clang-tidy emits the warning.

Huh, that could be a bug with VSCode?

I have the warning enabled for the compile and I'm pointing clang-tidy to my compile_commands.json with the warning enabled, but clang-tidy doesn't emit the warning. Do these all have to be enabled with --extra-arg?

Okay, something odd is going on then because I cannot reproduce that behavior. If the warning is enabled for your compile, clang-tidy should emit the warning. Can you provide a small reproducer that includes one source file and a compile_commands.json for it? Maybe I'm trying something different from what you're doing.

Reopening the issue while we continue the discussion.

@AaronBallman AaronBallman reopened this Nov 22, 2024
@hoyhoy
Copy link
Author

hoyhoy commented Nov 22, 2024

Let me see if I can repro it with a simple example.

I was attempting to make VSCode flag these as "problems" so it could (in theory) automatically fix them. I'm working on an old code base that had over 50 -Wstrict-prototypes issues. I ended up just fixing those all by hand.

What I did get to work was using VSCode to fix over 200 readability-inconsistent-declaration-parameter-name problems in our code base. Unfortunately, doing a mass "Quick Fix" opened up 200 tabs in the editor. It seems VSCode wasn't really intended to batch modify this many files using Code Analysis "Quick Fix"es. It did work without crashing though. So there's that.

@hoyhoy
Copy link
Author

hoyhoy commented Nov 22, 2024

Yeah, clang-tidy works if I pass it a compile_commands.json with -Wstrict-prototypes enabled...

[
{
  "directory": ".",
  "command": "/opt/llvm19.1.4/bin/clang strict_prototype.c -Wstrict-prototypes -o strict_prototype",
  "file": "/tmp/strict_prototype.c",
  "output": "strict_prototype"
}
]
$ clang-tidy --config-file=.clang-tidy-new-code -p compile_commands.json strict_prototype.c 
276 warnings generated.
strict_prototype.c:3:15: error: a function declaration without a prototype is deprecated in all versions of C [clang-diagnostic-strict-prototypes,-warnings-as-errors]
    3 | void bad_proto() {
      |               ^
      |                void

Must be a VSCode issue or maybe my compile_commands.json didn't have the flag set...

It's kinda surprising that just enabling clang-diagnostics-strict-prototypes doesn't work by itself though.

@hoyhoy hoyhoy closed this as completed Nov 22, 2024
@EugeneZelenko EugeneZelenko closed this as not planned Won't fix, can't repro, duplicate, stale Nov 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
clang-tidy invalid Resolved as invalid, i.e. not a bug
Projects
None yet
Development

No branches or pull requests

3 participants