// RUN: %check_clang_tidy %s bugprone-casting-through-void %t using V = void*; using CV = const void*; int i = 100; double d = 100; const int ci = 100; const double cd = 100; void normal_test() { static_cast(static_cast(&d)); // CHECK-MESSAGES: :[[@LINE-1]]:22: warning: do not cast 'double *' to 'int *' through 'void *' [bugprone-casting-through-void] static_cast(static_cast(&d)); // CHECK-MESSAGES: :[[@LINE-1]]:22: warning: do not cast 'double *' to 'int *' through 'V' (aka 'void *') [bugprone-casting-through-void] static_cast(static_cast(&i)); // CHECK-MESSAGES: :[[@LINE-1]]:22: warning: do not cast 'int *' to 'int *' through 'void *' [bugprone-casting-through-void] static_cast(static_cast(&i)); } void const_pointer_test() { static_cast(static_cast(&d)); // CHECK-MESSAGES: :[[@LINE-1]]:27: warning: do not cast 'double *' to 'int *const' through 'void *' [bugprone-casting-through-void] static_cast(static_cast(&d)); // CHECK-MESSAGES: :[[@LINE-1]]:27: warning: do not cast 'double *' to 'int *const' through 'V' (aka 'void *') [bugprone-casting-through-void] static_cast(static_cast(&i)); // CHECK-MESSAGES: :[[@LINE-1]]:27: warning: do not cast 'int *' to 'int *const' through 'void *' [bugprone-casting-through-void] static_cast(static_cast(&i)); } void const_test() { static_cast(static_cast(&d)); // CHECK-MESSAGES: :[[@LINE-1]]:28: warning: do not cast 'double *' to 'const int *' through 'const void *' [bugprone-casting-through-void] static_cast(static_cast(&d)); // CHECK-MESSAGES: :[[@LINE-1]]:28: warning: do not cast 'double *' to 'const int *' through 'const V' (aka 'void *const') [bugprone-casting-through-void] static_cast(static_cast(&i)); // CHECK-MESSAGES: :[[@LINE-1]]:28: warning: do not cast 'int *' to 'const int *' through 'const void *' [bugprone-casting-through-void] static_cast(static_cast(&i)); static_cast(static_cast(&cd)); // CHECK-MESSAGES: :[[@LINE-1]]:28: warning: do not cast 'const double *' to 'const int *' through 'const void *' [bugprone-casting-through-void] static_cast(static_cast(&cd)); // CHECK-MESSAGES: :[[@LINE-1]]:28: warning: do not cast 'const double *' to 'const int *' through 'const CV' (aka 'const void *const') [bugprone-casting-through-void] static_cast(static_cast(&ci)); // CHECK-MESSAGES: :[[@LINE-1]]:28: warning: do not cast 'const int *' to 'const int *' through 'const void *' [bugprone-casting-through-void] static_cast(static_cast(&ci)); } void reinterpret_cast_test() { static_cast(reinterpret_cast(&d)); // CHECK-MESSAGES: :[[@LINE-1]]:22: warning: do not cast 'double *' to 'int *' through 'void *' [bugprone-casting-through-void] reinterpret_cast(static_cast(&d)); // CHECK-MESSAGES: :[[@LINE-1]]:27: warning: do not cast 'double *' to 'int *' through 'void *' [bugprone-casting-through-void] reinterpret_cast(reinterpret_cast(&d)); // CHECK-MESSAGES: :[[@LINE-1]]:27: warning: do not cast 'double *' to 'int *' through 'void *' [bugprone-casting-through-void] static_cast(reinterpret_cast(&i)); reinterpret_cast(reinterpret_cast(&i)); reinterpret_cast(static_cast(&i)); } void c_style_cast_test() { static_cast((void *)&d); // CHECK-MESSAGES: :[[@LINE-1]]:22: warning: do not cast 'double *' to 'int *' through 'void *' [bugprone-casting-through-void] (int *)(void *)&d; // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: do not cast 'double *' to 'int *' through 'void *' [bugprone-casting-through-void] static_cast((void *)&d); // CHECK-MESSAGES: :[[@LINE-1]]:22: warning: do not cast 'double *' to 'int *' through 'void *' [bugprone-casting-through-void] static_cast((void *)&i); } struct A { A(void*); }; using I = int *; void cxx_functional_cast() { A(static_cast(&d)); I(static_cast(&d)); // CHECK-MESSAGES: :[[@LINE-1]]:5: warning: do not cast 'double *' to 'I' (aka 'int *') through 'void *' [bugprone-casting-through-void] } void bit_cast() { __builtin_bit_cast(int *, static_cast(&d)); // CHECK-MESSAGES: :[[@LINE-1]]:29: warning: do not cast 'double *' to 'int *' through 'void *' [bugprone-casting-through-void] }