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
12namespace std {
13struct string {};
14} // namespace std
15class Matrix {};
16
17void 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
22void 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
27void test3(int Val1, int Val2) {} // NO-WARN.
28
29void test4(int ValA, int Valb) {} // NO-WARN.
30
31void test5(int Val1, int ValZ) {} // NO-WARN.
32
33void test6(int PValue, int QValue) {} // NO-WARN.
34
35void test7(std::string Astr, std::string Bstr) {} // NO-WARN.
36
37void 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
42void test9(Matrix Qmat, Matrix Rmat, Matrix Tmat) {} // NO-WARN.
43
44void 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
53void 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

source code of clang-tools-extra/test/clang-tidy/checkers/bugprone/easily-swappable-parameters-prefixsuffixname.cpp