1 // Remove UNSUPPORTED for powerpc64le when the problem introduced by
2 // r288563 is resolved.
3 // UNSUPPORTED: powerpc64le
4 // RUN: %check_clang_tidy %s readability-identifier-naming %t -- \
5 // RUN: -config='{CheckOptions: [ \
6 // RUN: {key: readability-identifier-naming.AbstractClassCase, value: CamelCase}, \
7 // RUN: {key: readability-identifier-naming.AbstractClassPrefix, value: 'A'}, \
8 // RUN: {key: readability-identifier-naming.ClassCase, value: CamelCase}, \
9 // RUN: {key: readability-identifier-naming.ClassPrefix, value: 'C'}, \
10 // RUN: {key: readability-identifier-naming.ClassConstantCase, value: CamelCase}, \
11 // RUN: {key: readability-identifier-naming.ClassConstantPrefix, value: 'k'}, \
12 // RUN: {key: readability-identifier-naming.ClassMemberCase, value: CamelCase}, \
13 // RUN: {key: readability-identifier-naming.ClassMethodCase, value: camelBack}, \
14 // RUN: {key: readability-identifier-naming.ConstantCase, value: UPPER_CASE}, \
15 // RUN: {key: readability-identifier-naming.ConstantSuffix, value: '_CST'}, \
16 // RUN: {key: readability-identifier-naming.ConstexprFunctionCase, value: lower_case}, \
17 // RUN: {key: readability-identifier-naming.ConstexprMethodCase, value: lower_case}, \
18 // RUN: {key: readability-identifier-naming.ConstexprVariableCase, value: lower_case}, \
19 // RUN: {key: readability-identifier-naming.EnumCase, value: CamelCase}, \
20 // RUN: {key: readability-identifier-naming.EnumPrefix, value: 'E'}, \
21 // RUN: {key: readability-identifier-naming.ScopedEnumConstantCase, value: CamelCase}, \
22 // RUN: {key: readability-identifier-naming.EnumConstantCase, value: UPPER_CASE}, \
23 // RUN: {key: readability-identifier-naming.FunctionCase, value: camelBack}, \
24 // RUN: {key: readability-identifier-naming.GlobalConstantCase, value: UPPER_CASE}, \
25 // RUN: {key: readability-identifier-naming.GlobalFunctionCase, value: CamelCase}, \
26 // RUN: {key: readability-identifier-naming.GlobalVariableCase, value: lower_case}, \
27 // RUN: {key: readability-identifier-naming.GlobalVariablePrefix, value: 'g_'}, \
28 // RUN: {key: readability-identifier-naming.InlineNamespaceCase, value: lower_case}, \
29 // RUN: {key: readability-identifier-naming.LocalConstantCase, value: CamelCase}, \
30 // RUN: {key: readability-identifier-naming.LocalConstantPrefix, value: 'k'}, \
31 // RUN: {key: readability-identifier-naming.LocalVariableCase, value: lower_case}, \
32 // RUN: {key: readability-identifier-naming.MemberCase, value: CamelCase}, \
33 // RUN: {key: readability-identifier-naming.MemberPrefix, value: 'm_'}, \
34 // RUN: {key: readability-identifier-naming.ConstantMemberCase, value: lower_case}, \
35 // RUN: {key: readability-identifier-naming.PrivateMemberPrefix, value: '__'}, \
36 // RUN: {key: readability-identifier-naming.ProtectedMemberPrefix, value: '_'}, \
37 // RUN: {key: readability-identifier-naming.PublicMemberCase, value: lower_case}, \
38 // RUN: {key: readability-identifier-naming.MethodCase, value: camelBack}, \
39 // RUN: {key: readability-identifier-naming.PrivateMethodPrefix, value: '__'}, \
40 // RUN: {key: readability-identifier-naming.ProtectedMethodPrefix, value: '_'}, \
41 // RUN: {key: readability-identifier-naming.NamespaceCase, value: lower_case}, \
42 // RUN: {key: readability-identifier-naming.ParameterCase, value: camelBack}, \
43 // RUN: {key: readability-identifier-naming.ParameterPrefix, value: 'a_'}, \
44 // RUN: {key: readability-identifier-naming.ConstantParameterCase, value: camelBack}, \
45 // RUN: {key: readability-identifier-naming.ConstantParameterPrefix, value: 'i_'}, \
46 // RUN: {key: readability-identifier-naming.ParameterPackCase, value: camelBack}, \
47 // RUN: {key: readability-identifier-naming.PureFunctionCase, value: lower_case}, \
48 // RUN: {key: readability-identifier-naming.PureMethodCase, value: camelBack}, \
49 // RUN: {key: readability-identifier-naming.StaticConstantCase, value: UPPER_CASE}, \
50 // RUN: {key: readability-identifier-naming.StaticVariableCase, value: camelBack}, \
51 // RUN: {key: readability-identifier-naming.StaticVariablePrefix, value: 's_'}, \
52 // RUN: {key: readability-identifier-naming.StructCase, value: lower_case}, \
53 // RUN: {key: readability-identifier-naming.TemplateParameterCase, value: UPPER_CASE}, \
54 // RUN: {key: readability-identifier-naming.TemplateTemplateParameterCase, value: CamelCase}, \
55 // RUN: {key: readability-identifier-naming.TemplateUsingCase, value: lower_case}, \
56 // RUN: {key: readability-identifier-naming.TemplateUsingPrefix, value: 'u_'}, \
57 // RUN: {key: readability-identifier-naming.TypeTemplateParameterCase, value: camelBack}, \
58 // RUN: {key: readability-identifier-naming.TypeTemplateParameterSuffix, value: '_t'}, \
59 // RUN: {key: readability-identifier-naming.TypedefCase, value: lower_case}, \
60 // RUN: {key: readability-identifier-naming.TypedefSuffix, value: '_t'}, \
61 // RUN: {key: readability-identifier-naming.UnionCase, value: CamelCase}, \
62 // RUN: {key: readability-identifier-naming.UnionPrefix, value: 'U'}, \
63 // RUN: {key: readability-identifier-naming.UsingCase, value: lower_case}, \
64 // RUN: {key: readability-identifier-naming.ValueTemplateParameterCase, value: camelBack}, \
65 // RUN: {key: readability-identifier-naming.VariableCase, value: lower_case}, \
66 // RUN: {key: readability-identifier-naming.VirtualMethodCase, value: Camel_Snake_Case}, \
67 // RUN: {key: readability-identifier-naming.VirtualMethodPrefix, value: 'v_'}, \
68 // RUN: {key: readability-identifier-naming.MacroDefinitionCase, value: UPPER_CASE}, \
69 // RUN: {key: readability-identifier-naming.TypeAliasCase, value: camel_Snake_Back}, \
70 // RUN: {key: readability-identifier-naming.TypeAliasSuffix, value: '_t'}, \
71 // RUN: {key: readability-identifier-naming.IgnoreFailedSplit, value: false}, \
72 // RUN: {key: readability-identifier-naming.GlobalPointerCase, value: CamelCase}, \
73 // RUN: {key: readability-identifier-naming.GlobalPointerSuffix, value: '_Ptr'}, \
74 // RUN: {key: readability-identifier-naming.GlobalConstantPointerCase, value: UPPER_CASE}, \
75 // RUN: {key: readability-identifier-naming.GlobalConstantPointerSuffix, value: '_Ptr'}, \
76 // RUN: {key: readability-identifier-naming.PointerParameterCase, value: lower_case}, \
77 // RUN: {key: readability-identifier-naming.PointerParameterPrefix, value: 'p_'}, \
78 // RUN: {key: readability-identifier-naming.ConstantPointerParameterCase, value: CamelCase}, \
79 // RUN: {key: readability-identifier-naming.ConstantPointerParameterPrefix, value: 'cp_'}, \
80 // RUN: {key: readability-identifier-naming.LocalPointerCase, value: CamelCase}, \
81 // RUN: {key: readability-identifier-naming.LocalPointerPrefix, value: 'l_'}, \
82 // RUN: {key: readability-identifier-naming.LocalConstantPointerCase, value: CamelCase}, \
83 // RUN: {key: readability-identifier-naming.LocalConstantPointerPrefix, value: 'lc_'}, \
84 // RUN: ]}' -- -fno-delayed-template-parsing -Dbad_macro -std=c++17 -fcoroutines-ts \
85 // RUN: -I%S/Inputs/identifier-naming \
86 // RUN: -isystem %S/Inputs/identifier-naming/system
87
88 // clang-format off
89
90 #include <system-header.h>
91 #include <coroutines.h>
92 #include "user-header.h"
93 // NO warnings or fixes expected from declarations within header files without
94 // the -header-filter= option
95
96 namespace FOO_NS {
97 // CHECK-MESSAGES: :[[@LINE-1]]:11: warning: invalid case style for namespace 'FOO_NS' [readability-identifier-naming]
98 // CHECK-FIXES: {{^}}namespace foo_ns {{{$}}
99 inline namespace InlineNamespace {
100 // CHECK-MESSAGES: :[[@LINE-1]]:18: warning: invalid case style for inline namespace 'InlineNamespace'
101 // CHECK-FIXES: {{^}}inline namespace inline_namespace {{{$}}
102
103 SYSTEM_NS::structure g_s1;
104 // NO warnings or fixes expected as SYSTEM_NS and structure are declared in a header file
105
106 USER_NS::object g_s2;
107 // NO warnings or fixes expected as USER_NS and object are declared in a header file
108
109 SYSTEM_MACRO(var1);
110 // NO warnings or fixes expected as var1 is from macro expansion
111
112 USER_MACRO(var2);
113 // NO warnings or fixes expected as var2 is declared in a macro expansion
114
115 #define BLA int FOO_bar
116 BLA;
117 // NO warnings or fixes expected as FOO_bar is from macro expansion
118
119 int global0;
120 #define USE_NUMBERED_GLOBAL(number) auto use_global##number = global##number
121 USE_NUMBERED_GLOBAL(0);
122 // NO warnings or fixes expected as global0 is pieced together in a macro
123 // expansion.
124
125 int global1;
126 #define USE_NUMBERED_BAL(prefix, number) \
127 auto use_##prefix##bal##number = prefix##bal##number
128 USE_NUMBERED_BAL(glo, 1);
129 // NO warnings or fixes expected as global1 is pieced together in a macro
130 // expansion.
131
132 int global2;
133 #define USE_RECONSTRUCTED(glo, bal) auto use_##glo##bal = glo##bal
134 USE_RECONSTRUCTED(glo, bal2);
135 // NO warnings or fixes expected as global2 is pieced together in a macro
136 // expansion.
137
138 int global;
139 // CHECK-MESSAGES: :[[@LINE-1]]:5: warning: invalid case style for global variable 'global'
140 // CHECK-FIXES: {{^}}int g_global;{{$}}
141 #define USE_IN_MACRO(m) auto use_##m = m
142 USE_IN_MACRO(global);
143
144 int global3;
145 // CHECK-MESSAGES: :[[@LINE-1]]:5: warning: invalid case style for global variable 'global3'
146 // CHECK-FIXES: {{^}}int g_global3;{{$}}
147 #define ADD_TO_SELF(m) (m) + (m)
148 int g_twice_global3 = ADD_TO_SELF(global3);
149 // CHECK-FIXES: {{^}}int g_twice_global3 = ADD_TO_SELF(g_global3);{{$}}
150
151 int g_Global4;
152 // CHECK-MESSAGES: :[[@LINE-1]]:5: warning: invalid case style for global variable 'g_Global4'
153 // CHECK-FIXES: {{^}}int g_global4;{{$}}
154
155 enum my_enumeration {
156 // CHECK-MESSAGES: :[[@LINE-1]]:6: warning: invalid case style for enum 'my_enumeration'
157 // CHECK-FIXES: {{^}}enum EMyEnumeration {{{$}}
158 MyConstant = 1,
159 // CHECK-MESSAGES: :[[@LINE-1]]:5: warning: invalid case style for enum constant 'MyConstant'
160 // CHECK-FIXES: {{^}} MY_CONSTANT = 1,{{$}}
161 your_CONST = 1,
162 // CHECK-MESSAGES: :[[@LINE-1]]:5: warning: invalid case style for enum constant 'your_CONST'
163 // CHECK-FIXES: {{^}} YOUR_CONST = 1,{{$}}
164 THIS_ConstValue = 1,
165 // CHECK-MESSAGES: :[[@LINE-1]]:5: warning: invalid case style for enum constant 'THIS_ConstValue'
166 // CHECK-FIXES: {{^}} THIS_CONST_VALUE = 1,{{$}}
167 };
168
169 enum class EMyEnumeration {
170 myConstant = 1,
171 // CHECK-MESSAGES: :[[@LINE-1]]:5: warning: invalid case style for scoped enum constant 'myConstant'
172 // CHECK-FIXES: {{^}} MyConstant = 1,{{$}}
173 your_CONST = 1,
174 // CHECK-MESSAGES: :[[@LINE-1]]:5: warning: invalid case style for scoped enum constant 'your_CONST'
175 // CHECK-FIXES: {{^}} YourConst = 1,{{$}}
176 THIS_ConstValue = 1,
177 // CHECK-MESSAGES: :[[@LINE-1]]:5: warning: invalid case style for scoped enum constant 'THIS_ConstValue'
178 // CHECK-FIXES: {{^}} ThisConstValue = 1,{{$}}
179 };
180
181 constexpr int ConstExpr_variable = MyConstant;
182 // CHECK-MESSAGES: :[[@LINE-1]]:15: warning: invalid case style for constexpr variable 'ConstExpr_variable'
183 // CHECK-FIXES: {{^}}constexpr int const_expr_variable = MY_CONSTANT;{{$}}
184
185 class my_class {
186 // CHECK-MESSAGES: :[[@LINE-1]]:7: warning: invalid case style for class 'my_class'
187 // CHECK-FIXES: {{^}}class CMyClass {{{$}}
188 public:
189 my_class();
190 // CHECK-FIXES: {{^}} CMyClass();{{$}}
191
my_class(void *)192 my_class(void*) : my_class() {}
193 // CHECK-FIXES: {{^}} CMyClass(void*) : CMyClass() {}{{$}}
194
195 ~
196 my_class();
197 // (space in destructor token test, we could check trigraph but they will be deprecated)
198 // CHECK-FIXES: {{^}} ~{{$}}
199 // CHECK-FIXES: {{^}} CMyClass();{{$}}
200
201 private:
202 const int MEMBER_one_1 = ConstExpr_variable;
203 // CHECK-MESSAGES: :[[@LINE-1]]:13: warning: invalid case style for constant member 'MEMBER_one_1'
204 // CHECK-FIXES: {{^}} const int member_one_1 = const_expr_variable;{{$}}
205 int member2 = 2;
206 // CHECK-MESSAGES: :[[@LINE-1]]:7: warning: invalid case style for private member 'member2'
207 // CHECK-FIXES: {{^}} int __member2 = 2;{{$}}
208 int _memberWithExtraUnderscores_ = 42;
209 // CHECK-MESSAGES: :[[@LINE-1]]:7: warning: invalid case style for private member '_memberWithExtraUnderscores_'
210 // CHECK-FIXES: {{^}} int __memberWithExtraUnderscores = 42;{{$}}
211
212 private:
213 int private_member = 3;
214 // CHECK-MESSAGES: :[[@LINE-1]]:9: warning: invalid case style for private member 'private_member'
215 // CHECK-FIXES: {{^}} int __private_member = 3;{{$}}
216
217 protected:
218 int ProtMember;
219 // CHECK-MESSAGES: :[[@LINE-1]]:9: warning: invalid case style for protected member 'ProtMember'
220 // CHECK-FIXES: {{^}} int _ProtMember;{{$}}
221
222 public:
223 int PubMem;
224 // CHECK-MESSAGES: :[[@LINE-1]]:9: warning: invalid case style for public member 'PubMem'
225 // CHECK-FIXES: {{^}} int pub_mem;{{$}}
226
227 static const int classConstant;
228 // CHECK-MESSAGES: :[[@LINE-1]]:22: warning: invalid case style for class constant 'classConstant'
229 // CHECK-FIXES: {{^}} static const int kClassConstant;{{$}}
230 static int ClassMember_2;
231 // CHECK-MESSAGES: :[[@LINE-1]]:16: warning: invalid case style for class member 'ClassMember_2'
232 // CHECK-FIXES: {{^}} static int ClassMember2;{{$}}
233 };
234 class my_class;
235 // No warning needed here as this is tied to the previous declaration.
236 // Just make sure the fix is applied.
237 // CHECK-FIXES: {{^}}class CMyClass;{{$}}
238
239 class my_forward_declared_class; // No warning should be triggered.
240
241 const int my_class::classConstant = 4;
242 // CHECK-FIXES: {{^}}const int CMyClass::kClassConstant = 4;{{$}}
243
244 int my_class::ClassMember_2 = 5;
245 // CHECK-FIXES: {{^}}int CMyClass::ClassMember2 = 5;{{$}}
246
247 class my_derived_class : public virtual my_class {};
248 // CHECK-MESSAGES: :[[@LINE-1]]:7: warning: invalid case style for class 'my_derived_class'
249 // CHECK-FIXES: {{^}}class CMyDerivedClass : public virtual CMyClass {};{{$}}
250
251 class CMyWellNamedClass {};
252 // No warning expected as this class is well named.
253
254 template <typename t_t>
255 class CMyWellNamedClass2 : public my_class {
256 // CHECK-FIXES: {{^}}class CMyWellNamedClass2 : public CMyClass {{{$}}
257 t_t my_Bad_Member;
258 // CHECK-MESSAGES: :[[@LINE-1]]:7: warning: invalid case style for private member 'my_Bad_Member'
259 // CHECK-FIXES: {{^}} t_t __my_Bad_Member;{{$}}
260 int my_Other_Bad_Member = 42;
261 // CHECK-MESSAGES: :[[@LINE-1]]:7: warning: invalid case style for private member 'my_Other_Bad_Member'
262 // CHECK-FIXES: {{^}} int __my_Other_Bad_Member = 42;{{$}}
263 public:
264 CMyWellNamedClass2() = default;
265 CMyWellNamedClass2(CMyWellNamedClass2 const&) = default;
266 CMyWellNamedClass2(CMyWellNamedClass2 &&) = default;
CMyWellNamedClass2(t_t a_v,void * p_p)267 CMyWellNamedClass2(t_t a_v, void *p_p) : my_class(p_p), my_Bad_Member(a_v) {}
268 // CHECK-FIXES: {{^}} CMyWellNamedClass2(t_t a_v, void *p_p) : CMyClass(p_p), __my_Bad_Member(a_v) {}{{$}}
269
CMyWellNamedClass2(t_t a_v)270 CMyWellNamedClass2(t_t a_v) : my_class(), my_Bad_Member(a_v), my_Other_Bad_Member(11) {}
271 // CHECK-FIXES: {{^}} CMyWellNamedClass2(t_t a_v) : CMyClass(), __my_Bad_Member(a_v), __my_Other_Bad_Member(11) {}{{$}}
272 };
InstantiateClassMethods()273 void InstantiateClassMethods() {
274 // Ensure we trigger the instantiation of each constructor
275 CMyWellNamedClass2<int> x;
276 CMyWellNamedClass2<int> x2 = x;
277 CMyWellNamedClass2<int> x3 = static_cast<CMyWellNamedClass2<int>&&>(x2);
278 CMyWellNamedClass2<int> x4(42);
279 CMyWellNamedClass2<int> x5(42, nullptr);
280 }
281
282 class AOverridden {
283 public:
284 virtual ~AOverridden() = default;
285 virtual void BadBaseMethod() = 0;
286 // CHECK-MESSAGES: :[[@LINE-1]]:16: warning: invalid case style for virtual method 'BadBaseMethod'
287 // CHECK-FIXES: {{^}} virtual void v_Bad_Base_Method() = 0;
288
289 virtual void BadBaseMethodNoAttr() = 0;
290 // CHECK-MESSAGES: :[[@LINE-1]]:16: warning: invalid case style for virtual method 'BadBaseMethodNoAttr'
291 // CHECK-FIXES: {{^}} virtual void v_Bad_Base_Method_No_Attr() = 0;
292 };
293
294 class COverriding : public AOverridden {
295 public:
296 // Overriding a badly-named base isn't a new violation.
BadBaseMethod()297 void BadBaseMethod() override {}
298 // CHECK-FIXES: {{^}} void v_Bad_Base_Method() override {}
299
BadBaseMethodNoAttr()300 void BadBaseMethodNoAttr() /* override */ {}
301 // CHECK-FIXES: {{^}} void v_Bad_Base_Method_No_Attr() /* override */ {}
302
foo()303 void foo() {
304 BadBaseMethod();
305 // CHECK-FIXES: {{^}} v_Bad_Base_Method();
306 this->BadBaseMethod();
307 // CHECK-FIXES: {{^}} this->v_Bad_Base_Method();
308 AOverridden::BadBaseMethod();
309 // CHECK-FIXES: {{^}} AOverridden::v_Bad_Base_Method();
310 COverriding::BadBaseMethod();
311 // CHECK-FIXES: {{^}} COverriding::v_Bad_Base_Method();
312
313 BadBaseMethodNoAttr();
314 // CHECK-FIXES: {{^}} v_Bad_Base_Method_No_Attr();
315 this->BadBaseMethodNoAttr();
316 // CHECK-FIXES: {{^}} this->v_Bad_Base_Method_No_Attr();
317 AOverridden::BadBaseMethodNoAttr();
318 // CHECK-FIXES: {{^}} AOverridden::v_Bad_Base_Method_No_Attr();
319 COverriding::BadBaseMethodNoAttr();
320 // CHECK-FIXES: {{^}} COverriding::v_Bad_Base_Method_No_Attr();
321 }
322 };
323
324 // Same test as above, now with a dependent base class.
325 template<typename some_t>
326 class ATOverridden {
327 public:
328 virtual void BadBaseMethod() = 0;
329 // CHECK-MESSAGES: :[[@LINE-1]]:16: warning: invalid case style for virtual method 'BadBaseMethod'
330 // CHECK-FIXES: {{^}} virtual void v_Bad_Base_Method() = 0;
331
332 virtual void BadBaseMethodNoAttr() = 0;
333 // CHECK-MESSAGES: :[[@LINE-1]]:16: warning: invalid case style for virtual method 'BadBaseMethodNoAttr'
334 // CHECK-FIXES: {{^}} virtual void v_Bad_Base_Method_No_Attr() = 0;
335 };
336
337 template<typename some_t>
338 class CTOverriding : public ATOverridden<some_t> {
339 // Overriding a badly-named base isn't a new violation.
340 // FIXME: The fixes from the base class should be propagated to the derived class here
341 // (note that there could be specializations of the template base class, though)
BadBaseMethod()342 void BadBaseMethod() override {}
343
344 // Without the "override" attribute, and due to the dependent base class, it is not
345 // known whether this method overrides anything, so we get the warning here.
BadBaseMethodNoAttr()346 virtual void BadBaseMethodNoAttr() {};
347 // CHECK-MESSAGES: :[[@LINE-1]]:16: warning: invalid case style for virtual method 'BadBaseMethodNoAttr'
348 // CHECK-FIXES: {{^}} virtual void v_Bad_Base_Method_No_Attr() {};
349 };
350
351 template<typename some_t>
VirtualCall(AOverridden & a_vItem,ATOverridden<some_t> & a_vTitem)352 void VirtualCall(AOverridden &a_vItem, ATOverridden<some_t> &a_vTitem) {
353 a_vItem.BadBaseMethod();
354 // CHECK-FIXES: {{^}} a_vItem.v_Bad_Base_Method();
355
356 // FIXME: The fixes from ATOverridden should be propagated to the following call
357 a_vTitem.BadBaseMethod();
358 }
359
360 // Same test as above, now with a dependent base class that is instantiated below.
361 template<typename some_t>
362 class ATIOverridden {
363 public:
364 virtual void BadBaseMethod() = 0;
365 // CHECK-MESSAGES: :[[@LINE-1]]:16: warning: invalid case style for virtual method 'BadBaseMethod'
366 // CHECK-FIXES: {{^}} virtual void v_Bad_Base_Method() = 0;
367 };
368
369 template<typename some_t>
370 class CTIOverriding : public ATIOverridden<some_t> {
371 public:
372 // Overriding a badly-named base isn't a new violation.
BadBaseMethod()373 void BadBaseMethod() override {}
374 // CHECK-FIXES: {{^}} void v_Bad_Base_Method() override {}
375 };
376
377 template class CTIOverriding<int>;
378
VirtualCallI(ATIOverridden<int> & a_vItem,CTIOverriding<int> & a_vCitem)379 void VirtualCallI(ATIOverridden<int>& a_vItem, CTIOverriding<int>& a_vCitem) {
380 a_vItem.BadBaseMethod();
381 // CHECK-FIXES: {{^}} a_vItem.v_Bad_Base_Method();
382
383 a_vCitem.BadBaseMethod();
384 // CHECK-FIXES: {{^}} a_vCitem.v_Bad_Base_Method();
385 }
386
387 template <typename derived_t>
388 class CRTPBase {
389 public:
BadBaseMethod(int)390 void BadBaseMethod(int) {}
391 // CHECK-MESSAGES: :[[@LINE-1]]:8: warning: invalid case style for method 'BadBaseMethod'
392 };
393
394 class CRTPDerived : CRTPBase<CRTPDerived> {
395 public:
396 // Hiding a badly-named base isn't a new violation.
BadBaseMethod(double)397 double BadBaseMethod(double) { return 0; }
398 };
399
400 template<typename T>
401 // CHECK-MESSAGES: :[[@LINE-1]]:19: warning: invalid case style for type template parameter 'T'
402 // CHECK-FIXES: {{^}}template<typename t_t>{{$}}
403 class my_templated_class : CMyWellNamedClass {};
404 // CHECK-MESSAGES: :[[@LINE-1]]:7: warning: invalid case style for class 'my_templated_class'
405 // CHECK-FIXES: {{^}}class CMyTemplatedClass : CMyWellNamedClass {};{{$}}
406
407 template<typename T>
408 // CHECK-MESSAGES: :[[@LINE-1]]:19: warning: invalid case style for type template parameter 'T'
409 // CHECK-FIXES: {{^}}template<typename t_t>{{$}}
410 class my_other_templated_class : my_templated_class< my_class>, private my_derived_class {};
411 // CHECK-MESSAGES: :[[@LINE-1]]:7: warning: invalid case style for class 'my_other_templated_class'
412 // CHECK-FIXES: {{^}}class CMyOtherTemplatedClass : CMyTemplatedClass< CMyClass>, private CMyDerivedClass {};{{$}}
413
414 template<typename t_t>
415 using mysuper_tpl_t = my_other_templated_class <:: FOO_NS ::my_class>;
416 // CHECK-FIXES: {{^}}using mysuper_tpl_t = CMyOtherTemplatedClass <:: foo_ns ::CMyClass>;{{$}}
417
418 const int global_Constant = 6;
419 // CHECK-MESSAGES: :[[@LINE-1]]:11: warning: invalid case style for global constant 'global_Constant'
420 // CHECK-FIXES: {{^}}const int GLOBAL_CONSTANT = 6;{{$}}
421 int Global_variable = 7;
422 // CHECK-MESSAGES: :[[@LINE-1]]:5: warning: invalid case style for global variable 'Global_variable'
423 // CHECK-FIXES: {{^}}int g_global_variable = 7;{{$}}
424
global_function(int PARAMETER_1,int const CONST_parameter)425 void global_function(int PARAMETER_1, int const CONST_parameter) {
426 // CHECK-MESSAGES: :[[@LINE-1]]:6: warning: invalid case style for global function 'global_function'
427 // CHECK-MESSAGES: :[[@LINE-2]]:26: warning: invalid case style for parameter 'PARAMETER_1'
428 // CHECK-MESSAGES: :[[@LINE-3]]:49: warning: invalid case style for constant parameter 'CONST_parameter'
429 // CHECK-FIXES: {{^}}void GlobalFunction(int a_parameter1, int const i_constParameter) {{{$}}
430 static const int THIS_static_ConsTant = 4;
431 // CHECK-MESSAGES: :[[@LINE-1]]:22: warning: invalid case style for static constant 'THIS_static_ConsTant'
432 // CHECK-FIXES: {{^}} static const int THIS_STATIC_CONS_TANT = 4;{{$}}
433 static int THIS_static_variable;
434 // CHECK-MESSAGES: :[[@LINE-1]]:16: warning: invalid case style for static variable 'THIS_static_variable'
435 // CHECK-FIXES: {{^}} static int s_thisStaticVariable;{{$}}
436 int const local_Constant = 3;
437 // CHECK-MESSAGES: :[[@LINE-1]]:15: warning: invalid case style for local constant 'local_Constant'
438 // CHECK-FIXES: {{^}} int const kLocalConstant = 3;{{$}}
439 int LOCAL_VARIABLE;
440 // CHECK-MESSAGES: :[[@LINE-1]]:9: warning: invalid case style for local variable 'LOCAL_VARIABLE'
441 // CHECK-FIXES: {{^}} int local_variable;{{$}}
442
443 int LOCAL_Array__[] = {0, 1, 2};
444 // CHECK-MESSAGES: :[[@LINE-1]]:9: warning: invalid case style for local variable 'LOCAL_Array__'
445 // CHECK-FIXES: {{^}} int local_array[] = {0, 1, 2};{{$}}
446
447 for (auto _ : LOCAL_Array__) {
448 }
449 }
450
451 template<typename ... TYPE_parameters>
452 // CHECK-MESSAGES: :[[@LINE-1]]:23: warning: invalid case style for type template parameter 'TYPE_parameters'
453 // CHECK-FIXES: {{^}}template<typename ... typeParameters_t>{{$}}
Global_Fun(TYPE_parameters...PARAMETER_PACK)454 void Global_Fun(TYPE_parameters... PARAMETER_PACK) {
455 // CHECK-MESSAGES: :[[@LINE-1]]:6: warning: invalid case style for global function 'Global_Fun'
456 // CHECK-MESSAGES: :[[@LINE-2]]:36: warning: invalid case style for parameter pack 'PARAMETER_PACK'
457 // CHECK-FIXES: {{^}}void GlobalFun(typeParameters_t... parameterPack) {{{$}}
458 global_function(1, 2);
459 // CHECK-FIXES: {{^}} GlobalFunction(1, 2);{{$}}
460 FOO_bar = Global_variable;
461 // CHECK-FIXES: {{^}} FOO_bar = g_global_variable;{{$}}
462 // NO fix expected for FOO_bar declared in macro expansion
463 }
464
465 template<template<typename> class TPL_parameter, int COUNT_params, typename ... TYPE_parameters>
466 // CHECK-MESSAGES: :[[@LINE-1]]:35: warning: invalid case style for template template parameter 'TPL_parameter'
467 // CHECK-MESSAGES: :[[@LINE-2]]:54: warning: invalid case style for value template parameter 'COUNT_params'
468 // CHECK-MESSAGES: :[[@LINE-3]]:81: warning: invalid case style for type template parameter 'TYPE_parameters'
469 // CHECK-FIXES: {{^}}template<template<typename> class TplParameter, int countParams, typename ... typeParameters_t>{{$}}
470 class test_CLASS {
471 // CHECK-MESSAGES: :[[@LINE-1]]:7: warning: invalid case style for class 'test_CLASS'
472 // CHECK-FIXES: {{^}}class CTestClass {{{$}}
473 };
474
475 class abstract_class {
476 // CHECK-MESSAGES: :[[@LINE-1]]:7: warning: invalid case style for abstract class 'abstract_class'
477 // CHECK-FIXES: {{^}}class AAbstractClass {{{$}}
478 virtual ~abstract_class() = 0;
479 // CHECK-FIXES: {{^}} virtual ~AAbstractClass() = 0;{{$}}
480 virtual void VIRTUAL_METHOD();
481 // CHECK-MESSAGES: :[[@LINE-1]]:18: warning: invalid case style for virtual method 'VIRTUAL_METHOD'
482 // CHECK-FIXES: {{^}} virtual void v_Virtual_Method();{{$}}
non_Virtual_METHOD()483 void non_Virtual_METHOD() {}
484 // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: invalid case style for private method 'non_Virtual_METHOD'
485 // CHECK-FIXES: {{^}} void __non_Virtual_METHOD() {}{{$}}
486
487 public:
CLASS_METHOD()488 static void CLASS_METHOD() {}
489 // CHECK-MESSAGES: :[[@LINE-1]]:17: warning: invalid case style for class method 'CLASS_METHOD'
490 // CHECK-FIXES: {{^}} static void classMethod() {}{{$}}
491
CST_expr_Method()492 constexpr int CST_expr_Method() { return 2; }
493 // CHECK-MESSAGES: :[[@LINE-1]]:19: warning: invalid case style for constexpr method 'CST_expr_Method'
494 // CHECK-FIXES: {{^}} constexpr int cst_expr_method() { return 2; }{{$}}
495
496 private:
497 void PRIVate_Method();
498 // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: invalid case style for private method 'PRIVate_Method'
499 // CHECK-FIXES: {{^}} void __PRIVate_Method();{{$}}
500 protected:
501 void protected_Method();
502 // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: invalid case style for protected method 'protected_Method'
503 // CHECK-FIXES: {{^}} void _protected_Method();{{$}}
504 public:
505 void public_Method();
506 // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: invalid case style for method 'public_Method'
507 // CHECK-FIXES: {{^}} void publicMethod();{{$}}
508 };
509
CE_function()510 constexpr int CE_function() { return 3; }
511 // CHECK-MESSAGES: :[[@LINE-1]]:15: warning: invalid case style for constexpr function 'CE_function'
512 // CHECK-FIXES: {{^}}constexpr int ce_function() { return 3; }{{$}}
513
514 struct THIS___Structure {
515 // CHECK-MESSAGES: :[[@LINE-1]]:8: warning: invalid case style for struct 'THIS___Structure'
516 // CHECK-FIXES: {{^}}struct this_structure {{{$}}
517 THIS___Structure();
518 // CHECK-FIXES: {{^}} this_structure();{{$}}
519
520 union __MyUnion_is_wonderful__ {};
521 // CHECK-MESSAGES: :[[@LINE-1]]:9: warning: invalid case style for union '__MyUnion_is_wonderful__'
522 // CHECK-FIXES: {{^}} union UMyUnionIsWonderful {};{{$}}
523 };
524
525 typedef THIS___Structure struct_type;
526 // CHECK-MESSAGES: :[[@LINE-1]]:26: warning: invalid case style for typedef 'struct_type'
527 // CHECK-FIXES: {{^}}typedef this_structure struct_type_t;{{$}}
528
GlobalTypedefTestFunction(struct_type a_argument1)529 struct_type GlobalTypedefTestFunction(struct_type a_argument1) {
530 // CHECK-FIXES: {{^}}struct_type_t GlobalTypedefTestFunction(struct_type_t a_argument1) {
531 struct_type typedef_test_1;
532 // CHECK-FIXES: {{^}} struct_type_t typedef_test_1;
533 }
534
535 using my_struct_type = THIS___Structure;
536 // CHECK-MESSAGES: :[[@LINE-1]]:7: warning: invalid case style for type alias 'my_struct_type'
537 // CHECK-FIXES: {{^}}using my_Struct_Type_t = this_structure;{{$}}
538
539 template<typename t_t>
540 using SomeOtherTemplate = my_other_templated_class <:: FOO_NS ::my_class>;
541 // CHECK-MESSAGES: :[[@LINE-1]]:7: warning: invalid case style for type alias 'SomeOtherTemplate'
542 // CHECK-FIXES: {{^}}using some_Other_Template_t = CMyOtherTemplatedClass <:: foo_ns ::CMyClass>;{{$}}
543
static_Function()544 static void static_Function() {
545 // CHECK-MESSAGES: :[[@LINE-1]]:13: warning: invalid case style for function 'static_Function'
546 // CHECK-FIXES: {{^}}static void staticFunction() {{{$}}
547
548 ::FOO_NS::InlineNamespace::abstract_class::CLASS_METHOD();
549 // CHECK-FIXES: {{^}} ::foo_ns::inline_namespace::AAbstractClass::classMethod();{{$}}
550 ::FOO_NS::InlineNamespace::static_Function();
551 // CHECK-FIXES: {{^}} ::foo_ns::inline_namespace::staticFunction();{{$}}
552
553 using ::FOO_NS::InlineNamespace::CE_function;
554 // CHECK-FIXES: {{^}} using ::foo_ns::inline_namespace::ce_function;{{$}}
555
556 unsigned MY_LOCAL_array[] = {1,2,3};
557 // CHECK-MESSAGES: :[[@LINE-1]]:12: warning: invalid case style for local variable 'MY_LOCAL_array'
558 // CHECK-FIXES: {{^}} unsigned my_local_array[] = {1,2,3};{{$}}
559
560 unsigned const MyConstLocal_array[] = {1,2,3};
561 // CHECK-MESSAGES: :[[@LINE-1]]:18: warning: invalid case style for local constant 'MyConstLocal_array'
562 // CHECK-FIXES: {{^}} unsigned const kMyConstLocalArray[] = {1,2,3};{{$}}
563
564 static unsigned MY_STATIC_array[] = {1,2,3};
565 // CHECK-MESSAGES: :[[@LINE-1]]:19: warning: invalid case style for static variable 'MY_STATIC_array'
566 // CHECK-FIXES: {{^}} static unsigned s_myStaticArray[] = {1,2,3};{{$}}
567
568 static unsigned const MyConstStatic_array[] = {1,2,3};
569 // CHECK-MESSAGES: :[[@LINE-1]]:25: warning: invalid case style for static constant 'MyConstStatic_array'
570 // CHECK-FIXES: {{^}} static unsigned const MY_CONST_STATIC_ARRAY[] = {1,2,3};{{$}}
571
572 char MY_LOCAL_string[] = "123";
573 // CHECK-MESSAGES: :[[@LINE-1]]:8: warning: invalid case style for local variable 'MY_LOCAL_string'
574 // CHECK-FIXES: {{^}} char my_local_string[] = "123";{{$}}
575
576 char const MyConstLocal_string[] = "123";
577 // CHECK-MESSAGES: :[[@LINE-1]]:14: warning: invalid case style for local constant 'MyConstLocal_string'
578 // CHECK-FIXES: {{^}} char const kMyConstLocalString[] = "123";{{$}}
579
580 static char MY_STATIC_string[] = "123";
581 // CHECK-MESSAGES: :[[@LINE-1]]:15: warning: invalid case style for static variable 'MY_STATIC_string'
582 // CHECK-FIXES: {{^}} static char s_myStaticString[] = "123";{{$}}
583
584 static char const MyConstStatic_string[] = "123";
585 // CHECK-MESSAGES: :[[@LINE-1]]:21: warning: invalid case style for static constant 'MyConstStatic_string'
586 // CHECK-FIXES: {{^}} static char const MY_CONST_STATIC_STRING[] = "123";{{$}}
587 }
588
589 #define MY_TEST_Macro(X) X()
590 // CHECK-MESSAGES: :[[@LINE-1]]:9: warning: invalid case style for macro definition 'MY_TEST_Macro'
591 // CHECK-FIXES: {{^}}#define MY_TEST_MACRO(X) X()
592
MY_TEST_Macro(function)593 void MY_TEST_Macro(function) {}
594 // CHECK-FIXES: {{^}}void MY_TEST_MACRO(function) {}
595 }
596 }
597
598 template <typename t_t> struct a {
599 typename t_t::template b<> c;
600
601 char const MY_ConstMember_string[4] = "123";
602 // CHECK-MESSAGES: :[[@LINE-1]]:14: warning: invalid case style for constant member 'MY_ConstMember_string'
603 // CHECK-FIXES: {{^}} char const my_const_member_string[4] = "123";{{$}}
604
605 static char const MyConstClass_string[];
606 // CHECK-MESSAGES: :[[@LINE-1]]:21: warning: invalid case style for class constant 'MyConstClass_string'
607 // CHECK-FIXES: {{^}} static char const kMyConstClassString[];{{$}}
608 };
609
610 template<typename t_t>
611 char const a<t_t>::MyConstClass_string[] = "123";
612 // CHECK-FIXES: {{^}}char const a<t_t>::kMyConstClassString[] = "123";{{$}}
613
614 template <template <typename> class A> struct b { A<int> c; };
615
616 unsigned MY_GLOBAL_array[] = {1,2,3};
617 // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: invalid case style for global variable 'MY_GLOBAL_array'
618 // CHECK-FIXES: {{^}}unsigned g_my_global_array[] = {1,2,3};{{$}}
619
620 unsigned const MyConstGlobal_array[] = {1,2,3};
621 // CHECK-MESSAGES: :[[@LINE-1]]:16: warning: invalid case style for global constant 'MyConstGlobal_array'
622 // CHECK-FIXES: {{^}}unsigned const MY_CONST_GLOBAL_ARRAY[] = {1,2,3};{{$}}
623
624 int * MyGlobal_Ptr;// -> ok
625 int * my_second_global_Ptr;
626 // CHECK-MESSAGES: :[[@LINE-1]]:7: warning: invalid case style for global pointer 'my_second_global_Ptr'
627 // CHECK-FIXES: {{^}}int * MySecondGlobal_Ptr;{{$}}
628 int * const MyConstantGlobalPointer = nullptr;
629 // CHECK-MESSAGES: :[[@LINE-1]]:13: warning: invalid case style for global constant pointer 'MyConstantGlobalPointer'
630 // CHECK-FIXES: {{^}}int * const MY_CONSTANT_GLOBAL_POINTER_Ptr = nullptr;{{$}}
631
MyPoiterFunction(int * p_normal_pointer,int * const constant_ptr)632 void MyPoiterFunction(int * p_normal_pointer, int * const constant_ptr){
633 // CHECK-MESSAGES: :[[@LINE-1]]:59: warning: invalid case style for constant pointer parameter 'constant_ptr'
634 // CHECK-FIXES: {{^}}void MyPoiterFunction(int * p_normal_pointer, int * const cp_ConstantPtr){{{$}}
635 int * l_PointerA;
636 int * const pointer_b = nullptr;
637 // CHECK-MESSAGES: :[[@LINE-1]]:17: warning: invalid case style for local constant pointer 'pointer_b'
638 // CHECK-FIXES: {{^}} int * const lc_PointerB = nullptr;{{$}}
639 }
640
641 using namespace FOO_NS;
642 // CHECK-FIXES: {{^}}using namespace foo_ns;
643
644 using namespace FOO_NS::InlineNamespace;
645 // CHECK-FIXES: {{^}}using namespace foo_ns::inline_namespace;
646
647 void QualifiedTypeLocTest(THIS___Structure);
648 // CHECK-FIXES: {{^}}void QualifiedTypeLocTest(this_structure);{{$}}
649 void QualifiedTypeLocTest(THIS___Structure &);
650 // CHECK-FIXES: {{^}}void QualifiedTypeLocTest(this_structure &);{{$}}
651 void QualifiedTypeLocTest(THIS___Structure &&);
652 // CHECK-FIXES: {{^}}void QualifiedTypeLocTest(this_structure &&);{{$}}
653 void QualifiedTypeLocTest(const THIS___Structure);
654 // CHECK-FIXES: {{^}}void QualifiedTypeLocTest(const this_structure);{{$}}
655 void QualifiedTypeLocTest(const THIS___Structure &);
656 // CHECK-FIXES: {{^}}void QualifiedTypeLocTest(const this_structure &);{{$}}
657 void QualifiedTypeLocTest(volatile THIS___Structure &);
658 // CHECK-FIXES: {{^}}void QualifiedTypeLocTest(volatile this_structure &);{{$}}
659
660 namespace redecls {
661 // We only want the warning to show up once here for the first decl.
662 // CHECK-MESSAGES: :[[@LINE+1]]:6: warning: invalid case style for global function 'badNamedFunction'
663 void badNamedFunction();
664 void badNamedFunction();
badNamedFunction()665 void badNamedFunction(){}
666 // CHECK-FIXES: {{^}}void BadNamedFunction();
667 // CHECK-FIXES-NEXT: {{^}}void BadNamedFunction();
668 // CHECK-FIXES-NEXT: {{^}}void BadNamedFunction(){}
ReferenceBadNamedFunction()669 void ReferenceBadNamedFunction() {
670 auto l_Ptr = badNamedFunction;
671 // CHECK-FIXES: {{^}} auto l_Ptr = BadNamedFunction;
672 l_Ptr();
673 badNamedFunction();
674 // CHECK-FIXES: {{^}} BadNamedFunction();
675 }
676
677 } // namespace redecls
678
679 namespace scratchspace {
680 #define DUP(Tok) Tok
681 #define M1(Tok) DUP(badName##Tok())
682
683 // We don't want a warning here as the call to this in Foo is in a scratch
684 // buffer so its fix-it wouldn't be applied, resulting in invalid code.
685 void badNameWarn();
686
Foo()687 void Foo() {
688 M1(Warn);
689 }
690
691 #undef M1
692 #undef DUP
693 } // namespace scratchspace
694
695 template<typename type_t>
696 auto GetRes(type_t& Param) -> decltype(Param.res());
697 // CHECK-MESSAGES: :[[@LINE-1]]:21: warning: invalid case style for parameter 'Param'
698 // CHECK-FIXES: auto GetRes(type_t& a_param) -> decltype(a_param.res());
699
700 // Check implicit declarations in coroutines
701
702 struct async_obj {
703 public:
704 never_suspend operator co_await() const noexcept;
705 };
706
ImplicitDeclTest(async_obj & a_object)707 task ImplicitDeclTest(async_obj &a_object) {
708 co_await a_object; // CHECK-MESSAGES-NOT: warning: invalid case style for local variable
709 }
710