1 // RUN: %check_clang_tidy %s bugprone-easily-swappable-parameters %t \
2 // RUN:   -config='{CheckOptions: [ \
3 // RUN:     {key: bugprone-easily-swappable-parameters.MinimumLength, value: 2}, \
4 // RUN:     {key: bugprone-easily-swappable-parameters.IgnoredParameterNames, value: ""}, \
5 // RUN:     {key: bugprone-easily-swappable-parameters.IgnoredParameterTypeSuffixes, value: ""}, \
6 // RUN:     {key: bugprone-easily-swappable-parameters.QualifiersMix, value: 0}, \
7 // RUN:     {key: bugprone-easily-swappable-parameters.ModelImplicitConversions, value: 1}, \
8 // RUN:     {key: bugprone-easily-swappable-parameters.SuppressParametersUsedTogether, value: 0}, \
9 // RUN:     {key: bugprone-easily-swappable-parameters.NamePrefixSuffixSilenceDissimilarityTreshold, value: 0} \
10 // RUN:  ]}' --
11 
implicitDoesntBreakOtherStuff(int A,int B)12 void implicitDoesntBreakOtherStuff(int A, int B) {}
13 // CHECK-MESSAGES: :[[@LINE-1]]:36: warning: 2 adjacent parameters of 'implicitDoesntBreakOtherStuff' of similar type ('int') are easily swapped by mistake [bugprone-easily-swappable-parameters]
14 // CHECK-MESSAGES: :[[@LINE-2]]:40: note: the first parameter in the range is 'A'
15 // CHECK-MESSAGES: :[[@LINE-3]]:47: note: the last parameter in the range is 'B'
16 
arrayAndPtr1(int * IP,int IA[])17 void arrayAndPtr1(int *IP, int IA[]) { arrayAndPtr1(IA, IP); }
18 // CHECK-MESSAGES: :[[@LINE-1]]:19: warning: 2 adjacent parameters of 'arrayAndPtr1' of similar type ('int *')
19 // CHECK-MESSAGES: :[[@LINE-2]]:24: note: the first parameter in the range is 'IP'
20 // CHECK-MESSAGES: :[[@LINE-3]]:32: note: the last parameter in the range is 'IA'
21 
arrayAndPtr2(int * IP,int IA[8])22 void arrayAndPtr2(int *IP, int IA[8]) { arrayAndPtr2(IA, IP); }
23 // CHECK-MESSAGES: :[[@LINE-1]]:19: warning: 2 adjacent parameters of 'arrayAndPtr2' of similar type ('int *')
24 // CHECK-MESSAGES: :[[@LINE-2]]:24: note: the first parameter in the range is 'IP'
25 // CHECK-MESSAGES: :[[@LINE-3]]:32: note: the last parameter in the range is 'IA'
26 
arrayAndElement(int I,int IA[])27 void arrayAndElement(int I, int IA[]) {} // NO-WARN.
28 
numericConversion1(int I,double D)29 void numericConversion1(int I, double D) { numericConversion1(D, I); }
30 // CHECK-MESSAGES: :[[@LINE-1]]:25: warning: 2 adjacent parameters of 'numericConversion1' of convertible types are easily swapped by mistake [bugprone-easily-swappable-parameters]
31 // CHECK-MESSAGES: :[[@LINE-2]]:29: note: the first parameter in the range is 'I'
32 // CHECK-MESSAGES: :[[@LINE-3]]:39: note: the last parameter in the range is 'D'
33 // CHECK-MESSAGES: :[[@LINE-4]]:32: note: 'int' and 'double' may be implicitly converted{{$}}
34 
numericConversion2(int I,short S)35 void numericConversion2(int I, short S) { numericConversion2(S, I); }
36 // CHECK-MESSAGES: :[[@LINE-1]]:25: warning: 2 adjacent parameters of 'numericConversion2' of convertible types
37 // CHECK-MESSAGES: :[[@LINE-2]]:29: note: the first parameter in the range is 'I'
38 // CHECK-MESSAGES: :[[@LINE-3]]:38: note: the last parameter in the range is 'S'
39 // CHECK-MESSAGES: :[[@LINE-4]]:32: note: 'int' and 'short' may be implicitly converted{{$}}
40 
numericConversion3(float F,unsigned long UL)41 void numericConversion3(float F, unsigned long UL) { numericConversion3(UL, F); }
42 // CHECK-MESSAGES: :[[@LINE-1]]:25: warning: 2 adjacent parameters of 'numericConversion3' of convertible types
43 // CHECK-MESSAGES: :[[@LINE-2]]:31: note: the first parameter in the range is 'F'
44 // CHECK-MESSAGES: :[[@LINE-3]]:48: note: the last parameter in the range is 'UL'
45 // CHECK-MESSAGES: :[[@LINE-4]]:34: note: 'float' and 'unsigned long' may be implicitly converted{{$}}
46 
47 enum Unscoped { U_A,
48                 U_B };
49 enum UnscopedFixed : char { UF_A,
50                             UF_B };
51 
numericConversion4(int I,enum Unscoped U)52 void numericConversion4(int I, enum Unscoped U) { numericConversion4(U, I); }
53 // CHECK-MESSAGES: :[[@LINE-1]]:25: warning: 2 adjacent parameters of 'numericConversion4' of convertible types
54 // CHECK-MESSAGES: :[[@LINE-2]]:29: note: the first parameter in the range is 'I'
55 // CHECK-MESSAGES: :[[@LINE-3]]:46: note: the last parameter in the range is 'U'
56 // CHECK-MESSAGES: :[[@LINE-4]]:32: note: 'int' and 'enum Unscoped' may be implicitly converted{{$}}
57 
numericConversion5(int I,enum UnscopedFixed UF)58 void numericConversion5(int I, enum UnscopedFixed UF) { numericConversion5(UF, I); }
59 // CHECK-MESSAGES: :[[@LINE-1]]:25: warning: 2 adjacent parameters of 'numericConversion5' of convertible types
60 // CHECK-MESSAGES: :[[@LINE-2]]:29: note: the first parameter in the range is 'I'
61 // CHECK-MESSAGES: :[[@LINE-3]]:51: note: the last parameter in the range is 'UF'
62 // CHECK-MESSAGES: :[[@LINE-4]]:32: note: 'int' and 'enum UnscopedFixed' may be implicitly converted{{$}}
63 
numericConversion7(double D,enum Unscoped U)64 void numericConversion7(double D, enum Unscoped U) { numericConversion7(U, D); }
65 // CHECK-MESSAGES: :[[@LINE-1]]:25: warning: 2 adjacent parameters of 'numericConversion7' of convertible types
66 // CHECK-MESSAGES: :[[@LINE-2]]:32: note: the first parameter in the range is 'D'
67 // CHECK-MESSAGES: :[[@LINE-3]]:49: note: the last parameter in the range is 'U'
68 // CHECK-MESSAGES: :[[@LINE-4]]:35: note: 'double' and 'enum Unscoped' may be implicitly converted{{$}}
69 
numericConversion8(double D,enum UnscopedFixed UF)70 void numericConversion8(double D, enum UnscopedFixed UF) { numericConversion8(UF, D); }
71 // CHECK-MESSAGES: :[[@LINE-1]]:25: warning: 2 adjacent parameters of 'numericConversion8' of convertible types
72 // CHECK-MESSAGES: :[[@LINE-2]]:32: note: the first parameter in the range is 'D'
73 // CHECK-MESSAGES: :[[@LINE-3]]:54: note: the last parameter in the range is 'UF'
74 // CHECK-MESSAGES: :[[@LINE-4]]:35: note: 'double' and 'enum UnscopedFixed' may be implicitly converted{{$}}
75 
pointeeConverison(int * IP,double * DP)76 void pointeeConverison(int *IP, double *DP) { pointeeConversion(DP, IP); }
77 // NO-WARN: Even though this is possible in C, a swap is diagnosed by the compiler.
78