1// RUN: %check_clang_tidy %s misc-confusable-identifiers %t
2
3int l0;
4int lO;
5// CHECK-MESSAGES: :[[#@LINE-1]]:5: warning: 'lO' is confusable with 'l0' [misc-confusable-identifiers]
6// CHECK-MESSAGES: :[[#@LINE-3]]:5: note: other declaration found here
7
8void no() {
9 int 𝐟oo;
10}
11
12void worry() {
13 int foo;
14}
15int l1;
16int ll;
17// CHECK-MESSAGES: :[[#@LINE-1]]:5: warning: 'll' is confusable with 'l1' [misc-confusable-identifiers]
18// CHECK-MESSAGES: :[[#@LINE-3]]:5: note: other declaration found here
19
20bool f0(const char *q1, const char *ql) {
21 // CHECK-MESSAGES: :[[#@LINE-1]]:37: warning: 'ql' is confusable with 'q1' [misc-confusable-identifiers]
22 // CHECK-MESSAGES: :[[#@LINE-2]]:21: note: other declaration found here
23 return q1 < ql;
24}
25
26// should not print anything
27namespace ns {
28struct Foo {};
29} // namespace ns
30auto f = ns::Foo();
31
32struct Test {
33 void f1(const char *pl);
34};
35
36bool f2(const char *p1, const char *ql) {
37 return p1 < ql;
38}
39
40bool f3(const char *q0, const char *q1) {
41 return q0 < q1;
42}
43
44template <typename i1>
45struct S {
46 template <typename il>
47 void f4() {}
48 // CHECK-MESSAGES: :[[#@LINE-2]]:22: warning: 'il' is confusable with 'i1' [misc-confusable-identifiers]
49 // CHECK-MESSAGES: :[[#@LINE-5]]:20: note: other declaration found here
50};
51
52template <typename i1>
53void f5(int il) {
54 // CHECK-MESSAGES: :[[#@LINE-1]]:13: warning: 'il' is confusable with 'i1' [misc-confusable-identifiers]
55 // CHECK-MESSAGES: :[[#@LINE-3]]:20: note: other declaration found here
56}
57
58namespace f7 {
59int i1;
60}
61
62namespace f8 {
63int il; // no warning, different namespace
64}
65
66namespace f7 {
67int il;
68// CHECK-MESSAGES: :[[#@LINE-1]]:5: warning: 'il' is confusable with 'i1' [misc-confusable-identifiers]
69// CHECK-MESSAGES: :[[#@LINE-10]]:5: note: other declaration found here
70} // namespace f7
71
72template <typename t1, typename tl>
73// CHECK-MESSAGES: :[[#@LINE-1]]:33: warning: 'tl' is confusable with 't1' [misc-confusable-identifiers]
74// CHECK-MESSAGES: :[[#@LINE-2]]:20: note: other declaration found here
75void f9();
76
77struct Base0 {
78 virtual void mO0();
79
80private:
81 void mII();
82};
83
84struct Derived0 : Base0 {
85 void mOO();
86 // CHECK-MESSAGES: :[[#@LINE-1]]:8: warning: 'mOO' is confusable with 'mO0' [misc-confusable-identifiers]
87 // CHECK-MESSAGES: :[[#@LINE-9]]:16: note: other declaration found here
88
89 void mI1(); // no warning: mII is private
90};
91
92struct Base1 {
93 long mO0;
94
95private:
96 long mII;
97};
98
99struct Derived1 : Base1 {
100 long mOO;
101 // CHECK-MESSAGES: :[[#@LINE-1]]:8: warning: 'mOO' is confusable with 'mO0' [misc-confusable-identifiers]
102 // CHECK-MESSAGES: :[[#@LINE-9]]:8: note: other declaration found here
103
104 long mI1(); // no warning: mII is private
105};
106

source code of clang-tools-extra/test/clang-tidy/checkers/misc/confusable-identifiers.cpp