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: 0, \
7*e8a3ddafSNathan James // RUN:     bugprone-easily-swappable-parameters.ModelImplicitConversions: 1, \
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 
implicitDoesntBreakOtherStuff(int A,int B)1289a1d03eSRichard void implicitDoesntBreakOtherStuff(int A, int B) {}
1389a1d03eSRichard // CHECK-MESSAGES: :[[@LINE-1]]:36: warning: 2 adjacent parameters of 'implicitDoesntBreakOtherStuff' of similar type ('int') are easily swapped by mistake [bugprone-easily-swappable-parameters]
1489a1d03eSRichard // CHECK-MESSAGES: :[[@LINE-2]]:40: note: the first parameter in the range is 'A'
1589a1d03eSRichard // CHECK-MESSAGES: :[[@LINE-3]]:47: note: the last parameter in the range is 'B'
1689a1d03eSRichard 
arrayAndPtr1(int * IP,int IA[])1789a1d03eSRichard void arrayAndPtr1(int *IP, int IA[]) { arrayAndPtr1(IA, IP); }
1889a1d03eSRichard // CHECK-MESSAGES: :[[@LINE-1]]:19: warning: 2 adjacent parameters of 'arrayAndPtr1' of similar type ('int *')
1989a1d03eSRichard // CHECK-MESSAGES: :[[@LINE-2]]:24: note: the first parameter in the range is 'IP'
2089a1d03eSRichard // CHECK-MESSAGES: :[[@LINE-3]]:32: note: the last parameter in the range is 'IA'
2189a1d03eSRichard 
arrayAndPtr2(int * IP,int IA[8])2289a1d03eSRichard void arrayAndPtr2(int *IP, int IA[8]) { arrayAndPtr2(IA, IP); }
2389a1d03eSRichard // CHECK-MESSAGES: :[[@LINE-1]]:19: warning: 2 adjacent parameters of 'arrayAndPtr2' of similar type ('int *')
2489a1d03eSRichard // CHECK-MESSAGES: :[[@LINE-2]]:24: note: the first parameter in the range is 'IP'
2589a1d03eSRichard // CHECK-MESSAGES: :[[@LINE-3]]:32: note: the last parameter in the range is 'IA'
2689a1d03eSRichard 
arrayAndElement(int I,int IA[])2789a1d03eSRichard void arrayAndElement(int I, int IA[]) {} // NO-WARN.
2889a1d03eSRichard 
numericConversion1(int I,double D)2989a1d03eSRichard void numericConversion1(int I, double D) { numericConversion1(D, I); }
3089a1d03eSRichard // CHECK-MESSAGES: :[[@LINE-1]]:25: warning: 2 adjacent parameters of 'numericConversion1' of convertible types are easily swapped by mistake [bugprone-easily-swappable-parameters]
3189a1d03eSRichard // CHECK-MESSAGES: :[[@LINE-2]]:29: note: the first parameter in the range is 'I'
3289a1d03eSRichard // CHECK-MESSAGES: :[[@LINE-3]]:39: note: the last parameter in the range is 'D'
3389a1d03eSRichard // CHECK-MESSAGES: :[[@LINE-4]]:32: note: 'int' and 'double' may be implicitly converted{{$}}
3489a1d03eSRichard 
numericConversion2(int I,short S)3589a1d03eSRichard void numericConversion2(int I, short S) { numericConversion2(S, I); }
3689a1d03eSRichard // CHECK-MESSAGES: :[[@LINE-1]]:25: warning: 2 adjacent parameters of 'numericConversion2' of convertible types
3789a1d03eSRichard // CHECK-MESSAGES: :[[@LINE-2]]:29: note: the first parameter in the range is 'I'
3889a1d03eSRichard // CHECK-MESSAGES: :[[@LINE-3]]:38: note: the last parameter in the range is 'S'
3989a1d03eSRichard // CHECK-MESSAGES: :[[@LINE-4]]:32: note: 'int' and 'short' may be implicitly converted{{$}}
4089a1d03eSRichard 
numericConversion3(float F,unsigned long UL)4189a1d03eSRichard void numericConversion3(float F, unsigned long UL) { numericConversion3(UL, F); }
4289a1d03eSRichard // CHECK-MESSAGES: :[[@LINE-1]]:25: warning: 2 adjacent parameters of 'numericConversion3' of convertible types
4389a1d03eSRichard // CHECK-MESSAGES: :[[@LINE-2]]:31: note: the first parameter in the range is 'F'
4489a1d03eSRichard // CHECK-MESSAGES: :[[@LINE-3]]:48: note: the last parameter in the range is 'UL'
4589a1d03eSRichard // CHECK-MESSAGES: :[[@LINE-4]]:34: note: 'float' and 'unsigned long' may be implicitly converted{{$}}
4689a1d03eSRichard 
4789a1d03eSRichard enum Unscoped { U_A,
4889a1d03eSRichard                 U_B };
4989a1d03eSRichard enum UnscopedFixed : char { UF_A,
5089a1d03eSRichard                             UF_B };
5189a1d03eSRichard 
numericConversion4(int I,enum Unscoped U)5289a1d03eSRichard void numericConversion4(int I, enum Unscoped U) { numericConversion4(U, I); }
5389a1d03eSRichard // CHECK-MESSAGES: :[[@LINE-1]]:25: warning: 2 adjacent parameters of 'numericConversion4' of convertible types
5489a1d03eSRichard // CHECK-MESSAGES: :[[@LINE-2]]:29: note: the first parameter in the range is 'I'
5589a1d03eSRichard // CHECK-MESSAGES: :[[@LINE-3]]:46: note: the last parameter in the range is 'U'
5689a1d03eSRichard // CHECK-MESSAGES: :[[@LINE-4]]:32: note: 'int' and 'enum Unscoped' may be implicitly converted{{$}}
5789a1d03eSRichard 
numericConversion5(int I,enum UnscopedFixed UF)5889a1d03eSRichard void numericConversion5(int I, enum UnscopedFixed UF) { numericConversion5(UF, I); }
5989a1d03eSRichard // CHECK-MESSAGES: :[[@LINE-1]]:25: warning: 2 adjacent parameters of 'numericConversion5' of convertible types
6089a1d03eSRichard // CHECK-MESSAGES: :[[@LINE-2]]:29: note: the first parameter in the range is 'I'
6189a1d03eSRichard // CHECK-MESSAGES: :[[@LINE-3]]:51: note: the last parameter in the range is 'UF'
6289a1d03eSRichard // CHECK-MESSAGES: :[[@LINE-4]]:32: note: 'int' and 'enum UnscopedFixed' may be implicitly converted{{$}}
6389a1d03eSRichard 
numericConversion7(double D,enum Unscoped U)6489a1d03eSRichard void numericConversion7(double D, enum Unscoped U) { numericConversion7(U, D); }
6589a1d03eSRichard // CHECK-MESSAGES: :[[@LINE-1]]:25: warning: 2 adjacent parameters of 'numericConversion7' of convertible types
6689a1d03eSRichard // CHECK-MESSAGES: :[[@LINE-2]]:32: note: the first parameter in the range is 'D'
6789a1d03eSRichard // CHECK-MESSAGES: :[[@LINE-3]]:49: note: the last parameter in the range is 'U'
6889a1d03eSRichard // CHECK-MESSAGES: :[[@LINE-4]]:35: note: 'double' and 'enum Unscoped' may be implicitly converted{{$}}
6989a1d03eSRichard 
numericConversion8(double D,enum UnscopedFixed UF)7089a1d03eSRichard void numericConversion8(double D, enum UnscopedFixed UF) { numericConversion8(UF, D); }
7189a1d03eSRichard // CHECK-MESSAGES: :[[@LINE-1]]:25: warning: 2 adjacent parameters of 'numericConversion8' of convertible types
7289a1d03eSRichard // CHECK-MESSAGES: :[[@LINE-2]]:32: note: the first parameter in the range is 'D'
7389a1d03eSRichard // CHECK-MESSAGES: :[[@LINE-3]]:54: note: the last parameter in the range is 'UF'
7489a1d03eSRichard // CHECK-MESSAGES: :[[@LINE-4]]:35: note: 'double' and 'enum UnscopedFixed' may be implicitly converted{{$}}
7589a1d03eSRichard 
pointeeConversion(int * IP,double * DP)7689a1d03eSRichard void pointeeConversion(int *IP, double *DP) { pointeeConversion(DP, IP); }
7789a1d03eSRichard // NO-WARN: Even though this is possible in C, a swap is diagnosed by the compiler.
78