189a1d03eSRichard // RUN: %check_clang_tidy %s bugprone-easily-swappable-parameters %t \
2*e8a3ddafSNathan James // RUN:   -config='{CheckOptions: { \
3*e8a3ddafSNathan James // RUN:     bugprone-easily-swappable-parameters.MinimumLength: 2, \
4*e8a3ddafSNathan James // RUN:     bugprone-easily-swappable-parameters.IgnoredParameterNames: "", \
5*e8a3ddafSNathan James // RUN:     bugprone-easily-swappable-parameters.IgnoredParameterTypeSuffixes: "", \
6*e8a3ddafSNathan James // RUN:     bugprone-easily-swappable-parameters.QualifiersMix: 1, \
7*e8a3ddafSNathan James // RUN:     bugprone-easily-swappable-parameters.ModelImplicitConversions: 0, \
8*e8a3ddafSNathan James // RUN:     bugprone-easily-swappable-parameters.SuppressParametersUsedTogether: 0, \
9*e8a3ddafSNathan James // RUN:     bugprone-easily-swappable-parameters.NamePrefixSuffixSilenceDissimilarityTreshold: 0 \
10*e8a3ddafSNathan James // RUN:  }}' --
1189a1d03eSRichard 
1289a1d03eSRichard typedef int MyInt1;
1389a1d03eSRichard typedef int MyInt2;
1489a1d03eSRichard using CInt = const int;
1589a1d03eSRichard using CMyInt1 = const MyInt1;
1689a1d03eSRichard using CMyInt2 = const MyInt2;
1789a1d03eSRichard 
qualified1(int I,const int CI)1889a1d03eSRichard void qualified1(int I, const int CI) {}
1989a1d03eSRichard // CHECK-MESSAGES: :[[@LINE-1]]:17: warning: 2 adjacent parameters of 'qualified1' of similar type are easily swapped by mistake [bugprone-easily-swappable-parameters]
2089a1d03eSRichard // CHECK-MESSAGES: :[[@LINE-2]]:21: note: the first parameter in the range is 'I'
2189a1d03eSRichard // CHECK-MESSAGES: :[[@LINE-3]]:34: note: the last parameter in the range is 'CI'
2289a1d03eSRichard // CHECK-MESSAGES: :[[@LINE-4]]:24: note: 'int' and 'const int' parameters accept and bind the same kind of values
2389a1d03eSRichard 
qualified2(int I,volatile int VI)2489a1d03eSRichard void qualified2(int I, volatile int VI) {}
2589a1d03eSRichard // CHECK-MESSAGES: :[[@LINE-1]]:17: warning: 2 adjacent parameters of 'qualified2' of similar type are
2689a1d03eSRichard // CHECK-MESSAGES: :[[@LINE-2]]:21: note: the first parameter in the range is 'I'
2789a1d03eSRichard // CHECK-MESSAGES: :[[@LINE-3]]:37: note: the last parameter in the range is 'VI'
2889a1d03eSRichard // CHECK-MESSAGES: :[[@LINE-4]]:24: note: 'int' and 'volatile int' parameters accept and bind the same kind of values
2989a1d03eSRichard 
qualified3(int I,const volatile int CVI)3089a1d03eSRichard void qualified3(int I, const volatile int CVI) {}
3189a1d03eSRichard // CHECK-MESSAGES: :[[@LINE-1]]:17: warning: 2 adjacent parameters of 'qualified3' of similar type are
3289a1d03eSRichard // CHECK-MESSAGES: :[[@LINE-2]]:21: note: the first parameter in the range is 'I'
3389a1d03eSRichard // CHECK-MESSAGES: :[[@LINE-3]]:43: note: the last parameter in the range is 'CVI'
3489a1d03eSRichard // CHECK-MESSAGES: :[[@LINE-4]]:24: note: 'int' and 'const volatile int' parameters accept and bind the same kind of values
3589a1d03eSRichard 
qualified4(int * IP,const int * CIP)3689a1d03eSRichard void qualified4(int *IP, const int *CIP) {}
3789a1d03eSRichard // CHECK-MESSAGES: :[[@LINE-1]]:17: warning: 2 adjacent parameters of 'qualified4' of similar type are
3889a1d03eSRichard // CHECK-MESSAGES: :[[@LINE-2]]:22: note: the first parameter in the range is 'IP'
3989a1d03eSRichard // CHECK-MESSAGES: :[[@LINE-3]]:37: note: the last parameter in the range is 'CIP'
4089a1d03eSRichard // CHECK-MESSAGES: :[[@LINE-4]]:26: note: 'int *' and 'const int *' parameters accept and bind the same kind of values
4189a1d03eSRichard 
qualified5(const int CI,const long CL)4289a1d03eSRichard void qualified5(const int CI, const long CL) {} // NO-WARN: Not the same type
4389a1d03eSRichard 
qualifiedPtr1(int * IP,int * const IPC)4489a1d03eSRichard void qualifiedPtr1(int *IP, int *const IPC) {}
4589a1d03eSRichard // CHECK-MESSAGES: :[[@LINE-1]]:20: warning: 2 adjacent parameters of 'qualifiedPtr1' of similar type are
4689a1d03eSRichard // CHECK-MESSAGES: :[[@LINE-2]]:25: note: the first parameter in the range is 'IP'
4789a1d03eSRichard // CHECK-MESSAGES: :[[@LINE-3]]:40: note: the last parameter in the range is 'IPC'
4889a1d03eSRichard // CHECK-MESSAGES: :[[@LINE-4]]:29: note: 'int *' and 'int *const' parameters accept and bind the same kind of values
4989a1d03eSRichard 
qualifiedPtr2(int * IP,int * volatile IPV)5089a1d03eSRichard void qualifiedPtr2(int *IP, int *volatile IPV) {}
5189a1d03eSRichard // CHECK-MESSAGES: :[[@LINE-1]]:20: warning: 2 adjacent parameters of 'qualifiedPtr2' of similar type are
5289a1d03eSRichard // CHECK-MESSAGES: :[[@LINE-2]]:25: note: the first parameter in the range is 'IP'
5389a1d03eSRichard // CHECK-MESSAGES: :[[@LINE-3]]:43: note: the last parameter in the range is 'IPV'
5489a1d03eSRichard // CHECK-MESSAGES: :[[@LINE-4]]:29: note: 'int *' and 'int *volatile' parameters accept and bind the same kind of values
5589a1d03eSRichard 
qualifiedTypeAndQualifiedPtr1(const int * CIP,int * const volatile IPCV)5689a1d03eSRichard void qualifiedTypeAndQualifiedPtr1(const int *CIP, int *const volatile IPCV) {}
5789a1d03eSRichard // CHECK-MESSAGES: :[[@LINE-1]]:36: warning: 2 adjacent parameters of 'qualifiedTypeAndQualifiedPtr1' of similar type are
5889a1d03eSRichard // CHECK-MESSAGES: :[[@LINE-2]]:47: note: the first parameter in the range is 'CIP'
5989a1d03eSRichard // CHECK-MESSAGES: :[[@LINE-3]]:72: note: the last parameter in the range is 'IPCV'
6089a1d03eSRichard // CHECK-MESSAGES: :[[@LINE-4]]:52: note: 'const int *' and 'int *const volatile' parameters accept and bind the same kind of values
6189a1d03eSRichard 
qualifiedThroughTypedef1(int I,CInt CI)6289a1d03eSRichard void qualifiedThroughTypedef1(int I, CInt CI) {}
6389a1d03eSRichard // CHECK-MESSAGES: :[[@LINE-1]]:31: warning: 2 adjacent parameters of 'qualifiedThroughTypedef1' of similar type are
6489a1d03eSRichard // CHECK-MESSAGES: :[[@LINE-2]]:35: note: the first parameter in the range is 'I'
6589a1d03eSRichard // CHECK-MESSAGES: :[[@LINE-3]]:43: note: the last parameter in the range is 'CI'
6689a1d03eSRichard // CHECK-MESSAGES: :[[@LINE-4]]:31: note: after resolving type aliases, 'int' and 'CInt' share a common type
6789a1d03eSRichard // CHECK-MESSAGES: :[[@LINE-5]]:38: note: 'int' and 'CInt' parameters accept and bind the same kind of values
6889a1d03eSRichard 
qualifiedThroughTypedef2(CInt CI1,const int CI2)6989a1d03eSRichard void qualifiedThroughTypedef2(CInt CI1, const int CI2) {}
7089a1d03eSRichard // CHECK-MESSAGES: :[[@LINE-1]]:31: warning: 2 adjacent parameters of 'qualifiedThroughTypedef2' of similar type are
7189a1d03eSRichard // CHECK-MESSAGES: :[[@LINE-2]]:36: note: the first parameter in the range is 'CI1'
7289a1d03eSRichard // CHECK-MESSAGES: :[[@LINE-3]]:51: note: the last parameter in the range is 'CI2'
7389a1d03eSRichard // CHECK-MESSAGES: :[[@LINE-4]]:31: note: after resolving type aliases, 'CInt' and 'const int' are the same
7489a1d03eSRichard 
qualifiedThroughTypedef3(CInt CI1,const MyInt1 CI2,const int CI3)7589a1d03eSRichard void qualifiedThroughTypedef3(CInt CI1, const MyInt1 CI2, const int CI3) {}
7689a1d03eSRichard // CHECK-MESSAGES: :[[@LINE-1]]:31: warning: 3 adjacent parameters of 'qualifiedThroughTypedef3' of similar type are
7789a1d03eSRichard // CHECK-MESSAGES: :[[@LINE-2]]:36: note: the first parameter in the range is 'CI1'
7889a1d03eSRichard // CHECK-MESSAGES: :[[@LINE-3]]:69: note: the last parameter in the range is 'CI3'
7989a1d03eSRichard // CHECK-MESSAGES: :[[@LINE-4]]:31: note: after resolving type aliases, the common type of 'CInt' and 'const MyInt1' is 'const int'
8089a1d03eSRichard // CHECK-MESSAGES: :[[@LINE-5]]:31: note: after resolving type aliases, 'CInt' and 'const int' are the same
8189a1d03eSRichard // CHECK-MESSAGES: :[[@LINE-6]]:41: note: after resolving type aliases, 'const MyInt1' and 'const int' are the same
8289a1d03eSRichard 
qualifiedThroughTypedef4(CInt CI1,const MyInt1 CI2,const MyInt2 CI3)8389a1d03eSRichard void qualifiedThroughTypedef4(CInt CI1, const MyInt1 CI2, const MyInt2 CI3) {}
8489a1d03eSRichard // CHECK-MESSAGES: :[[@LINE-1]]:31: warning: 3 adjacent parameters of 'qualifiedThroughTypedef4' of similar type are
8589a1d03eSRichard // CHECK-MESSAGES: :[[@LINE-2]]:36: note: the first parameter in the range is 'CI1'
8689a1d03eSRichard // CHECK-MESSAGES: :[[@LINE-3]]:72: note: the last parameter in the range is 'CI3'
8789a1d03eSRichard // CHECK-MESSAGES: :[[@LINE-4]]:31: note: after resolving type aliases, the common type of 'CInt' and 'const MyInt1' is 'const int'
8889a1d03eSRichard // CHECK-MESSAGES: :[[@LINE-5]]:31: note: after resolving type aliases, the common type of 'CInt' and 'const MyInt2' is 'const int'
8989a1d03eSRichard // CHECK-MESSAGES: :[[@LINE-6]]:41: note: after resolving type aliases, the common type of 'const MyInt1' and 'const MyInt2' is 'const int'
9089a1d03eSRichard 
qualifiedThroughTypedef5(CMyInt1 CMI1,CMyInt2 CMI2)9189a1d03eSRichard void qualifiedThroughTypedef5(CMyInt1 CMI1, CMyInt2 CMI2) {}
9289a1d03eSRichard // CHECK-MESSAGES: :[[@LINE-1]]:31: warning: 2 adjacent parameters of 'qualifiedThroughTypedef5' of similar type are
9389a1d03eSRichard // CHECK-MESSAGES: :[[@LINE-2]]:39: note: the first parameter in the range is 'CMI1'
9489a1d03eSRichard // CHECK-MESSAGES: :[[@LINE-3]]:53: note: the last parameter in the range is 'CMI2'
9589a1d03eSRichard // CHECK-MESSAGES: :[[@LINE-4]]:31: note: after resolving type aliases, the common type of 'CMyInt1' and 'CMyInt2' is 'const int'
9689a1d03eSRichard 
qualifiedThroughTypedef6(CMyInt1 CMI1,int I)9789a1d03eSRichard void qualifiedThroughTypedef6(CMyInt1 CMI1, int I) {}
9889a1d03eSRichard // CHECK-MESSAGES: :[[@LINE-1]]:31: warning: 2 adjacent parameters of 'qualifiedThroughTypedef6' of similar type are
9989a1d03eSRichard // CHECK-MESSAGES: :[[@LINE-2]]:39: note: the first parameter in the range is 'CMI1'
10089a1d03eSRichard // CHECK-MESSAGES: :[[@LINE-3]]:49: note: the last parameter in the range is 'I'
10189a1d03eSRichard // CHECK-MESSAGES: :[[@LINE-4]]:31: note: after resolving type aliases, 'CMyInt1' and 'int' share a common type
10289a1d03eSRichard // CHECK-MESSAGES: :[[@LINE-5]]:45: note: 'CMyInt1' and 'int' parameters accept and bind the same kind of values
10389a1d03eSRichard 
referenceToTypedef1(CInt & CIR,int I)10489a1d03eSRichard void referenceToTypedef1(CInt &CIR, int I) {}
10589a1d03eSRichard // CHECK-MESSAGES: :[[@LINE-1]]:26: warning: 2 adjacent parameters of 'referenceToTypedef1' of similar type are
10689a1d03eSRichard // CHECK-MESSAGES: :[[@LINE-2]]:32: note: the first parameter in the range is 'CIR'
10789a1d03eSRichard // CHECK-MESSAGES: :[[@LINE-3]]:41: note: the last parameter in the range is 'I'
10889a1d03eSRichard // CHECK-MESSAGES: :[[@LINE-4]]:37: note: 'CInt &' and 'int' parameters accept and bind the same kind of values
10989a1d03eSRichard 
11089a1d03eSRichard template <typename T>
copy(const T * Dest,T * Source)11189a1d03eSRichard void copy(const T *Dest, T *Source) {}
11289a1d03eSRichard // CHECK-MESSAGES: :[[@LINE-1]]:11: warning: 2 adjacent parameters of 'copy' of similar type are
11389a1d03eSRichard // CHECK-MESSAGES: :[[@LINE-2]]:20: note: the first parameter in the range is 'Dest'
11489a1d03eSRichard // CHECK-MESSAGES: :[[@LINE-3]]:29: note: the last parameter in the range is 'Source'
11589a1d03eSRichard // CHECK-MESSAGES: :[[@LINE-4]]:26: note: 'const T *' and 'T *' parameters accept and bind the same kind of values
11689a1d03eSRichard 
attributedParam1TypedefRef(const int & OneR,MyInt1 & TwoR)11789a1d03eSRichard void attributedParam1TypedefRef(
11889a1d03eSRichard     const __attribute__((address_space(256))) int &OneR,
11989a1d03eSRichard     __attribute__((address_space(256))) MyInt1 &TwoR) {}
12089a1d03eSRichard // CHECK-MESSAGES: :[[@LINE-2]]:5: warning: 2 adjacent parameters of 'attributedParam1TypedefRef' of similar type are
12189a1d03eSRichard // CHECK-MESSAGES: :[[@LINE-3]]:52: note: the first parameter in the range is 'OneR'
12289a1d03eSRichard // CHECK-MESSAGES: :[[@LINE-3]]:49: note: the last parameter in the range is 'TwoR'
12389a1d03eSRichard // 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 &'
12489a1d03eSRichard // 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
12589a1d03eSRichard 
attributedParam2(int * One,const MyInt1 * Two)12689a1d03eSRichard void attributedParam2(__attribute__((address_space(256))) int *One,
12789a1d03eSRichard                       const __attribute__((address_space(256))) MyInt1 *Two) {}
12889a1d03eSRichard // CHECK-MESSAGES: :[[@LINE-2]]:23: warning: 2 adjacent parameters of 'attributedParam2' of similar type are
12989a1d03eSRichard // CHECK-MESSAGES: :[[@LINE-3]]:64: note: the first parameter in the range is 'One'
13089a1d03eSRichard // CHECK-MESSAGES: :[[@LINE-3]]:73: note: the last parameter in the range is 'Two'
13189a1d03eSRichard // 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
13289a1d03eSRichard // 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