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: 0}, \
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 \
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 "user-header.h"
92 // NO warnings or fixes expected from declarations within header files without
93 // the -header-filter= option
94 
95 namespace FOO_NS {
96 // CHECK-MESSAGES: :[[@LINE-1]]:11: warning: invalid case style for namespace 'FOO_NS' [readability-identifier-naming]
97 // CHECK-FIXES: {{^}}namespace foo_ns {{{$}}
98 inline namespace InlineNamespace {
99 // CHECK-MESSAGES: :[[@LINE-1]]:18: warning: invalid case style for inline namespace 'InlineNamespace'
100 // CHECK-FIXES: {{^}}inline namespace inline_namespace {{{$}}
101 
102 SYSTEM_NS::structure g_s1;
103 // NO warnings or fixes expected as SYSTEM_NS and structure are declared in a header file
104 
105 USER_NS::object g_s2;
106 // NO warnings or fixes expected as USER_NS and object are declared in a header file
107 
108 SYSTEM_MACRO(var1);
109 // NO warnings or fixes expected as var1 is from macro expansion
110 
111 USER_MACRO(var2);
112 // NO warnings or fixes expected as var2 is declared in a macro expansion
113 
114 #define BLA int FOO_bar
115 BLA;
116 // NO warnings or fixes expected as FOO_bar is from macro expansion
117 
118 int global0;
119 #define USE_NUMBERED_GLOBAL(number) auto use_global##number = global##number
120 USE_NUMBERED_GLOBAL(0);
121 // NO warnings or fixes expected as global0 is pieced together in a macro
122 // expansion.
123 
124 int global1;
125 #define USE_NUMBERED_BAL(prefix, number) \
126   auto use_##prefix##bal##number = prefix##bal##number
127 USE_NUMBERED_BAL(glo, 1);
128 // NO warnings or fixes expected as global1 is pieced together in a macro
129 // expansion.
130 
131 int global2;
132 #define USE_RECONSTRUCTED(glo, bal) auto use_##glo##bal = glo##bal
133 USE_RECONSTRUCTED(glo, bal2);
134 // NO warnings or fixes expected as global2 is pieced together in a macro
135 // expansion.
136 
137 int global;
138 // CHECK-MESSAGES: :[[@LINE-1]]:5: warning: invalid case style for global variable 'global'
139 // CHECK-FIXES: {{^}}int g_global;{{$}}
140 #define USE_IN_MACRO(m) auto use_##m = m
141 USE_IN_MACRO(global);
142 
143 int global3;
144 // CHECK-MESSAGES: :[[@LINE-1]]:5: warning: invalid case style for global variable 'global3'
145 // CHECK-FIXES: {{^}}int g_global3;{{$}}
146 #define ADD_TO_SELF(m) (m) + (m)
147 int g_twice_global3 = ADD_TO_SELF(global3);
148 // CHECK-FIXES: {{^}}int g_twice_global3 = ADD_TO_SELF(g_global3);{{$}}
149 
150 enum my_enumeration {
151 // CHECK-MESSAGES: :[[@LINE-1]]:6: warning: invalid case style for enum 'my_enumeration'
152 // CHECK-FIXES: {{^}}enum EMyEnumeration {{{$}}
153     MyConstant = 1,
154 // CHECK-MESSAGES: :[[@LINE-1]]:5: warning: invalid case style for enum constant 'MyConstant'
155 // CHECK-FIXES: {{^}}    MY_CONSTANT = 1,{{$}}
156     your_CONST = 1,
157 // CHECK-MESSAGES: :[[@LINE-1]]:5: warning: invalid case style for enum constant 'your_CONST'
158 // CHECK-FIXES: {{^}}    YOUR_CONST = 1,{{$}}
159     THIS_ConstValue = 1,
160 // CHECK-MESSAGES: :[[@LINE-1]]:5: warning: invalid case style for enum constant 'THIS_ConstValue'
161 // CHECK-FIXES: {{^}}    THIS_CONST_VALUE = 1,{{$}}
162 };
163 
164 enum class EMyEnumeration {
165     myConstant = 1,
166 // CHECK-MESSAGES: :[[@LINE-1]]:5: warning: invalid case style for scoped enum constant 'myConstant'
167 // CHECK-FIXES: {{^}}    MyConstant = 1,{{$}}
168     your_CONST = 1,
169 // CHECK-MESSAGES: :[[@LINE-1]]:5: warning: invalid case style for scoped enum constant 'your_CONST'
170 // CHECK-FIXES: {{^}}    YourConst = 1,{{$}}
171     THIS_ConstValue = 1,
172 // CHECK-MESSAGES: :[[@LINE-1]]:5: warning: invalid case style for scoped enum constant 'THIS_ConstValue'
173 // CHECK-FIXES: {{^}}    ThisConstValue = 1,{{$}}
174 };
175 
176 constexpr int ConstExpr_variable = MyConstant;
177 // CHECK-MESSAGES: :[[@LINE-1]]:15: warning: invalid case style for constexpr variable 'ConstExpr_variable'
178 // CHECK-FIXES: {{^}}constexpr int const_expr_variable = MY_CONSTANT;{{$}}
179 
180 class my_class {
181 // CHECK-MESSAGES: :[[@LINE-1]]:7: warning: invalid case style for class 'my_class'
182 // CHECK-FIXES: {{^}}class CMyClass {{{$}}
183 public:
184     my_class();
185 // CHECK-FIXES: {{^}}    CMyClass();{{$}}
186 
my_class(void *)187     my_class(void*) : my_class() {}
188 // CHECK-FIXES: {{^}}    CMyClass(void*) : CMyClass() {}{{$}}
189 
190     ~
191       my_class();
192 // (space in destructor token test, we could check trigraph but they will be deprecated)
193 // CHECK-FIXES: {{^}}    ~{{$}}
194 // CHECK-FIXES: {{^}}      CMyClass();{{$}}
195 
196 private:
197   const int MEMBER_one_1 = ConstExpr_variable;
198 // CHECK-MESSAGES: :[[@LINE-1]]:13: warning: invalid case style for constant member 'MEMBER_one_1'
199 // CHECK-FIXES: {{^}}  const int member_one_1 = const_expr_variable;{{$}}
200   int member2 = 2;
201 // CHECK-MESSAGES: :[[@LINE-1]]:7: warning: invalid case style for private member 'member2'
202 // CHECK-FIXES: {{^}}  int __member2 = 2;{{$}}
203   int _memberWithExtraUnderscores_ = 42;
204 // CHECK-MESSAGES: :[[@LINE-1]]:7: warning: invalid case style for private member '_memberWithExtraUnderscores_'
205 // CHECK-FIXES: {{^}}  int __memberWithExtraUnderscores = 42;{{$}}
206 
207 private:
208     int private_member = 3;
209 // CHECK-MESSAGES: :[[@LINE-1]]:9: warning: invalid case style for private member 'private_member'
210 // CHECK-FIXES: {{^}}    int __private_member = 3;{{$}}
211 
212 protected:
213     int ProtMember;
214 // CHECK-MESSAGES: :[[@LINE-1]]:9: warning: invalid case style for protected member 'ProtMember'
215 // CHECK-FIXES: {{^}}    int _ProtMember;{{$}}
216 
217 public:
218     int PubMem;
219 // CHECK-MESSAGES: :[[@LINE-1]]:9: warning: invalid case style for public member 'PubMem'
220 // CHECK-FIXES: {{^}}    int pub_mem;{{$}}
221 
222     static const int classConstant;
223 // CHECK-MESSAGES: :[[@LINE-1]]:22: warning: invalid case style for class constant 'classConstant'
224 // CHECK-FIXES: {{^}}    static const int kClassConstant;{{$}}
225     static int ClassMember_2;
226 // CHECK-MESSAGES: :[[@LINE-1]]:16: warning: invalid case style for class member 'ClassMember_2'
227 // CHECK-FIXES: {{^}}    static int ClassMember2;{{$}}
228 };
229 class my_class;
230 // No warning needed here as this is tied to the previous declaration.
231 // Just make sure the fix is applied.
232 // CHECK-FIXES: {{^}}class CMyClass;{{$}}
233 
234 class my_forward_declared_class; // No warning should be triggered.
235 
236 const int my_class::classConstant = 4;
237 // CHECK-FIXES: {{^}}const int CMyClass::kClassConstant = 4;{{$}}
238 
239 int my_class::ClassMember_2 = 5;
240 // CHECK-FIXES: {{^}}int CMyClass::ClassMember2 = 5;{{$}}
241 
242 class my_derived_class : public virtual my_class {};
243 // CHECK-MESSAGES: :[[@LINE-1]]:7: warning: invalid case style for class 'my_derived_class'
244 // CHECK-FIXES: {{^}}class CMyDerivedClass : public virtual CMyClass {};{{$}}
245 
246 class CMyWellNamedClass {};
247 // No warning expected as this class is well named.
248 
249 template <typename t_t>
250 class CMyWellNamedClass2 : public my_class {
251   // CHECK-FIXES: {{^}}class CMyWellNamedClass2 : public CMyClass {{{$}}
252   t_t my_Bad_Member;
253   // CHECK-MESSAGES: :[[@LINE-1]]:7: warning: invalid case style for private member 'my_Bad_Member'
254   // CHECK-FIXES: {{^}}  t_t __my_Bad_Member;{{$}}
255   int my_Other_Bad_Member = 42;
256   // CHECK-MESSAGES: :[[@LINE-1]]:7: warning: invalid case style for private member 'my_Other_Bad_Member'
257   // CHECK-FIXES: {{^}}  int __my_Other_Bad_Member = 42;{{$}}
258 public:
259   CMyWellNamedClass2() = default;
260   CMyWellNamedClass2(CMyWellNamedClass2 const&) = default;
261   CMyWellNamedClass2(CMyWellNamedClass2 &&) = default;
CMyWellNamedClass2(t_t a_v,void * p_p)262   CMyWellNamedClass2(t_t a_v, void *p_p) : my_class(p_p), my_Bad_Member(a_v) {}
263   // CHECK-FIXES: {{^}}  CMyWellNamedClass2(t_t a_v, void *p_p) : CMyClass(p_p), __my_Bad_Member(a_v) {}{{$}}
264 
CMyWellNamedClass2(t_t a_v)265   CMyWellNamedClass2(t_t a_v) : my_class(), my_Bad_Member(a_v), my_Other_Bad_Member(11) {}
266   // CHECK-FIXES: {{^}}  CMyWellNamedClass2(t_t a_v) : CMyClass(), __my_Bad_Member(a_v), __my_Other_Bad_Member(11) {}{{$}}
267 };
InstantiateClassMethods()268 void InstantiateClassMethods() {
269   // Ensure we trigger the instantiation of each constructor
270   CMyWellNamedClass2<int> x;
271   CMyWellNamedClass2<int> x2 = x;
272   CMyWellNamedClass2<int> x3 = static_cast<CMyWellNamedClass2<int>&&>(x2);
273   CMyWellNamedClass2<int> x4(42);
274   CMyWellNamedClass2<int> x5(42, nullptr);
275 }
276 
277 class AOverridden {
278 public:
279   virtual ~AOverridden() = default;
280   virtual void BadBaseMethod() = 0;
281   // CHECK-MESSAGES: :[[@LINE-1]]:16: warning: invalid case style for virtual method 'BadBaseMethod'
282   // CHECK-FIXES: {{^}}  virtual void v_Bad_Base_Method() = 0;
283 };
284 
285 class COverriding : public AOverridden {
286 public:
287   // Overriding a badly-named base isn't a new violation.
BadBaseMethod()288   void BadBaseMethod() override {}
289   // CHECK-FIXES: {{^}}  void v_Bad_Base_Method() override {}
290 
foo()291   void foo() {
292     BadBaseMethod();
293     // CHECK-FIXES: {{^}}    v_Bad_Base_Method();
294     this->BadBaseMethod();
295     // CHECK-FIXES: {{^}}    this->v_Bad_Base_Method();
296     AOverridden::BadBaseMethod();
297     // CHECK-FIXES: {{^}}    AOverridden::v_Bad_Base_Method();
298     COverriding::BadBaseMethod();
299     // CHECK-FIXES: {{^}}    COverriding::v_Bad_Base_Method();
300   }
301 };
302 
VirtualCall(AOverridden & a_vItem)303 void VirtualCall(AOverridden &a_vItem) {
304   a_vItem.BadBaseMethod();
305   // CHECK-FIXES: {{^}}  a_vItem.v_Bad_Base_Method();
306 }
307 
308 template <typename derived_t>
309 class CRTPBase {
310 public:
BadBaseMethod(int)311   void BadBaseMethod(int) {}
312   // CHECK-MESSAGES: :[[@LINE-1]]:8: warning: invalid case style for method 'BadBaseMethod'
313 };
314 
315 class CRTPDerived : CRTPBase<CRTPDerived> {
316 public:
317   // Hiding a badly-named base isn't a new violation.
BadBaseMethod(double)318   double BadBaseMethod(double) { return 0; }
319 };
320 
321 template<typename T>
322 // CHECK-MESSAGES: :[[@LINE-1]]:19: warning: invalid case style for type template parameter 'T'
323 // CHECK-FIXES: {{^}}template<typename t_t>{{$}}
324 class my_templated_class : CMyWellNamedClass {};
325 // CHECK-MESSAGES: :[[@LINE-1]]:7: warning: invalid case style for class 'my_templated_class'
326 // CHECK-FIXES: {{^}}class CMyTemplatedClass : CMyWellNamedClass {};{{$}}
327 
328 template<typename T>
329 // CHECK-MESSAGES: :[[@LINE-1]]:19: warning: invalid case style for type template parameter 'T'
330 // CHECK-FIXES: {{^}}template<typename t_t>{{$}}
331 class my_other_templated_class : my_templated_class<  my_class>, private my_derived_class {};
332 // CHECK-MESSAGES: :[[@LINE-1]]:7: warning: invalid case style for class 'my_other_templated_class'
333 // CHECK-FIXES: {{^}}class CMyOtherTemplatedClass : CMyTemplatedClass<  CMyClass>, private CMyDerivedClass {};{{$}}
334 
335 template<typename t_t>
336 using mysuper_tpl_t = my_other_templated_class  <:: FOO_NS  ::my_class>;
337 // CHECK-FIXES: {{^}}using mysuper_tpl_t = CMyOtherTemplatedClass  <:: foo_ns  ::CMyClass>;{{$}}
338 
339 const int global_Constant = 6;
340 // CHECK-MESSAGES: :[[@LINE-1]]:11: warning: invalid case style for global constant 'global_Constant'
341 // CHECK-FIXES: {{^}}const int GLOBAL_CONSTANT = 6;{{$}}
342 int Global_variable = 7;
343 // CHECK-MESSAGES: :[[@LINE-1]]:5: warning: invalid case style for global variable 'Global_variable'
344 // CHECK-FIXES: {{^}}int g_global_variable = 7;{{$}}
345 
global_function(int PARAMETER_1,int const CONST_parameter)346 void global_function(int PARAMETER_1, int const CONST_parameter) {
347 // CHECK-MESSAGES: :[[@LINE-1]]:6: warning: invalid case style for global function 'global_function'
348 // CHECK-MESSAGES: :[[@LINE-2]]:26: warning: invalid case style for parameter 'PARAMETER_1'
349 // CHECK-MESSAGES: :[[@LINE-3]]:49: warning: invalid case style for constant parameter 'CONST_parameter'
350 // CHECK-FIXES: {{^}}void GlobalFunction(int a_parameter1, int const i_constParameter) {{{$}}
351     static const int THIS_static_ConsTant = 4;
352 // CHECK-MESSAGES: :[[@LINE-1]]:22: warning: invalid case style for static constant 'THIS_static_ConsTant'
353 // CHECK-FIXES: {{^}}    static const int THIS_STATIC_CONS_TANT = 4;{{$}}
354     static int THIS_static_variable;
355 // CHECK-MESSAGES: :[[@LINE-1]]:16: warning: invalid case style for static variable 'THIS_static_variable'
356 // CHECK-FIXES: {{^}}    static int s_thisStaticVariable;{{$}}
357     int const local_Constant = 3;
358 // CHECK-MESSAGES: :[[@LINE-1]]:15: warning: invalid case style for local constant 'local_Constant'
359 // CHECK-FIXES: {{^}}    int const kLocalConstant = 3;{{$}}
360     int LOCAL_VARIABLE;
361 // CHECK-MESSAGES: :[[@LINE-1]]:9: warning: invalid case style for local variable 'LOCAL_VARIABLE'
362 // CHECK-FIXES: {{^}}    int local_variable;{{$}}
363 
364     int LOCAL_Array__[] = {0, 1, 2};
365 // CHECK-MESSAGES: :[[@LINE-1]]:9: warning: invalid case style for local variable 'LOCAL_Array__'
366 // CHECK-FIXES: {{^}}    int local_array[] = {0, 1, 2};{{$}}
367 
368     for (auto _ : LOCAL_Array__) {
369     }
370 }
371 
372 template<typename ... TYPE_parameters>
373 // CHECK-MESSAGES: :[[@LINE-1]]:23: warning: invalid case style for type template parameter 'TYPE_parameters'
374 // CHECK-FIXES: {{^}}template<typename ... typeParameters_t>{{$}}
Global_Fun(TYPE_parameters...PARAMETER_PACK)375 void Global_Fun(TYPE_parameters... PARAMETER_PACK) {
376 // CHECK-MESSAGES: :[[@LINE-1]]:6: warning: invalid case style for global function 'Global_Fun'
377 // CHECK-MESSAGES: :[[@LINE-2]]:36: warning: invalid case style for parameter pack 'PARAMETER_PACK'
378 // CHECK-FIXES: {{^}}void GlobalFun(typeParameters_t... parameterPack) {{{$}}
379     global_function(1, 2);
380 // CHECK-FIXES: {{^}}    GlobalFunction(1, 2);{{$}}
381     FOO_bar = Global_variable;
382 // CHECK-FIXES: {{^}}    FOO_bar = g_global_variable;{{$}}
383 // NO fix expected for FOO_bar declared in macro expansion
384 }
385 
386 template<template<typename> class TPL_parameter, int COUNT_params, typename ... TYPE_parameters>
387 // CHECK-MESSAGES: :[[@LINE-1]]:35: warning: invalid case style for template template parameter 'TPL_parameter'
388 // CHECK-MESSAGES: :[[@LINE-2]]:54: warning: invalid case style for value template parameter 'COUNT_params'
389 // CHECK-MESSAGES: :[[@LINE-3]]:81: warning: invalid case style for type template parameter 'TYPE_parameters'
390 // CHECK-FIXES: {{^}}template<template<typename> class TplParameter, int countParams, typename ... typeParameters_t>{{$}}
391 class test_CLASS {
392 // CHECK-MESSAGES: :[[@LINE-1]]:7: warning: invalid case style for class 'test_CLASS'
393 // CHECK-FIXES: {{^}}class CTestClass {{{$}}
394 };
395 
396 class abstract_class {
397 // CHECK-MESSAGES: :[[@LINE-1]]:7: warning: invalid case style for abstract class 'abstract_class'
398 // CHECK-FIXES: {{^}}class AAbstractClass {{{$}}
399     virtual ~abstract_class() = 0;
400 // CHECK-FIXES: {{^}}    virtual ~AAbstractClass() = 0;{{$}}
401     virtual void VIRTUAL_METHOD();
402 // CHECK-MESSAGES: :[[@LINE-1]]:18: warning: invalid case style for virtual method 'VIRTUAL_METHOD'
403 // CHECK-FIXES: {{^}}    virtual void v_Virtual_Method();{{$}}
non_Virtual_METHOD()404     void non_Virtual_METHOD() {}
405 // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: invalid case style for private method 'non_Virtual_METHOD'
406 // CHECK-FIXES: {{^}}    void __non_Virtual_METHOD() {}{{$}}
407 
408 public:
CLASS_METHOD()409     static void CLASS_METHOD() {}
410 // CHECK-MESSAGES: :[[@LINE-1]]:17: warning: invalid case style for class method 'CLASS_METHOD'
411 // CHECK-FIXES: {{^}}    static void classMethod() {}{{$}}
412 
CST_expr_Method()413     constexpr int CST_expr_Method() { return 2; }
414 // CHECK-MESSAGES: :[[@LINE-1]]:19: warning: invalid case style for constexpr method 'CST_expr_Method'
415 // CHECK-FIXES: {{^}}    constexpr int cst_expr_method() { return 2; }{{$}}
416 
417 private:
418     void PRIVate_Method();
419 // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: invalid case style for private method 'PRIVate_Method'
420 // CHECK-FIXES: {{^}}    void __PRIVate_Method();{{$}}
421 protected:
422     void protected_Method();
423 // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: invalid case style for protected method 'protected_Method'
424 // CHECK-FIXES: {{^}}    void _protected_Method();{{$}}
425 public:
426     void public_Method();
427 // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: invalid case style for method 'public_Method'
428 // CHECK-FIXES: {{^}}    void publicMethod();{{$}}
429 };
430 
CE_function()431 constexpr int CE_function() { return 3; }
432 // CHECK-MESSAGES: :[[@LINE-1]]:15: warning: invalid case style for constexpr function 'CE_function'
433 // CHECK-FIXES: {{^}}constexpr int ce_function() { return 3; }{{$}}
434 
435 struct THIS___Structure {
436 // CHECK-MESSAGES: :[[@LINE-1]]:8: warning: invalid case style for struct 'THIS___Structure'
437 // CHECK-FIXES: {{^}}struct this_structure {{{$}}
438     THIS___Structure();
439 // CHECK-FIXES: {{^}}    this_structure();{{$}}
440 
441   union __MyUnion_is_wonderful__ {};
442 // CHECK-MESSAGES: :[[@LINE-1]]:9: warning: invalid case style for union '__MyUnion_is_wonderful__'
443 // CHECK-FIXES: {{^}}  union UMyUnionIsWonderful {};{{$}}
444 };
445 
446 typedef THIS___Structure struct_type;
447 // CHECK-MESSAGES: :[[@LINE-1]]:26: warning: invalid case style for typedef 'struct_type'
448 // CHECK-FIXES: {{^}}typedef this_structure struct_type_t;{{$}}
449 
GlobalTypedefTestFunction(struct_type a_argument1)450 struct_type GlobalTypedefTestFunction(struct_type a_argument1) {
451 // CHECK-FIXES: {{^}}struct_type_t GlobalTypedefTestFunction(struct_type_t a_argument1) {
452     struct_type typedef_test_1;
453 // CHECK-FIXES: {{^}}    struct_type_t typedef_test_1;
454 }
455 
456 using my_struct_type = THIS___Structure;
457 // CHECK-MESSAGES: :[[@LINE-1]]:7: warning: invalid case style for type alias 'my_struct_type'
458 // CHECK-FIXES: {{^}}using my_Struct_Type_t = this_structure;{{$}}
459 
460 template<typename t_t>
461 using SomeOtherTemplate = my_other_templated_class  <:: FOO_NS  ::my_class>;
462 // CHECK-MESSAGES: :[[@LINE-1]]:7: warning: invalid case style for type alias 'SomeOtherTemplate'
463 // CHECK-FIXES: {{^}}using some_Other_Template_t = CMyOtherTemplatedClass  <:: foo_ns  ::CMyClass>;{{$}}
464 
static_Function()465 static void static_Function() {
466 // CHECK-MESSAGES: :[[@LINE-1]]:13: warning: invalid case style for function 'static_Function'
467 // CHECK-FIXES: {{^}}static void staticFunction() {{{$}}
468 
469   ::FOO_NS::InlineNamespace::abstract_class::CLASS_METHOD();
470 // CHECK-FIXES: {{^}}  ::foo_ns::inline_namespace::AAbstractClass::classMethod();{{$}}
471   ::FOO_NS::InlineNamespace::static_Function();
472 // CHECK-FIXES: {{^}}  ::foo_ns::inline_namespace::staticFunction();{{$}}
473 
474   using ::FOO_NS::InlineNamespace::CE_function;
475 // CHECK-FIXES: {{^}}  using ::foo_ns::inline_namespace::ce_function;{{$}}
476 
477   unsigned MY_LOCAL_array[] = {1,2,3};
478 // CHECK-MESSAGES: :[[@LINE-1]]:12: warning: invalid case style for local variable 'MY_LOCAL_array'
479 // CHECK-FIXES: {{^}}  unsigned my_local_array[] = {1,2,3};{{$}}
480 
481   unsigned const MyConstLocal_array[] = {1,2,3};
482 // CHECK-MESSAGES: :[[@LINE-1]]:18: warning: invalid case style for local constant 'MyConstLocal_array'
483 // CHECK-FIXES: {{^}}  unsigned const kMyConstLocalArray[] = {1,2,3};{{$}}
484 
485   static unsigned MY_STATIC_array[] = {1,2,3};
486 // CHECK-MESSAGES: :[[@LINE-1]]:19: warning: invalid case style for static variable 'MY_STATIC_array'
487 // CHECK-FIXES: {{^}}  static unsigned s_myStaticArray[] = {1,2,3};{{$}}
488 
489   static unsigned const MyConstStatic_array[] = {1,2,3};
490 // CHECK-MESSAGES: :[[@LINE-1]]:25: warning: invalid case style for static constant 'MyConstStatic_array'
491 // CHECK-FIXES: {{^}}  static unsigned const MY_CONST_STATIC_ARRAY[] = {1,2,3};{{$}}
492 
493   char MY_LOCAL_string[] = "123";
494 // CHECK-MESSAGES: :[[@LINE-1]]:8: warning: invalid case style for local variable 'MY_LOCAL_string'
495 // CHECK-FIXES: {{^}}  char my_local_string[] = "123";{{$}}
496 
497   char const MyConstLocal_string[] = "123";
498 // CHECK-MESSAGES: :[[@LINE-1]]:14: warning: invalid case style for local constant 'MyConstLocal_string'
499 // CHECK-FIXES: {{^}}  char const kMyConstLocalString[] = "123";{{$}}
500 
501   static char MY_STATIC_string[] = "123";
502 // CHECK-MESSAGES: :[[@LINE-1]]:15: warning: invalid case style for static variable 'MY_STATIC_string'
503 // CHECK-FIXES: {{^}}  static char s_myStaticString[] = "123";{{$}}
504 
505   static char const MyConstStatic_string[] = "123";
506 // CHECK-MESSAGES: :[[@LINE-1]]:21: warning: invalid case style for static constant 'MyConstStatic_string'
507 // CHECK-FIXES: {{^}}  static char const MY_CONST_STATIC_STRING[] = "123";{{$}}
508 }
509 
510 #define MY_TEST_Macro(X) X()
511 // CHECK-MESSAGES: :[[@LINE-1]]:9: warning: invalid case style for macro definition 'MY_TEST_Macro'
512 // CHECK-FIXES: {{^}}#define MY_TEST_MACRO(X) X()
513 
MY_TEST_Macro(function)514 void MY_TEST_Macro(function) {}
515 // CHECK-FIXES: {{^}}void MY_TEST_MACRO(function) {}
516 }
517 }
518 
519 template <typename t_t> struct a {
520   typename t_t::template b<> c;
521 
522   char const MY_ConstMember_string[4] = "123";
523 // CHECK-MESSAGES: :[[@LINE-1]]:14: warning: invalid case style for constant member 'MY_ConstMember_string'
524 // CHECK-FIXES: {{^}}  char const my_const_member_string[4] = "123";{{$}}
525 
526   static char const MyConstClass_string[];
527 // CHECK-MESSAGES: :[[@LINE-1]]:21: warning: invalid case style for class constant 'MyConstClass_string'
528 // CHECK-FIXES: {{^}}  static char const kMyConstClassString[];{{$}}
529 };
530 
531 template<typename t_t>
532 char const a<t_t>::MyConstClass_string[] = "123";
533 // CHECK-FIXES: {{^}}char const a<t_t>::kMyConstClassString[] = "123";{{$}}
534 
535 template <template <typename> class A> struct b { A<int> c; };
536 
537 unsigned MY_GLOBAL_array[] = {1,2,3};
538 // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: invalid case style for global variable 'MY_GLOBAL_array'
539 // CHECK-FIXES: {{^}}unsigned g_my_global_array[] = {1,2,3};{{$}}
540 
541 unsigned const MyConstGlobal_array[] = {1,2,3};
542 // CHECK-MESSAGES: :[[@LINE-1]]:16: warning: invalid case style for global constant 'MyConstGlobal_array'
543 // CHECK-FIXES: {{^}}unsigned const MY_CONST_GLOBAL_ARRAY[] = {1,2,3};{{$}}
544 
545 int * MyGlobal_Ptr;// -> ok
546 int * const MyConstantGlobalPointer = nullptr;
547 // CHECK-MESSAGES: :[[@LINE-1]]:13: warning: invalid case style for global constant pointer 'MyConstantGlobalPointer'
548 // CHECK-FIXES: {{^}}int * const MY_CONSTANT_GLOBAL_POINTER_Ptr = nullptr;{{$}}
549 
MyPoiterFunction(int * p_normal_pointer,int * const constant_ptr)550 void MyPoiterFunction(int * p_normal_pointer, int * const constant_ptr){
551 // CHECK-MESSAGES: :[[@LINE-1]]:59: warning: invalid case style for constant pointer parameter 'constant_ptr'
552 // CHECK-FIXES: {{^}}void MyPoiterFunction(int * p_normal_pointer, int * const cp_ConstantPtr){{{$}}
553     int * l_PointerA;
554     int * const pointer_b = nullptr;
555 // CHECK-MESSAGES: :[[@LINE-1]]:17: warning: invalid case style for local constant pointer 'pointer_b'
556 // CHECK-FIXES: {{^}}    int * const lc_PointerB = nullptr;{{$}}
557 }
558 
559 using namespace FOO_NS;
560 // CHECK-FIXES: {{^}}using namespace foo_ns;
561 
562 using namespace FOO_NS::InlineNamespace;
563 // CHECK-FIXES: {{^}}using namespace foo_ns::inline_namespace;
564 
565 void QualifiedTypeLocTest(THIS___Structure);
566 // CHECK-FIXES: {{^}}void QualifiedTypeLocTest(this_structure);{{$}}
567 void QualifiedTypeLocTest(THIS___Structure &);
568 // CHECK-FIXES: {{^}}void QualifiedTypeLocTest(this_structure &);{{$}}
569 void QualifiedTypeLocTest(THIS___Structure &&);
570 // CHECK-FIXES: {{^}}void QualifiedTypeLocTest(this_structure &&);{{$}}
571 void QualifiedTypeLocTest(const THIS___Structure);
572 // CHECK-FIXES: {{^}}void QualifiedTypeLocTest(const this_structure);{{$}}
573 void QualifiedTypeLocTest(const THIS___Structure &);
574 // CHECK-FIXES: {{^}}void QualifiedTypeLocTest(const this_structure &);{{$}}
575 void QualifiedTypeLocTest(volatile THIS___Structure &);
576 // CHECK-FIXES: {{^}}void QualifiedTypeLocTest(volatile this_structure &);{{$}}
577 
578 namespace redecls {
579 // We only want the warning to show up once here for the first decl.
580 // CHECK-MESSAGES: :[[@LINE+1]]:6: warning: invalid case style for global function 'badNamedFunction'
581 void badNamedFunction();
582 void badNamedFunction();
badNamedFunction()583 void badNamedFunction(){}
584 //      CHECK-FIXES: {{^}}void BadNamedFunction();
585 // CHECK-FIXES-NEXT: {{^}}void BadNamedFunction();
586 // CHECK-FIXES-NEXT: {{^}}void BadNamedFunction(){}
ReferenceBadNamedFunction()587 void ReferenceBadNamedFunction() {
588   auto l_Ptr = badNamedFunction;
589   // CHECK-FIXES: {{^}}  auto l_Ptr = BadNamedFunction;
590   l_Ptr();
591   badNamedFunction();
592   // CHECK-FIXES: {{^}}  BadNamedFunction();
593 }
594 
595 } // namespace redecls
596 
597 namespace scratchspace {
598 #define DUP(Tok) Tok
599 #define M1(Tok) DUP(badName##Tok())
600 
601 // We don't want a warning here as the call to this in Foo is in a scratch
602 // buffer so its fix-it wouldn't be applied, resulting in invalid code.
603 void badNameWarn();
604 
Foo()605 void Foo() {
606   M1(Warn);
607 }
608 
609 #undef M1
610 #undef DUP
611 } // namespace scratchspace
612 
613 template<typename type_t>
614 auto GetRes(type_t& Param) -> decltype(Param.res());
615 // CHECK-MESSAGES: :[[@LINE-1]]:21: warning: invalid case style for parameter 'Param'
616 // CHECK-FIXES: auto GetRes(type_t& a_param) -> decltype(a_param.res());
617