File tree 3 files changed +26
-1
lines changed
3 files changed +26
-1
lines changed Original file line number Diff line number Diff line change @@ -48,12 +48,21 @@ AST_MATCHER(ImplicitCastExpr, isMultiLevelPointerConversion) {
48
48
return SourcePtrLevel != TargetPtrLevel;
49
49
}
50
50
51
+ AST_MATCHER (QualType, isPointerType) {
52
+ const QualType Type =
53
+ Node.getCanonicalType ().getNonReferenceType ().getUnqualifiedType ();
54
+
55
+ return !Type.isNull () && Type->isPointerType ();
56
+ }
57
+
51
58
} // namespace
52
59
53
60
void MultiLevelImplicitPointerConversionCheck::registerMatchers (
54
61
MatchFinder *Finder) {
55
62
Finder->addMatcher (
56
- implicitCastExpr (hasCastKind (CK_BitCast), isMultiLevelPointerConversion ())
63
+ implicitCastExpr (hasCastKind (CK_BitCast), isMultiLevelPointerConversion (),
64
+ unless (hasParent (explicitCastExpr (
65
+ hasDestinationType (isPointerType ())))))
57
66
.bind (" expr" ),
58
67
this );
59
68
}
Original file line number Diff line number Diff line change @@ -224,6 +224,10 @@ Changes in existing checks
224
224
check by ignoring ``__func__ `` macro in lambda captures, initializers of
225
225
default parameters and nested function declarations.
226
226
227
+ - Improved :doc: `bugprone-multi-level-implicit-pointer-conversion
228
+ <clang-tidy/checks/bugprone/multi-level-implicit-pointer-conversion>` check
229
+ by ignoring implicit pointer conversions that are part of a cast expression.
230
+
227
231
- Improved :doc: `bugprone-non-zero-enum-to-bool-conversion
228
232
<clang-tidy/checks/bugprone/non-zero-enum-to-bool-conversion>` check by
229
233
eliminating false positives resulting from direct usage of bitwise operators
Original file line number Diff line number Diff line change @@ -63,3 +63,15 @@ void test()
63
63
64
64
takeSecondLevelVoidPtr (getSecondLevelVoidPtr ());
65
65
}
66
+
67
+ namespace PR93959 {
68
+ void free (void *);
69
+
70
+ void test () {
71
+ char **p = nullptr ;
72
+ free (p);
73
+ // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: multilevel pointer conversion from 'char **' to 'void *', please use explicit cast [bugprone-multi-level-implicit-pointer-conversion]
74
+ free ((void *)p);
75
+ free (static_cast <void *>(p));
76
+ }
77
+ }
You can’t perform that action at this time.
0 commit comments