1 | // RUN: %check_clang_tidy %s readability-identifier-naming %t -- \ |
2 | // RUN: -config='{CheckOptions: { \ |
3 | // RUN: readability-identifier-naming.MemberCase: CamelCase, \ |
4 | // RUN: readability-identifier-naming.ParameterCase: CamelCase, \ |
5 | // RUN: readability-identifier-naming.MethodCase: camelBack, \ |
6 | // RUN: readability-identifier-naming.AggressiveDependentMemberLookup: true \ |
7 | // RUN: }}' -- -fno-delayed-template-parsing |
8 | |
9 | int set_up(int); |
10 | int clear(int); |
11 | |
12 | class Foo { |
13 | public: |
14 | const int bar_baz; // comment-0 |
15 | // CHECK-MESSAGES: :[[@LINE-1]]:13: warning: invalid case style for member 'bar_baz' |
16 | // CHECK-FIXES: {{^}} const int BarBaz; // comment-0 |
17 | |
18 | Foo(int Val) : bar_baz(Val) { // comment-1 |
19 | // CHECK-FIXES: {{^}} Foo(int Val) : BarBaz(Val) { // comment-1 |
20 | set_up(bar_baz); // comment-2 |
21 | // CHECK-FIXES: {{^}} set_up(BarBaz); // comment-2 |
22 | } |
23 | |
24 | Foo() : Foo(0) {} |
25 | |
26 | ~Foo() { |
27 | clear(bar_baz); // comment-3 |
28 | // CHECK-FIXES: {{^}} clear(BarBaz); // comment-3 |
29 | } |
30 | |
31 | int getBar() const { return bar_baz; } // comment-4 |
32 | // CHECK-FIXES: {{^}} int getBar() const { return BarBaz; } // comment-4 |
33 | }; |
34 | |
35 | class FooBar : public Foo { |
36 | public: |
37 | int getFancyBar() const { |
38 | return this->bar_baz; // comment-5 |
39 | // CHECK-FIXES: {{^}} return this->BarBaz; // comment-5 |
40 | } |
41 | }; |
42 | |
43 | int getBar(const Foo &Foo) { |
44 | return Foo.bar_baz; // comment-6 |
45 | // CHECK-FIXES: {{^}} return Foo.BarBaz; // comment-6 |
46 | } |
47 | |
48 | int getBar(const FooBar &Foobar) { |
49 | return Foobar.bar_baz; // comment-7 |
50 | // CHECK-FIXES: {{^}} return Foobar.BarBaz; // comment-7 |
51 | } |
52 | |
53 | int getFancyBar(const FooBar &Foobar) { |
54 | return Foobar.getFancyBar(); |
55 | } |
56 | |
57 | template <typename Dummy> |
58 | class TempTest : public Foo { |
59 | public: |
60 | TempTest() = default; |
61 | TempTest(int Val) : Foo(Val) {} |
62 | int getBar() const { return Foo::bar_baz; } // comment-8 |
63 | // CHECK-FIXES: {{^}} int getBar() const { return Foo::BarBaz; } // comment-8 |
64 | int getBar2() const { return this->bar_baz; } // comment-9 |
65 | // CHECK-FIXES: {{^}} int getBar2() const { return this->BarBaz; } // comment-9 |
66 | }; |
67 | |
68 | namespace Bug41122 { |
69 | namespace std { |
70 | |
71 | // for this example we aren't bothered about how std::vector is treated |
72 | template <typename T> // NOLINT |
73 | struct vector { // NOLINT |
74 | void push_back(bool); // NOLINT |
75 | void pop_back(); // NOLINT |
76 | }; // NOLINT |
77 | }; // namespace std |
78 | |
79 | class Foo { |
80 | std::vector<bool> &stack; |
81 | // CHECK-MESSAGES: :[[@LINE-1]]:22: warning: invalid case style for member 'stack' [readability-identifier-naming] |
82 | public: |
83 | Foo(std::vector<bool> &stack) |
84 | // CHECK-MESSAGES: :[[@LINE-1]]:26: warning: invalid case style for parameter 'stack' [readability-identifier-naming] |
85 | // CHECK-FIXES: {{^}} Foo(std::vector<bool> &Stack) |
86 | : stack(stack) { |
87 | // CHECK-FIXES: {{^}} : Stack(Stack) { |
88 | stack.push_back(true); |
89 | // CHECK-FIXES: {{^}} Stack.push_back(true); |
90 | } |
91 | ~Foo() { |
92 | stack.pop_back(); |
93 | // CHECK-FIXES: {{^}} Stack.pop_back(); |
94 | } |
95 | }; |
96 | }; // namespace Bug41122 |
97 | |
98 | namespace Bug29005 { |
99 | class Foo { |
100 | public: |
101 | int a_member_of_foo = 0; |
102 | // CHECK-MESSAGES: :[[@LINE-1]]:7: warning: invalid case style for member 'a_member_of_foo' |
103 | // CHECK-FIXES: {{^}} int AMemberOfFoo = 0; |
104 | }; |
105 | |
106 | int main() { |
107 | Foo foo; |
108 | return foo.a_member_of_foo; |
109 | // CHECK-FIXES: {{^}} return foo.AMemberOfFoo; |
110 | } |
111 | }; // namespace Bug29005 |
112 | |
113 | namespace CtorInits { |
114 | template <typename T, unsigned N> |
115 | class Container { |
116 | T storage[N]; |
117 | // CHECK-MESSAGES: :[[@LINE-1]]:5: warning: invalid case style for member 'storage' |
118 | // CHECK-FIXES: {{^}} T Storage[N]; |
119 | T *pointer = &storage[0]; |
120 | // CHECK-MESSAGES: :[[@LINE-1]]:6: warning: invalid case style for member 'pointer' |
121 | // CHECK-FIXES: {{^}} T *Pointer = &Storage[0]; |
122 | public: |
123 | Container() : pointer(&storage[0]) {} |
124 | // CHECK-FIXES: {{^}} Container() : Pointer(&Storage[0]) {} |
125 | }; |
126 | |
127 | void foo() { |
128 | Container<int, 5> container; |
129 | } |
130 | } // namespace CtorInits |
131 | |
132 | namespace resolved_dependance { |
133 | template <typename T> |
134 | struct A0 { |
135 | int value; |
136 | // CHECK-MESSAGES: :[[@LINE-1]]:7: warning: invalid case style for member 'value' |
137 | A0 &operator=(const A0 &Other) { |
138 | value = Other.value; // A0 |
139 | this->value = Other.value; // A0 |
140 | // CHECK-FIXES: {{^}} Value = Other.Value; // A0 |
141 | // CHECK-FIXES-NEXT: {{^}} this->Value = Other.Value; // A0 |
142 | return *this; |
143 | } |
144 | void outOfLineReset(); |
145 | }; |
146 | |
147 | template <typename T> |
148 | void A0<T>::outOfLineReset() { |
149 | this->value -= value; // A0 |
150 | // CHECK-FIXES: {{^}} this->Value -= Value; // A0 |
151 | } |
152 | |
153 | template <typename T> |
154 | struct A1 { |
155 | int value; // A1 |
156 | // CHECK-MESSAGES: :[[@LINE-1]]:7: warning: invalid case style for member 'value' |
157 | // CHECK-FIXES: {{^}} int Value; // A1 |
158 | int GetValue() const { return value; } // A1 |
159 | // CHECK-MESSAGES: :[[@LINE-1]]:7: warning: invalid case style for method 'GetValue' |
160 | // CHECK-FIXES {{^}} int getValue() const { return Value; } // A1 |
161 | void SetValue(int Value) { this->value = Value; } // A1 |
162 | // CHECK-MESSAGES: :[[@LINE-1]]:8: warning: invalid case style for method 'SetValue' |
163 | // CHECK-FIXES {{^}} void setValue(int Value) { this->Value = Value; } // A1 |
164 | A1 &operator=(const A1 &Other) { |
165 | this->SetValue(Other.GetValue()); // A1 |
166 | this->value = Other.value; // A1 |
167 | // CHECK-FIXES: {{^}} this->setValue(Other.getValue()); // A1 |
168 | // CHECK-FIXES-NEXT: {{^}} this->Value = Other.Value; // A1 |
169 | return *this; |
170 | } |
171 | void outOfLineReset(); |
172 | }; |
173 | |
174 | template <typename T> |
175 | void A1<T>::outOfLineReset() { |
176 | this->value -= value; // A1 |
177 | // CHECK-FIXES: {{^}} this->Value -= Value; // A1 |
178 | } |
179 | |
180 | template <unsigned T> |
181 | struct A2 { |
182 | int value; // A2 |
183 | // CHECK-MESSAGES: :[[@LINE-1]]:7: warning: invalid case style for member 'value' |
184 | // CHECK-FIXES: {{^}} int Value; // A2 |
185 | A2 &operator=(const A2 &Other) { |
186 | value = Other.value; // A2 |
187 | this->value = Other.value; // A2 |
188 | // CHECK-FIXES: {{^}} Value = Other.Value; // A2 |
189 | // CHECK-FIXES-NEXT: {{^}} this->Value = Other.Value; // A2 |
190 | return *this; |
191 | } |
192 | }; |
193 | |
194 | // create some instances to check it works when instantiated. |
195 | A1<int> AInt{}; |
196 | A1<int> BInt = (AInt.outOfLineReset(), AInt); |
197 | A1<unsigned> AUnsigned{}; |
198 | A1<unsigned> BUnsigned = AUnsigned; |
199 | } // namespace resolved_dependance |
200 | |
201 | namespace unresolved_dependance { |
202 | template <typename T> |
203 | struct DependentBase { |
204 | int depValue; |
205 | // CHECK-MESSAGES: :[[@LINE-1]]:7: warning: invalid case style for member 'depValue' |
206 | // CHECK-FIXES: {{^}} int DepValue; |
207 | }; |
208 | |
209 | template <typename T> |
210 | struct Derived : DependentBase<T> { |
211 | Derived &operator=(const Derived &Other) { |
212 | this->depValue = Other.depValue; |
213 | // CHECK-FIXES: {{^}} this->DepValue = Other.DepValue; |
214 | return *this; |
215 | } |
216 | }; |
217 | |
218 | } // namespace unresolved_dependance |
219 | |