| 1 | // RUN: %check_clang_tidy %s bugprone-easily-swappable-parameters %t \ |
| 2 | // RUN: -config='{CheckOptions: { \ |
| 3 | // RUN: bugprone-easily-swappable-parameters.MinimumLength: 2, \ |
| 4 | // RUN: bugprone-easily-swappable-parameters.IgnoredParameterNames: "", \ |
| 5 | // RUN: bugprone-easily-swappable-parameters.IgnoredParameterTypeSuffixes: "", \ |
| 6 | // RUN: bugprone-easily-swappable-parameters.QualifiersMix: 1, \ |
| 7 | // RUN: bugprone-easily-swappable-parameters.ModelImplicitConversions: 0, \ |
| 8 | // RUN: bugprone-easily-swappable-parameters.SuppressParametersUsedTogether: 0, \ |
| 9 | // RUN: bugprone-easily-swappable-parameters.NamePrefixSuffixSilenceDissimilarityTreshold: 0 \ |
| 10 | // RUN: }}' -- |
| 11 | |
| 12 | typedef int MyInt1; |
| 13 | typedef int MyInt2; |
| 14 | using CInt = const int; |
| 15 | using CMyInt1 = const MyInt1; |
| 16 | using CMyInt2 = const MyInt2; |
| 17 | |
| 18 | void qualified1(int I, const int CI) {} |
| 19 | // CHECK-MESSAGES: :[[@LINE-1]]:17: warning: 2 adjacent parameters of 'qualified1' of similar type are easily swapped by mistake [bugprone-easily-swappable-parameters] |
| 20 | // CHECK-MESSAGES: :[[@LINE-2]]:21: note: the first parameter in the range is 'I' |
| 21 | // CHECK-MESSAGES: :[[@LINE-3]]:34: note: the last parameter in the range is 'CI' |
| 22 | // CHECK-MESSAGES: :[[@LINE-4]]:24: note: 'int' and 'const int' parameters accept and bind the same kind of values |
| 23 | |
| 24 | void qualified2(int I, volatile int VI) {} |
| 25 | // CHECK-MESSAGES: :[[@LINE-1]]:17: warning: 2 adjacent parameters of 'qualified2' of similar type are |
| 26 | // CHECK-MESSAGES: :[[@LINE-2]]:21: note: the first parameter in the range is 'I' |
| 27 | // CHECK-MESSAGES: :[[@LINE-3]]:37: note: the last parameter in the range is 'VI' |
| 28 | // CHECK-MESSAGES: :[[@LINE-4]]:24: note: 'int' and 'volatile int' parameters accept and bind the same kind of values |
| 29 | |
| 30 | void qualified3(int I, const volatile int CVI) {} |
| 31 | // CHECK-MESSAGES: :[[@LINE-1]]:17: warning: 2 adjacent parameters of 'qualified3' of similar type are |
| 32 | // CHECK-MESSAGES: :[[@LINE-2]]:21: note: the first parameter in the range is 'I' |
| 33 | // CHECK-MESSAGES: :[[@LINE-3]]:43: note: the last parameter in the range is 'CVI' |
| 34 | // CHECK-MESSAGES: :[[@LINE-4]]:24: note: 'int' and 'const volatile int' parameters accept and bind the same kind of values |
| 35 | |
| 36 | void qualified4(int *IP, const int *CIP) {} |
| 37 | // CHECK-MESSAGES: :[[@LINE-1]]:17: warning: 2 adjacent parameters of 'qualified4' of similar type are |
| 38 | // CHECK-MESSAGES: :[[@LINE-2]]:22: note: the first parameter in the range is 'IP' |
| 39 | // CHECK-MESSAGES: :[[@LINE-3]]:37: note: the last parameter in the range is 'CIP' |
| 40 | // CHECK-MESSAGES: :[[@LINE-4]]:26: note: 'int *' and 'const int *' parameters accept and bind the same kind of values |
| 41 | |
| 42 | void qualified5(const int CI, const long CL) {} // NO-WARN: Not the same type |
| 43 | |
| 44 | void qualifiedPtr1(int *IP, int *const IPC) {} |
| 45 | // CHECK-MESSAGES: :[[@LINE-1]]:20: warning: 2 adjacent parameters of 'qualifiedPtr1' of similar type are |
| 46 | // CHECK-MESSAGES: :[[@LINE-2]]:25: note: the first parameter in the range is 'IP' |
| 47 | // CHECK-MESSAGES: :[[@LINE-3]]:40: note: the last parameter in the range is 'IPC' |
| 48 | // CHECK-MESSAGES: :[[@LINE-4]]:29: note: 'int *' and 'int *const' parameters accept and bind the same kind of values |
| 49 | |
| 50 | void qualifiedPtr2(int *IP, int *volatile IPV) {} |
| 51 | // CHECK-MESSAGES: :[[@LINE-1]]:20: warning: 2 adjacent parameters of 'qualifiedPtr2' of similar type are |
| 52 | // CHECK-MESSAGES: :[[@LINE-2]]:25: note: the first parameter in the range is 'IP' |
| 53 | // CHECK-MESSAGES: :[[@LINE-3]]:43: note: the last parameter in the range is 'IPV' |
| 54 | // CHECK-MESSAGES: :[[@LINE-4]]:29: note: 'int *' and 'int *volatile' parameters accept and bind the same kind of values |
| 55 | |
| 56 | void qualifiedTypeAndQualifiedPtr1(const int *CIP, int *const volatile IPCV) {} |
| 57 | // CHECK-MESSAGES: :[[@LINE-1]]:36: warning: 2 adjacent parameters of 'qualifiedTypeAndQualifiedPtr1' of similar type are |
| 58 | // CHECK-MESSAGES: :[[@LINE-2]]:47: note: the first parameter in the range is 'CIP' |
| 59 | // CHECK-MESSAGES: :[[@LINE-3]]:72: note: the last parameter in the range is 'IPCV' |
| 60 | // CHECK-MESSAGES: :[[@LINE-4]]:52: note: 'const int *' and 'int *const volatile' parameters accept and bind the same kind of values |
| 61 | |
| 62 | void qualifiedThroughTypedef1(int I, CInt CI) {} |
| 63 | // CHECK-MESSAGES: :[[@LINE-1]]:31: warning: 2 adjacent parameters of 'qualifiedThroughTypedef1' of similar type are |
| 64 | // CHECK-MESSAGES: :[[@LINE-2]]:35: note: the first parameter in the range is 'I' |
| 65 | // CHECK-MESSAGES: :[[@LINE-3]]:43: note: the last parameter in the range is 'CI' |
| 66 | // CHECK-MESSAGES: :[[@LINE-4]]:31: note: after resolving type aliases, 'int' and 'CInt' share a common type |
| 67 | // CHECK-MESSAGES: :[[@LINE-5]]:38: note: 'int' and 'CInt' parameters accept and bind the same kind of values |
| 68 | |
| 69 | void qualifiedThroughTypedef2(CInt CI1, const int CI2) {} |
| 70 | // CHECK-MESSAGES: :[[@LINE-1]]:31: warning: 2 adjacent parameters of 'qualifiedThroughTypedef2' of similar type are |
| 71 | // CHECK-MESSAGES: :[[@LINE-2]]:36: note: the first parameter in the range is 'CI1' |
| 72 | // CHECK-MESSAGES: :[[@LINE-3]]:51: note: the last parameter in the range is 'CI2' |
| 73 | // CHECK-MESSAGES: :[[@LINE-4]]:31: note: after resolving type aliases, 'CInt' and 'const int' are the same |
| 74 | |
| 75 | void qualifiedThroughTypedef3(CInt CI1, const MyInt1 CI2, const int CI3) {} |
| 76 | // CHECK-MESSAGES: :[[@LINE-1]]:31: warning: 3 adjacent parameters of 'qualifiedThroughTypedef3' of similar type are |
| 77 | // CHECK-MESSAGES: :[[@LINE-2]]:36: note: the first parameter in the range is 'CI1' |
| 78 | // CHECK-MESSAGES: :[[@LINE-3]]:69: note: the last parameter in the range is 'CI3' |
| 79 | // CHECK-MESSAGES: :[[@LINE-4]]:31: note: after resolving type aliases, the common type of 'CInt' and 'const MyInt1' is 'const int' |
| 80 | // CHECK-MESSAGES: :[[@LINE-5]]:31: note: after resolving type aliases, 'CInt' and 'const int' are the same |
| 81 | // CHECK-MESSAGES: :[[@LINE-6]]:41: note: after resolving type aliases, 'const MyInt1' and 'const int' are the same |
| 82 | |
| 83 | void qualifiedThroughTypedef4(CInt CI1, const MyInt1 CI2, const MyInt2 CI3) {} |
| 84 | // CHECK-MESSAGES: :[[@LINE-1]]:31: warning: 3 adjacent parameters of 'qualifiedThroughTypedef4' of similar type are |
| 85 | // CHECK-MESSAGES: :[[@LINE-2]]:36: note: the first parameter in the range is 'CI1' |
| 86 | // CHECK-MESSAGES: :[[@LINE-3]]:72: note: the last parameter in the range is 'CI3' |
| 87 | // CHECK-MESSAGES: :[[@LINE-4]]:31: note: after resolving type aliases, the common type of 'CInt' and 'const MyInt1' is 'const int' |
| 88 | // CHECK-MESSAGES: :[[@LINE-5]]:31: note: after resolving type aliases, the common type of 'CInt' and 'const MyInt2' is 'const int' |
| 89 | // CHECK-MESSAGES: :[[@LINE-6]]:41: note: after resolving type aliases, the common type of 'const MyInt1' and 'const MyInt2' is 'const int' |
| 90 | |
| 91 | void qualifiedThroughTypedef5(CMyInt1 CMI1, CMyInt2 CMI2) {} |
| 92 | // CHECK-MESSAGES: :[[@LINE-1]]:31: warning: 2 adjacent parameters of 'qualifiedThroughTypedef5' of similar type are |
| 93 | // CHECK-MESSAGES: :[[@LINE-2]]:39: note: the first parameter in the range is 'CMI1' |
| 94 | // CHECK-MESSAGES: :[[@LINE-3]]:53: note: the last parameter in the range is 'CMI2' |
| 95 | // CHECK-MESSAGES: :[[@LINE-4]]:31: note: after resolving type aliases, the common type of 'CMyInt1' and 'CMyInt2' is 'const int' |
| 96 | |
| 97 | void qualifiedThroughTypedef6(CMyInt1 CMI1, int I) {} |
| 98 | // CHECK-MESSAGES: :[[@LINE-1]]:31: warning: 2 adjacent parameters of 'qualifiedThroughTypedef6' of similar type are |
| 99 | // CHECK-MESSAGES: :[[@LINE-2]]:39: note: the first parameter in the range is 'CMI1' |
| 100 | // CHECK-MESSAGES: :[[@LINE-3]]:49: note: the last parameter in the range is 'I' |
| 101 | // CHECK-MESSAGES: :[[@LINE-4]]:31: note: after resolving type aliases, 'CMyInt1' and 'int' share a common type |
| 102 | // CHECK-MESSAGES: :[[@LINE-5]]:45: note: 'CMyInt1' and 'int' parameters accept and bind the same kind of values |
| 103 | |
| 104 | void referenceToTypedef1(CInt &CIR, int I) {} |
| 105 | // CHECK-MESSAGES: :[[@LINE-1]]:26: warning: 2 adjacent parameters of 'referenceToTypedef1' of similar type are |
| 106 | // CHECK-MESSAGES: :[[@LINE-2]]:32: note: the first parameter in the range is 'CIR' |
| 107 | // CHECK-MESSAGES: :[[@LINE-3]]:41: note: the last parameter in the range is 'I' |
| 108 | // CHECK-MESSAGES: :[[@LINE-4]]:37: note: 'CInt &' and 'int' parameters accept and bind the same kind of values |
| 109 | |
| 110 | template <typename T> |
| 111 | void copy(const T *Dest, T *Source) {} |
| 112 | // CHECK-MESSAGES: :[[@LINE-1]]:11: warning: 2 adjacent parameters of 'copy' of similar type are |
| 113 | // CHECK-MESSAGES: :[[@LINE-2]]:20: note: the first parameter in the range is 'Dest' |
| 114 | // CHECK-MESSAGES: :[[@LINE-3]]:29: note: the last parameter in the range is 'Source' |
| 115 | // CHECK-MESSAGES: :[[@LINE-4]]:26: note: 'const T *' and 'T *' parameters accept and bind the same kind of values |
| 116 | |
| 117 | void attributedParam1TypedefRef( |
| 118 | const __attribute__((address_space(256))) int &OneR, |
| 119 | __attribute__((address_space(256))) MyInt1 &TwoR) {} |
| 120 | // CHECK-MESSAGES: :[[@LINE-2]]:5: warning: 2 adjacent parameters of 'attributedParam1TypedefRef' of similar type are |
| 121 | // CHECK-MESSAGES: :[[@LINE-3]]:52: note: the first parameter in the range is 'OneR' |
| 122 | // CHECK-MESSAGES: :[[@LINE-3]]:49: note: the last parameter in the range is 'TwoR' |
| 123 | // CHECK-MESSAGES: :[[@LINE-5]]:5: note: after resolving type aliases, the common type of 'const __attribute__((address_space(256))) int &' and '__attribute__((address_space(256))) MyInt1 &' is '__attribute__((address_space(256))) int &' |
| 124 | // CHECK-MESSAGES: :[[@LINE-5]]:5: note: 'const __attribute__((address_space(256))) int &' and '__attribute__((address_space(256))) MyInt1 &' parameters accept and bind the same kind of values |
| 125 | |
| 126 | void attributedParam2(__attribute__((address_space(256))) int *One, |
| 127 | const __attribute__((address_space(256))) MyInt1 *Two) {} |
| 128 | // CHECK-MESSAGES: :[[@LINE-2]]:23: warning: 2 adjacent parameters of 'attributedParam2' of similar type are |
| 129 | // CHECK-MESSAGES: :[[@LINE-3]]:64: note: the first parameter in the range is 'One' |
| 130 | // CHECK-MESSAGES: :[[@LINE-3]]:73: note: the last parameter in the range is 'Two' |
| 131 | // CHECK-MESSAGES: :[[@LINE-5]]:23: note: after resolving type aliases, '__attribute__((address_space(256))) int *' and 'const __attribute__((address_space(256))) MyInt1 *' share a common type |
| 132 | // CHECK-MESSAGES: :[[@LINE-5]]:23: note: '__attribute__((address_space(256))) int *' and 'const __attribute__((address_space(256))) MyInt1 *' parameters accept and bind the same kind of values |
| 133 | |