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: 0}, \
8 // RUN:     {key: bugprone-easily-swappable-parameters.SuppressParametersUsedTogether, value: 0}, \
9 // RUN:     {key: bugprone-easily-swappable-parameters.NamePrefixSuffixSilenceDissimilarityTreshold, value: 0} \
10 // RUN:  ]}' --
11 
12 namespace std {
13 using size_t = decltype(sizeof(int));
14 } // namespace std
15 
16 #define assert(X) ((void)(X))
17 
18 void declaration(int Param, int Other); // NO-WARN: No chance to change this function.
19 
20 struct S {};
21 
allocate()22 S *allocate() { return nullptr; }                           // NO-WARN: 0 parameters.
allocate(S ** Out)23 void allocate(S **Out) {}                                   // NO-WARN: 1 parameter.
operator <(const S & LHS,const S & RHS)24 bool operator<(const S &LHS, const S &RHS) { return true; } // NO-WARN: Binary operator.
25 
26 struct MyComparator {
operator ()MyComparator27   bool operator()(const S &LHS, const S &RHS) { return true; } // NO-WARN: Binary operator.
28 };
29 
30 struct MyFactory {
operator ()MyFactory31   S operator()() { return {}; }             // NO-WARN: 0 parameters, overloaded operator.
operator ()MyFactory32   S operator()(int I) { return {}; }        // NO-WARN: 1 parameter, overloaded operator.
operator ()MyFactory33   S operator()(int I, int J) { return {}; } // NO-WARN: Binary operator.
34 
operator ()MyFactory35   S operator()(int I, int J, int K) { return {}; }
36   // CHECK-MESSAGES: :[[@LINE-1]]:16: warning: 3 adjacent parameters of 'operator()' of similar type ('int') are easily swapped by mistake [bugprone-easily-swappable-parameters]
37   // CHECK-MESSAGES: :[[@LINE-2]]:20: note: the first parameter in the range is 'I'
38   // CHECK-MESSAGES: :[[@LINE-3]]:34: note: the last parameter in the range is 'K'
39 };
40 
41 // Variadic functions are not checked because the types are not seen from the
42 // *definition*. It would require analysing the call sites to do something
43 // for these.
printf(const char * Format,...)44 int printf(const char *Format, ...) { return 0; } // NO-WARN: Variadic function not checked.
sum(...)45 int sum(...) { return 0; }                        // NO-WARN: Variadic function not checked.
46 
operator new(std::size_t Count,S & Manager,S & Janitor)47 void *operator new(std::size_t Count, S &Manager, S &Janitor) noexcept { return nullptr; }
48 // CHECK-MESSAGES: :[[@LINE-1]]:39: warning: 2 adjacent parameters of 'operator new' of similar type ('S &')
49 // CHECK-MESSAGES: :[[@LINE-2]]:42: note: the first parameter in the range is 'Manager'
50 // CHECK-MESSAGES: :[[@LINE-3]]:54: note: the last parameter in the range is 'Janitor'
51 
52 void redeclChain(int, int, int);
53 void redeclChain(int I, int, int);
54 void redeclChain(int, int J, int);
redeclChain(int I,int J,int K)55 void redeclChain(int I, int J, int K) {}
56 // CHECK-MESSAGES: :[[@LINE-1]]:18: warning: 3 adjacent parameters of 'redeclChain' of similar type ('int')
57 // CHECK-MESSAGES: :[[@LINE-2]]:22: note: the first parameter in the range is 'I'
58 // CHECK-MESSAGES: :[[@LINE-3]]:36: note: the last parameter in the range is 'K'
59 
copyMany(S * Src,S * Dst,unsigned Num)60 void copyMany(S *Src, S *Dst, unsigned Num) {}
61 // CHECK-MESSAGES: :[[@LINE-1]]:15: warning: 2 adjacent parameters of 'copyMany' of similar type ('S *')
62 // CHECK-MESSAGES: :[[@LINE-2]]:18: note: the first parameter in the range is 'Src'
63 // CHECK-MESSAGES: :[[@LINE-3]]:26: note: the last parameter in the range is 'Dst'
64 
65 template <typename T, typename U>
binaryPredicate(T L,U R)66 bool binaryPredicate(T L, U R) { return false; } // NO-WARN: Distinct types in template.
67 
68 template <> // Explicit specialisation.
binaryPredicate(S * L,S * R)69 bool binaryPredicate(S *L, S *R) { return true; }
70 // CHECK-MESSAGES: :[[@LINE-1]]:22: warning: 2 adjacent parameters of 'binaryPredicate<S *, S *>' of similar type ('S *')
71 // CHECK-MESSAGES: :[[@LINE-2]]:25: note: the first parameter in the range is 'L'
72 // CHECK-MESSAGES: :[[@LINE-3]]:31: note: the last parameter in the range is 'R'
73 
74 template <typename T>
algebraicOperation(T L,T R)75 T algebraicOperation(T L, T R) { return L; }
76 // CHECK-MESSAGES: :[[@LINE-1]]:22: warning: 2 adjacent parameters of 'algebraicOperation' of similar type ('T')
77 // CHECK-MESSAGES: :[[@LINE-2]]:24: note: the first parameter in the range is 'L'
78 // CHECK-MESSAGES: :[[@LINE-3]]:29: note: the last parameter in the range is 'R'
79 
applyBinaryToS(S SInstance)80 void applyBinaryToS(S SInstance) { // NO-WARN: 1 parameter.
81   assert(binaryPredicate(SInstance, SInstance) !=
82          binaryPredicate(&SInstance, &SInstance));
83   // NO-WARN: binaryPredicate(S, S) is instantiated, but it's not written
84   // by the user.
85 }
86 
unnamedParameter(int I,int,int K,int)87 void unnamedParameter(int I, int, int K, int) {}
88 // CHECK-MESSAGES: :[[@LINE-1]]:23: warning: 4 adjacent parameters of 'unnamedParameter' of similar type ('int')
89 // CHECK-MESSAGES: :[[@LINE-2]]:27: note: the first parameter in the range is 'I'
90 // CHECK-MESSAGES: :[[@LINE-3]]:45: note: the last parameter in the range is '<unnamed>'
91 
fullyUnnamed(int,int)92 void fullyUnnamed(int, int) {}
93 // CHECK-MESSAGES: :[[@LINE-1]]:19: warning: 2 adjacent parameters of 'fullyUnnamed' of similar type ('int')
94 // CHECK-MESSAGES: :[[@LINE-2]]:22: note: the first parameter in the range is '<unnamed>'
95 // CHECK-MESSAGES: :[[@LINE-3]]:27: note: the last parameter in the range is '<unnamed>'
96 
multipleDistinctTypes(int I,int J,long L,long M)97 void multipleDistinctTypes(int I, int J, long L, long M) {}
98 // CHECK-MESSAGES: :[[@LINE-1]]:28: warning: 2 adjacent parameters of 'multipleDistinctTypes' of similar type ('int')
99 // CHECK-MESSAGES: :[[@LINE-2]]:32: note: the first parameter in the range is 'I'
100 // CHECK-MESSAGES: :[[@LINE-3]]:39: note: the last parameter in the range is 'J'
101 // CHECK-MESSAGES: :[[@LINE-4]]:42: warning: 2 adjacent parameters of 'multipleDistinctTypes' of similar type ('long')
102 // CHECK-MESSAGES: :[[@LINE-5]]:47: note: the first parameter in the range is 'L'
103 // CHECK-MESSAGES: :[[@LINE-6]]:55: note: the last parameter in the range is 'M'
104 
variableAndPtr(int I,int * IP)105 void variableAndPtr(int I, int *IP) {} // NO-WARN: Not the same type.
106 
differentPtrs(int * IP,long * LP)107 void differentPtrs(int *IP, long *LP) {} // NO-WARN: Not the same type.
108 
109 typedef int MyInt1;
110 using MyInt2 = int;
111 typedef MyInt2 MyInt2b;
112 
113 using CInt = const int;
114 using CMyInt1 = const MyInt1;
115 using CMyInt2 = const MyInt2;
116 
117 typedef long MyLong1;
118 using MyLong2 = long;
119 
typedefAndTypedef1(MyInt1 I1,MyInt1 I2)120 void typedefAndTypedef1(MyInt1 I1, MyInt1 I2) {}
121 // CHECK-MESSAGES: :[[@LINE-1]]:25: warning: 2 adjacent parameters of 'typedefAndTypedef1' of similar type ('MyInt1')
122 // CHECK-MESSAGES: :[[@LINE-2]]:32: note: the first parameter in the range is 'I1'
123 // CHECK-MESSAGES: :[[@LINE-3]]:43: note: the last parameter in the range is 'I2'
124 
typedefAndTypedef2(MyInt2 I1,MyInt2 I2)125 void typedefAndTypedef2(MyInt2 I1, MyInt2 I2) {}
126 // CHECK-MESSAGES: :[[@LINE-1]]:25: warning: 2 adjacent parameters of 'typedefAndTypedef2' of similar type ('MyInt2')
127 // CHECK-MESSAGES: :[[@LINE-2]]:32: note: the first parameter in the range is 'I1'
128 // CHECK-MESSAGES: :[[@LINE-3]]:43: note: the last parameter in the range is 'I2'
129 
typedefMultiple(MyInt1 I1,MyInt2 I2x,MyInt2 I2y)130 void typedefMultiple(MyInt1 I1, MyInt2 I2x, MyInt2 I2y) {}
131 // CHECK-MESSAGES: :[[@LINE-1]]:22: warning: 3 adjacent parameters of 'typedefMultiple' of similar type are
132 // CHECK-MESSAGES: :[[@LINE-2]]:29: note: the first parameter in the range is 'I1'
133 // CHECK-MESSAGES: :[[@LINE-3]]:52: note: the last parameter in the range is 'I2y'
134 // CHECK-MESSAGES: :[[@LINE-4]]:22: note: after resolving type aliases, the common type of 'MyInt1' and 'MyInt2' is 'int'
135 
throughTypedef1(int I,MyInt1 J)136 void throughTypedef1(int I, MyInt1 J) {}
137 // CHECK-MESSAGES: :[[@LINE-1]]:22: warning: 2 adjacent parameters of 'throughTypedef1' of similar type are
138 // CHECK-MESSAGES: :[[@LINE-2]]:26: note: the first parameter in the range is 'I'
139 // CHECK-MESSAGES: :[[@LINE-3]]:36: note: the last parameter in the range is 'J'
140 // CHECK-MESSAGES: :[[@LINE-4]]:22: note: after resolving type aliases, 'int' and 'MyInt1' are the same
141 
betweenTypedef2(MyInt1 I,MyInt2 J)142 void betweenTypedef2(MyInt1 I, MyInt2 J) {}
143 // CHECK-MESSAGES: :[[@LINE-1]]:22: warning: 2 adjacent parameters of 'betweenTypedef2' of similar type are
144 // CHECK-MESSAGES: :[[@LINE-2]]:29: note: the first parameter in the range is 'I'
145 // CHECK-MESSAGES: :[[@LINE-3]]:39: note: the last parameter in the range is 'J'
146 // CHECK-MESSAGES: :[[@LINE-4]]:22: note: after resolving type aliases, the common type of 'MyInt1' and 'MyInt2' is 'int'
147 
typedefChain(int I,MyInt1 MI1,MyInt2 MI2,MyInt2b MI2b)148 void typedefChain(int I, MyInt1 MI1, MyInt2 MI2, MyInt2b MI2b) {}
149 // CHECK-MESSAGES: :[[@LINE-1]]:19: warning: 4 adjacent parameters of 'typedefChain' of similar type are
150 // CHECK-MESSAGES: :[[@LINE-2]]:23: note: the first parameter in the range is 'I'
151 // CHECK-MESSAGES: :[[@LINE-3]]:58: note: the last parameter in the range is 'MI2b'
152 // CHECK-MESSAGES: :[[@LINE-4]]:19: note: after resolving type aliases, 'int' and 'MyInt1' are the same
153 // CHECK-MESSAGES: :[[@LINE-5]]:19: note: after resolving type aliases, 'int' and 'MyInt2' are the same
154 // CHECK-MESSAGES: :[[@LINE-6]]:19: note: after resolving type aliases, 'int' and 'MyInt2b' are the same
155 
throughTypedefToOtherType(MyInt1 I,MyLong1 J)156 void throughTypedefToOtherType(MyInt1 I, MyLong1 J) {} // NO-WARN: int and long.
157 
qualified1(int I,const int CI)158 void qualified1(int I, const int CI) {} // NO-WARN: Different qualifiers.
159 
qualified2(int I,volatile int VI)160 void qualified2(int I, volatile int VI) {} // NO-WARN: Different qualifiers.
161 
qualified3(int * IP,const int * CIP)162 void qualified3(int *IP, const int *CIP) {} // NO-WARN: Different qualifiers.
163 
qualified4(const int CI,const long CL)164 void qualified4(const int CI, const long CL) {} // NO-WARN: Not the same type.
165 
qualifiedPtr1(int * IP,int * const IPC)166 void qualifiedPtr1(int *IP, int *const IPC) {} // NO-WARN: Different qualifiers.
167 
qualifiedTypeAndQualifiedPtr1(const int * CIP,int * const volatile IPCV)168 void qualifiedTypeAndQualifiedPtr1(const int *CIP, int *const volatile IPCV) {} // NO-WARN: Not the same type.
169 
qualifiedThroughTypedef1(int I,CInt CI)170 void qualifiedThroughTypedef1(int I, CInt CI) {} // NO-WARN: Different qualifiers.
171 
qualifiedThroughTypedef2(CInt CI1,const int CI2)172 void qualifiedThroughTypedef2(CInt CI1, const int CI2) {}
173 // CHECK-MESSAGES: :[[@LINE-1]]:31: warning: 2 adjacent parameters of 'qualifiedThroughTypedef2' of similar type are
174 // CHECK-MESSAGES: :[[@LINE-2]]:36: note: the first parameter in the range is 'CI1'
175 // CHECK-MESSAGES: :[[@LINE-3]]:51: note: the last parameter in the range is 'CI2'
176 // CHECK-MESSAGES: :[[@LINE-4]]:31: note: after resolving type aliases, 'CInt' and 'const int' are the same
177 
qualifiedThroughTypedef3(CInt CI1,const MyInt1 CI2,const int CI3)178 void qualifiedThroughTypedef3(CInt CI1, const MyInt1 CI2, const int CI3) {}
179 // CHECK-MESSAGES: :[[@LINE-1]]:31: warning: 3 adjacent parameters of 'qualifiedThroughTypedef3' of similar type are
180 // CHECK-MESSAGES: :[[@LINE-2]]:36: note: the first parameter in the range is 'CI1'
181 // CHECK-MESSAGES: :[[@LINE-3]]:69: note: the last parameter in the range is 'CI3'
182 // CHECK-MESSAGES: :[[@LINE-4]]:31: note: after resolving type aliases, the common type of 'CInt' and 'const MyInt1' is 'const int'
183 // CHECK-MESSAGES: :[[@LINE-5]]:31: note: after resolving type aliases, 'CInt' and 'const int' are the same
184 // CHECK-MESSAGES: :[[@LINE-6]]:41: note: after resolving type aliases, 'const MyInt1' and 'const int' are the same
185 
qualifiedThroughTypedef4(CInt CI1,const MyInt1 CI2,const MyInt2 CI3)186 void qualifiedThroughTypedef4(CInt CI1, const MyInt1 CI2, const MyInt2 CI3) {}
187 // CHECK-MESSAGES: :[[@LINE-1]]:31: warning: 3 adjacent parameters of 'qualifiedThroughTypedef4' of similar type are
188 // CHECK-MESSAGES: :[[@LINE-2]]:36: note: the first parameter in the range is 'CI1'
189 // CHECK-MESSAGES: :[[@LINE-3]]:72: note: the last parameter in the range is 'CI3'
190 // CHECK-MESSAGES: :[[@LINE-4]]:31: note: after resolving type aliases, the common type of 'CInt' and 'const MyInt1' is 'const int'
191 // CHECK-MESSAGES: :[[@LINE-5]]:31: note: after resolving type aliases, the common type of 'CInt' and 'const MyInt2' is 'const int'
192 // CHECK-MESSAGES: :[[@LINE-6]]:41: note: after resolving type aliases, the common type of 'const MyInt1' and 'const MyInt2' is 'const int'
193 
qualifiedThroughTypedef5(CMyInt1 CMI1,CMyInt2 CMI2)194 void qualifiedThroughTypedef5(CMyInt1 CMI1, CMyInt2 CMI2) {}
195 // CHECK-MESSAGES: :[[@LINE-1]]:31: warning: 2 adjacent parameters of 'qualifiedThroughTypedef5' of similar type are
196 // CHECK-MESSAGES: :[[@LINE-2]]:39: note: the first parameter in the range is 'CMI1'
197 // CHECK-MESSAGES: :[[@LINE-3]]:53: note: the last parameter in the range is 'CMI2'
198 // CHECK-MESSAGES: :[[@LINE-4]]:31: note: after resolving type aliases, the common type of 'CMyInt1' and 'CMyInt2' is 'const int'
199 
qualifiedThroughTypedef6(CMyInt1 CMI1,int I)200 void qualifiedThroughTypedef6(CMyInt1 CMI1, int I) {} // NO-WARN: Different qualifiers.
201 
202 template <typename T>
copy(const T * Dest,T * Source)203 void copy(const T *Dest, T *Source) {} // NO-WARN: Different qualifiers.
204 
reference1(int I,int & IR)205 void reference1(int I, int &IR) {} // NO-WARN: Distinct semantics when called.
206 
reference2(int I,const int & CIR)207 void reference2(int I, const int &CIR) {}
208 // CHECK-MESSAGES: :[[@LINE-1]]:17: warning: 2 adjacent parameters of 'reference2' of similar type are
209 // CHECK-MESSAGES: :[[@LINE-2]]:21: note: the first parameter in the range is 'I'
210 // CHECK-MESSAGES: :[[@LINE-3]]:35: note: the last parameter in the range is 'CIR'
211 // CHECK-MESSAGES: :[[@LINE-4]]:24: note: 'int' and 'const int &' parameters accept and bind the same kind of values
212 
reference3(int I,int && IRR)213 void reference3(int I, int &&IRR) {} // NO-WARN: Distinct semantics when called.
214 
reference4(int I,const int && CIRR)215 void reference4(int I, const int &&CIRR) {} // NO-WARN: Distinct semantics when called.
216 
reference5(const int CI,const int & CIR)217 void reference5(const int CI, const int &CIR) {}
218 // CHECK-MESSAGES: :[[@LINE-1]]:17: warning: 2 adjacent parameters of 'reference5' of similar type are
219 // CHECK-MESSAGES: :[[@LINE-2]]:27: note: the first parameter in the range is 'CI'
220 // CHECK-MESSAGES: :[[@LINE-3]]:42: note: the last parameter in the range is 'CIR'
221 // CHECK-MESSAGES: :[[@LINE-4]]:31: note: 'const int' and 'const int &' parameters accept and bind the same kind of values
222 
reference6(int I,const int & CIR,int J,const int & CJR)223 void reference6(int I, const int &CIR, int J, const int &CJR) {}
224 // CHECK-MESSAGES: :[[@LINE-1]]:17: warning: 4 adjacent parameters of 'reference6' of similar type are
225 // CHECK-MESSAGES: :[[@LINE-2]]:21: note: the first parameter in the range is 'I'
226 // CHECK-MESSAGES: :[[@LINE-3]]:58: note: the last parameter in the range is 'CJR'
227 // CHECK-MESSAGES: :[[@LINE-4]]:24: note: 'int' and 'const int &' parameters accept and bind the same kind of values
228 
229 using ICRTy = const int &;
230 using MyIntCRTy = const MyInt1 &;
231 
referenceToTypedef1(CInt & CIR,int I)232 void referenceToTypedef1(CInt &CIR, int I) {}
233 // CHECK-MESSAGES: :[[@LINE-1]]:26: warning: 2 adjacent parameters of 'referenceToTypedef1' of similar type are
234 // CHECK-MESSAGES: :[[@LINE-2]]:32: note: the first parameter in the range is 'CIR'
235 // CHECK-MESSAGES: :[[@LINE-3]]:41: note: the last parameter in the range is 'I'
236 // CHECK-MESSAGES: :[[@LINE-4]]:37: note: 'CInt &' and 'int' parameters accept and bind the same kind of values
237 
referenceThroughTypedef(int I,ICRTy Builtin,MyIntCRTy MyInt)238 void referenceThroughTypedef(int I, ICRTy Builtin, MyIntCRTy MyInt) {}
239 // CHECK-MESSAGES: :[[@LINE-1]]:30: warning: 3 adjacent parameters of 'referenceThroughTypedef' of similar type are
240 // CHECK-MESSAGES: :[[@LINE-2]]:34: note: the first parameter in the range is 'I'
241 // CHECK-MESSAGES: :[[@LINE-3]]:62: note: the last parameter in the range is 'MyInt'
242 // CHECK-MESSAGES: :[[@LINE-4]]:37: note: 'int' and 'ICRTy' parameters accept and bind the same kind of values
243 // CHECK-MESSAGES: :[[@LINE-5]]:30: note: after resolving type aliases, 'int' and 'MyIntCRTy' are the same
244 // CHECK-MESSAGES: :[[@LINE-6]]:52: note: 'int' and 'MyIntCRTy' parameters accept and bind the same kind of values
245 // CHECK-MESSAGES: :[[@LINE-7]]:37: note: after resolving type aliases, the common type of 'ICRTy' and 'MyIntCRTy' is 'const int &'
246 
247 typedef int Point2D[2];
248 typedef int Point3D[3];
249 
arrays1(Point2D P2D,Point3D P3D)250 void arrays1(Point2D P2D, Point3D P3D) {} // In reality this is (int*, int*).
251 // CHECK-MESSAGES: :[[@LINE-1]]:14: warning: 2 adjacent parameters of 'arrays1' of similar type ('int *') are
252 // CHECK-MESSAGES: :[[@LINE-2]]:22: note: the first parameter in the range is 'P2D'
253 // CHECK-MESSAGES: :[[@LINE-3]]:35: note: the last parameter in the range is 'P3D'
254 
crefToArrayTypedef1(int I,const Point2D & P)255 void crefToArrayTypedef1(int I, const Point2D &P) {}
256 // NO-WARN.
257 
crefToArrayTypedef2(int * IA,const Point2D & P)258 void crefToArrayTypedef2(int *IA, const Point2D &P) {}
259 // NO-WARN.
260 
crefToArrayTypedef3(int P1[2],const Point2D & P)261 void crefToArrayTypedef3(int P1[2], const Point2D &P) {}
262 // NO-WARN.
263 
crefToArrayTypedefBoth1(const Point2D & VecDescartes,const Point3D & VecThreeD)264 void crefToArrayTypedefBoth1(const Point2D &VecDescartes, const Point3D &VecThreeD) {}
265 // NO-WARN: Distinct types and no conversion because of &.
266 
267 short const typedef int unsigned Eldritch;
268 typedef const unsigned short Holy;
269 
collapse(Eldritch Cursed,Holy Blessed)270 void collapse(Eldritch Cursed, Holy Blessed) {}
271 // CHECK-MESSAGES: :[[@LINE-1]]:15: warning: 2 adjacent parameters of 'collapse' of similar type are
272 // CHECK-MESSAGES: :[[@LINE-2]]:24: note: the first parameter in the range is 'Cursed'
273 // CHECK-MESSAGES: :[[@LINE-3]]:37: note: the last parameter in the range is 'Blessed'
274 // CHECK-MESSAGES: :[[@LINE-4]]:15: note: after resolving type aliases, the common type of 'Eldritch' and 'Holy' is 'const unsigned short'
275 
collapseAndTypedef(Eldritch Cursed,const Holy & Blessed)276 void collapseAndTypedef(Eldritch Cursed, const Holy &Blessed) {}
277 // CHECK-MESSAGES: :[[@LINE-1]]:25: warning: 2 adjacent parameters of 'collapseAndTypedef' of similar type are
278 // CHECK-MESSAGES: :[[@LINE-2]]:34: note: the first parameter in the range is 'Cursed'
279 // CHECK-MESSAGES: :[[@LINE-3]]:54: note: the last parameter in the range is 'Blessed'
280 // CHECK-MESSAGES: :[[@LINE-4]]:25: note: after resolving type aliases, the common type of 'Eldritch' and 'const Holy &' is 'const unsigned short'
281 // CHECK-MESSAGES: :[[@LINE-5]]:42: note: 'Eldritch' and 'const Holy &' parameters accept and bind the same kind of values
282 
283 template <typename T1, typename T2>
284 struct Pair {};
285 
templateParam1(Pair<int,int> P1,Pair<int,int> P2)286 void templateParam1(Pair<int, int> P1, Pair<int, int> P2) {}
287 // CHECK-MESSAGES: :[[@LINE-1]]:21: warning: 2 adjacent parameters of 'templateParam1' of similar type ('Pair<int, int>')
288 // CHECK-MESSAGES: :[[@LINE-2]]:36: note: the first parameter in the range is 'P1'
289 // CHECK-MESSAGES: :[[@LINE-3]]:55: note: the last parameter in the range is 'P2'
290 
templateParam2(Pair<int,long> P1,Pair<int,long> P2)291 void templateParam2(Pair<int, long> P1, Pair<int, long> P2) {}
292 // CHECK-MESSAGES: :[[@LINE-1]]:21: warning: 2 adjacent parameters of 'templateParam2' of similar type ('Pair<int, long>')
293 // CHECK-MESSAGES: :[[@LINE-2]]:37: note: the first parameter in the range is 'P1'
294 // CHECK-MESSAGES: :[[@LINE-3]]:57: note: the last parameter in the range is 'P2'
295 
templateParam3(Pair<int,int> P1,Pair<int,long> P2)296 void templateParam3(Pair<int, int> P1, Pair<int, long> P2) {} // NO-WARN: Not the same type.
297 
298 template <typename X, typename Y>
299 struct Coord {};
300 
templateAndOtherTemplate1(Pair<int,int> P,Coord<int,int> C)301 void templateAndOtherTemplate1(Pair<int, int> P, Coord<int, int> C) {} // NO-WARN: Not the same type.
302 
303 template <typename Ts>
templateVariadic1(Ts TVars...)304 void templateVariadic1(Ts TVars...) {} // NO-WARN: Requires instantiation to check.
305 
306 template <typename T, typename... Us>
templateVariadic2(T TVar,Us...UVars)307 void templateVariadic2(T TVar, Us... UVars) {} // NO-WARN: Distinct types in primary template.
308 
309 template <>
templateVariadic2(int TVar,int UVars1,int UVars2)310 void templateVariadic2(int TVar, int UVars1, int UVars2) {}
311 // CHECK-MESSAGES: :[[@LINE-1]]:24: warning: 3 adjacent parameters of 'templateVariadic2<int, int, int>' of similar type ('int')
312 // CHECK-MESSAGES: :[[@LINE-2]]:28: note: the first parameter in the range is 'TVar'
313 // CHECK-MESSAGES: :[[@LINE-3]]:50: note: the last parameter in the range is 'UVars2'
314 
315 template <typename T>
316 using TwoOf = Pair<T, T>;
317 
templateAndAliasTemplate(Pair<int,int> P,TwoOf<int> I)318 void templateAndAliasTemplate(Pair<int, int> P, TwoOf<int> I) {}
319 // CHECK-MESSAGES: :[[@LINE-1]]:31: warning: 2 adjacent parameters of 'templateAndAliasTemplate' of similar type ('Pair<int, int>')
320 // CHECK-MESSAGES: :[[@LINE-2]]:46: note: the first parameter in the range is 'P'
321 // CHECK-MESSAGES: :[[@LINE-3]]:60: note: the last parameter in the range is 'I'
322 
323 template <int N, int M>
templatedArrayRef(int (& Array1)[N],int (& Array2)[M])324 void templatedArrayRef(int (&Array1)[N], int (&Array2)[M]) {}
325 // NO-WARN: Distinct template types in the primary template.
326 
templatedArrayRefTest()327 void templatedArrayRefTest() {
328   int Foo[12], Bar[12];
329   templatedArrayRef(Foo, Bar);
330 
331   int Baz[12], Quux[42];
332   templatedArrayRef(Baz, Quux);
333 
334   // NO-WARN: Implicit instantiations are not checked.
335 }
336 
337 template <>
templatedArrayRef(int (& Array1)[8],int (& Array2)[8])338 void templatedArrayRef(int (&Array1)[8], int (&Array2)[8]) { templatedArrayRef(Array2, Array1); }
339 // CHECK-MESSAGES: :[[@LINE-1]]:24: warning: 2 adjacent parameters of 'templatedArrayRef<8, 8>' of similar type ('int (&)[8]') are
340 // CHECK-MESSAGES: :[[@LINE-2]]:30: note: the first parameter in the range is 'Array1'
341 // CHECK-MESSAGES: :[[@LINE-3]]:48: note: the last parameter in the range is 'Array2'
342 
343 template <>
templatedArrayRef(int (& Array1)[16],int (& Array2)[24])344 void templatedArrayRef(int (&Array1)[16], int (&Array2)[24]) {}
345 // NO-WARN: Not the same type.
346 
347 template <typename T>
348 struct Vector {
349   typedef T element_type;
350   typedef T &reference_type;
351   typedef const T const_element_type;
352   typedef const T &const_reference_type;
353 };
354 
memberTypedef(int I,Vector<int>::element_type E)355 void memberTypedef(int I, Vector<int>::element_type E) {}
356 // CHECK-MESSAGES: :[[@LINE-1]]:20: warning: 2 adjacent parameters of 'memberTypedef' of similar type are
357 // CHECK-MESSAGES: :[[@LINE-2]]:24: note: the first parameter in the range is 'I'
358 // CHECK-MESSAGES: :[[@LINE-3]]:53: note: the last parameter in the range is 'E'
359 // CHECK-MESSAGES: :[[@LINE-4]]:20: note: after resolving type aliases, 'int' and 'Vector<int>::element_type' are the same
360 
361 template <typename T>
memberTypedefDependent1(T T1,typename Vector<T>::element_type T2)362 void memberTypedefDependent1(T T1, typename Vector<T>::element_type T2) {} // NO-WARN: Dependent name is not instantiated and resolved against other type.
363 
364 template <typename T>
memberTypedefDependent2(typename Vector<T>::element_type E1,typename Vector<T>::element_type E2)365 void memberTypedefDependent2(typename Vector<T>::element_type E1,
366                              typename Vector<T>::element_type E2) {}
367 // CHECK-MESSAGES: :[[@LINE-2]]:30: warning: 2 adjacent parameters of 'memberTypedefDependent2' of similar type ('typename Vector<T>::element_type')
368 // CHECK-MESSAGES: :[[@LINE-3]]:63: note: the first parameter in the range is 'E1'
369 // CHECK-MESSAGES: :[[@LINE-3]]:63: note: the last parameter in the range is 'E2'
370 
371 template <typename T>
memberTypedefDependentReference1(typename Vector<T>::element_type E,typename Vector<T>::const_element_type & R)372 void memberTypedefDependentReference1(
373     typename Vector<T>::element_type E,
374     typename Vector<T>::const_element_type &R) {} // NO-WARN: Not instantiated.
375 
376 template <typename T>
memberTypedefDependentReference2(typename Vector<T>::element_type E,typename Vector<T>::const_reference_type R)377 void memberTypedefDependentReference2(
378     typename Vector<T>::element_type E,
379     typename Vector<T>::const_reference_type R) {} // NO-WARN: Not instantiated.
380 
381 template <typename T>
memberTypedefDependentReference3(typename Vector<T>::element_type E,const typename Vector<T>::element_type & R)382 void memberTypedefDependentReference3(
383     typename Vector<T>::element_type E,
384     const typename Vector<T>::element_type &R) {}
385 // CHECK-MESSAGES: :[[@LINE-2]]:5: warning: 2 adjacent parameters of 'memberTypedefDependentReference3' of similar type are
386 // CHECK-MESSAGES: :[[@LINE-3]]:38: note: the first parameter in the range is 'E'
387 // CHECK-MESSAGES: :[[@LINE-3]]:45: note: the last parameter in the range is 'R'
388 // CHECK-MESSAGES: :[[@LINE-4]]:5: note: 'typename Vector<T>::element_type' and 'const typename Vector<T>::element_type &' parameters accept and bind the same kind of values
389 
functionPrototypeLosesNoexcept(void (* NonThrowing)()noexcept,void (* Throwing)())390 void functionPrototypeLosesNoexcept(void (*NonThrowing)() noexcept, void (*Throwing)()) {}
391 // NO-WARN: This call cannot be swapped, even if "getCanonicalType()" believes otherwise.
392 
attributedParam1(const int * One,const int * Two)393 void attributedParam1(const __attribute__((address_space(256))) int *One,
394                       const __attribute__((address_space(256))) int *Two) {}
395 // CHECK-MESSAGES: :[[@LINE-2]]:23: warning: 2 adjacent parameters of 'attributedParam1' of similar type ('const __attribute__((address_space(256))) int *') are
396 // CHECK-MESSAGES: :[[@LINE-3]]:70: note: the first parameter in the range is 'One'
397 // CHECK-MESSAGES: :[[@LINE-3]]:70: note: the last parameter in the range is 'Two'
398 
attributedParam1Typedef(const int * One,const MyInt1 * Two)399 void attributedParam1Typedef(const __attribute__((address_space(256))) int *One,
400                              const __attribute__((address_space(256))) MyInt1 *Two) {}
401 // CHECK-MESSAGES: :[[@LINE-2]]:30: warning: 2 adjacent parameters of 'attributedParam1Typedef' of similar type are
402 // CHECK-MESSAGES: :[[@LINE-3]]:77: note: the first parameter in the range is 'One'
403 // CHECK-MESSAGES: :[[@LINE-3]]:80: note: the last parameter in the range is 'Two'
404 // CHECK-MESSAGES: :[[@LINE-5]]:30: note: after resolving type aliases, 'const __attribute__((address_space(256))) int *' and 'const __attribute__((address_space(256))) MyInt1 *' are the same
405 
attributedParam1TypedefRef(const int & OneR,MyInt1 & TwoR)406 void attributedParam1TypedefRef(
407     const __attribute__((address_space(256))) int &OneR,
408     __attribute__((address_space(256))) MyInt1 &TwoR) {}
409 // NO-WARN: One is CVR-qualified, the other is not.
410 
attributedParam1TypedefCRef(const int & OneR,const MyInt1 & TwoR)411 void attributedParam1TypedefCRef(
412     const __attribute__((address_space(256))) int &OneR,
413     const __attribute__((address_space(256))) MyInt1 &TwoR) {}
414 // CHECK-MESSAGES: :[[@LINE-2]]:5: warning: 2 adjacent parameters of 'attributedParam1TypedefCRef' of similar type are
415 // CHECK-MESSAGES: :[[@LINE-3]]:52: note: the first parameter in the range is 'OneR'
416 // CHECK-MESSAGES: :[[@LINE-3]]:55: note: the last parameter in the range is 'TwoR'
417 // CHECK-MESSAGES: :[[@LINE-5]]:5: note: after resolving type aliases, 'const __attribute__((address_space(256))) int &' and 'const __attribute__((address_space(256))) MyInt1 &' are the same
418 
attributedParam2(int * One,const MyInt1 * Two)419 void attributedParam2(__attribute__((address_space(256))) int *One,
420                       const __attribute__((address_space(256))) MyInt1 *Two) {}
421 // NO-WARN: One is CVR-qualified, the other is not.
422 
attributedParam3(const int * One,const MyInt1 * Two)423 void attributedParam3(const int *One,
424                       const __attribute__((address_space(256))) MyInt1 *Two) {}
425 // NO-WARN: One is attributed, the other is not.
426 
attributedParam4(const int * One,const MyInt1 * Two)427 void attributedParam4(const __attribute__((address_space(512))) int *One,
428                       const __attribute__((address_space(256))) MyInt1 *Two) {}
429 // NO-WARN: Different value of the attribute.
430