The current interface
Right now to enable additional clang diagnostics, one has to specify extra arguments on either the command line, or in the .clang-tidy
config file.
This means invocations like the ones below:
clang-tidy --checks="bugprone-*" foo.c -- -Wall
clang-tidy --checks="bugprone-*" --extra-arg="-Wall" foo.c --
As well as config files like the one below.
# .clang-tidy Checks: bugprone-* ExtraArgs: ["-Wall"]
The proposed checks
The idea is to merge this functionality with the commonly used checks interface, so the invocation for enabling the -Wall
flag would look like this:
clang-tidy --checks="clang-additional-diagnostic-all" foo.c --
This would allow users to control additional diagnostics and checks with the same interface. Also with this change it would be possible to enable multiple common warnings with only one check instead of having to type out each of them separately.
- clang-tidy --extra-arg="-Wunused-but-set-parameter" --extra-arg="-Wunused-command-line-argument" ... + clang-tidy --checks="clang-additional-diagnostic-unused-*" ...
Similarity with existing checks
The clang-additional-diagnostic
name was chosen to avoid interfering with the already existing clang-diagnostic
checks, which can be used to filter default warning messages.
clang-tidy --checks="-*,clang-diagnostic-return-type,..." foo.c --
The above call means that none of the default warnings reported by clang are shown to the user except for -Wreturn-type
.
Check to flag mapping
The clang-additional-diagnostic
checks would map like this:
--checks="clang-additional-diagnostic-unused"
→-Wunused
--checks="-clang-additional-diagnostic-unused"
→-Wno-unused
Optionally we could allow passing values to the warning flags as well, although I think only one warning allows it at the moment:
--checks="clang-additional-frame-larger-than" --config="{CheckOptions: [{key: clang-additional-frame-larger-than, value:X}]}"
→ -Wframe-larger-than=X
RFC
The idea came up during a discussion in a PR, and I wonder what the community thinks about implementing such a change.
Would you find it helpful?