42 lines · cpp
1// RUN: %check_clang_tidy %s bugprone-bitwise-pointer-cast %t2 3void memcpy(void* to, void* dst, unsigned long long size)4{5 // Dummy implementation for the purpose of the test6}7 8namespace std9{10using ::memcpy;11}12 13void pointer2pointer()14{15 int x{};16 int* px{};17 float y{};18 float* py{};19 20 memcpy(&py, &px, sizeof(px));21 // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: do not use 'memcpy' to cast between pointers [bugprone-bitwise-pointer-cast]22 std::memcpy(&py, &px, sizeof(px));23 // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: do not use 'memcpy' to cast between pointers [bugprone-bitwise-pointer-cast]24 25 std::memcpy(&y, &x, sizeof(x));26}27 28// Pointer-integer conversions are allowed by this check29void int2pointer()30{31 unsigned long long addr{};32 float* p{};33 std::memcpy(&p, &addr, sizeof(addr));34}35 36void pointer2int()37{38 unsigned long long addr{};39 float* p{};40 std::memcpy(&addr, &p, sizeof(p));41}42