[clang-tools-extra] [clang-tidy]Add new check bugprone-casting-through-void (PR #69465)
Piotr Zegar via cfe-commits
cfe-commits at lists.llvm.org
Wed Oct 18 07:28:57 PDT 2023
================
@@ -0,0 +1,18 @@
+// RUN: %check_clang_tidy %s bugprone-casting-through-void %t
+
+using T = void*;
+
+void test() {
+ int i = 100;
+ double d = 100;
+
+ static_cast<int *>(static_cast<void *>(&d));
+ // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: do not cast double * to int * through void * [bugprone-casting-through-void]
+
+ static_cast<int *>(static_cast<T>(&d));
+ // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: do not cast double * to int * through void * [bugprone-casting-through-void]
+
+ static_cast<int *>(static_cast<void *>(&i));
+
+ static_cast<void *>(static_cast<void *>(&i));
+}
----------------
PiotrZSL wrote:
add more mixed tests, with c-cast, reinterpret cast, const_cast.
Add test with cast to `const void*`, and also test with functional cast would be needed like:
```
struct A
{
A(void*);
};
return A(static_cast<void*>(ptr)); // need to be checked if this trigger CXXFunctinalCast with ConstructorConversion kind.
```
https://github.com/llvm/llvm-project/pull/69465
More information about the cfe-commits
mailing list