File tree Expand file tree Collapse file tree 5 files changed +42
-2
lines changed Expand file tree Collapse file tree 5 files changed +42
-2
lines changed Original file line number Diff line number Diff line change @@ -57,6 +57,17 @@ AST_MATCHER(QualType, isPointerType) {
5757
5858} // namespace
5959
60+ MultiLevelImplicitPointerConversionCheck::
61+ MultiLevelImplicitPointerConversionCheck (StringRef Name,
62+ ClangTidyContext *Context)
63+ : ClangTidyCheck(Name, Context), EnableInC(Options.get(" EnableInC" , true )) {
64+ }
65+
66+ void MultiLevelImplicitPointerConversionCheck::storeOptions (
67+ ClangTidyOptions::OptionMap &Opts) {
68+ Options.store (Opts, " EnableInC" , EnableInC);
69+ }
70+
6071void MultiLevelImplicitPointerConversionCheck::registerMatchers (
6172 MatchFinder *Finder) {
6273 Finder->addMatcher (
Original file line number Diff line number Diff line change @@ -21,11 +21,17 @@ namespace clang::tidy::bugprone {
2121class MultiLevelImplicitPointerConversionCheck : public ClangTidyCheck {
2222public:
2323 MultiLevelImplicitPointerConversionCheck (StringRef Name,
24- ClangTidyContext *Context)
25- : ClangTidyCheck(Name, Context) {}
24+ ClangTidyContext *Context);
25+ void storeOptions (ClangTidyOptions::OptionMap &Opts) override ;
2626 void registerMatchers (ast_matchers::MatchFinder *Finder) override ;
2727 void check (const ast_matchers::MatchFinder::MatchResult &Result) override ;
2828 std::optional<TraversalKind> getCheckTraversalKind () const override ;
29+ bool isLanguageVersionSupported (const LangOptions &LangOpts) const override {
30+ return EnableInC ? true : LangOpts.CPlusPlus ;
31+ }
32+
33+ private:
34+ bool const EnableInC;
2935};
3036
3137} // namespace clang::tidy::bugprone
Original file line number Diff line number Diff line change @@ -159,6 +159,10 @@ Changes in existing checks
159159 false positives on deleted constructors that cannot be used to construct
160160 objects, even if they have public or protected access.
161161
162+ - Added an option to :doc: `bugprone-multi-level-implicit-pointer-conversion
163+ <clang-tidy/checks/bugprone/multi-level-implicit-pointer-conversion>` to
164+ choose whether to enable the check in C code or not.
165+
162166- Improved :doc: `bugprone-optional-value-conversion
163167 <clang-tidy/checks/bugprone/optional-value-conversion>` check to detect
164168 conversion in argument of ``std::make_optional ``.
Original file line number Diff line number Diff line change @@ -42,3 +42,11 @@ Additionally, it is recommended that developers thoroughly check and verify the
4242safety of the conversion before using an explicit cast. This extra level of
4343caution can help catch potential issues early on in the development process,
4444improving the overall reliability and maintainability of the code.
45+
46+ Options
47+ -------
48+
49+ .. option :: EnableInC
50+
51+ If `true `, enables the check in C code (it is always enabled in C++ code).
52+ Default is `true `.
Original file line number Diff line number Diff line change 1+ // RUN: %check_clang_tidy -check-suffixes=ENABLE-IN-C %s bugprone-multi-level-implicit-pointer-conversion %t -- -config="{CheckOptions: {bugprone-multi-level-implicit-pointer-conversion.EnableInC: true}}"
2+ // RUN: %check_clang_tidy -check-suffixes=DISABLE-IN-C %s bugprone-multi-level-implicit-pointer-conversion %t -- -config="{CheckOptions: {bugprone-multi-level-implicit-pointer-conversion.EnableInC: false}}"
3+
4+ void free (void * );
5+
6+ void test () {
7+ char * * p ;
8+ free (p );
9+ // CHECK-MESSAGES-ENABLE-IN-C: :[[@LINE-1]]:8: warning: multilevel pointer conversion from 'char **' to 'void *', please use explicit cast [bugprone-multi-level-implicit-pointer-conversion]
10+ free ((void * )p );
11+ }
You can’t perform that action at this time.
0 commit comments