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
77namespace different_contexts {
78 // No warning for names in unrelated contexts.
79 template <typename u1> void different_templates_1();
80 template <typename ul> void different_templates_2();
81 namespace inner {
82 int ul;
83 }
84}
85
86namespace same_template {
87 template <typename u1, typename ul> using T = int;
88 // CHECK-MESSAGES: :[[#@LINE-1]]:35: warning: 'ul' is confusable with 'u1' [misc-confusable-identifiers]
89 // CHECK-MESSAGES: :[[#@LINE-2]]:22: note: other declaration found here
90
91 template <typename v1, typename vl> int n;
92 // CHECK-MESSAGES: :[[#@LINE-1]]:35: warning: 'vl' is confusable with 'v1' [misc-confusable-identifiers]
93 // CHECK-MESSAGES: :[[#@LINE-2]]:22: note: other declaration found here
94
95 template <typename w1> int wl;
96 // CHECK-MESSAGES: :[[#@LINE-1]]:22: warning: 'w1' is confusable with 'wl' [misc-confusable-identifiers]
97 // CHECK-MESSAGES: :[[#@LINE-2]]:30: note: other declaration found here
98
99 int xl;
100 template <typename x1> int x;
101 // CHECK-MESSAGES: :[[#@LINE-1]]:22: warning: 'x1' is confusable with 'xl' [misc-confusable-identifiers]
102 // CHECK-MESSAGES: :[[#@LINE-3]]:7: note: other declaration found here
103}
104
105namespace f10 {
106int il;
107namespace inner {
108 int i1;
109 // CHECK-MESSAGES: :[[#@LINE-1]]:7: warning: 'i1' is confusable with 'il' [misc-confusable-identifiers]
110 // CHECK-MESSAGES: :[[#@LINE-4]]:5: note: other declaration found here
111 int j1;
112 // CHECK-MESSAGES: :[[#@LINE-1]]:7: warning: 'j1' is confusable with 'jl' [misc-confusable-identifiers]
113 // CHECK-MESSAGES: :[[#@LINE+2]]:5: note: other declaration found here
114}
115int jl;
116}
117
118struct Base0 {
119 virtual void mO0();
120
121private:
122 void mII();
123};
124
125struct Derived0 : Base0 {
126 void mOO();
127 // CHECK-MESSAGES: :[[#@LINE-1]]:8: warning: 'mOO' is confusable with 'mO0' [misc-confusable-identifiers]
128 // CHECK-MESSAGES: :[[#@LINE-9]]:16: note: other declaration found here
129
130 void mI1(); // no warning: mII is private
131};
132
133struct Base1 {
134 long mO0;
135
136private:
137 long mII;
138};
139
140struct Derived1 : Base1 {
141 long mOO;
142 // CHECK-MESSAGES: :[[#@LINE-1]]:8: warning: 'mOO' is confusable with 'mO0' [misc-confusable-identifiers]
143 // CHECK-MESSAGES: :[[#@LINE-9]]:8: note: other declaration found here
144
145 long mI1(); // no warning: mII is private
146};
147
148struct Base2 {
149 long nO0;
150
151private:
152 long nII;
153};
154
155struct Mid2 : Base0, Base1, Base2 {
156};
157
158struct Derived2 : Mid2 {
159 long nOO;
160 // CHECK-MESSAGES: :[[#@LINE-1]]:8: warning: 'nOO' is confusable with 'nO0' [misc-confusable-identifiers]
161 // CHECK-MESSAGES: :[[#@LINE-12]]:8: note: other declaration found here
162
163 long nI1(); // no warning: mII is private
164};
165

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