File tree Expand file tree Collapse file tree 5 files changed +43
-2
lines changed Expand file tree Collapse file tree 5 files changed +43
-2
lines changed Original file line number Diff line number Diff line change @@ -57,6 +57,17 @@ AST_MATCHER(QualType, isPointerType) {
57
57
58
58
} // namespace
59
59
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
+
60
71
void MultiLevelImplicitPointerConversionCheck::registerMatchers (
61
72
MatchFinder *Finder) {
62
73
Finder->addMatcher (
Original file line number Diff line number Diff line change @@ -21,11 +21,17 @@ namespace clang::tidy::bugprone {
21
21
class MultiLevelImplicitPointerConversionCheck : public ClangTidyCheck {
22
22
public:
23
23
MultiLevelImplicitPointerConversionCheck (StringRef Name,
24
- ClangTidyContext *Context)
25
- : ClangTidyCheck(Name, Context) {}
24
+ ClangTidyContext *Context);
25
+ void storeOptions (ClangTidyOptions::OptionMap &Opts) override ;
26
26
void registerMatchers (ast_matchers::MatchFinder *Finder) override ;
27
27
void check (const ast_matchers::MatchFinder::MatchResult &Result) override ;
28
28
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;
29
35
};
30
36
31
37
} // namespace clang::tidy::bugprone
Original file line number Diff line number Diff line change @@ -159,6 +159,10 @@ Changes in existing checks
159
159
false positives on deleted constructors that cannot be used to construct
160
160
objects, even if they have public or protected access.
161
161
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
+
162
166
- Improved :doc: `bugprone-optional-value-conversion
163
167
<clang-tidy/checks/bugprone/optional-value-conversion>` check to detect
164
168
conversion in argument of ``std::make_optional ``.
Original file line number Diff line number Diff line change @@ -42,3 +42,12 @@ Additionally, it is recommended that developers thoroughly check and verify the
42
42
safety of the conversion before using an explicit cast. This extra level of
43
43
caution can help catch potential issues early on in the development process,
44
44
improving the overall reliability and maintainability of the code.
45
+
46
+
47
+ Options
48
+ -------
49
+
50
+ .. option :: EnableInC
51
+
52
+ If `true `, enables the check in C code (it is always enabled in C++ code).
53
+ 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