1// RUN: %check_clang_tidy %s bugprone-multi-level-implicit-pointer-conversion %t
2
3using OneStar = void*;
4using OneStarFancy = OneStar;
5
6void takeFirstLevelVoidPtr(OneStar message);
7void takeFirstLevelConstVoidPtr(const OneStarFancy message);
8void takeFirstLevelConstVoidPtrConst(const void* const message);
9void takeSecondLevelVoidPtr(void** message);
10
11void** getSecondLevelVoidPtr();
12void* getFirstLevelVoidPtr();
13int** getSecondLevelIntPtr();
14int* getFirstLevelIntPtr();
15
16int table[5];
17
18void test()
19{
20 void** secondLevelVoidPtr;
21 int* firstLevelIntPtr;
22
23 // CHECK-MESSAGES: :[[@LINE+1]]:13: warning: multilevel pointer conversion from 'void **' to 'void *', please use explicit cast [bugprone-multi-level-implicit-pointer-conversion]
24 void* a = getSecondLevelVoidPtr();
25
26 void** b = getSecondLevelVoidPtr();
27 void* c = getFirstLevelVoidPtr();
28
29 // CHECK-MESSAGES: :[[@LINE+1]]:13: warning: multilevel pointer conversion from 'int **' to 'void *', please use explicit cast [bugprone-multi-level-implicit-pointer-conversion]
30 void* d = getSecondLevelIntPtr();
31
32 takeFirstLevelVoidPtr(message: &table);
33
34 takeFirstLevelVoidPtr(message: firstLevelIntPtr);
35
36 takeFirstLevelVoidPtr(message: getFirstLevelIntPtr());
37
38 // CHECK-MESSAGES: :[[@LINE+1]]:25: warning: multilevel pointer conversion from 'void **' to 'void *', please use explicit cast [bugprone-multi-level-implicit-pointer-conversion]
39 takeFirstLevelVoidPtr(message: secondLevelVoidPtr);
40
41 // CHECK-MESSAGES: :[[@LINE+1]]:30: warning: multilevel pointer conversion from 'void **' to 'void *', please use explicit cast [bugprone-multi-level-implicit-pointer-conversion]
42 takeFirstLevelConstVoidPtr(message: secondLevelVoidPtr);
43
44 // CHECK-MESSAGES: :[[@LINE+1]]:35: warning: multilevel pointer conversion from 'void **' to 'const void *', please use explicit cast [bugprone-multi-level-implicit-pointer-conversion]
45 takeFirstLevelConstVoidPtrConst(message: secondLevelVoidPtr);
46
47 // CHECK-MESSAGES: :[[@LINE+1]]:35: warning: multilevel pointer conversion from 'void ***' to 'const void *', please use explicit cast [bugprone-multi-level-implicit-pointer-conversion]
48 takeFirstLevelConstVoidPtrConst(message: &secondLevelVoidPtr);
49
50 takeSecondLevelVoidPtr(message: secondLevelVoidPtr);
51
52 // CHECK-MESSAGES: :[[@LINE+1]]:25: warning: multilevel pointer conversion from 'void **' to 'void *', please use explicit cast [bugprone-multi-level-implicit-pointer-conversion]
53 takeFirstLevelVoidPtr(message: getSecondLevelVoidPtr());
54
55 // CHECK-MESSAGES: :[[@LINE+1]]:30: warning: multilevel pointer conversion from 'void **' to 'void *', please use explicit cast [bugprone-multi-level-implicit-pointer-conversion]
56 takeFirstLevelConstVoidPtr(message: getSecondLevelVoidPtr());
57
58 // CHECK-MESSAGES: :[[@LINE+1]]:35: warning: multilevel pointer conversion from 'void **' to 'const void *', please use explicit cast [bugprone-multi-level-implicit-pointer-conversion]
59 takeFirstLevelConstVoidPtrConst(message: getSecondLevelVoidPtr());
60
61 // CHECK-MESSAGES: :[[@LINE+1]]:25: warning: multilevel pointer conversion from 'int **' to 'void *', please use explicit cast [bugprone-multi-level-implicit-pointer-conversion]
62 takeFirstLevelVoidPtr(message: getSecondLevelIntPtr());
63
64 takeSecondLevelVoidPtr(message: getSecondLevelVoidPtr());
65}
66

source code of clang-tools-extra/test/clang-tidy/checkers/bugprone/multi-level-implicit-pointer-conversion.cpp