Index: clang-tidy/readability/IdentifierNamingCheck.cpp =================================================================== --- clang-tidy/readability/IdentifierNamingCheck.cpp +++ clang-tidy/readability/IdentifierNamingCheck.cpp @@ -449,12 +449,11 @@ if (const auto *Decl = dyn_cast(D)) { QualType Type = Decl->getType(); - if (!Type.isNull() && Type.isLocalConstQualified() && + if (!Type.isNull() && Type.isConstQualified() && NamingStyles[SK_ConstantMember]) return SK_ConstantMember; - if (!Type.isNull() && Type.isLocalConstQualified() && - NamingStyles[SK_Constant]) + if (!Type.isNull() && Type.isConstQualified() && NamingStyles[SK_Constant]) return SK_Constant; if (Decl->getAccess() == AS_private && NamingStyles[SK_PrivateMember]) @@ -478,12 +477,11 @@ if (Decl->isConstexpr() && NamingStyles[SK_ConstexprVariable]) return SK_ConstexprVariable; - if (!Type.isNull() && Type.isLocalConstQualified() && + if (!Type.isNull() && Type.isConstQualified() && NamingStyles[SK_ConstantParameter]) return SK_ConstantParameter; - if (!Type.isNull() && Type.isLocalConstQualified() && - NamingStyles[SK_Constant]) + if (!Type.isNull() && Type.isConstQualified() && NamingStyles[SK_Constant]) return SK_Constant; if (Decl->isParameterPack() && NamingStyles[SK_ParameterPack]) @@ -501,28 +499,27 @@ if (Decl->isConstexpr() && NamingStyles[SK_ConstexprVariable]) return SK_ConstexprVariable; - if (!Type.isNull() && Type.isLocalConstQualified() && + if (!Type.isNull() && Type.isConstQualified() && Decl->isStaticDataMember() && NamingStyles[SK_ClassConstant]) return SK_ClassConstant; - if (!Type.isNull() && Type.isLocalConstQualified() && - Decl->isFileVarDecl() && NamingStyles[SK_GlobalConstant]) + if (!Type.isNull() && Type.isConstQualified() && Decl->isFileVarDecl() && + NamingStyles[SK_GlobalConstant]) return SK_GlobalConstant; - if (!Type.isNull() && Type.isLocalConstQualified() && - Decl->isStaticLocal() && NamingStyles[SK_StaticConstant]) + if (!Type.isNull() && Type.isConstQualified() && Decl->isStaticLocal() && + NamingStyles[SK_StaticConstant]) return SK_StaticConstant; - if (!Type.isNull() && Type.isLocalConstQualified() && - Decl->isLocalVarDecl() && NamingStyles[SK_LocalConstant]) + if (!Type.isNull() && Type.isConstQualified() && Decl->isLocalVarDecl() && + NamingStyles[SK_LocalConstant]) return SK_LocalConstant; - if (!Type.isNull() && Type.isLocalConstQualified() && + if (!Type.isNull() && Type.isConstQualified() && Decl->isFunctionOrMethodVarDecl() && NamingStyles[SK_LocalConstant]) return SK_LocalConstant; - if (!Type.isNull() && Type.isLocalConstQualified() && - NamingStyles[SK_Constant]) + if (!Type.isNull() && Type.isConstQualified() && NamingStyles[SK_Constant]) return SK_Constant; if (Decl->isStaticDataMember() && NamingStyles[SK_ClassMember]) @@ -681,8 +678,9 @@ static void addUsage(IdentifierNamingCheck::NamingCheckFailureMap &Failures, const NamedDecl *Decl, SourceRange Range, SourceManager *SourceMgr = nullptr) { - return addUsage(Failures, IdentifierNamingCheck::NamingCheckId( - Decl->getLocation(), Decl->getNameAsString()), + return addUsage(Failures, + IdentifierNamingCheck::NamingCheckId(Decl->getLocation(), + Decl->getNameAsString()), Range, SourceMgr); } @@ -699,7 +697,8 @@ if (!Init->isWritten() || Init->isInClassMemberInitializer()) continue; if (const auto *FD = Init->getAnyMember()) - addUsage(NamingCheckFailures, FD, SourceRange(Init->getMemberLocation())); + addUsage(NamingCheckFailures, FD, + SourceRange(Init->getMemberLocation())); // Note: delegating constructors and base class initializers are handled // via the "typeLoc" matcher. } Index: test/clang-tidy/readability-identifier-naming.cpp =================================================================== --- test/clang-tidy/readability-identifier-naming.cpp +++ test/clang-tidy/readability-identifier-naming.cpp @@ -405,6 +405,38 @@ using ::FOO_NS::InlineNamespace::CE_function; // CHECK-FIXES: {{^}} using ::foo_ns::inline_namespace::ce_function;{{$}} + + unsigned MY_LOCAL_array[] = {1,2,3}; +// CHECK-MESSAGES: :[[@LINE-1]]:12: warning: invalid case style for local variable 'MY_LOCAL_array' +// CHECK-FIXES: {{^}} unsigned my_local_array[] = {1,2,3};{{$}} + + unsigned const MyConstLocal_array[] = {1,2,3}; +// CHECK-MESSAGES: :[[@LINE-1]]:18: warning: invalid case style for local constant 'MyConstLocal_array' +// CHECK-FIXES: {{^}} unsigned const kMyConstLocalArray[] = {1,2,3};{{$}} + + static unsigned MY_STATIC_array[] = {1,2,3}; +// CHECK-MESSAGES: :[[@LINE-1]]:19: warning: invalid case style for static variable 'MY_STATIC_array' +// CHECK-FIXES: {{^}} static unsigned s_myStaticArray[] = {1,2,3};{{$}} + + static unsigned const MyConstStatic_array[] = {1,2,3}; +// CHECK-MESSAGES: :[[@LINE-1]]:25: warning: invalid case style for static constant 'MyConstStatic_array' +// CHECK-FIXES: {{^}} static unsigned const MY_CONST_STATIC_ARRAY[] = {1,2,3};{{$}} + + char MY_LOCAL_string[] = "123"; +// CHECK-MESSAGES: :[[@LINE-1]]:8: warning: invalid case style for local variable 'MY_LOCAL_string' +// CHECK-FIXES: {{^}} char my_local_string[] = "123";{{$}} + + char const MyConstLocal_string[] = "123"; +// CHECK-MESSAGES: :[[@LINE-1]]:14: warning: invalid case style for local constant 'MyConstLocal_string' +// CHECK-FIXES: {{^}} char const kMyConstLocalString[] = "123";{{$}} + + static char MY_STATIC_string[] = "123"; +// CHECK-MESSAGES: :[[@LINE-1]]:15: warning: invalid case style for static variable 'MY_STATIC_string' +// CHECK-FIXES: {{^}} static char s_myStaticString[] = "123";{{$}} + + static char const MyConstStatic_string[] = "123"; +// CHECK-MESSAGES: :[[@LINE-1]]:21: warning: invalid case style for static constant 'MyConstStatic_string' +// CHECK-FIXES: {{^}} static char const MY_CONST_STATIC_STRING[] = "123";{{$}} } #define MY_TEST_Macro(X) X() @@ -418,6 +450,27 @@ template struct a { typename t_t::template b<> c; + + char const MY_ConstMember_string[4] = "123"; +// CHECK-MESSAGES: :[[@LINE-1]]:14: warning: invalid case style for constant member 'MY_ConstMember_string' +// CHECK-FIXES: {{^}} char const my_const_member_string[4] = "123";{{$}} + + static char const MyConstClass_string[]; +// CHECK-MESSAGES: :[[@LINE-1]]:21: warning: invalid case style for class constant 'MyConstClass_string' +// CHECK-FIXES: {{^}} static char const kMyConstClassString[];{{$}} }; +template +char const a::MyConstClass_string[] = "123"; +// CHECK-MESSAGES: :[[@LINE-1]]:20: warning: invalid case style for class constant 'MyConstClass_string' +// CHECK-FIXES: {{^}}char const a::kMyConstClassString[] = "123";{{$}} + template