brintos

brintos / llvm-project-archived public Read only

0
0
Text · 24.1 KiB · d933891 Raw
430 lines · cpp
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: 0, \7// RUN:     bugprone-easily-swappable-parameters.ModelImplicitConversions: 0, \8// RUN:     bugprone-easily-swappable-parameters.SuppressParametersUsedTogether: 0, \9// RUN:     bugprone-easily-swappable-parameters.NamePrefixSuffixSilenceDissimilarityThreshold: 0 \10// RUN:  }}' --11 12namespace std {13using size_t = decltype(sizeof(int));14} // namespace std15 16#define assert(X) ((void)(X))17 18void declaration(int Param, int Other); // NO-WARN: No chance to change this function.19 20struct S {};21 22S *allocate() { return nullptr; }                           // NO-WARN: 0 parameters.23void allocate(S **Out) {}                                   // NO-WARN: 1 parameter.24bool operator<(const S &LHS, const S &RHS) { return true; } // NO-WARN: Binary operator.25 26struct MyComparator {27  bool operator()(const S &LHS, const S &RHS) { return true; } // NO-WARN: Binary operator.28};29 30struct MyFactory {31  S operator()() { return {}; }             // NO-WARN: 0 parameters, overloaded operator.32  S operator()(int I) { return {}; }        // NO-WARN: 1 parameter, overloaded operator.33  S operator()(int I, int J) { return {}; } // NO-WARN: Binary operator.34 35  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 the42// *definition*. It would require analysing the call sites to do something43// for these.44int printf(const char *Format, ...) { return 0; } // NO-WARN: Variadic function not checked.45int sum(...) { return 0; }                        // NO-WARN: Variadic function not checked.46 47void *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 52void redeclChain(int, int, int);53void redeclChain(int I, int, int);54void redeclChain(int, int J, int);55void 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 60void 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 65template <typename T, typename U>66bool binaryPredicate(T L, U R) { return false; } // NO-WARN: Distinct types in template.67 68template <> // Explicit specialisation.69bool 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 74template <typename T>75T 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 80void 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 written84  // by the user.85}86 87void 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 92void 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 97void 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 105void variableAndPtr(int I, int *IP) {} // NO-WARN: Not the same type.106 107void differentPtrs(int *IP, long *LP) {} // NO-WARN: Not the same type.108 109typedef int MyInt1;110using MyInt2 = int;111typedef MyInt2 MyInt2b;112 113using CInt = const int;114using CMyInt1 = const MyInt1;115using CMyInt2 = const MyInt2;116 117typedef long MyLong1;118using MyLong2 = long;119 120void 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 125void 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 130void typedefMultiple(MyInt1 I1, MyInt2 I2x, MyInt2 I2y) {}131// CHECK-MESSAGES: :[[@LINE-1]]:22: warning: 3 adjacent parameters of 'typedefMultiple' of similar type are132// 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 136void throughTypedef1(int I, MyInt1 J) {}137// CHECK-MESSAGES: :[[@LINE-1]]:22: warning: 2 adjacent parameters of 'throughTypedef1' of similar type are138// 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 same141 142void betweenTypedef2(MyInt1 I, MyInt2 J) {}143// CHECK-MESSAGES: :[[@LINE-1]]:22: warning: 2 adjacent parameters of 'betweenTypedef2' of similar type are144// 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 148void typedefChain(int I, MyInt1 MI1, MyInt2 MI2, MyInt2b MI2b) {}149// CHECK-MESSAGES: :[[@LINE-1]]:19: warning: 4 adjacent parameters of 'typedefChain' of similar type are150// 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 same153// CHECK-MESSAGES: :[[@LINE-5]]:19: note: after resolving type aliases, 'int' and 'MyInt2' are the same154// CHECK-MESSAGES: :[[@LINE-6]]:19: note: after resolving type aliases, 'int' and 'MyInt2b' are the same155 156void throughTypedefToOtherType(MyInt1 I, MyLong1 J) {} // NO-WARN: int and long.157 158void qualified1(int I, const int CI) {} // NO-WARN: Different qualifiers.159 160void qualified2(int I, volatile int VI) {} // NO-WARN: Different qualifiers.161 162void qualified3(int *IP, const int *CIP) {} // NO-WARN: Different qualifiers.163 164void qualified4(const int CI, const long CL) {} // NO-WARN: Not the same type.165 166void qualifiedPtr1(int *IP, int *const IPC) {} // NO-WARN: Different qualifiers.167 168void qualifiedTypeAndQualifiedPtr1(const int *CIP, int *const volatile IPCV) {} // NO-WARN: Not the same type.169 170void qualifiedThroughTypedef1(int I, CInt CI) {} // NO-WARN: Different qualifiers.171 172void qualifiedThroughTypedef2(CInt CI1, const int CI2) {}173// CHECK-MESSAGES: :[[@LINE-1]]:31: warning: 2 adjacent parameters of 'qualifiedThroughTypedef2' of similar type are174// 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 same177 178void qualifiedThroughTypedef3(CInt CI1, const MyInt1 CI2, const int CI3) {}179// CHECK-MESSAGES: :[[@LINE-1]]:31: warning: 3 adjacent parameters of 'qualifiedThroughTypedef3' of similar type are180// 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 same184// CHECK-MESSAGES: :[[@LINE-6]]:41: note: after resolving type aliases, 'const MyInt1' and 'const int' are the same185 186void qualifiedThroughTypedef4(CInt CI1, const MyInt1 CI2, const MyInt2 CI3) {}187// CHECK-MESSAGES: :[[@LINE-1]]:31: warning: 3 adjacent parameters of 'qualifiedThroughTypedef4' of similar type are188// 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 194void qualifiedThroughTypedef5(CMyInt1 CMI1, CMyInt2 CMI2) {}195// CHECK-MESSAGES: :[[@LINE-1]]:31: warning: 2 adjacent parameters of 'qualifiedThroughTypedef5' of similar type are196// 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 200void qualifiedThroughTypedef6(CMyInt1 CMI1, int I) {} // NO-WARN: Different qualifiers.201 202template <typename T>203void copy(const T *Dest, T *Source) {} // NO-WARN: Different qualifiers.204 205void reference1(int I, int &IR) {} // NO-WARN: Distinct semantics when called.206 207void reference2(int I, const int &CIR) {}208// CHECK-MESSAGES: :[[@LINE-1]]:17: warning: 2 adjacent parameters of 'reference2' of similar type are209// 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 values212 213void reference3(int I, int &&IRR) {} // NO-WARN: Distinct semantics when called.214 215void reference4(int I, const int &&CIRR) {} // NO-WARN: Distinct semantics when called.216 217void reference5(const int CI, const int &CIR) {}218// CHECK-MESSAGES: :[[@LINE-1]]:17: warning: 2 adjacent parameters of 'reference5' of similar type are219// 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 values222 223void 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 are225// 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 values228 229using ICRTy = const int &;230using MyIntCRTy = const MyInt1 &;231 232void referenceToTypedef1(CInt &CIR, int I) {}233// CHECK-MESSAGES: :[[@LINE-1]]:26: warning: 2 adjacent parameters of 'referenceToTypedef1' of similar type are234// 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 values237 238void referenceThroughTypedef(int I, ICRTy Builtin, MyIntCRTy MyInt) {}239// CHECK-MESSAGES: :[[@LINE-1]]:30: warning: 3 adjacent parameters of 'referenceThroughTypedef' of similar type are240// 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 values243// CHECK-MESSAGES: :[[@LINE-5]]:30: note: after resolving type aliases, 'int' and 'MyIntCRTy' are the same244// CHECK-MESSAGES: :[[@LINE-6]]:52: note: 'int' and 'MyIntCRTy' parameters accept and bind the same kind of values245// CHECK-MESSAGES: :[[@LINE-7]]:37: note: after resolving type aliases, the common type of 'ICRTy' and 'MyIntCRTy' is 'const int &'246 247typedef int Point2D[2];248typedef int Point3D[3];249 250void 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 *') are252// 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 255void crefToArrayTypedef1(int I, const Point2D &P) {}256// NO-WARN.257 258void crefToArrayTypedef2(int *IA, const Point2D &P) {}259// NO-WARN.260 261void crefToArrayTypedef3(int P1[2], const Point2D &P) {}262// NO-WARN.263 264void crefToArrayTypedefBoth1(const Point2D &VecDescartes, const Point3D &VecThreeD) {}265// NO-WARN: Distinct types and no conversion because of &.266 267short const typedef int unsigned Eldritch;268typedef const unsigned short Holy;269 270void collapse(Eldritch Cursed, Holy Blessed) {}271// CHECK-MESSAGES: :[[@LINE-1]]:15: warning: 2 adjacent parameters of 'collapse' of similar type are272// 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 276void collapseAndTypedef(Eldritch Cursed, const Holy &Blessed) {}277// CHECK-MESSAGES: :[[@LINE-1]]:25: warning: 2 adjacent parameters of 'collapseAndTypedef' of similar type are278// 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 values282 283template <typename T1, typename T2>284struct Pair {};285 286void 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 291void 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 296void templateParam3(Pair<int, int> P1, Pair<int, long> P2) {} // NO-WARN: Not the same type.297 298template <typename X, typename Y>299struct Coord {};300 301void templateAndOtherTemplate1(Pair<int, int> P, Coord<int, int> C) {} // NO-WARN: Not the same type.302 303template <typename Ts>304void templateVariadic1(Ts TVars...) {} // NO-WARN: Requires instantiation to check.305 306template <typename T, typename... Us>307void templateVariadic2(T TVar, Us... UVars) {} // NO-WARN: Distinct types in primary template.308 309template <>310void 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 315template <typename T>316using TwoOf = Pair<T, T>;317 318void 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 323template <int N, int M>324void templatedArrayRef(int (&Array1)[N], int (&Array2)[M]) {}325// NO-WARN: Distinct template types in the primary template.326 327void 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 337template <>338void 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]') are340// 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 343template <>344void templatedArrayRef(int (&Array1)[16], int (&Array2)[24]) {}345// NO-WARN: Not the same type.346 347template <typename T>348struct 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 355void memberTypedef(int I, Vector<int>::element_type E) {}356// CHECK-MESSAGES: :[[@LINE-1]]:20: warning: 2 adjacent parameters of 'memberTypedef' of similar type are357// 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 same360 361template <typename T>362void memberTypedefDependent1(T T1, typename Vector<T>::element_type T2) {} // NO-WARN: Dependent name is not instantiated and resolved against other type.363 364template <typename T>365void 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 371template <typename T>372void memberTypedefDependentReference1(373    typename Vector<T>::element_type E,374    typename Vector<T>::const_element_type &R) {} // NO-WARN: Not instantiated.375 376template <typename T>377void memberTypedefDependentReference2(378    typename Vector<T>::element_type E,379    typename Vector<T>::const_reference_type R) {} // NO-WARN: Not instantiated.380 381template <typename T>382void 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 are386// 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 values389 390void functionPrototypeLosesNoexcept(void (*NonThrowing)() noexcept, void (*Throwing)()) {}391// NO-WARN: This call cannot be swapped, even if "getCanonicalType()" believes otherwise.392 393void 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 *') are396// 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 399void 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 are402// 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 same405 406void 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 411void 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 are415// 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 same418 419void 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 423void attributedParam3(const int *One,424                      const __attribute__((address_space(256))) MyInt1 *Two) {}425// NO-WARN: One is attributed, the other is not.426 427void 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