File tree Expand file tree Collapse file tree 3 files changed +14
-3
lines changed Expand file tree Collapse file tree 3 files changed +14
-3
lines changed Original file line number Diff line number Diff line change 7
7
// ===----------------------------------------------------------------------===//
8
8
9
9
#include " CastingThroughVoidCheck.h"
10
- #include " clang/AST/ASTContext.h"
11
10
#include " clang/AST/Expr.h"
12
11
#include " clang/AST/Type.h"
13
12
#include " clang/ASTMatchers/ASTMatchFinder.h"
14
13
#include " clang/ASTMatchers/ASTMatchers.h"
15
- #include " llvm/ADT/StringSet.h"
16
14
17
15
using namespace clang ::ast_matchers;
18
16
@@ -27,7 +25,8 @@ void CastingThroughVoidCheck::registerMatchers(MatchFinder *Finder) {
27
25
hasSourceExpression (
28
26
explicitCastExpr (
29
27
hasSourceExpression (
30
- expr (hasType (qualType ().bind (" source_type" )))),
28
+ expr (hasType (qualType (unless (pointsTo (voidType ())))
29
+ .bind (" source_type" )))),
31
30
hasDestinationType (
32
31
qualType (pointsTo (voidType ())).bind (" void_type" )))
33
32
.bind (" cast" ))),
Original file line number Diff line number Diff line change @@ -173,6 +173,11 @@ Changes in existing checks
173
173
<clang-tidy/checks/bugprone/assert-side-effect>` check by detecting side
174
174
effect from calling a method with non-const reference parameters.
175
175
176
+ - Improved :doc: `bugprone-casting-through-void
177
+ <clang-tidy/checks/bugprone/casting-through-void>` check by ignoring casts
178
+ where source is already a ``void` `` pointer, making middle ``void `` pointer
179
+ casts bug-free.
180
+
176
181
- Improved :doc: `bugprone-forwarding-reference-overload
177
182
<clang-tidy/checks/bugprone/forwarding-reference-overload>`
178
183
check to ignore deleted constructors which won't hide other overloads.
Original file line number Diff line number Diff line change @@ -89,3 +89,10 @@ void bit_cast() {
89
89
__builtin_bit_cast (int *, static_cast <void *>(&d));
90
90
// CHECK-MESSAGES: :[[@LINE-1]]:29: warning: do not cast 'double *' to 'int *' through 'void *' [bugprone-casting-through-void]
91
91
}
92
+
93
+ namespace PR87069 {
94
+ void castconstVoidToVoid () {
95
+ const void * ptr = nullptr ;
96
+ int * numberPtr = static_cast <int *>(const_cast <void *>(ptr));
97
+ }
98
+ }
You can’t perform that action at this time.
0 commit comments