brintos

brintos / llvm-project-archived public Read only

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