| 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.NamePrefixSuffixSilenceDissimilarityTreshold: 1 \ |
| 10 | // RUN: }}' -- |
| 11 | |
| 12 | namespace std { |
| 13 | struct string {}; |
| 14 | } // namespace std |
| 15 | class Matrix {}; |
| 16 | |
| 17 | void test1(int Foo, int Bar) {} |
| 18 | // CHECK-MESSAGES: :[[@LINE-1]]:12: warning: 2 adjacent parameters of 'test1' of similar type ('int') are easily swapped by mistake [bugprone-easily-swappable-parameters] |
| 19 | // CHECK-MESSAGES: :[[@LINE-2]]:16: note: the first parameter in the range is 'Foo' |
| 20 | // CHECK-MESSAGES: :[[@LINE-3]]:25: note: the last parameter in the range is 'Bar' |
| 21 | |
| 22 | void test2(int A, int B) {} |
| 23 | // CHECK-MESSAGES: :[[@LINE-1]]:12: warning: 2 adjacent parameters of 'test2' of similar type ('int') |
| 24 | // CHECK-MESSAGES: :[[@LINE-2]]:16: note: the first parameter in the range is 'A' |
| 25 | // CHECK-MESSAGES: :[[@LINE-3]]:23: note: the last parameter in the range is 'B' |
| 26 | |
| 27 | void test3(int Val1, int Val2) {} // NO-WARN. |
| 28 | |
| 29 | void test4(int ValA, int Valb) {} // NO-WARN. |
| 30 | |
| 31 | void test5(int Val1, int ValZ) {} // NO-WARN. |
| 32 | |
| 33 | void test6(int PValue, int QValue) {} // NO-WARN. |
| 34 | |
| 35 | void test7(std::string Astr, std::string Bstr) {} // NO-WARN. |
| 36 | |
| 37 | void test8(int Aladdin, int Alabaster) {} |
| 38 | // CHECK-MESSAGES: :[[@LINE-1]]:12: warning: 2 adjacent parameters of 'test8' of similar type ('int') |
| 39 | // CHECK-MESSAGES: :[[@LINE-2]]:16: note: the first parameter in the range is 'Aladdin' |
| 40 | // CHECK-MESSAGES: :[[@LINE-3]]:29: note: the last parameter in the range is 'Alabaster' |
| 41 | |
| 42 | void test9(Matrix Qmat, Matrix Rmat, Matrix Tmat) {} // NO-WARN. |
| 43 | |
| 44 | void test10(int Something, int Other, int Foo, int Bar1, int Bar2, int Baz, int Qux) {} |
| 45 | // CHECK-MESSAGES: :[[@LINE-1]]:13: warning: 4 adjacent parameters of 'test10' of similar type ('int') are |
| 46 | // CHECK-MESSAGES: :[[@LINE-2]]:17: note: the first parameter in the range is 'Something' |
| 47 | // CHECK-MESSAGES: :[[@LINE-3]]:52: note: the last parameter in the range is 'Bar1' |
| 48 | // |
| 49 | // CHECK-MESSAGES: :[[@LINE-5]]:58: warning: 3 adjacent parameters of 'test10' of similar type ('int') are |
| 50 | // CHECK-MESSAGES: :[[@LINE-6]]:62: note: the first parameter in the range is 'Bar2' |
| 51 | // CHECK-MESSAGES: :[[@LINE-7]]:81: note: the last parameter in the range is 'Qux' |
| 52 | |
| 53 | void test11(int Foobar, int Foo) {} |
| 54 | // CHECK-MESSAGES: :[[@LINE-1]]:13: warning: 2 adjacent parameters of 'test11' of similar type ('int') |
| 55 | // CHECK-MESSAGES: :[[@LINE-2]]:17: note: the first parameter in the range is 'Foobar' |
| 56 | // CHECK-MESSAGES: :[[@LINE-3]]:29: note: the last parameter in the range is 'Foo' |
| 57 | |