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/readability-identifier-naming \
86 // RUN:   -isystem %S/Inputs/readability-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 
290 class COverriding : public AOverridden {
291 public:
292   // Overriding a badly-named base isn't a new violation.
BadBaseMethod()293   void BadBaseMethod() override {}
294   // CHECK-FIXES: {{^}}  void v_Bad_Base_Method() override {}
295 
foo()296   void foo() {
297     BadBaseMethod();
298     // CHECK-FIXES: {{^}}    v_Bad_Base_Method();
299     this->BadBaseMethod();
300     // CHECK-FIXES: {{^}}    this->v_Bad_Base_Method();
301     AOverridden::BadBaseMethod();
302     // CHECK-FIXES: {{^}}    AOverridden::v_Bad_Base_Method();
303     COverriding::BadBaseMethod();
304     // CHECK-FIXES: {{^}}    COverriding::v_Bad_Base_Method();
305   }
306 };
307 
VirtualCall(AOverridden & a_vItem)308 void VirtualCall(AOverridden &a_vItem) {
309   a_vItem.BadBaseMethod();
310   // CHECK-FIXES: {{^}}  a_vItem.v_Bad_Base_Method();
311 }
312 
313 template <typename derived_t>
314 class CRTPBase {
315 public:
BadBaseMethod(int)316   void BadBaseMethod(int) {}
317   // CHECK-MESSAGES: :[[@LINE-1]]:8: warning: invalid case style for method 'BadBaseMethod'
318 };
319 
320 class CRTPDerived : CRTPBase<CRTPDerived> {
321 public:
322   // Hiding a badly-named base isn't a new violation.
BadBaseMethod(double)323   double BadBaseMethod(double) { return 0; }
324 };
325 
326 template<typename T>
327 // CHECK-MESSAGES: :[[@LINE-1]]:19: warning: invalid case style for type template parameter 'T'
328 // CHECK-FIXES: {{^}}template<typename t_t>{{$}}
329 class my_templated_class : CMyWellNamedClass {};
330 // CHECK-MESSAGES: :[[@LINE-1]]:7: warning: invalid case style for class 'my_templated_class'
331 // CHECK-FIXES: {{^}}class CMyTemplatedClass : CMyWellNamedClass {};{{$}}
332 
333 template<typename T>
334 // CHECK-MESSAGES: :[[@LINE-1]]:19: warning: invalid case style for type template parameter 'T'
335 // CHECK-FIXES: {{^}}template<typename t_t>{{$}}
336 class my_other_templated_class : my_templated_class<  my_class>, private my_derived_class {};
337 // CHECK-MESSAGES: :[[@LINE-1]]:7: warning: invalid case style for class 'my_other_templated_class'
338 // CHECK-FIXES: {{^}}class CMyOtherTemplatedClass : CMyTemplatedClass<  CMyClass>, private CMyDerivedClass {};{{$}}
339 
340 template<typename t_t>
341 using mysuper_tpl_t = my_other_templated_class  <:: FOO_NS  ::my_class>;
342 // CHECK-FIXES: {{^}}using mysuper_tpl_t = CMyOtherTemplatedClass  <:: foo_ns  ::CMyClass>;{{$}}
343 
344 const int global_Constant = 6;
345 // CHECK-MESSAGES: :[[@LINE-1]]:11: warning: invalid case style for global constant 'global_Constant'
346 // CHECK-FIXES: {{^}}const int GLOBAL_CONSTANT = 6;{{$}}
347 int Global_variable = 7;
348 // CHECK-MESSAGES: :[[@LINE-1]]:5: warning: invalid case style for global variable 'Global_variable'
349 // CHECK-FIXES: {{^}}int g_global_variable = 7;{{$}}
350 
global_function(int PARAMETER_1,int const CONST_parameter)351 void global_function(int PARAMETER_1, int const CONST_parameter) {
352 // CHECK-MESSAGES: :[[@LINE-1]]:6: warning: invalid case style for global function 'global_function'
353 // CHECK-MESSAGES: :[[@LINE-2]]:26: warning: invalid case style for parameter 'PARAMETER_1'
354 // CHECK-MESSAGES: :[[@LINE-3]]:49: warning: invalid case style for constant parameter 'CONST_parameter'
355 // CHECK-FIXES: {{^}}void GlobalFunction(int a_parameter1, int const i_constParameter) {{{$}}
356     static const int THIS_static_ConsTant = 4;
357 // CHECK-MESSAGES: :[[@LINE-1]]:22: warning: invalid case style for static constant 'THIS_static_ConsTant'
358 // CHECK-FIXES: {{^}}    static const int THIS_STATIC_CONS_TANT = 4;{{$}}
359     static int THIS_static_variable;
360 // CHECK-MESSAGES: :[[@LINE-1]]:16: warning: invalid case style for static variable 'THIS_static_variable'
361 // CHECK-FIXES: {{^}}    static int s_thisStaticVariable;{{$}}
362     int const local_Constant = 3;
363 // CHECK-MESSAGES: :[[@LINE-1]]:15: warning: invalid case style for local constant 'local_Constant'
364 // CHECK-FIXES: {{^}}    int const kLocalConstant = 3;{{$}}
365     int LOCAL_VARIABLE;
366 // CHECK-MESSAGES: :[[@LINE-1]]:9: warning: invalid case style for local variable 'LOCAL_VARIABLE'
367 // CHECK-FIXES: {{^}}    int local_variable;{{$}}
368 
369     int LOCAL_Array__[] = {0, 1, 2};
370 // CHECK-MESSAGES: :[[@LINE-1]]:9: warning: invalid case style for local variable 'LOCAL_Array__'
371 // CHECK-FIXES: {{^}}    int local_array[] = {0, 1, 2};{{$}}
372 
373     for (auto _ : LOCAL_Array__) {
374     }
375 }
376 
377 template<typename ... TYPE_parameters>
378 // CHECK-MESSAGES: :[[@LINE-1]]:23: warning: invalid case style for type template parameter 'TYPE_parameters'
379 // CHECK-FIXES: {{^}}template<typename ... typeParameters_t>{{$}}
Global_Fun(TYPE_parameters...PARAMETER_PACK)380 void Global_Fun(TYPE_parameters... PARAMETER_PACK) {
381 // CHECK-MESSAGES: :[[@LINE-1]]:6: warning: invalid case style for global function 'Global_Fun'
382 // CHECK-MESSAGES: :[[@LINE-2]]:36: warning: invalid case style for parameter pack 'PARAMETER_PACK'
383 // CHECK-FIXES: {{^}}void GlobalFun(typeParameters_t... parameterPack) {{{$}}
384     global_function(1, 2);
385 // CHECK-FIXES: {{^}}    GlobalFunction(1, 2);{{$}}
386     FOO_bar = Global_variable;
387 // CHECK-FIXES: {{^}}    FOO_bar = g_global_variable;{{$}}
388 // NO fix expected for FOO_bar declared in macro expansion
389 }
390 
391 template<template<typename> class TPL_parameter, int COUNT_params, typename ... TYPE_parameters>
392 // CHECK-MESSAGES: :[[@LINE-1]]:35: warning: invalid case style for template template parameter 'TPL_parameter'
393 // CHECK-MESSAGES: :[[@LINE-2]]:54: warning: invalid case style for value template parameter 'COUNT_params'
394 // CHECK-MESSAGES: :[[@LINE-3]]:81: warning: invalid case style for type template parameter 'TYPE_parameters'
395 // CHECK-FIXES: {{^}}template<template<typename> class TplParameter, int countParams, typename ... typeParameters_t>{{$}}
396 class test_CLASS {
397 // CHECK-MESSAGES: :[[@LINE-1]]:7: warning: invalid case style for class 'test_CLASS'
398 // CHECK-FIXES: {{^}}class CTestClass {{{$}}
399 };
400 
401 class abstract_class {
402 // CHECK-MESSAGES: :[[@LINE-1]]:7: warning: invalid case style for abstract class 'abstract_class'
403 // CHECK-FIXES: {{^}}class AAbstractClass {{{$}}
404     virtual ~abstract_class() = 0;
405 // CHECK-FIXES: {{^}}    virtual ~AAbstractClass() = 0;{{$}}
406     virtual void VIRTUAL_METHOD();
407 // CHECK-MESSAGES: :[[@LINE-1]]:18: warning: invalid case style for virtual method 'VIRTUAL_METHOD'
408 // CHECK-FIXES: {{^}}    virtual void v_Virtual_Method();{{$}}
non_Virtual_METHOD()409     void non_Virtual_METHOD() {}
410 // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: invalid case style for private method 'non_Virtual_METHOD'
411 // CHECK-FIXES: {{^}}    void __non_Virtual_METHOD() {}{{$}}
412 
413 public:
CLASS_METHOD()414     static void CLASS_METHOD() {}
415 // CHECK-MESSAGES: :[[@LINE-1]]:17: warning: invalid case style for class method 'CLASS_METHOD'
416 // CHECK-FIXES: {{^}}    static void classMethod() {}{{$}}
417 
CST_expr_Method()418     constexpr int CST_expr_Method() { return 2; }
419 // CHECK-MESSAGES: :[[@LINE-1]]:19: warning: invalid case style for constexpr method 'CST_expr_Method'
420 // CHECK-FIXES: {{^}}    constexpr int cst_expr_method() { return 2; }{{$}}
421 
422 private:
423     void PRIVate_Method();
424 // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: invalid case style for private method 'PRIVate_Method'
425 // CHECK-FIXES: {{^}}    void __PRIVate_Method();{{$}}
426 protected:
427     void protected_Method();
428 // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: invalid case style for protected method 'protected_Method'
429 // CHECK-FIXES: {{^}}    void _protected_Method();{{$}}
430 public:
431     void public_Method();
432 // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: invalid case style for method 'public_Method'
433 // CHECK-FIXES: {{^}}    void publicMethod();{{$}}
434 };
435 
CE_function()436 constexpr int CE_function() { return 3; }
437 // CHECK-MESSAGES: :[[@LINE-1]]:15: warning: invalid case style for constexpr function 'CE_function'
438 // CHECK-FIXES: {{^}}constexpr int ce_function() { return 3; }{{$}}
439 
440 struct THIS___Structure {
441 // CHECK-MESSAGES: :[[@LINE-1]]:8: warning: invalid case style for struct 'THIS___Structure'
442 // CHECK-FIXES: {{^}}struct this_structure {{{$}}
443     THIS___Structure();
444 // CHECK-FIXES: {{^}}    this_structure();{{$}}
445 
446   union __MyUnion_is_wonderful__ {};
447 // CHECK-MESSAGES: :[[@LINE-1]]:9: warning: invalid case style for union '__MyUnion_is_wonderful__'
448 // CHECK-FIXES: {{^}}  union UMyUnionIsWonderful {};{{$}}
449 };
450 
451 typedef THIS___Structure struct_type;
452 // CHECK-MESSAGES: :[[@LINE-1]]:26: warning: invalid case style for typedef 'struct_type'
453 // CHECK-FIXES: {{^}}typedef this_structure struct_type_t;{{$}}
454 
GlobalTypedefTestFunction(struct_type a_argument1)455 struct_type GlobalTypedefTestFunction(struct_type a_argument1) {
456 // CHECK-FIXES: {{^}}struct_type_t GlobalTypedefTestFunction(struct_type_t a_argument1) {
457     struct_type typedef_test_1;
458 // CHECK-FIXES: {{^}}    struct_type_t typedef_test_1;
459 }
460 
461 using my_struct_type = THIS___Structure;
462 // CHECK-MESSAGES: :[[@LINE-1]]:7: warning: invalid case style for type alias 'my_struct_type'
463 // CHECK-FIXES: {{^}}using my_Struct_Type_t = this_structure;{{$}}
464 
465 template<typename t_t>
466 using SomeOtherTemplate = my_other_templated_class  <:: FOO_NS  ::my_class>;
467 // CHECK-MESSAGES: :[[@LINE-1]]:7: warning: invalid case style for type alias 'SomeOtherTemplate'
468 // CHECK-FIXES: {{^}}using some_Other_Template_t = CMyOtherTemplatedClass  <:: foo_ns  ::CMyClass>;{{$}}
469 
static_Function()470 static void static_Function() {
471 // CHECK-MESSAGES: :[[@LINE-1]]:13: warning: invalid case style for function 'static_Function'
472 // CHECK-FIXES: {{^}}static void staticFunction() {{{$}}
473 
474   ::FOO_NS::InlineNamespace::abstract_class::CLASS_METHOD();
475 // CHECK-FIXES: {{^}}  ::foo_ns::inline_namespace::AAbstractClass::classMethod();{{$}}
476   ::FOO_NS::InlineNamespace::static_Function();
477 // CHECK-FIXES: {{^}}  ::foo_ns::inline_namespace::staticFunction();{{$}}
478 
479   using ::FOO_NS::InlineNamespace::CE_function;
480 // CHECK-FIXES: {{^}}  using ::foo_ns::inline_namespace::ce_function;{{$}}
481 
482   unsigned MY_LOCAL_array[] = {1,2,3};
483 // CHECK-MESSAGES: :[[@LINE-1]]:12: warning: invalid case style for local variable 'MY_LOCAL_array'
484 // CHECK-FIXES: {{^}}  unsigned my_local_array[] = {1,2,3};{{$}}
485 
486   unsigned const MyConstLocal_array[] = {1,2,3};
487 // CHECK-MESSAGES: :[[@LINE-1]]:18: warning: invalid case style for local constant 'MyConstLocal_array'
488 // CHECK-FIXES: {{^}}  unsigned const kMyConstLocalArray[] = {1,2,3};{{$}}
489 
490   static unsigned MY_STATIC_array[] = {1,2,3};
491 // CHECK-MESSAGES: :[[@LINE-1]]:19: warning: invalid case style for static variable 'MY_STATIC_array'
492 // CHECK-FIXES: {{^}}  static unsigned s_myStaticArray[] = {1,2,3};{{$}}
493 
494   static unsigned const MyConstStatic_array[] = {1,2,3};
495 // CHECK-MESSAGES: :[[@LINE-1]]:25: warning: invalid case style for static constant 'MyConstStatic_array'
496 // CHECK-FIXES: {{^}}  static unsigned const MY_CONST_STATIC_ARRAY[] = {1,2,3};{{$}}
497 
498   char MY_LOCAL_string[] = "123";
499 // CHECK-MESSAGES: :[[@LINE-1]]:8: warning: invalid case style for local variable 'MY_LOCAL_string'
500 // CHECK-FIXES: {{^}}  char my_local_string[] = "123";{{$}}
501 
502   char const MyConstLocal_string[] = "123";
503 // CHECK-MESSAGES: :[[@LINE-1]]:14: warning: invalid case style for local constant 'MyConstLocal_string'
504 // CHECK-FIXES: {{^}}  char const kMyConstLocalString[] = "123";{{$}}
505 
506   static char MY_STATIC_string[] = "123";
507 // CHECK-MESSAGES: :[[@LINE-1]]:15: warning: invalid case style for static variable 'MY_STATIC_string'
508 // CHECK-FIXES: {{^}}  static char s_myStaticString[] = "123";{{$}}
509 
510   static char const MyConstStatic_string[] = "123";
511 // CHECK-MESSAGES: :[[@LINE-1]]:21: warning: invalid case style for static constant 'MyConstStatic_string'
512 // CHECK-FIXES: {{^}}  static char const MY_CONST_STATIC_STRING[] = "123";{{$}}
513 }
514 
515 #define MY_TEST_Macro(X) X()
516 // CHECK-MESSAGES: :[[@LINE-1]]:9: warning: invalid case style for macro definition 'MY_TEST_Macro'
517 // CHECK-FIXES: {{^}}#define MY_TEST_MACRO(X) X()
518 
MY_TEST_Macro(function)519 void MY_TEST_Macro(function) {}
520 // CHECK-FIXES: {{^}}void MY_TEST_MACRO(function) {}
521 }
522 }
523 
524 template <typename t_t> struct a {
525   typename t_t::template b<> c;
526 
527   char const MY_ConstMember_string[4] = "123";
528 // CHECK-MESSAGES: :[[@LINE-1]]:14: warning: invalid case style for constant member 'MY_ConstMember_string'
529 // CHECK-FIXES: {{^}}  char const my_const_member_string[4] = "123";{{$}}
530 
531   static char const MyConstClass_string[];
532 // CHECK-MESSAGES: :[[@LINE-1]]:21: warning: invalid case style for class constant 'MyConstClass_string'
533 // CHECK-FIXES: {{^}}  static char const kMyConstClassString[];{{$}}
534 };
535 
536 template<typename t_t>
537 char const a<t_t>::MyConstClass_string[] = "123";
538 // CHECK-FIXES: {{^}}char const a<t_t>::kMyConstClassString[] = "123";{{$}}
539 
540 template <template <typename> class A> struct b { A<int> c; };
541 
542 unsigned MY_GLOBAL_array[] = {1,2,3};
543 // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: invalid case style for global variable 'MY_GLOBAL_array'
544 // CHECK-FIXES: {{^}}unsigned g_my_global_array[] = {1,2,3};{{$}}
545 
546 unsigned const MyConstGlobal_array[] = {1,2,3};
547 // CHECK-MESSAGES: :[[@LINE-1]]:16: warning: invalid case style for global constant 'MyConstGlobal_array'
548 // CHECK-FIXES: {{^}}unsigned const MY_CONST_GLOBAL_ARRAY[] = {1,2,3};{{$}}
549 
550 int * MyGlobal_Ptr;// -> ok
551 int * my_second_global_Ptr;
552 // CHECK-MESSAGES: :[[@LINE-1]]:7: warning: invalid case style for global pointer 'my_second_global_Ptr'
553 // CHECK-FIXES: {{^}}int * MySecondGlobal_Ptr;{{$}}
554 int * const MyConstantGlobalPointer = nullptr;
555 // CHECK-MESSAGES: :[[@LINE-1]]:13: warning: invalid case style for global constant pointer 'MyConstantGlobalPointer'
556 // CHECK-FIXES: {{^}}int * const MY_CONSTANT_GLOBAL_POINTER_Ptr = nullptr;{{$}}
557 
MyPoiterFunction(int * p_normal_pointer,int * const constant_ptr)558 void MyPoiterFunction(int * p_normal_pointer, int * const constant_ptr){
559 // CHECK-MESSAGES: :[[@LINE-1]]:59: warning: invalid case style for constant pointer parameter 'constant_ptr'
560 // CHECK-FIXES: {{^}}void MyPoiterFunction(int * p_normal_pointer, int * const cp_ConstantPtr){{{$}}
561     int * l_PointerA;
562     int * const pointer_b = nullptr;
563 // CHECK-MESSAGES: :[[@LINE-1]]:17: warning: invalid case style for local constant pointer 'pointer_b'
564 // CHECK-FIXES: {{^}}    int * const lc_PointerB = nullptr;{{$}}
565 }
566 
567 using namespace FOO_NS;
568 // CHECK-FIXES: {{^}}using namespace foo_ns;
569 
570 using namespace FOO_NS::InlineNamespace;
571 // CHECK-FIXES: {{^}}using namespace foo_ns::inline_namespace;
572 
573 void QualifiedTypeLocTest(THIS___Structure);
574 // CHECK-FIXES: {{^}}void QualifiedTypeLocTest(this_structure);{{$}}
575 void QualifiedTypeLocTest(THIS___Structure &);
576 // CHECK-FIXES: {{^}}void QualifiedTypeLocTest(this_structure &);{{$}}
577 void QualifiedTypeLocTest(THIS___Structure &&);
578 // CHECK-FIXES: {{^}}void QualifiedTypeLocTest(this_structure &&);{{$}}
579 void QualifiedTypeLocTest(const THIS___Structure);
580 // CHECK-FIXES: {{^}}void QualifiedTypeLocTest(const this_structure);{{$}}
581 void QualifiedTypeLocTest(const THIS___Structure &);
582 // CHECK-FIXES: {{^}}void QualifiedTypeLocTest(const this_structure &);{{$}}
583 void QualifiedTypeLocTest(volatile THIS___Structure &);
584 // CHECK-FIXES: {{^}}void QualifiedTypeLocTest(volatile this_structure &);{{$}}
585 
586 namespace redecls {
587 // We only want the warning to show up once here for the first decl.
588 // CHECK-MESSAGES: :[[@LINE+1]]:6: warning: invalid case style for global function 'badNamedFunction'
589 void badNamedFunction();
590 void badNamedFunction();
badNamedFunction()591 void badNamedFunction(){}
592 //      CHECK-FIXES: {{^}}void BadNamedFunction();
593 // CHECK-FIXES-NEXT: {{^}}void BadNamedFunction();
594 // CHECK-FIXES-NEXT: {{^}}void BadNamedFunction(){}
ReferenceBadNamedFunction()595 void ReferenceBadNamedFunction() {
596   auto l_Ptr = badNamedFunction;
597   // CHECK-FIXES: {{^}}  auto l_Ptr = BadNamedFunction;
598   l_Ptr();
599   badNamedFunction();
600   // CHECK-FIXES: {{^}}  BadNamedFunction();
601 }
602 
603 } // namespace redecls
604 
605 namespace scratchspace {
606 #define DUP(Tok) Tok
607 #define M1(Tok) DUP(badName##Tok())
608 
609 // We don't want a warning here as the call to this in Foo is in a scratch
610 // buffer so its fix-it wouldn't be applied, resulting in invalid code.
611 void badNameWarn();
612 
Foo()613 void Foo() {
614   M1(Warn);
615 }
616 
617 #undef M1
618 #undef DUP
619 } // namespace scratchspace
620 
621 template<typename type_t>
622 auto GetRes(type_t& Param) -> decltype(Param.res());
623 // CHECK-MESSAGES: :[[@LINE-1]]:21: warning: invalid case style for parameter 'Param'
624 // CHECK-FIXES: auto GetRes(type_t& a_param) -> decltype(a_param.res());
625 
626 // Check implicit declarations in coroutines
627 
628 struct async_obj {
629 public:
630   never_suspend operator co_await() const noexcept;
631 };
632 
ImplicitDeclTest(async_obj & a_object)633 task ImplicitDeclTest(async_obj &a_object) {
634   co_await a_object;  // CHECK-MESSAGES-NOT: warning: invalid case style for local variable
635 }
636