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

source code of clang-tools-extra/test/clang-tidy/checkers/bugprone/bitwise-pointer-cast.cpp