Open zufuliu opened 6 months ago
@llvm/issue-subscribers-clang-static-analyzer
Author: Zufu Liu (zufuliu)
This is, unfortunately, indeed not supported right now, but, as far as I know, this is a planned improvement. (An issue, however, would be that if the CSA checker is taking a configuration flag, as far as I know, there is no way to pass checker configurations of CSA checkers from Clang-Tidy's interface.)
(Also note that this limitation of this "optin" checker is clearly documented: https://clang.llvm.org/docs/analyzer/checkers.html#optin-core-enumcastoutofrange-c-c . There are some plans to make this checker more general in the future, but until then it should not be enabled on projects that want to store flag combinations in enum variables.)
this limitation of this "optin" checker is clearly documented
Thanks for the link, however clang-analyzer-*
does not enable the check in clang-tidy 17.
This checker was improved by recent commits (authored by @gamesh411 and me), so in Clang 17 you can only find an earlier variant that's named alpha.cplusplus.EnumCastOutOfRange
. (Note: this checker is not especially connected to C++, the "cplusplus" in the old name is just misleading. Also note that the old documentation was highly incomplete.)
This checker wasn't enabled by clang-analyzer-*
in clang-tidy 17 because then it was an alpha checker (= has general quality issues, use at your own risk), while now it's an optin checker (= stable, but enforces a guideline or stylistic choice that is useful for some projects, but unwanted in others).
I'd say that the main issue is that the generic clang-analyzer-*
flag, which should provide a "sane default", turns on the optin checkers.
Unfortunately it seems that clang-analyzer-*
is just a "dump" wildcard expression, not a reference to a "smart", curated list of generally useful checkers.
The alpha checkers are disabled by a hardcoded setting, which can be disabled by a hidden undocumented command-line flag for those users who like to see lots of false positives. This solution is appropriate for the alpha checkers but we cannot "borrow" it for the optin checkers, because there we hope that many users will opt in to some of them (which are compatible with their goals).
I don't know what would be the good UI that (1) makes the optin checkers easy to access (2) ensures that the rough "turn on everything" setting produces sane behavior.
related to issue #48725.
https://godbolt.org/z/bhqcoPEPj