diff --git a/clang-tools-extra/clang-tidy/readability/IdentifierNamingCheck.h b/clang-tools-extra/clang-tidy/readability/IdentifierNamingCheck.h --- a/clang-tools-extra/clang-tidy/readability/IdentifierNamingCheck.h +++ b/clang-tools-extra/clang-tidy/readability/IdentifierNamingCheck.h @@ -36,7 +36,6 @@ IdentifierNamingCheck(StringRef Name, ClangTidyContext *Context); ~IdentifierNamingCheck(); - std::string getDeclTypeName(const clang::NamedDecl *Decl) const; void storeOptions(ClangTidyOptions::OptionMap &Opts) override; enum CaseType { @@ -46,8 +45,23 @@ CT_UpperCase, CT_CamelCase, CT_CamelSnakeCase, - CT_CamelSnakeBack, - CT_HungarianNotation + CT_CamelSnakeBack + }; + + enum HungarianPrefixOption { + HPO_Off = 0, + HPO_On, + HPO_LowerCase, + HPO_CamelCase, + }; + + struct HungarianNotationOption { + llvm::Optional Case; + llvm::StringMap General; + llvm::StringMap CString; + llvm::StringMap PrimitiveType; + llvm::StringMap UserDefinedType; + llvm::StringMap DerivedType; }; struct NamingStyle { @@ -57,9 +71,21 @@ const std::string &Suffix) : Case(Case), Prefix(Prefix), Suffix(Suffix) {} + NamingStyle(llvm::Optional Case, const std::string &Prefix, + const std::string &Suffix, + HungarianPrefixOption HungarianPrefixOpt, + const std::shared_ptr HNOption) + : Case(Case), Prefix(Prefix), Suffix(Suffix), + HungarianPrefixOpt(HungarianPrefixOpt), + HungarianNotationOption(HNOption) {} + llvm::Optional Case; std::string Prefix; std::string Suffix; + + HungarianPrefixOption HungarianPrefixOpt; + std::shared_ptr + HungarianNotationOption; }; private: diff --git a/clang-tools-extra/clang-tidy/readability/IdentifierNamingCheck.cpp b/clang-tools-extra/clang-tidy/readability/IdentifierNamingCheck.cpp --- a/clang-tools-extra/clang-tidy/readability/IdentifierNamingCheck.cpp +++ b/clang-tools-extra/clang-tidy/readability/IdentifierNamingCheck.cpp @@ -44,12 +44,33 @@ {readability::IdentifierNamingCheck::CT_CamelSnakeCase, "Camel_Snake_Case"}, {readability::IdentifierNamingCheck::CT_CamelSnakeBack, - "camel_Snake_Back"}, - {readability::IdentifierNamingCheck::CT_HungarianNotation, - "szHungarianNotation"}}; + "camel_Snake_Back"}}; return llvm::makeArrayRef(Mapping); } +template <> +struct OptionEnumMapping< + readability::IdentifierNamingCheck::HungarianPrefixOption> { + static llvm::ArrayRef> + getEnumMapping() { + static constexpr std::pair< + readability::IdentifierNamingCheck::HungarianPrefixOption, StringRef> + Mapping[] = { + {readability::IdentifierNamingCheck::HungarianPrefixOption::HPO_Off, + "Off"}, + {readability::IdentifierNamingCheck::HungarianPrefixOption::HPO_On, + "On"}, + {readability::IdentifierNamingCheck::HungarianPrefixOption:: + HPO_LowerCase, + "sz_LowerCase"}, + {readability::IdentifierNamingCheck::HungarianPrefixOption:: + HPO_CamelCase, + "szCamelCase"}}; + return llvm::makeArrayRef(Mapping); + } +}; + namespace readability { // clang-format off @@ -105,6 +126,7 @@ m(TypeAlias) \ m(MacroDefinition) \ m(ObjcIvar) \ + m(HungarianNotation) \ enum StyleKind { #define ENUMERATE(v) SK_ ## v, @@ -120,11 +142,326 @@ #undef STRINGIZE }; +#define HUNGARIAN_NOTATION_PRIMITIVE_TYPES(m) \ + m(int8_t) \ + m(int16_t) \ + m(int32_t) \ + m(int64_t) \ + m(uint8_t) \ + m(uint16_t) \ + m(uint32_t) \ + m(uint64_t) \ + m(char8_t) \ + m(char16_t) \ + m(char32_t) \ + m(float) \ + m(double) \ + m(char) \ + m(bool) \ + m(_Bool) \ + m(int) \ + m(size_t) \ + m(wchar_t) \ + m(short-int) \ + m(short) \ + m(signed-int) \ + m(signed-short) \ + m(signed-short-int) \ + m(signed-long-long-int) \ + m(signed-long-long) \ + m(signed-long-int) \ + m(signed-long) \ + m(signed) \ + m(unsigned-long-long-int) \ + m(unsigned-long-long) \ + m(unsigned-long-int) \ + m(unsigned-long) \ + m(unsigned-short-int) \ + m(unsigned-short) \ + m(unsigned-int) \ + m(unsigned) \ + m(long-long-int) \ + m(long-double) \ + m(long-long) \ + m(long-int) \ + m(long) \ + m(ptrdiff_t) \ + +static StringRef const HungarainNotationPrimitiveTypes[] = { +#define STRINGIZE(v) #v, + HUNGARIAN_NOTATION_PRIMITIVE_TYPES(STRINGIZE) +#undef STRINGIZE +}; + +#define HUNGARIAN_NOTATION_USER_DEFINED_TYPES(m) \ + m(BOOL) \ + m(BOOLEAN) \ + m(BYTE) \ + m(CHAR) \ + m(UCHAR) \ + m(SHORT) \ + m(USHORT) \ + m(WORD) \ + m(DWORD) \ + m(DWORD32) \ + m(DWORD64) \ + m(LONG) \ + m(ULONG) \ + m(ULONG32) \ + m(ULONG64) \ + m(ULONGLONG) \ + m(HANDLE) \ + m(INT) \ + m(INT8) \ + m(INT16) \ + m(INT32) \ + m(INT64) \ + m(UINT) \ + m(UINT8) \ + m(UINT16) \ + m(UINT32) \ + m(UINT64) \ + m(PVOID) \ + +static StringRef const HungarainNotationUserDefinedTypes[] = { +#define STRINGIZE(v) #v, + HUNGARIAN_NOTATION_USER_DEFINED_TYPES(STRINGIZE) +#undef STRINGIZE +}; + + #undef NAMING_KEYS // clang-format on +static void getHungarianNotationDefaultConfig( + std::shared_ptr HNOption) { + + // Options + const static llvm::StringMap Options = { + {"TreatStructAsClass", "false"}}; + for (auto &Opt : Options) { + std::string Val = HNOption->General.lookup(Opt.getKey()); + if (Val.empty()) { + HNOption->General.insert({Opt.getKey(), Opt.getValue()}); + } + } + + // Derived types + const static llvm::StringMap DerivedTypes = { + {"Array", "a"}, {"Pointer", "p"}, {"FunctionPointer", "fn"}}; + for (auto &Other : DerivedTypes) { + std::string Val = HNOption->DerivedType.lookup(Other.getKey()); + if (Val.empty()) { + HNOption->DerivedType.insert({Other.getKey(), Other.getValue()}); + } + } + + // C strings + const static llvm::StringMap CStrings = { + {"char*", "sz"}, {"char", "sz"}, {"wchar_t*", "wsz"}, {"wchar_t", "wsz"}}; + for (auto &CStr : CStrings) { + std::string Val = HNOption->CString.lookup(CStr.getKey()); + if (Val.empty()) { + HNOption->CString.insert({CStr.getKey(), CStr.getValue()}); + } + } + + // clang-format off + const static llvm::StringMap PrimitiveTypes = { + {"int8_t", "i8" }, + {"int16_t", "i16" }, + {"int32_t", "i32" }, + {"int64_t", "i64" }, + {"uint8_t", "u8" }, + {"uint16_t", "u16" }, + {"uint32_t", "u32" }, + {"uint64_t", "u64" }, + {"char8_t", "c8" }, + {"char16_t", "c16" }, + {"char32_t", "c32" }, + {"float", "f" }, + {"double", "d" }, + {"char", "c" }, + {"bool", "b" }, + {"_Bool", "b" }, + {"int", "i" }, + {"size_t", "n" }, + {"wchar_t", "wc" }, + {"short int", "si" }, + {"short", "s" }, + {"signed int", "si" }, + {"signed short", "ss" }, + {"signed short int", "ssi" }, + {"signed long long int", "slli"}, + {"signed long long", "sll" }, + {"signed long int", "sli" }, + {"signed long", "sl" }, + {"signed", "s" }, + {"unsigned long long int", "ulli"}, + {"unsigned long long", "ull" }, + {"unsigned long int", "uli" }, + {"unsigned long", "ul" }, + {"unsigned short int", "usi" }, + {"unsigned short", "us" }, + {"unsigned int", "ui" }, + {"unsigned", "u" }, + {"long long int", "lli" }, + {"long double", "ld" }, + {"long long", "ll" }, + {"long int", "li" }, + {"long", "l" }, + {"ptrdiff_t", "p" }}; + // clang-format on + for (auto &Type : PrimitiveTypes) { + std::string Val = HNOption->PrimitiveType.lookup(Type.getKey()); + if (Val.empty()) { + HNOption->PrimitiveType.insert({Type.getKey(), Type.getValue()}); + } + } + + // clang-format off + const static llvm::StringMap UserDefinedTypes = { + // Windows data types + {"BOOL", "b" }, + {"BOOLEAN", "b" }, + {"BYTE", "by" }, + {"CHAR", "c" }, + {"UCHAR", "uc" }, + {"SHORT", "s" }, + {"USHORT", "us" }, + {"WORD", "w" }, + {"DWORD", "dw" }, + {"DWORD32", "dw32"}, + {"DWORD64", "dw64"}, + {"LONG", "l" }, + {"ULONG", "ul" }, + {"ULONG32", "ul32"}, + {"ULONG64", "ul64"}, + {"ULONGLONG", "ull" }, + {"HANDLE", "h" }, + {"INT", "i" }, + {"INT8", "i8" }, + {"INT16", "i16" }, + {"INT32", "i32" }, + {"INT64", "i64" }, + {"UINT", "ui" }, + {"UINT8", "u8" }, + {"UINT16", "u16" }, + {"UINT32", "u32" }, + {"UINT64", "u64" }, + {"PVOID", "p" } }; + // clang-format on + for (auto &Type : UserDefinedTypes) { + std::string Val = HNOption->UserDefinedType.lookup(Type.getKey()); + if (Val.empty()) { + HNOption->UserDefinedType.insert({Type.getKey(), Type.getValue()}); + } + } +} + +static void getHungarianNotationFileConfig( + const ClangTidyCheck::OptionsView &Options, + std::shared_ptr HNOption) { + std::string Section = "HungarianNotation."; + + std::vector HNOpts = {"TreatStructAsClass"}; + for (auto const &Opt : HNOpts) { + std::string Key = Section + "General." + Opt; + + std::string Val = Options.get(Key, ""); + if (!Val.empty()) + HNOption->General[Opt] = Val; + } + + std::vector HNDerivedTypes = {"Array", "Pointer", + "FunctionPointer"}; + for (auto const &Type : HNDerivedTypes) { + std::string Key = Section + "DerivedType." + Type; + std::string Val = Options.get(Key, ""); + if (!Val.empty()) + HNOption->DerivedType[Type] = Val; + } + + std::vector> HNCStrings = { + {"CharPrinter", "char*"}, + {"CharArray", "char"}, + {"WideCharPrinter", "wchar_t*"}, + {"WideCharArray", "wchar_t"}}; + + for (auto const &CStr : HNCStrings) { + std::string Key = Section + "CString." + CStr.first; + std::string Val = Options.get(Key, ""); + if (!Val.empty()) + HNOption->CString[CStr.first] = Val; + } + + for (auto const &PrimType : HungarainNotationPrimitiveTypes) { + std::string Key = Section + "PrimitiveType." + PrimType.str(); + std::string Val = Options.get(Key, ""); + std::string Type = PrimType.str(); + if (!Val.empty()) { + if (Type.find('-') != std::string::npos) { + for (size_t i = 0; i < Type.length(); ++i) { + if (Type[i] == '-') { + Type.replace(i, 1, " "); + } + } + } + HNOption->PrimitiveType[Type] = Val; + } + } + + for (auto const &WDType : HungarainNotationUserDefinedTypes) { + std::string Key = Section + "UserDefinedType." + WDType.str(); + std::string Val = Options.get(Key, ""); + std::string Type = WDType.str(); + if (!Val.empty()) + HNOption->UserDefinedType[Type] = Val; + } +} + +static bool +isHungarianNotationOptionEnabled(const std::string OptionKey, + llvm::StringMap StrMap) { + if (OptionKey.empty()) + return false; + + std::string OptionVal = StrMap.lookup(OptionKey); + for (auto &C : OptionVal) { + C = toupper(C); + } + + if (OptionVal == "1" || OptionVal == "TRUE" || OptionVal == "ON") { + return true; + } + + return false; +} + +static IdentifierNamingCheck::HungarianPrefixOption +parseHungarianPrefix(std::string OptionVal) { + for (auto &C : OptionVal) + C = toupper(C); + + if (std::string::npos != OptionVal.find("LOWER_CASE")) + return IdentifierNamingCheck::HungarianPrefixOption::HPO_LowerCase; + + if (std::string::npos != OptionVal.find("CAMELCASE")) + return IdentifierNamingCheck::HungarianPrefixOption::HPO_CamelCase; + + if (OptionVal == "1" || OptionVal == "TRUE" || OptionVal == "ON") + return IdentifierNamingCheck::HungarianPrefixOption::HPO_On; + + return IdentifierNamingCheck::HungarianPrefixOption::HPO_Off; +} + static std::vector> getNamingStyles(const ClangTidyCheck::OptionsView &Options) { + auto HNOption = + std::make_shared(); + getHungarianNotationDefaultConfig(HNOption); + getHungarianNotationFileConfig(Options, HNOption); + std::vector> Styles; Styles.reserve(array_lengthof(StyleNames)); for (auto const &StyleName : StyleNames) { @@ -132,13 +469,22 @@ (StyleName + "Case").str()); auto Prefix = Options.get((StyleName + "Prefix").str(), ""); auto Postfix = Options.get((StyleName + "Suffix").str(), ""); - - if (CaseOptional || !Prefix.empty() || !Postfix.empty()) + auto HungarianPrefix = + Options.get((StyleName + "HungarianPrefix").str(), ""); + + if (CaseOptional || !Prefix.empty() || !Postfix.empty() || + !HungarianPrefix.empty()) { + HNOption->Case = CaseOptional; + IdentifierNamingCheck::HungarianPrefixOption HPOpt = + parseHungarianPrefix(HungarianPrefix); Styles.emplace_back(IdentifierNamingCheck::NamingStyle{ - std::move(CaseOptional), std::move(Prefix), std::move(Postfix)}); - else + std::move(CaseOptional), std::move(Prefix), std::move(Postfix), + std::move(HPOpt), HNOption}); + } else { Styles.emplace_back(llvm::None); + } } + return Styles; } @@ -174,107 +520,59 @@ NamingStyles[I]->Prefix); Options.store(Opts, (StyleNames[I] + "Suffix").str(), NamingStyles[I]->Suffix); + Options.store(Opts, (StyleNames[I] + "HungarianPrefix").str(), + NamingStyles[I]->HungarianPrefixOpt); } Options.store(Opts, "GetConfigPerFile", GetConfigPerFile); Options.store(Opts, "IgnoreFailedSplit", IgnoreFailedSplit); Options.store(Opts, "IgnoreMainLikeFunctions", IgnoreMainLikeFunctions); } -static const std::string -getHungarianNotationTypePrefix(const std::string &TypeName, - const NamedDecl *InputDecl) { - if (!InputDecl || TypeName.empty()) { +static const std::string getHungarianNotationDataTypePrefix( + const std::string &TypeName, const NamedDecl *ND, + const IdentifierNamingCheck::HungarianNotationOption &HNOption) { + if (!ND || TypeName.empty()) { return TypeName; } - // clang-format off - const static llvm::StringMap HungarianNotationTable = { - // Primitive types - {"int8_t", "i8"}, - {"int16_t", "i16"}, - {"int32_t", "i32"}, - {"int64_t", "i64"}, - {"uint8_t", "u8"}, - {"uint16_t", "u16"}, - {"uint32_t", "u32"}, - {"uint64_t", "u64"}, - {"char8_t", "c8"}, - {"char16_t", "c16"}, - {"char32_t", "c32"}, - {"float", "f"}, - {"double", "d"}, - {"char", "c"}, - {"bool", "b"}, - {"_Bool", "b"}, - {"int", "i"}, - {"size_t", "n"}, - {"wchar_t", "wc"}, - {"short", "s"}, - {"signed", "i"}, - {"unsigned", "u"}, - {"long", "l"}, - {"long long", "ll"}, - {"unsigned long", "ul"}, - {"long double", "ld"}, - {"ptrdiff_t", "p"}, - // Windows data types - {"BOOL", "b"}, - {"BOOLEAN", "b"}, - {"BYTE", "by"}, - {"WORD", "w"}, - {"DWORD", "dw"}}; - // clang-format on + std::string ModifiedTypeName = TypeName; - std::string ClonedTypeName = TypeName; - - // Handle null string + // Derived types std::string PrefixStr; - if (const auto *TD = dyn_cast(InputDecl)) { + if (const auto *TD = dyn_cast(ND)) { auto QT = TD->getType(); if (QT->isFunctionPointerType()) { - PrefixStr = "fn"; // Function Pointer + PrefixStr = HNOption.DerivedType.lookup("FunctionPointer"); } else if (QT->isPointerType()) { - // clang-format off - const static llvm::StringMap NullString = { - {"char*", "sz"}, - {"wchar_t*", "wsz"}}; - // clang-format on - for (const auto &Type : NullString) { - const auto &Key = Type.getKey(); - if (ClonedTypeName.find(Key.str()) == 0) { - PrefixStr = Type.getValue().str(); - ClonedTypeName = ClonedTypeName.substr( - Key.size(), ClonedTypeName.size() - Key.size()); + for (const auto &CStr : HNOption.CString) { + auto Key = CStr.getKey().str(); + if (ModifiedTypeName.find(Key) == 0) { + PrefixStr = CStr.getValue(); + ModifiedTypeName = ModifiedTypeName.substr( + Key.size(), ModifiedTypeName.size() - Key.size()); break; } } } else if (QT->isArrayType()) { - // clang-format off - const static llvm::StringMap NullString = { - {"char", "sz"}, - {"wchar_t", "wsz"}}; - // clang-format on - for (const auto &Type : NullString) { - const auto &Key = Type.getKey(); - if (ClonedTypeName.find(Key.str()) == 0) { - PrefixStr = Type.getValue().str(); - ClonedTypeName = ClonedTypeName.substr( - Key.size(), ClonedTypeName.size() - Key.size()); + for (const auto &CStr : HNOption.CString) { + auto Key = CStr.getKey().str(); + if (ModifiedTypeName.find(Key) == 0) { + PrefixStr = CStr.getValue(); break; } } if (PrefixStr.empty()) { - PrefixStr = 'a'; // Array + PrefixStr = HNOption.DerivedType.lookup("Array"); } } else if (QT->isReferenceType()) { - size_t Pos = ClonedTypeName.find_last_of("&"); + size_t Pos = ModifiedTypeName.find_last_of("&"); if (Pos != std::string::npos) { - ClonedTypeName = ClonedTypeName.substr(0, Pos); + ModifiedTypeName = ModifiedTypeName.substr(0, Pos); } } } - // Handle pointers + // Pointers size_t PtrCount = [&](std::string TypeName) -> size_t { size_t Pos = TypeName.find('*'); size_t Count = 0; @@ -283,55 +581,140 @@ break; } return Count; - }(ClonedTypeName); + }(ModifiedTypeName); if (PtrCount > 0) { - ClonedTypeName = [&](std::string Str, const std::string &From, - const std::string &To) { + ModifiedTypeName = [&](std::string Str, const std::string &From, + const std::string &To) { size_t StartPos = 0; while ((StartPos = Str.find(From, StartPos)) != std::string::npos) { Str.replace(StartPos, From.length(), To); StartPos += To.length(); } return Str; - }(ClonedTypeName, "*", ""); + }(ModifiedTypeName, "*", ""); } + // Primitive types if (PrefixStr.empty()) { - for (const auto &Type : HungarianNotationTable) { - const auto &Key = Type.getKey(); - if (ClonedTypeName == Key) { - PrefixStr = Type.getValue().str(); + for (const auto &Type : HNOption.PrimitiveType) { + const auto &key = Type.getKey().str(); + if (ModifiedTypeName == key) { + PrefixStr = Type.getValue(); break; } } } - if (PtrCount > 0) { - for (size_t Idx = 0; Idx < PtrCount; Idx++) { - PrefixStr.insert(PrefixStr.begin(), 'p'); + // User-Defined types + if (PrefixStr.empty()) { + for (const auto &Type : HNOption.UserDefinedType) { + const auto &key = Type.getKey().str(); + if (ModifiedTypeName == key) { + PrefixStr = Type.getValue(); + break; + } } } + for (size_t Idx = 0; Idx < PtrCount; Idx++) { + PrefixStr.insert(0, HNOption.DerivedType.lookup("Pointer")); + } + return PrefixStr; } -std::string -IdentifierNamingCheck::getDeclTypeName(const clang::NamedDecl *Decl) const { - const ValueDecl *ValDecl = dyn_cast(Decl); - if (!ValDecl) { +static std::string getHungarianNotationClassPrefix( + const CXXRecordDecl *CRD, + const IdentifierNamingCheck::HungarianNotationOption &HNOption) { + + if (CRD->isUnion()) { + return ""; + } + + if (CRD->isStruct()) { + if (!isHungarianNotationOptionEnabled("TreatStructAsClass", + HNOption.General)) { + return ""; + } + } + + // An abstract class has at least one pure virutal function. + bool IsAbstractClass = false; + for (const auto *Method : CRD->methods()) { + if (Method->isPure()) { + IsAbstractClass = true; + break; + } + } + + std::string Prefix; + if (IsAbstractClass) { + Prefix = "I"; + } else { + Prefix = "C"; + } + + return Prefix; +} + +static std::string getHungarianNotationEnumPrefix(const EnumConstantDecl *ECD) { + std::string Name = ECD->getType().getAsString(); + if (std::string::npos != Name.find("enum")) { + Name = Name.substr(strlen("enum"), Name.length() - strlen("enum")); + Name = Name.erase(0, Name.find_first_not_of(" ")); + } + + static llvm::Regex Splitter( + "([a-z0-9A-Z]*)(_+)|([A-Z]?[a-z0-9]+)([A-Z]|$)|([A-Z]+)([A-Z]|$)"); + + llvm::StringRef EnumName(Name); + SmallVector Substrs; + EnumName.split(Substrs, "_", -1, false); + + SmallVector Words; + SmallVector Groups; + for (auto Substr : Substrs) { + while (!Substr.empty()) { + Groups.clear(); + if (!Splitter.match(Substr, &Groups)) + break; + + if (Groups[2].size() > 0) { + Words.push_back(Groups[1]); + Substr = Substr.substr(Groups[0].size()); + } else if (Groups[3].size() > 0) { + Words.push_back(Groups[3]); + Substr = Substr.substr(Groups[0].size() - Groups[4].size()); + } else if (Groups[5].size() > 0) { + Words.push_back(Groups[5]); + Substr = Substr.substr(Groups[0].size() - Groups[6].size()); + } + } + } + + std::string Initial; + for (auto const &Word : Words) { + Initial += tolower(Word[0]); + } + return Initial; +} + +static std::string getDeclTypeName(const clang::NamedDecl *ND) { + const auto VD = dyn_cast(ND); + if (!VD) { return ""; } - if (clang::Decl::Kind::EnumConstant == Decl->getKind() || - clang::Decl::Kind::CXXMethod == Decl->getKind()|| - clang::Decl::Kind::Function == Decl->getKind()) { + if (clang::Decl::Kind::EnumConstant == ND->getKind() || + clang::Decl::Kind::CXXMethod == ND->getKind() || + clang::Decl::Kind::Function == ND->getKind()) { return ""; } // Get type text of variable declarations. - auto &SM = ValDecl->getASTContext().getSourceManager(); - const char *Begin = SM.getCharacterData(ValDecl->getBeginLoc()); - const char *End = SM.getCharacterData(ValDecl->getEndLoc()); + auto &SM = VD->getASTContext().getSourceManager(); + const char *Begin = SM.getCharacterData(VD->getBeginLoc()); + const char *End = SM.getCharacterData(VD->getEndLoc()); intptr_t StrLen = End - Begin; // FIXME: Sometimes the value that returns from ValDecl->getEndLoc() @@ -372,6 +755,7 @@ Type.replace(Pos, Kw.length(), ""); } } + TypeName = Type.erase(0, Type.find_first_not_of(" ")); // Replace spaces with single space. for (size_t Pos = 0; (Pos = Type.find(" ", Pos)) != std::string::npos; @@ -393,10 +777,11 @@ // Remove redundant tailing. const static std::list TailsOfMultiWordType = { - " int", " char", " double", " long"}; + " int", " char", " double", " long", " short"}; bool RedundantRemoved = false; - for (const std::string &Kw : TailsOfMultiWordType) { - for (size_t Pos = 0; (Pos = Type.find(Kw, Pos)) != std::string::npos;) { + for (const auto &Kw : TailsOfMultiWordType) { + size_t Pos = Type.rfind(Kw); + if (Pos != std::string::npos) { Type = Type.substr(0, Pos + Kw.length()); RedundantRemoved = true; break; @@ -416,49 +801,109 @@ return TypeName; } +static std::string getHungarianNotationPrefix( + const clang::Decl *D, + const IdentifierNamingCheck::HungarianNotationOption &HNOption) { + const auto ND = dyn_cast(D); + if (!ND) { + return ""; + } + + std::string Prefix; + switch (ND->getKind()) { + case clang::Decl::Kind::Var: + case clang::Decl::Kind::Field: + case clang::Decl::Kind::ParmVar: + case clang::Decl::Kind::Record: + if (ND) { + std::string TypeName = getDeclTypeName(ND); + if (!TypeName.empty()) + Prefix = getHungarianNotationDataTypePrefix(TypeName, ND, HNOption); + } + break; + + case clang::Decl::Kind::EnumConstant: + if (ND) { + const auto ECD = dyn_cast(ND); + Prefix = getHungarianNotationEnumPrefix(ECD); + } + break; + + case clang::Decl::Kind::CXXRecord: + if (ND) { + const auto CRD = dyn_cast(ND); + Prefix = getHungarianNotationClassPrefix(CRD, HNOption); + } + break; + + default: + break; + } + return Prefix; +} + +static bool removeDuplicatedHungarianNotationPrefix( + SmallVector &Words, + const IdentifierNamingCheck::HungarianNotationOption &HNOption) { + if (Words.size() <= 1) + return true; + + std::string CorrectName = Words[0].str(); + std::vector> MapList = { + HNOption.CString, HNOption.DerivedType, HNOption.PrimitiveType, + HNOption.UserDefinedType}; + + for (auto &Map : MapList) { + for (auto &Str : Map) { + bool Found = (Str.getValue() == CorrectName); + if (Found) { + Words.assign(Words.begin() + 1, Words.end()); + return true; + } + } + } + + return false; +} + static bool matchesStyle(StringRef Type, StringRef Name, IdentifierNamingCheck::NamingStyle Style, const NamedDecl *Decl) { - static llvm::Regex Matchers[] = { - llvm::Regex("^.*$"), - llvm::Regex("^[a-z][a-z0-9_]*$"), - llvm::Regex("^[a-z][a-zA-Z0-9]*$"), - llvm::Regex("^[A-Z][A-Z0-9_]*$"), - llvm::Regex("^[A-Z][a-zA-Z0-9]*$"), - llvm::Regex("^[A-Z]([a-z0-9]*(_[A-Z])?)*"), - llvm::Regex("^[a-z]([a-z0-9]*(_[A-Z])?)*"), - llvm::Regex("^[A-Z][a-zA-Z0-9]*$"), - }; + static llvm::Regex Matchers[] = {llvm::Regex("^.*$"), + llvm::Regex("^[a-z][a-z0-9_]*$"), + llvm::Regex("^[a-z][a-zA-Z0-9]*$"), + llvm::Regex("^[A-Z][A-Z0-9_]*$"), + llvm::Regex("^[A-Z][a-zA-Z0-9]*$"), + llvm::Regex("^[A-Z]([a-z0-9]*(_[A-Z])?)*"), + llvm::Regex("^[a-z]([a-z0-9]*(_[A-Z])?)*")}; if (!Name.consume_front(Style.Prefix)) return false; if (!Name.consume_back(Style.Suffix)) return false; + if (IdentifierNamingCheck::HungarianPrefixOption::HPO_Off != + Style.HungarianPrefixOpt) { + auto HNPrefix = + getHungarianNotationPrefix(Decl, *Style.HungarianNotationOption); + if (!Name.consume_front(HNPrefix)) + return false; + } // Ensure the name doesn't have any extra underscores beyond those specified // in the prefix and suffix. if (Name.startswith("_") || Name.endswith("_")) return false; - if (Style.Case == IdentifierNamingCheck::CaseType::CT_HungarianNotation) { - const std::string TypePrefix = - getHungarianNotationTypePrefix(Type.str(), Decl); - if (TypePrefix.length() > 0) { - if (!Name.startswith(TypePrefix)) - return false; - Name = Name.drop_front(TypePrefix.size()); - } - } - if (Style.Case && !Matchers[static_cast(*Style.Case)].match(Name)) return false; return true; } -static std::string fixupWithCase(const StringRef &Type, const StringRef &Name, - const Decl *InputDecl, - IdentifierNamingCheck::CaseType Case) { +static std::string +fixupWithCase(const StringRef &Type, const StringRef &Name, const Decl *D, + const IdentifierNamingCheck::NamingStyle &Style, + IdentifierNamingCheck::CaseType Case) { static llvm::Regex Splitter( "([a-z0-9A-Z]*)(_+)|([A-Z]?[a-z0-9]+)([A-Z]|$)|([A-Z]+)([A-Z]|$)"); @@ -489,6 +934,11 @@ if (Words.empty()) return Name.str(); + if (IdentifierNamingCheck::HungarianPrefixOption::HPO_Off != + Style.HungarianPrefixOpt) + removeDuplicatedHungarianNotationPrefix(Words, + *Style.HungarianNotationOption); + SmallString<128> Fixup; switch (Case) { case IdentifierNamingCheck::CT_AnyCase: @@ -549,26 +999,8 @@ Fixup += Word.substr(1).lower(); } break; - - case IdentifierNamingCheck::CT_HungarianNotation: { - const NamedDecl *ND = dyn_cast(InputDecl); - const std::string TypePrefix = - getHungarianNotationTypePrefix(Type.str(), ND); - Fixup = TypePrefix; - for (size_t Idx = 0; Idx < Words.size(); Idx++) { - // Skip first part if it's a lowercase string. - if (Idx == 0) { - bool LowerAlnum = - std::all_of(Words[Idx].begin(), Words[Idx].end(), - [](const char C) { return isdigit(C) || islower(C); }); - if (LowerAlnum) - continue; - } - Fixup += Words[Idx]; - } - break; - } } + return Fixup.str().str(); } @@ -635,15 +1067,33 @@ static std::string fixupWithStyle(const StringRef &Type, const StringRef &Name, - const IdentifierNamingCheck::NamingStyle &Style, - const Decl *InputDecl) { - const std::string Fixed = fixupWithCase( - Type, Name, InputDecl, + const IdentifierNamingCheck::NamingStyle &Style, const Decl *D) { + std::string Fixed = fixupWithCase( + Type, Name, D, Style, Style.Case.getValueOr(IdentifierNamingCheck::CaseType::CT_AnyCase)); + + std::string HungarianPrefix; + if (IdentifierNamingCheck::HungarianPrefixOption::HPO_Off != + Style.HungarianPrefixOpt) { + HungarianPrefix = + getHungarianNotationPrefix(D, *Style.HungarianNotationOption); + if (!HungarianPrefix.empty()) { + if (Style.HungarianPrefixOpt == + IdentifierNamingCheck::HungarianPrefixOption::HPO_LowerCase) { + HungarianPrefix += "_"; + } + if (Style.HungarianPrefixOpt == + IdentifierNamingCheck::HungarianPrefixOption::HPO_CamelCase) { + Fixed[0] = toupper(Fixed[0]); + } + } + } + StringRef Mid = StringRef(Fixed).trim("_"); if (Mid.empty()) Mid = "_"; - return (Style.Prefix + Mid + Style.Suffix).str(); + + return (Style.Prefix + HungarianPrefix + Mid + Style.Suffix).str(); } static StyleKind findStyleKind( @@ -926,7 +1376,7 @@ } static llvm::Optional getFailureInfo( - const StringRef &Type, const StringRef &Name, const NamedDecl *Decl, + const StringRef &Type, const StringRef &Name, const NamedDecl *ND, SourceLocation Location, ArrayRef> NamingStyles, StyleKind SK, const SourceManager &SM, bool IgnoreFailedSplit) { @@ -934,14 +1384,14 @@ return None; const IdentifierNamingCheck::NamingStyle &Style = *NamingStyles[SK]; - if (matchesStyle(Type, Name, Style, Decl)) + if (matchesStyle(Type, Name, Style, ND)) return None; - std::string KindName = fixupWithCase(Type, StyleNames[SK], Decl, + std::string KindName = fixupWithCase(Type, StyleNames[SK], ND, Style, IdentifierNamingCheck::CT_LowerCase); std::replace(KindName.begin(), KindName.end(), '_', ' '); - std::string Fixup = fixupWithStyle(Type, Name, Style, Decl); + std::string Fixup = fixupWithStyle(Type, Name, Style, ND); if (StringRef(Fixup).equals(Name)) { if (!IgnoreFailedSplit) { LLVM_DEBUG(Location.print(llvm::dbgs(), SM); diff --git a/clang-tools-extra/docs/ReleaseNotes.rst b/clang-tools-extra/docs/ReleaseNotes.rst --- a/clang-tools-extra/docs/ReleaseNotes.rst +++ b/clang-tools-extra/docs/ReleaseNotes.rst @@ -123,9 +123,8 @@ - Improved :doc:`readability-identifier-naming ` check. - Added a casing types `szHungarianNotation` to support variables could be - checked with Hungarian Notation which the prefix encodes the actual data type - of the variable. + Added new options HungarianPrefix for variable decls to check variable with + Hungarian Notation which the prefix encodes the actual data type of the variable. - Removed `google-runtime-references` check because the rule it checks does not exist in the Google Style Guide anymore. diff --git a/clang-tools-extra/docs/clang-tidy/checks/readability-identifier-naming.rst b/clang-tools-extra/docs/clang-tidy/checks/readability-identifier-naming.rst --- a/clang-tools-extra/docs/clang-tidy/checks/readability-identifier-naming.rst +++ b/clang-tools-extra/docs/clang-tidy/checks/readability-identifier-naming.rst @@ -17,8 +17,7 @@ - ``CamelCase``, - ``camel_Snake_Back``, - ``Camel_Snake_Case``, - - ``aNy_CasE``, - - ``szHungarianNotation``. + - ``aNy_CasE``. It also supports a fixed prefix and suffix that will be prepended or appended to the identifiers, regardless of the casing. @@ -31,115 +30,157 @@ but not where they are overridden, as it can't be fixed locally there. This also applies for pseudo-override patterns like CRTP. -Hungarian Notation casing type ------------------------------- -In Hungarian notation, a variable name starts with a group of lower-case -letters which are mnemonics for the type or purpose of that variable, followed -by whatever name the programmer has chosen; this last part is sometimes -distinguished as the given name. The first character of the given name can be -capitalized to separate it from the type indicators (see also CamelCase). -Otherwise the case of this character denotes scope. +Hungarian prefix options include: + + - ``Off``, + - ``On``, + - ``sz_lower_case``, + - ``szCamelCase``. + +Example1 (CamelCase): + + Config: + + .. code-block:: python + + VariableCase: CamelCase + VariablePrefix: PRE_ + VariableSuffix: _POST + VariableHungarianPrefix: (`Off`|`On`|`sz_lower_case`|`szCamelCase`) + + Before: + + .. code-block:: c++ -============ ============= ================ ============= =========== ============== -Primitive Types Microsoft data types ---------------------------------------------------------- -------------------------- - Type Prefix Type Prefix Type Prefix -============ ============= ================ ============= =========== ============== -int8_t i8 short s BOOL b -int16_t i16 signed i BOOLEAN b -int32_t i32 unsigned u BYTE by -int64_t i64 long l WORD w -uint8_t u8 long long ll DWORD dw -uint16_t u16 unsigned long ul -uint32_t u32 long double ld -uint64_t u64 ptrdiff_t p -char8_t c8 -char16_t c16 -char32_t c32 -float f -double d -char c -bool b -_Bool b -int i -size_t n -============ ============= ================ ============= =========== ============== + bool lower_case = true; + bool UPPER_CASE = true; + bool CamelCase = true; + After: + .. code-block:: c++ -- **Pointer type starts with `p`,** + // VariableCase: CamelCase + // VariableHungarianPrefix: Off + bool PRE_LowerCase_POST = true; + bool PRE_UpperCase_POST = true; + bool PRE_CamelCase_POST = true; - .. code-block:: c++ + // VariableCase: CamelCase + // VariableHungarianPrefix: On + bool PRE_bLowerCase_POST = true; + bool PRE_bUpperCase_POST = true; + bool PRE_bCamelCase_POST = true; - void *pData = NULL; - void **ppData = NULL; - uint8_t *pu8Data = NULL; + // VariableCase: CamelCase + // VariableHungarianPrefix: sz_lower_case + bool PRE_b_LowerCase_POST = true; + bool PRE_b_UpperCase_POST = true; + bool PRE_b_CamelCase_POST = true; -- **Array type start with `a`,** + // VariableCase: CamelCase + // VariableHungarianPrefix: szCamelCase + bool PRE_bLowerCase_POST = true; + bool PRE_bUpperCase_POST = true; + bool PRE_bCamelCase_POST = true; - .. code-block:: c++ - int aDataInt[1] = {0}; - int* paDataIntPtr[1] = {0}; +Example2 (lower_case): -- **Null terminated string starts with `sz`** + Config: - .. code-block:: c++ + .. code-block:: python - char szNameArray[] = {"Text"}; - char *szNamePtr = {"Text"}; - char **pszNamePtr = {"Text"}; - + VariableCase: lower_case + VariablePrefix: PRE_ + VariableSuffix: _POST + VariableHungarianPrefix: (`Off`|`On`|`sz_lower_case`|`szCamelCase`) + + Before: + + .. code-block:: c++ + + bool lower_case = true; + bool UPPER_CASE = true; + bool CamelCase = true; + + After: + + .. code-block:: c++ + + // VariableCase: lower_case + // VariableHungarianPrefix: Off + bool PRE_lower_case_POST = true; + bool PRE_upper_case_POST = true; + bool PRE_camel_case_POST = true; + + // VariableCase: lower_case + // VariableHungarianPrefix: On + bool PRE_blower_case_POST = true; + bool PRE_bupper_case_POST = true; + bool PRE_bcamel_case_POST = true; + + // VariableCase: lower_case + // VariableHungarianPrefix: sz_lower_case + bool PRE_b_lower_case_POST = true; + bool PRE_b_upper_case_POST = true; + bool PRE_b_camel_case_POST = true; + + // VariableCase: lower_case + // VariableHungarianPrefix: szCamelCase + bool PRE_bLower_case_POST = true; + bool PRE_bUpper_case_POST = true; + bool PRE_bCamel_case_POST = true; Options ------- The following options are describe below: - - :option:`AbstractClassCase`, :option:`AbstractClassPrefix`, :option:`AbstractClassSuffix` + - :option:`AbstractClassCase`, :option:`AbstractClassPrefix`, :option:`AbstractClassSuffix`, :option:`AbstractClassHungarianPrefix` - :option:`AggressiveDependentMemberLookup` - - :option:`ClassCase`, :option:`ClassPrefix`, :option:`ClassSuffix` - - :option:`ClassConstantCase`, :option:`ClassConstantPrefix`, :option:`ClassConstantSuffix` - - :option:`ClassMemberCase`, :option:`ClassMemberPrefix`, :option:`ClassMemberSuffix` + - :option:`ClassCase`, :option:`ClassPrefix`, :option:`ClassSuffix`, :option:`ClassHungarianPrefix` + - :option:`ClassConstantCase`, :option:`ClassConstantPrefix`, :option:`ClassConstantSuffix`, :option:`ClassConstantHungarianPrefix` + - :option:`ClassMemberCase`, :option:`ClassMemberPrefix`, :option:`ClassMemberSuffix`, :option:`ClassMemberHungarianPrefix` - :option:`ClassMethodCase`, :option:`ClassMethodPrefix`, :option:`ClassMethodSuffix` - - :option:`ConstantCase`, :option:`ConstantPrefix`, :option:`ConstantSuffix` - - :option:`ConstantMemberCase`, :option:`ConstantMemberPrefix`, :option:`ConstantMemberSuffix` - - :option:`ConstantParameterCase`, :option:`ConstantParameterPrefix`, :option:`ConstantParameterSuffix` - - :option:`ConstantPointerParameterCase`, :option:`ConstantPointerParameterPrefix`, :option:`ConstantPointerParameterSuffix` + - :option:`ConstantCase`, :option:`ConstantPrefix`, :option:`ConstantSuffix`, :option:`ConstantHungarianPrefix` + - :option:`ConstantMemberCase`, :option:`ConstantMemberPrefix`, :option:`ConstantMemberSuffix`, :option:`ConstantMemberHungarianPrefix` + - :option:`ConstantParameterCase`, :option:`ConstantParameterPrefix`, :option:`ConstantParameterSuffix`, :option:`ConstantParameterHungarianPrefix` + - :option:`ConstantPointerParameterCase`, :option:`ConstantPointerParameterPrefix`, :option:`ConstantPointerParameterSuffix`, :option:`ConstantPointerParameterHungarianPrefix` - :option:`ConstexprFunctionCase`, :option:`ConstexprFunctionPrefix`, :option:`ConstexprFunctionSuffix` - - :option:`ConstexprMethodCase`, :option:`ConstexprMethodPrefix`, :option:`ConstexprMethodSuffix` - - :option:`ConstexprVariableCase`, :option:`ConstexprVariablePrefix`, :option:`ConstexprVariableSuffix` + - :option:`ConstexprMethodCase`, :option:`ConstexprMethodPrefix` :option:`ConstexprMethodSuffix` + - :option:`ConstexprVariableCase`, :option:`ConstexprVariablePrefix`, :option:`ConstexprVariableSuffix`, :option:`ConstexprVariableHungarianPrefix` - :option:`EnumCase`, :option:`EnumPrefix`, :option:`EnumSuffix` - - :option:`EnumConstantCase`, :option:`EnumConstantPrefix`, :option:`EnumConstantSuffix` + - :option:`EnumConstantCase`, :option:`EnumConstantPrefix`, :option:`EnumConstantSuffix`, :option:`EnumConstantHungarianPrefix` - :option:`FunctionCase`, :option:`FunctionPrefix`, :option:`FunctionSuffix` - :option:`GetConfigPerFile` - - :option:`GlobalConstantCase`, :option:`GlobalConstantPrefix`, :option:`GlobalConstantSuffix` - - :option:`GlobalConstantPointerCase`, :option:`GlobalConstantPointerPrefix`, :option:`GlobalConstantPointerSuffix` + - :option:`GlobalConstantCase`, :option:`GlobalConstantPrefix`, :option:`GlobalConstantSuffix`, :option:`GlobalConstantHungarianPrefix` + - :option:`GlobalConstantPointerCase`, :option:`GlobalConstantPointerPrefix`, :option:`GlobalConstantPointerSuffix`, :option:`GlobalConstantPointerHungarianPrefix` - :option:`GlobalFunctionCase`, :option:`GlobalFunctionPrefix`, :option:`GlobalFunctionSuffix` - - :option:`GlobalPointerCase`, :option:`GlobalPointerPrefix`, :option:`GlobalPointerSuffix` - - :option:`GlobalVariableCase`, :option:`GlobalVariablePrefix`, :option:`GlobalVariableSuffix` + - :option:`GlobalPointerCase`, :option:`GlobalPointerPrefix`, :option:`GlobalPointerSuffix`, :option:`GlobalPointerHungarianPrefix` + - :option:`GlobalVariableCase`, :option:`GlobalVariablePrefix`, :option:`GlobalVariableSuffix`, :option:`GlobalVariableHungarianPrefix` - :option:`IgnoreMainLikeFunctions` - :option:`InlineNamespaceCase`, :option:`InlineNamespacePrefix`, :option:`InlineNamespaceSuffix` - - :option:`LocalConstantCase`, :option:`LocalConstantPrefix`, :option:`LocalConstantSuffix` - - :option:`LocalConstantPointerCase`, :option:`LocalConstantPointerPrefix`, :option:`LocalConstantPointerSuffix` - - :option:`LocalPointerCase`, :option:`LocalPointerPrefix`, :option:`LocalPointerSuffix` - - :option:`LocalVariableCase`, :option:`LocalVariablePrefix`, :option:`LocalVariableSuffix` + - :option:`LocalConstantCase`, :option:`LocalConstantPrefix`, :option:`LocalConstantSuffix`, :option:`LocalConstantHungarianPrefix` + - :option:`LocalConstantPointerCase`, :option:`LocalConstantPointerPrefix`, :option:`LocalConstantPointerSuffix`, :option:`LocalConstantPointerHungarianPrefix` + - :option:`LocalPointerCase`, :option:`LocalPointerPrefix`, :option:`LocalPointerSuffix`, :option:`LocalPointerHungarianPrefix` + - :option:`LocalVariableCase`, :option:`LocalVariablePrefix`, :option:`LocalVariableSuffix`, :option:`LocalVariableHungarianPrefix` - :option:`MacroDefinitionCase`, :option:`MacroDefinitionPrefix`, :option:`MacroDefinitionSuffix` - - :option:`MemberCase`, :option:`MemberPrefix`, :option:`MemberSuffix` + - :option:`MemberCase`, :option:`MemberPrefix`, :option:`MemberSuffix`, :option:`MemberHungarianPrefix` - :option:`MethodCase`, :option:`MethodPrefix`, :option:`MethodSuffix` - :option:`NamespaceCase`, :option:`NamespacePrefix`, :option:`NamespaceSuffix` - - :option:`ParameterCase`, :option:`ParameterPrefix`, :option:`ParameterSuffix` + - :option:`ParameterCase`, :option:`ParameterPrefix`, :option:`ParameterSuffix`, :option:`ParameterHungarianPrefix` - :option:`ParameterPackCase`, :option:`ParameterPackPrefix`, :option:`ParameterPackSuffix` - - :option:`PointerParameterCase`, :option:`PointerParameterPrefix`, :option:`PointerParameterSuffix` - - :option:`PrivateMemberCase`, :option:`PrivateMemberPrefix`, :option:`PrivateMemberSuffix` + - :option:`PointerParameterCase`, :option:`PointerParameterPrefix`, :option:`PointerParameterSuffix`, :option:`PointerParameterHungarianPrefix` + - :option:`PrivateMemberCase`, :option:`PrivateMemberPrefix`, :option:`PrivateMemberSuffix`, :option:`PrivateMemberHungarianPrefix` - :option:`PrivateMethodCase`, :option:`PrivateMethodPrefix`, :option:`PrivateMethodSuffix` - - :option:`ProtectedMemberCase`, :option:`ProtectedMemberPrefix`, :option:`ProtectedMemberSuffix` + - :option:`ProtectedMemberCase`, :option:`ProtectedMemberPrefix`, :option:`ProtectedMemberSuffix`, :option:`ProtectedMemberHungarianPrefix` - :option:`ProtectedMethodCase`, :option:`ProtectedMethodPrefix`, :option:`ProtectedMethodSuffix` - - :option:`PublicMemberCase`, :option:`PublicMemberPrefix`, :option:`PublicMemberSuffix` + - :option:`PublicMemberCase`, :option:`PublicMemberPrefix`, :option:`PublicMemberSuffix`, :option:`PublicMemberHungarianPrefix` - :option:`PublicMethodCase`, :option:`PublicMethodPrefix`, :option:`PublicMethodSuffix` - - :option:`StaticConstantCase`, :option:`StaticConstantPrefix`, :option:`StaticConstantSuffix` - - :option:`StaticVariableCase`, :option:`StaticVariablePrefix`, :option:`StaticVariableSuffix` + - :option:`StaticConstantCase`, :option:`StaticConstantPrefix`, :option:`StaticConstantSuffix`, :option:`StaticConstantHungarianPrefix` + - :option:`StaticVariableCase`, :option:`StaticVariablePrefix`, :option:`StaticVariableSuffix`, :option:`StaticVariableHungarianPrefix` - :option:`StructCase`, :option:`StructPrefix`, :option:`StructSuffix` - :option:`TemplateParameterCase`, :option:`TemplateParameterPrefix`, :option:`TemplateParameterSuffix` - :option:`TemplateTemplateParameterCase`, :option:`TemplateTemplateParameterPrefix`, :option:`TemplateTemplateParameterSuffix` @@ -148,7 +189,7 @@ - :option:`TypeTemplateParameterCase`, :option:`TypeTemplateParameterPrefix`, :option:`TypeTemplateParameterSuffix` - :option:`UnionCase`, :option:`UnionPrefix`, :option:`UnionSuffix` - :option:`ValueTemplateParameterCase`, :option:`ValueTemplateParameterPrefix`, :option:`ValueTemplateParameterSuffix` - - :option:`VariableCase`, :option:`VariablePrefix`, :option:`VariableSuffix` + - :option:`VariableCase`, :option:`VariablePrefix`, :option:`VariableSuffix`, :option:`VariableHungarianPrefix` - :option:`VirtualMethodCase`, :option:`VirtualMethodPrefix`, :option:`VirtualMethodSuffix` .. option:: AbstractClassCase @@ -166,11 +207,18 @@ When defined, the check will ensure abstract class names will add the suffix with the given value (regardless of casing). +.. option:: AbstractClassHungarianPrefix + + When set to `true` the check will ensure the name will add Hungarian Notation + prefix for the given data type. The default value is `Off`. + For example using values of: - AbstractClassCase of ``lower_case`` - AbstractClassPrefix of ``pre_`` - AbstractClassSuffix of ``_post`` + - AbstractClassHungarianPrefix of ``On`` + Identifies and/or transforms abstract class names as follows: @@ -265,11 +313,17 @@ When defined, the check will ensure class names will add the suffix with the given value (regardless of casing). +.. option:: ClassHungarianPrefix + + When set to `true` the check will ensure the name will add Hungarian Notation + prefix for the given data type. The default value is `Off`. + For example using values of: - ClassCase of ``lower_case`` - ClassPrefix of ``pre_`` - ClassSuffix of ``_post`` + - ClassHungarianPrefix of ``On`` Identifies and/or transforms class names as follows: @@ -308,11 +362,17 @@ When defined, the check will ensure class constant names will add the suffix with the given value (regardless of casing). +.. option:: ClassConstantHungarianPrefix + + When set to `true` the check will ensure the name will add Hungarian Notation + prefix for the given data type. The default value is `Off`. + For example using values of: - ClassConstantCase of ``lower_case`` - ClassConstantPrefix of ``pre_`` - ClassConstantSuffix of ``_post`` + - ClassConstantHungarianPrefix of ``On`` Identifies and/or transforms class constant names as follows: @@ -349,11 +409,17 @@ When defined, the check will ensure class member names will add the suffix with the given value (regardless of casing). +.. option:: ClassMemberHungarianPrefix + + When set to `true` the check will ensure the name will add Hungarian Notation + prefix for the given data type. The default value is `Off`. + For example using values of: - ClassMemberCase of ``lower_case`` - ClassMemberPrefix of ``pre_`` - ClassMemberSuffix of ``_post`` + - ClassMemberHungarianPrefix of ``On`` Identifies and/or transforms class member names as follows: @@ -390,11 +456,17 @@ When defined, the check will ensure class method names will add the suffix with the given value (regardless of casing). +.. option:: ClassMethodHungarianPrefix + + When set to `true` the check will ensure the name will add Hungarian Notation + prefix for the given data type. The default value is `Off`. + For example using values of: - ClassMethodCase of ``lower_case`` - ClassMethodPrefix of ``pre_`` - ClassMethodSuffix of ``_post`` + - ClassMethodHungarianPrefix of ``On`` Identifies and/or transforms class method names as follows: @@ -431,11 +503,17 @@ When defined, the check will ensure constant names will add the suffix with the given value (regardless of casing). +.. option:: ConstantHungarianPrefix + + When set to `true` the check will ensure the name will add Hungarian Notation + prefix for the given data type. The default value is `Off`. + For example using values of: - ConstantCase of ``lower_case`` - ConstantPrefix of ``pre_`` - ConstantSuffix of ``_post`` + - ConstantHungarianPrefix of ``On`` Identifies and/or transforms constant names as follows: @@ -466,11 +544,17 @@ When defined, the check will ensure constant member names will add the suffix with the given value (regardless of casing). +.. option:: ConstantMemberHungarianPrefix + + When set to `true` the check will ensure the name will add Hungarian Notation + prefix for the given data type. The default value is `Off`. + For example using values of: - ConstantMemberCase of ``lower_case`` - ConstantMemberPrefix of ``pre_`` - ConstantMemberSuffix of ``_post`` + - ConstantMemberHungarianPrefix of ``On`` Identifies and/or transforms constant member names as follows: @@ -505,11 +589,17 @@ When defined, the check will ensure constant parameter names will add the suffix with the given value (regardless of casing). +.. option:: ConstantParameterHungarianPrefix + + When set to `true` the check will ensure the name will add Hungarian Notation + prefix for the given data type. The default value is `Off`. + For example using values of: - ConstantParameterCase of ``lower_case`` - ConstantParameterPrefix of ``pre_`` - ConstantParameterSuffix of ``_post`` + - ConstantParameterHungarianPrefix of ``On`` Identifies and/or transforms constant parameter names as follows: @@ -540,11 +630,17 @@ When defined, the check will ensure constant pointer parameter names will add the suffix with the given value (regardless of casing). +.. option:: ConstantPointerParameterHungarianPrefix + + When set to `true` the check will ensure the name will add Hungarian Notation + prefix for the given data type. The default value is `Off`. + For example using values of: - ConstantPointerParameterCase of ``lower_case`` - ConstantPointerParameterPrefix of ``pre_`` - ConstantPointerParameterSuffix of ``_post`` + - ConstantPointerParameterHungarianPrefix of ``On`` Identifies and/or transforms constant pointer parameter names as follows: @@ -651,11 +747,17 @@ When defined, the check will ensure constexpr variable names will add the suffix with the given value (regardless of casing). +.. option:: ConstexprVariableHungarianPrefix + + When set to `true` the check will ensure the name will add Hungarian Notation + prefix for the given data type. The default value is `Off`. + For example using values of: - ConstexprVariableCase of ``lower_case`` - ConstexprVariablePrefix of ``pre_`` - ConstexprVariableSuffix of ``_post`` + - ConstexprVariableHungarianPrefix of ``On`` Identifies and/or transforms constexpr variable names as follows: @@ -721,11 +823,17 @@ When defined, the check will ensure enumeration constant names will add the suffix with the given value (regardless of casing). +.. option:: EnumConstantHungarianPrefix + + When set to `true` the check will ensure the name will add Hungarian Notation + prefix for the given data type. The default value is `Off`. + For example using values of: - EnumConstantCase of ``lower_case`` - EnumConstantPrefix of ``pre_`` - EnumConstantSuffix of ``_post`` + - EnumConstantHungarianPrefix of ``On`` Identifies and/or transforms enumeration constant names as follows: @@ -779,8 +887,8 @@ .. option:: GetConfigPerFile When `true` the check will look for the configuration for where an - identifier is declared. Useful for when included header files use a - different style. + identifier is declared. Useful for when included header files use a + different style. Default value is `true`. .. option:: GlobalConstantCase @@ -798,11 +906,17 @@ When defined, the check will ensure global constant names will add the suffix with the given value (regardless of casing). +.. option:: GlobalConstantHungarianPrefix + + When set to `true` the check will ensure the name will add Hungarian Notation + prefix for the given data type. The default value is `Off`. + For example using values of: - GlobalConstantCase of ``lower_case`` - GlobalConstantPrefix of ``pre_`` - GlobalConstantSuffix of ``_post`` + - GlobalConstantHungarianPrefix of ``On`` Identifies and/or transforms global constant names as follows: @@ -833,11 +947,17 @@ When defined, the check will ensure global constant pointer names will add the suffix with the given value (regardless of casing). +.. option:: GlobalConstantPointerHungarianPrefix + + When set to `true` the check will ensure the name will add Hungarian Notation + prefix for the given data type. The default value is `Off`. + For example using values of: - GlobalConstantPointerCase of ``lower_case`` - GlobalConstantPointerPrefix of ``pre_`` - GlobalConstantPointerSuffix of ``_post`` + - GlobalConstantPointerHungarianPrefix of ``On`` Identifies and/or transforms global constant pointer names as follows: @@ -903,11 +1023,17 @@ When defined, the check will ensure global pointer names will add the suffix with the given value (regardless of casing). +.. option:: GlobalPointerHungarianPrefix + + When set to `true` the check will ensure the name will add Hungarian Notation + prefix for the given data type. The default value is `Off`. + For example using values of: - GlobalPointerCase of ``lower_case`` - GlobalPointerPrefix of ``pre_`` - GlobalPointerSuffix of ``_post`` + - GlobalPointerHungarianPrefix of ``On`` Identifies and/or transforms global pointer names as follows: @@ -938,11 +1064,17 @@ When defined, the check will ensure global variable names will add the suffix with the given value (regardless of casing). +.. option:: GlobalVariableHungarianPrefix + + When set to `true` the check will ensure the name will add Hungarian Notation + prefix for the given data type. The default value is `Off`. + For example using values of: - GlobalVariableCase of ``lower_case`` - GlobalVariablePrefix of ``pre_`` - GlobalVariableSuffix of ``_post`` + - GlobalVariableHungarianPrefix of ``On`` Identifies and/or transforms global variable names as follows: @@ -960,7 +1092,7 @@ .. option:: IgnoreMainLikeFunctions - When set to `1` functions that have a similar signature to ``main`` or + When set to `1` functions that have a similar signature to ``main`` or ``wmain`` won't enforce checks on the names of their parameters. Default value is `0`. @@ -1022,11 +1154,17 @@ When defined, the check will ensure local constant names will add the suffix with the given value (regardless of casing). +.. option:: LocalConstantHungarianPrefix + + When set to `true` the check will ensure the name will add Hungarian Notation + prefix for the given data type. The default value is `Off`. + For example using values of: - LocalConstantCase of ``lower_case`` - LocalConstantPrefix of ``pre_`` - LocalConstantSuffix of ``_post`` + - LocalConstantHungarianPrefix of ``On`` Identifies and/or transforms local constant names as follows: @@ -1057,11 +1195,17 @@ When defined, the check will ensure local constant pointer names will add the suffix with the given value (regardless of casing). +.. option:: LocalConstantPointerHungarianPrefix + + When set to `true` the check will ensure the name will add Hungarian Notation + prefix for the given data type. The default value is `Off`. + For example using values of: - LocalConstantPointerCase of ``lower_case`` - LocalConstantPointerPrefix of ``pre_`` - LocalConstantPointerSuffix of ``_post`` + - LocalConstantPointerHungarianPrefix of ``On`` Identifies and/or transforms local constant pointer names as follows: @@ -1092,11 +1236,17 @@ When defined, the check will ensure local pointer names will add the suffix with the given value (regardless of casing). +.. option:: LocalPointerHungarianPrefix + + When set to `true` the check will ensure the name will add Hungarian Notation + prefix for the given data type. The default value is `Off`. + For example using values of: - LocalPointerCase of ``lower_case`` - LocalPointerPrefix of ``pre_`` - LocalPointerSuffix of ``_post`` + - LocalPointerHungarianPrefix of ``On`` Identifies and/or transforms local pointer names as follows: @@ -1127,11 +1277,17 @@ When defined, the check will ensure local variable names will add the suffix with the given value (regardless of casing). +.. option:: LocalVariableHungarianPrefix + + When set to `true` the check will ensure the name will add Hungarian Notation + prefix for the given data type. The default value is `Off`. + For example using values of: - LocalVariableCase of ``lower_case`` - LocalVariablePrefix of ``pre_`` - LocalVariableSuffix of ``_post`` + - LocalVariableHungarianPrefix of ``On`` Identifies and/or transforms local variable names as follows: @@ -1200,11 +1356,17 @@ When defined, the check will ensure member names will add the suffix with the given value (regardless of casing). +.. option:: MemberHungarianPrefix + + When set to `true` the check will ensure the name will add Hungarian Notation + prefix for the given data type. The default value is `Off`. + For example using values of: - MemberCase of ``lower_case`` - MemberPrefix of ``pre_`` - MemberSuffix of ``_post`` + - MemberHungarianPrefix of ``On`` Identifies and/or transforms member names as follows: @@ -1317,11 +1479,17 @@ When defined, the check will ensure parameter names will add the suffix with the given value (regardless of casing). +.. option:: ParameterHungarianPrefix + + When set to `true` the check will ensure the name will add Hungarian Notation + prefix for the given data type. The default value is `Off`. + For example using values of: - ParameterCase of ``lower_case`` - ParameterPrefix of ``pre_`` - ParameterSuffix of ``_post`` + - ParameterHungarianPrefix of ``On`` Identifies and/or transforms parameter names as follows: @@ -1391,11 +1559,17 @@ When defined, the check will ensure pointer parameter names will add the suffix with the given value (regardless of casing). +.. option:: PointerParameterHungarianPrefix + + When set to `true` the check will ensure the name will add Hungarian Notation + prefix for the given data type. The default value is `Off`. + For example using values of: - PointerParameterCase of ``lower_case`` - PointerParameterPrefix of ``pre_`` - PointerParameterSuffix of ``_post`` + - PointerParameterHungarianPrefix of ``On`` Identifies and/or transforms pointer parameter names as follows: @@ -1426,11 +1600,17 @@ When defined, the check will ensure private member names will add the suffix with the given value (regardless of casing). +.. option:: PrivateMemberHungarianPrefix + + When set to `true` the check will ensure the name will add Hungarian Notation + prefix for the given data type. The default value is `Off`. + For example using values of: - PrivateMemberCase of ``lower_case`` - PrivateMemberPrefix of ``pre_`` - PrivateMemberSuffix of ``_post`` + - PrivateMemberHungarianPrefix of ``On`` Identifies and/or transforms private member names as follows: @@ -1467,11 +1647,17 @@ When defined, the check will ensure private method names will add the suffix with the given value (regardless of casing). +.. option:: PrivateMethodHungarianPrefix + + When set to `true` the check will ensure the name will add Hungarian Notation + prefix for the given data type. The default value is `Off`. + For example using values of: - PrivateMethodCase of ``lower_case`` - PrivateMethodPrefix of ``pre_`` - PrivateMethodSuffix of ``_post`` + - PrivateMethodHungarianPrefix of ``On`` Identifies and/or transforms private method names as follows: @@ -1508,11 +1694,17 @@ When defined, the check will ensure protected member names will add the suffix with the given value (regardless of casing). +.. option:: ProtectedMemberHungarianPrefix + + When set to `true` the check will ensure the name will add Hungarian Notation + prefix for the given data type. The default value is `Off`. + For example using values of: - ProtectedMemberCase of ``lower_case`` - ProtectedMemberPrefix of ``pre_`` - ProtectedMemberSuffix of ``_post`` + - ProtectedMemberHungarianPrefix of ``On`` Identifies and/or transforms protected member names as follows: @@ -1590,11 +1782,17 @@ When defined, the check will ensure public member names will add the suffix with the given value (regardless of casing). +.. option:: PublicMemberHungarianPrefix + + When set to `true` the check will ensure the name will add Hungarian Notation + prefix for the given data type. The default value is `Off`. + For example using values of: - PublicMemberCase of ``lower_case`` - PublicMemberPrefix of ``pre_`` - PublicMemberSuffix of ``_post`` + - PublicMemberHungarianPrefix of ``On`` Identifies and/or transforms public member names as follows: @@ -1672,11 +1870,17 @@ When defined, the check will ensure static constant names will add the suffix with the given value (regardless of casing). +.. option:: StaticConstantHungarianPrefix + + When set to `true` the check will ensure the name will add Hungarian Notation + prefix for the given data type. The default value is `Off`. + For example using values of: - StaticConstantCase of ``lower_case`` - StaticConstantPrefix of ``pre_`` - StaticConstantSuffix of ``_post`` + - StaticConstantHungarianPrefix of ``On`` Identifies and/or transforms static constant names as follows: @@ -1707,11 +1911,17 @@ When defined, the check will ensure static variable names will add the suffix with the given value (regardless of casing). +.. option:: StaticVariableHungarianPrefix + + When set to `true` the check will ensure the name will add Hungarian Notation + prefix for the given data type. The default value is `Off`. + For example using values of: - StaticVariableCase of ``lower_case`` - StaticVariablePrefix of ``pre_`` - StaticVariableSuffix of ``_post`` + - StaticVariableHungarianPrefix of ``On`` Identifies and/or transforms static variable names as follows: @@ -2040,11 +2250,17 @@ When defined, the check will ensure variable names will add the suffix with the given value (regardless of casing). +.. option:: VariableHungarianPrefix + + When set to `true` the check will ensure the name will add Hungarian Notation + prefix for the given data type. The default value is `Off`. + For example using values of: - VariableCase of ``lower_case`` - VariablePrefix of ``pre_`` - VariableSuffix of ``_post`` + - VariableHungarianPrefix of ``On`` Identifies and/or transforms variable names as follows: @@ -2100,3 +2316,243 @@ public: virtual int pre_member_function_post(); } + + +The default mapping table of Hungarian Notation +----------------------------------------------- + +In Hungarian notation, a variable name starts with a group of lower-case +letters which are mnemonics for the type or purpose of that variable, followed +by whatever name the programmer has chosen; this last part is sometimes +distinguished as the given name. The first character of the given name can be +capitalized to separate it from the type indicators (see also CamelCase). +Otherwise the case of this character denotes scope. + +This tool supports all casing types that means not only CamelCase starts with +Hungarian Notation, others either. + +The following table is the default mapping table of Hungarian Notation which +maps Decl to its prefix string. You can also have your own style in config file. + +================= ============== ====================== ============== =========== ============== +Primitive Types Microsoft data types +---------------------------------------------------------------------- -------------------------- + Type Prefix Type Prefix Type Prefix +================= ============== ====================== ============== =========== ============== +int8_t i8 signed int si BOOL b +int16_t i16 signed short ss BOOLEAN b +int32_t i32 signed short int ssi BYTE by +int64_t i64 signed long long int slli CHAR c +uint8_t u8 signed long long sll UCHAR uc +uint16_t u16 signed long int sli SHORT s +uint32_t u32 signed long sl USHORT us +uint64_t u64 signed s WORD w +char8_t c8 unsigned long long int ulli DWORD dw +char16_t c16 unsigned long long ull DWORD32 dw32 +char32_t c32 unsigned long int uli DWORD64 dw64 +float f unsigned long ul LONG l +double d unsigned short int usi ULONG ul +char c unsigned short us ULONG32 ul32 +bool b unsigned int ui ULONG64 ul64 +_Bool b unsigned u ULONGLONG ull +int i long long int lli HANDLE h +size_t n long double ld INT i +short s long long ll INT8 i8 +signed i long int li INT16 i16 +unsigned u long l INT32 i32 +long l ptrdiff_t p INT64 i64 +long long ll UINT ui +unsigned long ul UINT8 u8 +long double ld UINT16 u16 +ptrdiff_t p UINT32 u32 +wchar_t wc UINT64 u64 +short int si PVOID p +short s +================= ============== ====================== ============== =========== ============== + +**There are more trivial options for Hungarian Notation:** + +**HungarianNotation.General.*** + Options are not belonging to any specific Decl. + +**HungarianNotation.CString.*** + Options for NULL terminated string, you can customized your prefix here. + +**HungarianNotation.DerivedType.*** + Options for derived types, you can customized your prefix here. + +**HungarianNotation.PrimitiveType.*** + Options for primitive types, you can customized your prefix here. + +**HungarianNotation.UserDefinedType.*** + Options for redefined types(Microsoft data types), you can customized your + prefix here. + + +Options for Hungarian Notation +------------------------------ + +- :option:`HungarianNotation.General.TreatStructAsClass` + +- :option:`HungarianNotation.DerivedType.Array` +- :option:`HungarianNotation.DerivedType.Pointer` +- :option:`HungarianNotation.DerivedType.FunctionPointer` + +- :option:`HungarianNotation.CString.CharPrinter` +- :option:`HungarianNotation.CString.CharArray` +- :option:`HungarianNotation.CString.WideCharPrinter` +- :option:`HungarianNotation.CString.WideCharArray` + +- :option:`HungarianNotation.PrimitiveType.*` +- :option:`HungarianNotation.UserDefinedType.*` + +.. option:: HungarianNotation.General.TreatStructAsClass + + When defined, the check will treat naming of struct as a class. + The default value is `false`. + +.. option:: HungarianNotation.DerivedType.Array + + When defined, the check will ensure variable name will add the prefix with + the given string. The default prefix is `a`. + +.. option:: HungarianNotation.DerivedType.Pointer + + When defined, the check will ensure variable name will add the prefix with + the given string. The default prefix is `p`. + +.. option:: HungarianNotation.DerivedType.FunctionPointer + + When defined, the check will ensure variable name will add the prefix with + the given string. The default prefix is `fn`. + + +Before: + +.. code-block:: c++ + + // Array + int DataArray[2] = {0}; + + // Pointer + void *DataBuffer = NULL; + + // FunctionPointer + typedef void (*FUNC_PTR)(); + FUNC_PTR FuncPtr = NULL; + +After: + +.. code-block:: c++ + + // Array + int aDataArray[2] = {0}; + + // Pointer + void *pDataBuffer = NULL; + + // FunctionPointer + typedef void (*FUNC_PTR)(); + FUNC_PTR fnFuncPtr = NULL; + + +.. option:: HungarianNotation.CString.CharPrinter + + When defined, the check will ensure variable name will add the prefix with + the given string. The default prefix is `sz`. + +.. option:: HungarianNotation.CString.CharArray + + When defined, the check will ensure variable name will add the prefix with + the given string. The default prefix is `sz`. + +.. option:: HungarianNotation.CString.WideCharPrinter + + When defined, the check will ensure variable name will add the prefix with + the given string. The default prefix is `wsz`. + +.. option:: HungarianNotation.CString.WideCharArray + + When defined, the check will ensure variable name will add the prefix with + the given string. The default prefix is `wsz`. + + +Before: + +.. code-block:: c++ + + // CharPrinter + const char *NamePtr = "Name"; + + // CharArray + const char NameArray[] = "Name"; + + // WideCharPrinter + const wchar_t *WideNamePtr = L"Name"; + + // WideCharArray + const wchar_t WideNameArray[] = L"Name"; + +After: + +.. code-block:: c++ + + // CharPrinter + const char *szNamePtr = "Name"; + + // CharArray + const char szNameArray[] = "Name"; + + // WideCharPrinter + const wchar_t *wszWideNamePtr = L"Name"; + + // WideCharArray + const wchar_t wszWideNameArray[] = L"Name"; + + +.. option:: HungarianNotation.PrimitiveType.* + + When defined, the check will ensure variable name of involved primitive + types will add the prefix with the given string. The default prefixes are + defined in the default mapping table. + +.. option:: HungarianNotation.UserDefinedType.* + + When defined, the check will ensure variable name of involved primitive + types will add the prefix with the given string. The default prefixes are + defined in the default mapping table. + + +Before: + +.. code-block:: c++ + + int8_t ValueI8 = 0; + int16_t ValueI16 = 0; + int32_t ValueI32 = 0; + int64_t ValueI64 = 0; + uint8_t ValueU8 = 0; + uint16_t ValueU16 = 0; + uint32_t ValueU32 = 0; + uint64_t ValueU64 = 0; + float ValueFloat = 0.0; + double ValueDouble = 0.0; + ULONG ValueUlong = 0; + DWORD ValueDword = 0; + +After: + +.. code-block:: c++ + + int8_t i8ValueI8 = 0; + int16_t i16ValueI16 = 0; + int32_t i32ValueI32 = 0; + int64_t i64ValueI64 = 0; + uint8_t u8ValueU8 = 0; + uint16_t u16ValueU16 = 0; + uint32_t u32ValueU32 = 0; + uint64_t u64ValueU64 = 0; + float fValueFloat = 0.0; + double dValueDouble = 0.0; + ULONG ulValueUlong = 0; + DWORD dwValueDword = 0; diff --git a/clang-tools-extra/test/clang-tidy/checkers/readability-identifier-naming-hungarian-notation-cfgfile.cpp b/clang-tools-extra/test/clang-tidy/checkers/readability-identifier-naming-hungarian-notation-cfgfile.cpp new file mode 100644 --- /dev/null +++ b/clang-tools-extra/test/clang-tidy/checkers/readability-identifier-naming-hungarian-notation-cfgfile.cpp @@ -0,0 +1,810 @@ +// RUN: %check_clang_tidy %s readability-identifier-naming %t -- \ +// RUN: -config='{ CheckOptions: [ \ +// RUN: { key: readability-identifier-naming.ClassCase , value: CamelCase }, \ +// RUN: { key: readability-identifier-naming.AbstractClassCase , value: CamelCase }, \ +// RUN: { key: readability-identifier-naming.ClassMemberCase , value: CamelCase }, \ +// RUN: { key: readability-identifier-naming.ConstantCase , value: CamelCase }, \ +// RUN: { key: readability-identifier-naming.ConstantMemberCase , value: CamelCase }, \ +// RUN: { key: readability-identifier-naming.ConstantParameterCase , value: CamelCase }, \ +// RUN: { key: readability-identifier-naming.ConstantPointerParameterCase , value: CamelCase }, \ +// RUN: { key: readability-identifier-naming.ConstexprVariableCase , value: CamelCase }, \ +// RUN: { key: readability-identifier-naming.GlobalConstantCase , value: CamelCase }, \ +// RUN: { key: readability-identifier-naming.GlobalConstantPointerCase , value: CamelCase }, \ +// RUN: { key: readability-identifier-naming.GlobalVariableCase , value: CamelCase }, \ +// RUN: { key: readability-identifier-naming.LocalConstantCase , value: CamelCase }, \ +// RUN: { key: readability-identifier-naming.LocalConstantPointerCase , value: CamelCase }, \ +// RUN: { key: readability-identifier-naming.LocalPointerCase , value: CamelCase }, \ +// RUN: { key: readability-identifier-naming.LocalVariableCase , value: CamelCase }, \ +// RUN: { key: readability-identifier-naming.MemberCase , value: CamelCase }, \ +// RUN: { key: readability-identifier-naming.ParameterCase , value: CamelCase }, \ +// RUN: { key: readability-identifier-naming.PointerParameterCase , value: CamelCase }, \ +// RUN: { key: readability-identifier-naming.PrivateMemberCase , value: CamelCase }, \ +// RUN: { key: readability-identifier-naming.StaticConstantCase , value: CamelCase }, \ +// RUN: { key: readability-identifier-naming.StaticVariableCase , value: CamelCase }, \ +// RUN: { key: readability-identifier-naming.StructCase , value: CamelCase }, \ +// RUN: { key: readability-identifier-naming.UnionCase , value: CamelCase }, \ +// RUN: { key: readability-identifier-naming.VariableCase , value: CamelCase }, \ +// RUN: { key: readability-identifier-naming.ClassHungarianPrefix , value: On }, \ +// RUN: { key: readability-identifier-naming.AbstractClassHungarianPrefix , value: On }, \ +// RUN: { key: readability-identifier-naming.ClassMemberHungarianPrefix , value: On }, \ +// RUN: { key: readability-identifier-naming.ConstantHungarianPrefix , value: On }, \ +// RUN: { key: readability-identifier-naming.ConstantMemberHungarianPrefix , value: On }, \ +// RUN: { key: readability-identifier-naming.ConstantParameterHungarianPrefix , value: On }, \ +// RUN: { key: readability-identifier-naming.ConstantPointerParameterHungarianPrefix , value: On }, \ +// RUN: { key: readability-identifier-naming.ConstexprVariableHungarianPrefix , value: On }, \ +// RUN: { key: readability-identifier-naming.GlobalConstantHungarianPrefix , value: On }, \ +// RUN: { key: readability-identifier-naming.GlobalConstantPointerHungarianPrefix , value: On }, \ +// RUN: { key: readability-identifier-naming.GlobalVariableHungarianPrefix , value: On }, \ +// RUN: { key: readability-identifier-naming.LocalConstantHungarianPrefix , value: On }, \ +// RUN: { key: readability-identifier-naming.LocalConstantPointerHungarianPrefix , value: On }, \ +// RUN: { key: readability-identifier-naming.LocalPointerHungarianPrefix , value: On }, \ +// RUN: { key: readability-identifier-naming.LocalVariableHungarianPrefix , value: On }, \ +// RUN: { key: readability-identifier-naming.MemberHungarianPrefix , value: On }, \ +// RUN: { key: readability-identifier-naming.ParameterHungarianPrefix , value: On }, \ +// RUN: { key: readability-identifier-naming.PointerParameterHungarianPrefix , value: On }, \ +// RUN: { key: readability-identifier-naming.PrivateMemberHungarianPrefix , value: On }, \ +// RUN: { key: readability-identifier-naming.StaticConstantHungarianPrefix , value: On }, \ +// RUN: { key: readability-identifier-naming.StaticVariableHungarianPrefix , value: On }, \ +// RUN: { key: readability-identifier-naming.StructHungarianPrefix , value: On }, \ +// RUN: { key: readability-identifier-naming.UnionHungarianPrefix , value: On }, \ +// RUN: { key: readability-identifier-naming.VariableHungarianPrefix , value: On }, \ +// RUN: { key: readability-identifier-naming.HungarianNotation.Options.TreatStructAsClass , value: false }, \ +// RUN: { key: readability-identifier-naming.HungarianNotation.DerivedType.Array , value: a }, \ +// RUN: { key: readability-identifier-naming.HungarianNotation.DerivedType.Pointer , value: p }, \ +// RUN: { key: readability-identifier-naming.HungarianNotation.DerivedType.FunctionPointer , value: fn }, \ +// RUN: { key: readability-identifier-naming.HungarianNotation.CString.CharPrinter , value: sz }, \ +// RUN: { key: readability-identifier-naming.HungarianNotation.CString.CharArray , value: sz }, \ +// RUN: { key: readability-identifier-naming.HungarianNotation.CString.WideCharPrinter , value: wsz }, \ +// RUN: { key: readability-identifier-naming.HungarianNotation.CString.WideCharArray , value: wsz }, \ +// RUN: { key: readability-identifier-naming.HungarianNotation.PrimitiveType.int8_t , value: i8 }, \ +// RUN: { key: readability-identifier-naming.HungarianNotation.PrimitiveType.int16_t , value: i16 }, \ +// RUN: { key: readability-identifier-naming.HungarianNotation.PrimitiveType.int32_t , value: i32 }, \ +// RUN: { key: readability-identifier-naming.HungarianNotation.PrimitiveType.int64_t , value: i64 }, \ +// RUN: { key: readability-identifier-naming.HungarianNotation.PrimitiveType.uint8_t , value: u8 }, \ +// RUN: { key: readability-identifier-naming.HungarianNotation.PrimitiveType.uint16_t , value: u16 }, \ +// RUN: { key: readability-identifier-naming.HungarianNotation.PrimitiveType.uint32_t , value: u32 }, \ +// RUN: { key: readability-identifier-naming.HungarianNotation.PrimitiveType.uint64_t , value: u64 }, \ +// RUN: { key: readability-identifier-naming.HungarianNotation.PrimitiveType.char8_t , value: c8 }, \ +// RUN: { key: readability-identifier-naming.HungarianNotation.PrimitiveType.char16_t , value: c16 }, \ +// RUN: { key: readability-identifier-naming.HungarianNotation.PrimitiveType.char32_t , value: c32 }, \ +// RUN: { key: readability-identifier-naming.HungarianNotation.PrimitiveType.float , value: f }, \ +// RUN: { key: readability-identifier-naming.HungarianNotation.PrimitiveType.double , value: d }, \ +// RUN: { key: readability-identifier-naming.HungarianNotation.PrimitiveType.char , value: c }, \ +// RUN: { key: readability-identifier-naming.HungarianNotation.PrimitiveType.bool , value: b }, \ +// RUN: { key: readability-identifier-naming.HungarianNotation.PrimitiveType._Bool , value: b }, \ +// RUN: { key: readability-identifier-naming.HungarianNotation.PrimitiveType.int , value: i }, \ +// RUN: { key: readability-identifier-naming.HungarianNotation.PrimitiveType.size_t , value: n }, \ +// RUN: { key: readability-identifier-naming.HungarianNotation.PrimitiveType.wchar_t , value: wc }, \ +// RUN: { key: readability-identifier-naming.HungarianNotation.PrimitiveType.short-int , value: si }, \ +// RUN: { key: readability-identifier-naming.HungarianNotation.PrimitiveType.short , value: s }, \ +// RUN: { key: readability-identifier-naming.HungarianNotation.PrimitiveType.signed-int , value: si }, \ +// RUN: { key: readability-identifier-naming.HungarianNotation.PrimitiveType.signed-short , value: ss }, \ +// RUN: { key: readability-identifier-naming.HungarianNotation.PrimitiveType.signed-short-int , value: ssi }, \ +// RUN: { key: readability-identifier-naming.HungarianNotation.PrimitiveType.signed-long-long-int , value: slli }, \ +// RUN: { key: readability-identifier-naming.HungarianNotation.PrimitiveType.signed-long-long , value: sll }, \ +// RUN: { key: readability-identifier-naming.HungarianNotation.PrimitiveType.signed-long-int , value: sli }, \ +// RUN: { key: readability-identifier-naming.HungarianNotation.PrimitiveType.signed-long , value: sl }, \ +// RUN: { key: readability-identifier-naming.HungarianNotation.PrimitiveType.signed , value: s }, \ +// RUN: { key: readability-identifier-naming.HungarianNotation.PrimitiveType.unsigned-long-long-int , value: ulli }, \ +// RUN: { key: readability-identifier-naming.HungarianNotation.PrimitiveType.unsigned-long-long , value: ull }, \ +// RUN: { key: readability-identifier-naming.HungarianNotation.PrimitiveType.unsigned-long-int , value: uli }, \ +// RUN: { key: readability-identifier-naming.HungarianNotation.PrimitiveType.unsigned-long , value: ul }, \ +// RUN: { key: readability-identifier-naming.HungarianNotation.PrimitiveType.unsigned-short-int , value: usi }, \ +// RUN: { key: readability-identifier-naming.HungarianNotation.PrimitiveType.unsigned-short , value: us }, \ +// RUN: { key: readability-identifier-naming.HungarianNotation.PrimitiveType.unsigned-int , value: ui }, \ +// RUN: { key: readability-identifier-naming.HungarianNotation.PrimitiveType.unsigned , value: u }, \ +// RUN: { key: readability-identifier-naming.HungarianNotation.PrimitiveType.long-long-int , value: lli }, \ +// RUN: { key: readability-identifier-naming.HungarianNotation.PrimitiveType.long-double , value: ld }, \ +// RUN: { key: readability-identifier-naming.HungarianNotation.PrimitiveType.long-long , value: ll }, \ +// RUN: { key: readability-identifier-naming.HungarianNotation.PrimitiveType.long-int , value: li }, \ +// RUN: { key: readability-identifier-naming.HungarianNotation.PrimitiveType.long , value: l }, \ +// RUN: { key: readability-identifier-naming.HungarianNotation.PrimitiveType.ptrdiff_t , value: p }, \ +// RUN: { key: readability-identifier-naming.HungarianNotation.UserDefinedType.BOOL , value: b }, \ +// RUN: { key: readability-identifier-naming.HungarianNotation.UserDefinedType.BOOLEAN , value: b }, \ +// RUN: { key: readability-identifier-naming.HungarianNotation.UserDefinedType.BYTE , value: by }, \ +// RUN: { key: readability-identifier-naming.HungarianNotation.UserDefinedType.CHAR , value: c }, \ +// RUN: { key: readability-identifier-naming.HungarianNotation.UserDefinedType.UCHAR , value: uc }, \ +// RUN: { key: readability-identifier-naming.HungarianNotation.UserDefinedType.SHORT , value: s }, \ +// RUN: { key: readability-identifier-naming.HungarianNotation.UserDefinedType.USHORT , value: us }, \ +// RUN: { key: readability-identifier-naming.HungarianNotation.UserDefinedType.WORD , value: w }, \ +// RUN: { key: readability-identifier-naming.HungarianNotation.UserDefinedType.DWORD , value: dw }, \ +// RUN: { key: readability-identifier-naming.HungarianNotation.UserDefinedType.DWORD32 , value: dw32 }, \ +// RUN: { key: readability-identifier-naming.HungarianNotation.UserDefinedType.DWORD64 , value: dw64 }, \ +// RUN: { key: readability-identifier-naming.HungarianNotation.UserDefinedType.LONG , value: l }, \ +// RUN: { key: readability-identifier-naming.HungarianNotation.UserDefinedType.ULONG , value: ul }, \ +// RUN: { key: readability-identifier-naming.HungarianNotation.UserDefinedType.ULONG32 , value: ul32 }, \ +// RUN: { key: readability-identifier-naming.HungarianNotation.UserDefinedType.ULONG64 , value: ul64 }, \ +// RUN: { key: readability-identifier-naming.HungarianNotation.UserDefinedType.ULONGLONG , value: ull }, \ +// RUN: { key: readability-identifier-naming.HungarianNotation.UserDefinedType.HANDLE , value: h }, \ +// RUN: { key: readability-identifier-naming.HungarianNotation.UserDefinedType.INT , value: i }, \ +// RUN: { key: readability-identifier-naming.HungarianNotation.UserDefinedType.INT8 , value: i8 }, \ +// RUN: { key: readability-identifier-naming.HungarianNotation.UserDefinedType.INT16 , value: i16 }, \ +// RUN: { key: readability-identifier-naming.HungarianNotation.UserDefinedType.INT32 , value: i32 }, \ +// RUN: { key: readability-identifier-naming.HungarianNotation.UserDefinedType.INT64 , value: i64 }, \ +// RUN: { key: readability-identifier-naming.HungarianNotation.UserDefinedType.UINT , value: ui }, \ +// RUN: { key: readability-identifier-naming.HungarianNotation.UserDefinedType.UINT8 , value: u8 }, \ +// RUN: { key: readability-identifier-naming.HungarianNotation.UserDefinedType.UINT16 , value: u16 }, \ +// RUN: { key: readability-identifier-naming.HungarianNotation.UserDefinedType.UINT32 , value: u32 }, \ +// RUN: { key: readability-identifier-naming.HungarianNotation.UserDefinedType.UINT64 , value: u64 }, \ +// RUN: { key: readability-identifier-naming.HungarianNotation.UserDefinedType.PVOID , value: p }, \ +// RUN: ]}' + +// clang-format off +typedef signed char int8_t; // NOLINT +typedef short int16_t; // NOLINT +typedef long int32_t; // NOLINT +typedef long long int64_t; // NOLINT +typedef unsigned char uint8_t; // NOLINT +typedef unsigned short uint16_t; // NOLINT +typedef unsigned long uint32_t; // NOLINT +typedef unsigned long long uint64_t; // NOLINT +#ifndef _WIN32 +typedef unsigned long long size_t; // NOLINT +#endif +typedef long intptr_t; // NOLINT +typedef unsigned long uintptr_t; // NOLINT +typedef long int ptrdiff_t; // NOLINT +typedef unsigned char BYTE; // NOLINT +typedef unsigned short WORD; // NOLINT +typedef unsigned long DWORD; // NOLINT +typedef int BOOL; // NOLINT +typedef int BOOLEAN; // NOLINT +typedef float FLOAT; // NOLINT +typedef int INT; // NOLINT +typedef unsigned int UINT; // NOLINT +typedef unsigned long ULONG; // NOLINT +typedef short SHORT; // NOLINT +typedef unsigned short USHORT; // NOLINT +typedef char CHAR; // NOLINT +typedef unsigned char UCHAR; // NOLINT +typedef signed char INT8; // NOLINT +typedef signed short INT16; // NOLINT +typedef signed int INT32; // NOLINT +typedef signed long long INT64; // NOLINT +typedef unsigned char UINT8; // NOLINT +typedef unsigned short UINT16; // NOLINT +typedef unsigned int UINT32; // NOLINT +typedef unsigned long long UINT64; // NOLINT +typedef long LONG; // NOLINT +typedef signed int LONG32; // NOLINT +typedef unsigned int ULONG32; // NOLINT +typedef uint64_t ULONG64; // NOLINT +typedef unsigned int DWORD32; // NOLINT +typedef uint64_t DWORD64; // NOLINT +typedef uint64_t ULONGLONG; // NOLINT +typedef void* PVOID; // NOLINT +typedef void* HANDLE; // NOLINT +typedef void* FILE; // NOLINT +#define NULL (0) // NOLINT +// clang-format on + +// clang-format off +//===----------------------------------------------------------------------===// +// Cases to CheckOptions +//===----------------------------------------------------------------------===// +class CMyClass1 { +public: + static int ClassMemberCase; + // CHECK-MESSAGES: :[[@LINE-1]]:14: warning: invalid case style for class member 'ClassMemberCase' [readability-identifier-naming] + // CHECK-FIXES: {{^}} static int iClassMemberCase; + + char const ConstantMemberCase = 0; + // CHECK-MESSAGES: :[[@LINE-1]]:14: warning: invalid case style for constant member 'ConstantMemberCase' [readability-identifier-naming] + // CHECK-FIXES: {{^}} char const cConstantMemberCase = 0; + + void MyFunc1(const int ConstantParameterCase); + // CHECK-MESSAGES: :[[@LINE-1]]:26: warning: invalid case style for constant parameter 'ConstantParameterCase' [readability-identifier-naming] + // CHECK-FIXES: {{^}} void MyFunc1(const int iConstantParameterCase); + + void MyFunc2(const int* ConstantPointerParameterCase); + // CHECK-MESSAGES: :[[@LINE-1]]:27: warning: invalid case style for pointer parameter 'ConstantPointerParameterCase' [readability-identifier-naming] + // CHECK-FIXES: {{^}} void MyFunc2(const int* piConstantPointerParameterCase); + + static constexpr int ConstexprVariableCase = 123; + // CHECK-MESSAGES: :[[@LINE-1]]:24: warning: invalid case style for constexpr variable 'ConstexprVariableCase' [readability-identifier-naming] + // CHECK-FIXES: {{^}} static constexpr int iConstexprVariableCase = 123; +}; + +const int GlobalConstantCase = 0; +// CHECK-MESSAGES: :[[@LINE-1]]:11: warning: invalid case style for global constant 'GlobalConstantCase' [readability-identifier-naming] +// CHECK-FIXES: {{^}}const int iGlobalConstantCase = 0; + +const int* GlobalConstantPointerCase = nullptr; +// CHECK-MESSAGES: :[[@LINE-1]]:12: warning: invalid case style for global variable 'GlobalConstantPointerCase' [readability-identifier-naming] +// CHECK-FIXES: {{^}}const int* piGlobalConstantPointerCase = nullptr; + +int GlobalVariableCase = 0; +// CHECK-MESSAGES: :[[@LINE-1]]:5: warning: invalid case style for global variable 'GlobalVariableCase' [readability-identifier-naming] +// CHECK-FIXES: {{^}}int iGlobalVariableCase = 0; + +void Func1(){ + int const LocalConstantCase = 3; + // CHECK-MESSAGES: :[[@LINE-1]]:13: warning: invalid case style for local constant 'LocalConstantCase' [readability-identifier-naming] + // CHECK-FIXES: {{^}} int const iLocalConstantCase = 3; + + int* const LocalConstantPointerCase = nullptr; + // CHECK-MESSAGES: :[[@LINE-1]]:14: warning: invalid case style for local constant pointer 'LocalConstantPointerCase' [readability-identifier-naming] + // CHECK-FIXES: {{^}} int* const piLocalConstantPointerCase = nullptr; + + int *LocalPointerCase = nullptr; + // CHECK-MESSAGES: :[[@LINE-1]]:8: warning: invalid case style for local pointer 'LocalPointerCase' [readability-identifier-naming] + // CHECK-FIXES: {{^}} int *piLocalPointerCase = nullptr; + + int LocalVariableCase = 0; + // CHECK-MESSAGES: :[[@LINE-1]]:7: warning: invalid case style for local variable 'LocalVariableCase' [readability-identifier-naming] + // CHECK-FIXES: {{^}} int iLocalVariableCase = 0; +} + +class CMyClass2 { + char MemberCase; + // CHECK-MESSAGES: :[[@LINE-1]]:8: warning: invalid case style for private member 'MemberCase' [readability-identifier-naming] + // CHECK-FIXES: {{^}} char cMemberCase; + + void Func1(int ParameterCase); + // CHECK-MESSAGES: :[[@LINE-1]]:18: warning: invalid case style for parameter 'ParameterCase' [readability-identifier-naming] + // CHECK-FIXES: {{^}} void Func1(int iParameterCase); + + void Func2(const int ParameterCase); + // CHECK-MESSAGES: :[[@LINE-1]]:24: warning: invalid case style for constant parameter 'ParameterCase' [readability-identifier-naming] + // CHECK-FIXES: {{^}} void Func2(const int iParameterCase); + + void Func3(const int *PointerParameterCase); + // CHECK-MESSAGES: :[[@LINE-1]]:25: warning: invalid case style for pointer parameter 'PointerParameterCase' [readability-identifier-naming] + // CHECK-FIXES: {{^}} void Func3(const int *piPointerParameterCase); +}; + +class CMyClass3 { +private: + char PrivateMemberCase; + // CHECK-MESSAGES: :[[@LINE-1]]:8: warning: invalid case style for private member 'PrivateMemberCase' [readability-identifier-naming] + // CHECK-FIXES: {{^}} char cPrivateMemberCase; +}; + +static const int StaticConstantCase = 3; +// CHECK-MESSAGES: :[[@LINE-1]]:18: warning: invalid case style for global constant 'StaticConstantCase' [readability-identifier-naming] +// CHECK-FIXES: {{^}}static const int iStaticConstantCase = 3; + +static int StaticVariableCase = 3; +// CHECK-MESSAGES: :[[@LINE-1]]:12: warning: invalid case style for global variable 'StaticVariableCase' [readability-identifier-naming] +// CHECK-FIXES: {{^}}static int iStaticVariableCase = 3; + +struct MyStruct { int StructCase; }; +// CHECK-MESSAGES: :[[@LINE-1]]:23: warning: invalid case style for member 'StructCase' [readability-identifier-naming] +// CHECK-FIXES: {{^}}struct MyStruct { int iStructCase; }; + +union MyUnion { int UnionCase1; long lUnionCase2; }; +// CHECK-MESSAGES: :[[@LINE-1]]:21: warning: invalid case style for member 'UnionCase1' [readability-identifier-naming] +// CHECK-FIXES: {{^}}union MyUnion { int iUnionCase1; long lUnionCase2; }; + +//===----------------------------------------------------------------------===// +// C string +//===----------------------------------------------------------------------===// +const char *NamePtr = "Name"; +// CHECK-MESSAGES: :[[@LINE-1]]:13: warning: invalid case style for global variable 'NamePtr' [readability-identifier-naming] +// CHECK-FIXES: {{^}}const char *szNamePtr = "Name"; + +const char NameArray[] = "Name"; +// CHECK-MESSAGES: :[[@LINE-1]]:12: warning: invalid case style for global constant 'NameArray' [readability-identifier-naming] +// CHECK-FIXES: {{^}}const char szNameArray[] = "Name"; + +const char *NamePtrArray[] = {"AA", "BB"}; +// CHECK-MESSAGES: :[[@LINE-1]]:13: warning: invalid case style for global variable 'NamePtrArray' [readability-identifier-naming] +// CHECK-FIXES: {{^}}const char *pszNamePtrArray[] = {"AA", "BB"}; + +const wchar_t *WideNamePtr = L"Name"; +// CHECK-MESSAGES: :[[@LINE-1]]:16: warning: invalid case style for global variable 'WideNamePtr' [readability-identifier-naming] +// CHECK-FIXES: {{^}}const wchar_t *wszWideNamePtr = L"Name"; + +const wchar_t WideNameArray[] = L"Name"; +// CHECK-MESSAGES: :[[@LINE-1]]:15: warning: invalid case style for global constant 'WideNameArray' [readability-identifier-naming] +// CHECK-FIXES: {{^}}const wchar_t wszWideNameArray[] = L"Name"; + +const wchar_t *WideNamePtrArray[] = {L"AA", L"BB"}; +// CHECK-MESSAGES: :[[@LINE-1]]:16: warning: invalid case style for global variable 'WideNamePtrArray' [readability-identifier-naming] +// CHECK-FIXES: {{^}}const wchar_t *pwszWideNamePtrArray[] = {L"AA", L"BB"}; + +class CMyClass4 { +private: + char *Name = "Text"; + // CHECK-MESSAGES: :[[@LINE-1]]:9: warning: invalid case style for private member 'Name' [readability-identifier-naming] + // CHECK-FIXES: {{^}} char *szName = "Text"; + + const char *ConstName = "Text"; + // CHECK-MESSAGES: :[[@LINE-1]]:15: warning: invalid case style for private member 'ConstName' [readability-identifier-naming] + // CHECK-FIXES: {{^}} const char *szConstName = "Text"; + +public: + const char* DuplicateString(const char* Input, size_t nRequiredSize); + // CHECK-MESSAGES: :[[@LINE-1]]:43: warning: invalid case style for pointer parameter 'Input' [readability-identifier-naming] + // CHECK-FIXES: {{^}} const char* DuplicateString(const char* szInput, size_t nRequiredSize); + + size_t UpdateText(const char* Buffer, size_t nBufferSize); + // CHECK-MESSAGES: :[[@LINE-1]]:33: warning: invalid case style for pointer parameter 'Buffer' [readability-identifier-naming] + // CHECK-FIXES: {{^}} size_t UpdateText(const char* szBuffer, size_t nBufferSize); +}; + + +//===----------------------------------------------------------------------===// +// Microsoft Windows data types +//===----------------------------------------------------------------------===// +DWORD MsDword = 0; +// CHECK-MESSAGES: :[[@LINE-1]]:7: warning: invalid case style for global variable 'MsDword' [readability-identifier-naming] +// CHECK-FIXES: {{^}}DWORD dwMsDword = 0; + +BYTE MsByte = 0; +// CHECK-MESSAGES: :[[@LINE-1]]:6: warning: invalid case style for global variable 'MsByte' [readability-identifier-naming] +// CHECK-FIXES: {{^}}BYTE byMsByte = 0; + +WORD MsWord = 0; +// CHECK-MESSAGES: :[[@LINE-1]]:6: warning: invalid case style for global variable 'MsWord' [readability-identifier-naming] +// CHECK-FIXES: {{^}}WORD wMsWord = 0; + +BOOL MsBool = 0; +// CHECK-MESSAGES: :[[@LINE-1]]:6: warning: invalid case style for global variable 'MsBool' [readability-identifier-naming] +// CHECK-FIXES: {{^}}BOOL bMsBool = 0; + +BOOLEAN MsBoolean = 0; +// CHECK-MESSAGES: :[[@LINE-1]]:9: warning: invalid case style for global variable 'MsBoolean' [readability-identifier-naming] +// CHECK-FIXES: {{^}}BOOLEAN bMsBoolean = 0; + +CHAR MsValueChar = 0; +// CHECK-MESSAGES: :[[@LINE-1]]:6: warning: invalid case style for global variable 'MsValueChar' [readability-identifier-naming] +// CHECK-FIXES: {{^}}CHAR cMsValueChar = 0; + +UCHAR MsValueUchar = 0; +// CHECK-MESSAGES: :[[@LINE-1]]:7: warning: invalid case style for global variable 'MsValueUchar' [readability-identifier-naming] +// CHECK-FIXES: {{^}}UCHAR ucMsValueUchar = 0; + +SHORT MsValueShort = 0; +// CHECK-MESSAGES: :[[@LINE-1]]:7: warning: invalid case style for global variable 'MsValueShort' [readability-identifier-naming] +// CHECK-FIXES: {{^}}SHORT sMsValueShort = 0; + +USHORT MsValueUshort = 0; +// CHECK-MESSAGES: :[[@LINE-1]]:8: warning: invalid case style for global variable 'MsValueUshort' [readability-identifier-naming] +// CHECK-FIXES: {{^}}USHORT usMsValueUshort = 0; + +WORD MsValueWord = 0; +// CHECK-MESSAGES: :[[@LINE-1]]:6: warning: invalid case style for global variable 'MsValueWord' [readability-identifier-naming] +// CHECK-FIXES: {{^}}WORD wMsValueWord = 0; + +DWORD MsValueDword = 0; +// CHECK-MESSAGES: :[[@LINE-1]]:7: warning: invalid case style for global variable 'MsValueDword' [readability-identifier-naming] +// CHECK-FIXES: {{^}}DWORD dwMsValueDword = 0; + +DWORD32 MsValueDword32 = 0; +// CHECK-MESSAGES: :[[@LINE-1]]:9: warning: invalid case style for global variable 'MsValueDword32' [readability-identifier-naming] +// CHECK-FIXES: {{^}}DWORD32 dw32MsValueDword32 = 0; + +DWORD64 MsValueDword64 = 0; +// CHECK-MESSAGES: :[[@LINE-1]]:9: warning: invalid case style for global variable 'MsValueDword64' [readability-identifier-naming] +// CHECK-FIXES: {{^}}DWORD64 dw64MsValueDword64 = 0; + +LONG MsValueLong = 0; +// CHECK-MESSAGES: :[[@LINE-1]]:6: warning: invalid case style for global variable 'MsValueLong' [readability-identifier-naming] +// CHECK-FIXES: {{^}}LONG lMsValueLong = 0; + +ULONG MsValueUlong = 0; +// CHECK-MESSAGES: :[[@LINE-1]]:7: warning: invalid case style for global variable 'MsValueUlong' [readability-identifier-naming] +// CHECK-FIXES: {{^}}ULONG ulMsValueUlong = 0; + +ULONG32 MsValueUlong32 = 0; +// CHECK-MESSAGES: :[[@LINE-1]]:9: warning: invalid case style for global variable 'MsValueUlong32' [readability-identifier-naming] +// CHECK-FIXES: {{^}}ULONG32 ul32MsValueUlong32 = 0; + +ULONG64 MsValueUlong64 = 0; +// CHECK-MESSAGES: :[[@LINE-1]]:9: warning: invalid case style for global variable 'MsValueUlong64' [readability-identifier-naming] +// CHECK-FIXES: {{^}}ULONG64 ul64MsValueUlong64 = 0; + +ULONGLONG MsValueUlongLong = 0; +// CHECK-MESSAGES: :[[@LINE-1]]:11: warning: invalid case style for global variable 'MsValueUlongLong' [readability-identifier-naming] +// CHECK-FIXES: {{^}}ULONGLONG ullMsValueUlongLong = 0; + +HANDLE MsValueHandle = 0; +// CHECK-MESSAGES: :[[@LINE-1]]:8: warning: invalid case style for global variable 'MsValueHandle' [readability-identifier-naming] +// CHECK-FIXES: {{^}}HANDLE hMsValueHandle = 0; + +INT MsValueInt = 0; +// CHECK-MESSAGES: :[[@LINE-1]]:5: warning: invalid case style for global variable 'MsValueInt' [readability-identifier-naming] +// CHECK-FIXES: {{^}}INT iMsValueInt = 0; + +INT8 MsValueInt8 = 0; +// CHECK-MESSAGES: :[[@LINE-1]]:6: warning: invalid case style for global variable 'MsValueInt8' [readability-identifier-naming] +// CHECK-FIXES: {{^}}INT8 i8MsValueInt8 = 0; + +INT16 MsValueInt16 = 0; +// CHECK-MESSAGES: :[[@LINE-1]]:7: warning: invalid case style for global variable 'MsValueInt16' [readability-identifier-naming] +// CHECK-FIXES: {{^}}INT16 i16MsValueInt16 = 0; + +INT32 MsValueInt32 = 0; +// CHECK-MESSAGES: :[[@LINE-1]]:7: warning: invalid case style for global variable 'MsValueInt32' [readability-identifier-naming] +// CHECK-FIXES: {{^}}INT32 i32MsValueInt32 = 0; + +INT64 MsValueINt64 = 0; +// CHECK-MESSAGES: :[[@LINE-1]]:7: warning: invalid case style for global variable 'MsValueINt64' [readability-identifier-naming] +// CHECK-FIXES: {{^}}INT64 i64MsValueINt64 = 0; + +UINT MsValueUint = 0; +// CHECK-MESSAGES: :[[@LINE-1]]:6: warning: invalid case style for global variable 'MsValueUint' [readability-identifier-naming] +// CHECK-FIXES: {{^}}UINT uiMsValueUint = 0; + +UINT8 MsValueUint8 = 0; +// CHECK-MESSAGES: :[[@LINE-1]]:7: warning: invalid case style for global variable 'MsValueUint8' [readability-identifier-naming] +// CHECK-FIXES: {{^}}UINT8 u8MsValueUint8 = 0; + +UINT16 MsValueUint16 = 0; +// CHECK-MESSAGES: :[[@LINE-1]]:8: warning: invalid case style for global variable 'MsValueUint16' [readability-identifier-naming] +// CHECK-FIXES: {{^}}UINT16 u16MsValueUint16 = 0; + +UINT32 MsValueUint32 = 0; +// CHECK-MESSAGES: :[[@LINE-1]]:8: warning: invalid case style for global variable 'MsValueUint32' [readability-identifier-naming] +// CHECK-FIXES: {{^}}UINT32 u32MsValueUint32 = 0; + +UINT64 MsValueUint64 = 0; +// CHECK-MESSAGES: :[[@LINE-1]]:8: warning: invalid case style for global variable 'MsValueUint64' [readability-identifier-naming] +// CHECK-FIXES: {{^}}UINT64 u64MsValueUint64 = 0; + +PVOID MsValuePvoid = NULL; +// CHECK-MESSAGES: :[[@LINE-1]]:7: warning: invalid case style for global variable 'MsValuePvoid' [readability-identifier-naming] +// CHECK-FIXES: {{^}}PVOID pMsValuePvoid = NULL; + + +//===----------------------------------------------------------------------===// +// Array +//===----------------------------------------------------------------------===// +unsigned GlobalUnsignedArray[] = {1, 2, 3}; +// CHECK-MESSAGES: :[[@LINE-1]]:10: warning: invalid case style for global variable 'GlobalUnsignedArray' [readability-identifier-naming] +// CHECK-FIXES: {{^}}unsigned aGlobalUnsignedArray[] = {1, 2, 3}; + +int GlobalIntArray[] = {1, 2, 3}; +// CHECK-MESSAGES: :[[@LINE-1]]:5: warning: invalid case style for global variable 'GlobalIntArray' [readability-identifier-naming] +// CHECK-FIXES: {{^}}int aGlobalIntArray[] = {1, 2, 3}; + +int DataInt[1] = {0}; +// CHECK-MESSAGES: :[[@LINE-1]]:5: warning: invalid case style for global variable 'DataInt' [readability-identifier-naming] +// CHECK-FIXES: {{^}}int aDataInt[1] = {0}; + +int DataArray[2] = {0}; +// CHECK-MESSAGES: :[[@LINE-1]]:5: warning: invalid case style for global variable 'DataArray' [readability-identifier-naming] +// CHECK-FIXES: {{^}}int aDataArray[2] = {0}; + + +//===----------------------------------------------------------------------===// +// Pointer +//===----------------------------------------------------------------------===// +int *DataIntPtr[1] = {0}; +// CHECK-MESSAGES: :[[@LINE-1]]:6: warning: invalid case style for global variable 'DataIntPtr' [readability-identifier-naming] +// CHECK-FIXES: {{^}}int *paDataIntPtr[1] = {0}; + +void *BufferPtr1; +// CHECK-MESSAGES: :[[@LINE-1]]:7: warning: invalid case style for global variable 'BufferPtr1' [readability-identifier-naming] +// CHECK-FIXES: {{^}}void *pBufferPtr1; + +void **BufferPtr2; +// CHECK-MESSAGES: :[[@LINE-1]]:8: warning: invalid case style for global variable 'BufferPtr2' [readability-identifier-naming] +// CHECK-FIXES: {{^}}void **ppBufferPtr2; + +void **pBufferPtr3; +// CHECK-MESSAGES: :[[@LINE-1]]:8: warning: invalid case style for global variable 'pBufferPtr3' [readability-identifier-naming] +// CHECK-FIXES: {{^}}void **ppBufferPtr3; + +int *pBufferPtr4; +// CHECK-MESSAGES: :[[@LINE-1]]:6: warning: invalid case style for global variable 'pBufferPtr4' [readability-identifier-naming] +// CHECK-FIXES: {{^}}int *piBufferPtr4; + +typedef void (*FUNC_PTR_HELLO)(); +FUNC_PTR_HELLO Hello = NULL; +// CHECK-MESSAGES: :[[@LINE-1]]:16: warning: invalid case style for global variable 'Hello' [readability-identifier-naming] +// CHECK-FIXES: {{^}}FUNC_PTR_HELLO fnHello = NULL; + +void *ValueVoidPtr = NULL; +// CHECK-MESSAGES: :[[@LINE-1]]:7: warning: invalid case style for global variable 'ValueVoidPtr' [readability-identifier-naming] +// CHECK-FIXES: {{^}}void *pValueVoidPtr = NULL; + +ptrdiff_t PtrDiff = NULL; +// CHECK-MESSAGES: :[[@LINE-1]]:11: warning: invalid case style for global variable 'PtrDiff' [readability-identifier-naming] +// CHECK-FIXES: {{^}}ptrdiff_t pPtrDiff = NULL; + +int8_t *ValueI8Ptr; +// CHECK-MESSAGES: :[[@LINE-1]]:9: warning: invalid case style for global variable 'ValueI8Ptr' [readability-identifier-naming] +// CHECK-FIXES: {{^}}int8_t *pi8ValueI8Ptr; + +uint8_t *ValueU8Ptr; +// CHECK-MESSAGES: :[[@LINE-1]]:10: warning: invalid case style for global variable 'ValueU8Ptr' [readability-identifier-naming] +// CHECK-FIXES: {{^}}uint8_t *pu8ValueU8Ptr; + +void MyFunc2(void* Val){} +// CHECK-MESSAGES: :[[@LINE-1]]:20: warning: invalid case style for pointer parameter 'Val' [readability-identifier-naming] +// CHECK-FIXES: {{^}}void MyFunc2(void* pVal){} + + +//===----------------------------------------------------------------------===// +// Reference +//===----------------------------------------------------------------------===// +int iValueIndex = 1; +int &RefValueIndex = iValueIndex; +// CHECK-MESSAGES: :[[@LINE-1]]:6: warning: invalid case style for global variable 'RefValueIndex' [readability-identifier-naming] +// CHECK-FIXES: {{^}}int &iRefValueIndex = iValueIndex; + +const int &ConstRefValue = iValueIndex; +// CHECK-MESSAGES: :[[@LINE-1]]:12: warning: invalid case style for global variable 'ConstRefValue' [readability-identifier-naming] +// CHECK-FIXES: {{^}}const int &iConstRefValue = iValueIndex; + +long long llValueLongLong = 2; +long long &RefValueLongLong = llValueLongLong; +// CHECK-MESSAGES: :[[@LINE-1]]:12: warning: invalid case style for global variable 'RefValueLongLong' [readability-identifier-naming] +// CHECK-FIXES: {{^}}long long &llRefValueLongLong = llValueLongLong; + + +//===----------------------------------------------------------------------===// +// Various types +//===----------------------------------------------------------------------===// +int8_t ValueI8; +// CHECK-MESSAGES: :[[@LINE-1]]:8: warning: invalid case style for global variable 'ValueI8' [readability-identifier-naming] +// CHECK-FIXES: {{^}}int8_t i8ValueI8; + +int16_t ValueI16 = 0; +// CHECK-MESSAGES: :[[@LINE-1]]:9: warning: invalid case style for global variable 'ValueI16' [readability-identifier-naming] +// CHECK-FIXES: {{^}}int16_t i16ValueI16 = 0; + +int32_t ValueI32 = 0; +// CHECK-MESSAGES: :[[@LINE-1]]:9: warning: invalid case style for global variable 'ValueI32' [readability-identifier-naming] +// CHECK-FIXES: {{^}}int32_t i32ValueI32 = 0; + +int64_t ValueI64 = 0; +// CHECK-MESSAGES: :[[@LINE-1]]:9: warning: invalid case style for global variable 'ValueI64' [readability-identifier-naming] +// CHECK-FIXES: {{^}}int64_t i64ValueI64 = 0; + +uint8_t ValueU8 = 0; +// CHECK-MESSAGES: :[[@LINE-1]]:9: warning: invalid case style for global variable 'ValueU8' [readability-identifier-naming] +// CHECK-FIXES: {{^}}uint8_t u8ValueU8 = 0; + +uint16_t ValueU16 = 0; +// CHECK-MESSAGES: :[[@LINE-1]]:10: warning: invalid case style for global variable 'ValueU16' [readability-identifier-naming] +// CHECK-FIXES: {{^}}uint16_t u16ValueU16 = 0; + +uint32_t ValueU32 = 0; +// CHECK-MESSAGES: :[[@LINE-1]]:10: warning: invalid case style for global variable 'ValueU32' [readability-identifier-naming] +// CHECK-FIXES: {{^}}uint32_t u32ValueU32 = 0; + +uint64_t ValueU64 = 0; +// CHECK-MESSAGES: :[[@LINE-1]]:10: warning: invalid case style for global variable 'ValueU64' [readability-identifier-naming] +// CHECK-FIXES: {{^}}uint64_t u64ValueU64 = 0; + +float ValueFloat = 0; +// CHECK-MESSAGES: :[[@LINE-1]]:7: warning: invalid case style for global variable 'ValueFloat' [readability-identifier-naming] +// CHECK-FIXES: {{^}}float fValueFloat = 0; + +double ValueDouble = 0; +// CHECK-MESSAGES: :[[@LINE-1]]:8: warning: invalid case style for global variable 'ValueDouble' [readability-identifier-naming] +// CHECK-FIXES: {{^}}double dValueDouble = 0; + +char ValueChar = 'c'; +// CHECK-MESSAGES: :[[@LINE-1]]:6: warning: invalid case style for global variable 'ValueChar' [readability-identifier-naming] +// CHECK-FIXES: {{^}}char cValueChar = 'c'; + +bool ValueBool = true; +// CHECK-MESSAGES: :[[@LINE-1]]:6: warning: invalid case style for global variable 'ValueBool' [readability-identifier-naming] +// CHECK-FIXES: {{^}}bool bValueBool = true; + +int ValueInt = 0; +// CHECK-MESSAGES: :[[@LINE-1]]:5: warning: invalid case style for global variable 'ValueInt' [readability-identifier-naming] +// CHECK-FIXES: {{^}}int iValueInt = 0; + +size_t ValueSize = 0; +// CHECK-MESSAGES: :[[@LINE-1]]:8: warning: invalid case style for global variable 'ValueSize' [readability-identifier-naming] +// CHECK-FIXES: {{^}}size_t nValueSize = 0; + +wchar_t ValueWchar = 'w'; +// CHECK-MESSAGES: :[[@LINE-1]]:9: warning: invalid case style for global variable 'ValueWchar' [readability-identifier-naming] +// CHECK-FIXES: {{^}}wchar_t wcValueWchar = 'w'; + +short ValueShort = 0; +// CHECK-MESSAGES: :[[@LINE-1]]:7: warning: invalid case style for global variable 'ValueShort' [readability-identifier-naming] +// CHECK-FIXES: {{^}}short sValueShort = 0; + +unsigned ValueUnsigned = 0; +// CHECK-MESSAGES: :[[@LINE-1]]:10: warning: invalid case style for global variable 'ValueUnsigned' [readability-identifier-naming] +// CHECK-FIXES: {{^}}unsigned uValueUnsigned = 0; + +signed ValueSigned = 0; +// CHECK-MESSAGES: :[[@LINE-1]]:8: warning: invalid case style for global variable 'ValueSigned' [readability-identifier-naming] +// CHECK-FIXES: {{^}}signed sValueSigned = 0; + +long ValueLong = 0; +// CHECK-MESSAGES: :[[@LINE-1]]:6: warning: invalid case style for global variable 'ValueLong' [readability-identifier-naming] +// CHECK-FIXES: {{^}}long lValueLong = 0; + +long long ValueLongLong = 0; +// CHECK-MESSAGES: :[[@LINE-1]]:11: warning: invalid case style for global variable 'ValueLongLong' [readability-identifier-naming] +// CHECK-FIXES: {{^}}long long llValueLongLong = 0; + +long long int ValueLongLongInt = 0; +// CHECK-MESSAGES: :[[@LINE-1]]:15: warning: invalid case style for global variable 'ValueLongLongInt' [readability-identifier-naming] +// CHECK-FIXES: {{^}}long long int lliValueLongLongInt = 0; + +long double ValueLongDouble = 0; +// CHECK-MESSAGES: :[[@LINE-1]]:13: warning: invalid case style for global variable 'ValueLongDouble' [readability-identifier-naming] +// CHECK-FIXES: {{^}}long double ldValueLongDouble = 0; + +signed int ValueSignedInt = 0; +// CHECK-MESSAGES: :[[@LINE-1]]:12: warning: invalid case style for global variable 'ValueSignedInt' [readability-identifier-naming] +// CHECK-FIXES: {{^}}signed int siValueSignedInt = 0; + +signed short ValueSignedShort = 0; +// CHECK-MESSAGES: :[[@LINE-1]]:14: warning: invalid case style for global variable 'ValueSignedShort' [readability-identifier-naming] +// CHECK-FIXES: {{^}}signed short ssValueSignedShort = 0; + +signed short int ValueSignedShortInt = 0; +// CHECK-MESSAGES: :[[@LINE-1]]:18: warning: invalid case style for global variable 'ValueSignedShortInt' [readability-identifier-naming] +// CHECK-FIXES: {{^}}signed short int ssiValueSignedShortInt = 0; + +signed long long ValueSignedLongLong = 0; +// CHECK-MESSAGES: :[[@LINE-1]]:18: warning: invalid case style for global variable 'ValueSignedLongLong' [readability-identifier-naming] +// CHECK-FIXES: {{^}}signed long long sllValueSignedLongLong = 0; + +signed long int ValueSignedLongInt = 0; +// CHECK-MESSAGES: :[[@LINE-1]]:17: warning: invalid case style for global variable 'ValueSignedLongInt' [readability-identifier-naming] +// CHECK-FIXES: {{^}}signed long int sliValueSignedLongInt = 0; + +signed long ValueSignedLong = 0; +// CHECK-MESSAGES: :[[@LINE-1]]:13: warning: invalid case style for global variable 'ValueSignedLong' [readability-identifier-naming] +// CHECK-FIXES: {{^}}signed long slValueSignedLong = 0; + +unsigned long long int ValueUnsignedLongLongInt = 0; +// CHECK-MESSAGES: :[[@LINE-1]]:24: warning: invalid case style for global variable 'ValueUnsignedLongLongInt' [readability-identifier-naming] +// CHECK-FIXES: {{^}}unsigned long long int ulliValueUnsignedLongLongInt = 0; + +unsigned long long ValueUnsignedLongLong = 0; +// CHECK-MESSAGES: :[[@LINE-1]]:20: warning: invalid case style for global variable 'ValueUnsignedLongLong' [readability-identifier-naming] +// CHECK-FIXES: {{^}}unsigned long long ullValueUnsignedLongLong = 0; + +unsigned long int ValueUnsignedLongInt = 0; +// CHECK-MESSAGES: :[[@LINE-1]]:19: warning: invalid case style for global variable 'ValueUnsignedLongInt' [readability-identifier-naming] +// CHECK-FIXES: {{^}}unsigned long int uliValueUnsignedLongInt = 0; + +unsigned long ValueUnsignedLong = 0; +// CHECK-MESSAGES: :[[@LINE-1]]:15: warning: invalid case style for global variable 'ValueUnsignedLong' [readability-identifier-naming] +// CHECK-FIXES: {{^}}unsigned long ulValueUnsignedLong = 0; + +unsigned short int ValueUnsignedShortInt = 0; +// CHECK-MESSAGES: :[[@LINE-1]]:20: warning: invalid case style for global variable 'ValueUnsignedShortInt' [readability-identifier-naming] +// CHECK-FIXES: {{^}}unsigned short int usiValueUnsignedShortInt = 0; + +unsigned short ValueUnsignedShort = 0; +// CHECK-MESSAGES: :[[@LINE-1]]:16: warning: invalid case style for global variable 'ValueUnsignedShort' [readability-identifier-naming] +// CHECK-FIXES: {{^}}unsigned short usValueUnsignedShort = 0; + +unsigned int ValueUnsignedInt = 0; +// CHECK-MESSAGES: :[[@LINE-1]]:14: warning: invalid case style for global variable 'ValueUnsignedInt' [readability-identifier-naming] +// CHECK-FIXES: {{^}}unsigned int uiValueUnsignedInt = 0; + +long int ValueLongInt = 0; +// CHECK-MESSAGES: :[[@LINE-1]]:10: warning: invalid case style for global variable 'ValueLongInt' [readability-identifier-naming] +// CHECK-FIXES: {{^}}long int liValueLongInt = 0; + + +//===----------------------------------------------------------------------===// +// Specifier, Qualifier, Other keywords +//===----------------------------------------------------------------------===// +volatile int VolatileInt = 0; +// CHECK-MESSAGES: :[[@LINE-1]]:14: warning: invalid case style for global variable 'VolatileInt' [readability-identifier-naming] +// CHECK-FIXES: {{^}}volatile int iVolatileInt = 0; + +thread_local int ThreadLocalValueInt = 0; +// CHECK-MESSAGES: :[[@LINE-1]]:18: warning: invalid case style for global variable 'ThreadLocalValueInt' [readability-identifier-naming] +// CHECK-FIXES: {{^}}thread_local int iThreadLocalValueInt = 0; + +extern int ExternValueInt; +// CHECK-MESSAGES: :[[@LINE-1]]:12: warning: invalid case style for global variable 'ExternValueInt' [readability-identifier-naming] +// CHECK-FIXES: {{^}}extern int iExternValueInt; + +struct DataBuffer { + mutable size_t Size; +}; +// CHECK-MESSAGES: :[[@LINE-2]]:20: warning: invalid case style for member 'Size' [readability-identifier-naming] +// CHECK-FIXES: {{^}} mutable size_t nSize; + +static constexpr int const &ConstExprInt = 42; +// CHECK-MESSAGES: :[[@LINE-1]]:29: warning: invalid case style for constexpr variable 'ConstExprInt' [readability-identifier-naming] +// CHECK-FIXES: {{^}}static constexpr int const &iConstExprInt = 42; + + +//===----------------------------------------------------------------------===// +// Redefined types +//===----------------------------------------------------------------------===// +typedef int INDEX; +INDEX iIndex = 0; +// CHECK-MESSAGES: :[[@LINE-1]]:7: warning: invalid case style for global variable 'iIndex' [readability-identifier-naming] +// CHECK-FIXES: {{^}}INDEX Index = 0; + + +//===----------------------------------------------------------------------===// +// Class +//===----------------------------------------------------------------------===// +class GenericClass { int Func(); }; +// CHECK-MESSAGES: :[[@LINE-1]]:7: warning: invalid case style for class 'GenericClass' [readability-identifier-naming] +// CHECK-FIXES: {{^}}class CGenericClass { int Func(); }; + +class AbstractClass { virtual int Func() = 0; }; +// CHECK-MESSAGES: :[[@LINE-1]]:7: warning: invalid case style for abstract class 'AbstractClass' [readability-identifier-naming] +// CHECK-FIXES: {{^}}class IAbstractClass { virtual int Func() = 0; }; + +class AbstractClass1 { virtual int Func1() = 0; int Func2(); }; +// CHECK-MESSAGES: :[[@LINE-1]]:7: warning: invalid case style for abstract class 'AbstractClass1' [readability-identifier-naming] +// CHECK-FIXES: {{^}}class IAbstractClass1 { virtual int Func1() = 0; int Func2(); }; + + +//===----------------------------------------------------------------------===// +// Other Cases +//===----------------------------------------------------------------------===// +int lower_case = 0; +// CHECK-MESSAGES: :[[@LINE-1]]:5: warning: invalid case style for global variable 'lower_case' [readability-identifier-naming] +// CHECK-FIXES: {{^}}int iLowerCase = 0; + +int lower_case1 = 0; +// CHECK-MESSAGES: :[[@LINE-1]]:5: warning: invalid case style for global variable 'lower_case1' [readability-identifier-naming] +// CHECK-FIXES: {{^}}int iLowerCase1 = 0; + +int lower_case_2 = 0; +// CHECK-MESSAGES: :[[@LINE-1]]:5: warning: invalid case style for global variable 'lower_case_2' [readability-identifier-naming] +// CHECK-FIXES: {{^}}int iLowerCase2 = 0; + +int UPPER_CASE = 0; +// CHECK-MESSAGES: :[[@LINE-1]]:5: warning: invalid case style for global variable 'UPPER_CASE' [readability-identifier-naming] +// CHECK-FIXES: {{^}}int iUpperCase = 0; + +int UPPER_CASE_1 = 0; +// CHECK-MESSAGES: :[[@LINE-1]]:5: warning: invalid case style for global variable 'UPPER_CASE_1' [readability-identifier-naming] +// CHECK-FIXES: {{^}}int iUpperCase1 = 0; + +int camelBack = 0; +// CHECK-MESSAGES: :[[@LINE-1]]:5: warning: invalid case style for global variable 'camelBack' [readability-identifier-naming] +// CHECK-FIXES: {{^}}int iCamelBack = 0; + +int camelBack_1 = 0; +// CHECK-MESSAGES: :[[@LINE-1]]:5: warning: invalid case style for global variable 'camelBack_1' [readability-identifier-naming] +// CHECK-FIXES: {{^}}int iCamelBack1 = 0; + +int camelBack2 = 0; +// CHECK-MESSAGES: :[[@LINE-1]]:5: warning: invalid case style for global variable 'camelBack2' [readability-identifier-naming] +// CHECK-FIXES: {{^}}int iCamelBack2 = 0; + +int CamelCase = 0; +// CHECK-MESSAGES: :[[@LINE-1]]:5: warning: invalid case style for global variable 'CamelCase' [readability-identifier-naming] +// CHECK-FIXES: {{^}}int iCamelCase = 0; + +int CamelCase_1 = 0; +// CHECK-MESSAGES: :[[@LINE-1]]:5: warning: invalid case style for global variable 'CamelCase_1' [readability-identifier-naming] +// CHECK-FIXES: {{^}}int iCamelCase1 = 0; + +int CamelCase2 = 0; +// CHECK-MESSAGES: :[[@LINE-1]]:5: warning: invalid case style for global variable 'CamelCase2' [readability-identifier-naming] +// CHECK-FIXES: {{^}}int iCamelCase2 = 0; + +int camel_Snake_Back = 0; +// CHECK-MESSAGES: :[[@LINE-1]]:5: warning: invalid case style for global variable 'camel_Snake_Back' [readability-identifier-naming] +// CHECK-FIXES: {{^}}int iCamelSnakeBack = 0; + +int camel_Snake_Back_1 = 0; +// CHECK-MESSAGES: :[[@LINE-1]]:5: warning: invalid case style for global variable 'camel_Snake_Back_1' [readability-identifier-naming] +// CHECK-FIXES: {{^}}int iCamelSnakeBack1 = 0; + +int Camel_Snake_Case = 0; +// CHECK-MESSAGES: :[[@LINE-1]]:5: warning: invalid case style for global variable 'Camel_Snake_Case' [readability-identifier-naming] +// CHECK-FIXES: {{^}}int iCamelSnakeCase = 0; + +int Camel_Snake_Case_1 = 0; +// CHECK-MESSAGES: :[[@LINE-1]]:5: warning: invalid case style for global variable 'Camel_Snake_Case_1' [readability-identifier-naming] +// CHECK-FIXES: {{^}}int iCamelSnakeCase1 = 0; + +//===----------------------------------------------------------------------===// +// Enum +//===----------------------------------------------------------------------===// +enum REVINFO_TYPE { RevValid }; +// CHECK-MESSAGES: :[[@LINE-1]]:21: warning: invalid case style for constant 'RevValid' [readability-identifier-naming] +// CHECK-FIXES: {{^}}enum REVINFO_TYPE { rtRevValid }; + +enum DataType { OneByte }; +// CHECK-MESSAGES: :[[@LINE-1]]:17: warning: invalid case style for constant 'OneByte' [readability-identifier-naming] +// CHECK-FIXES: {{^}}enum DataType { dtOneByte }; +// clang-format on diff --git a/clang-tools-extra/test/clang-tidy/checkers/readability-identifier-naming-hungarian-notation.cpp b/clang-tools-extra/test/clang-tidy/checkers/readability-identifier-naming-hungarian-notation.cpp --- a/clang-tools-extra/test/clang-tidy/checkers/readability-identifier-naming-hungarian-notation.cpp +++ b/clang-tools-extra/test/clang-tidy/checkers/readability-identifier-naming-hungarian-notation.cpp @@ -1,3 +1,56 @@ +// RUN: %check_clang_tidy %s readability-identifier-naming %t -- \ +// RUN: -config='{ CheckOptions: [ \ +// RUN: { key: readability-identifier-naming.ClassCase , value: CamelCase }, \ +// RUN: { key: readability-identifier-naming.AbstractClassCase , value: CamelCase }, \ +// RUN: { key: readability-identifier-naming.ClassMemberCase , value: CamelCase }, \ +// RUN: { key: readability-identifier-naming.ConstantCase , value: CamelCase }, \ +// RUN: { key: readability-identifier-naming.ConstantMemberCase , value: CamelCase }, \ +// RUN: { key: readability-identifier-naming.ConstantParameterCase , value: CamelCase }, \ +// RUN: { key: readability-identifier-naming.ConstantPointerParameterCase , value: CamelCase }, \ +// RUN: { key: readability-identifier-naming.ConstexprVariableCase , value: CamelCase }, \ +// RUN: { key: readability-identifier-naming.GlobalConstantCase , value: CamelCase }, \ +// RUN: { key: readability-identifier-naming.GlobalConstantPointerCase , value: CamelCase }, \ +// RUN: { key: readability-identifier-naming.GlobalVariableCase , value: CamelCase }, \ +// RUN: { key: readability-identifier-naming.LocalConstantCase , value: CamelCase }, \ +// RUN: { key: readability-identifier-naming.LocalConstantPointerCase , value: CamelCase }, \ +// RUN: { key: readability-identifier-naming.LocalPointerCase , value: CamelCase }, \ +// RUN: { key: readability-identifier-naming.LocalVariableCase , value: CamelCase }, \ +// RUN: { key: readability-identifier-naming.MemberCase , value: CamelCase }, \ +// RUN: { key: readability-identifier-naming.ParameterCase , value: CamelCase }, \ +// RUN: { key: readability-identifier-naming.PointerParameterCase , value: CamelCase }, \ +// RUN: { key: readability-identifier-naming.PrivateMemberCase , value: CamelCase }, \ +// RUN: { key: readability-identifier-naming.StaticConstantCase , value: CamelCase }, \ +// RUN: { key: readability-identifier-naming.StaticVariableCase , value: CamelCase }, \ +// RUN: { key: readability-identifier-naming.StructCase , value: CamelCase }, \ +// RUN: { key: readability-identifier-naming.UnionCase , value: CamelCase }, \ +// RUN: { key: readability-identifier-naming.VariableCase , value: CamelCase }, \ +// RUN: { key: readability-identifier-naming.ClassHungarianPrefix , value: true }, \ +// RUN: { key: readability-identifier-naming.AbstractClassHungarianPrefix , value: true }, \ +// RUN: { key: readability-identifier-naming.ClassMemberHungarianPrefix , value: true }, \ +// RUN: { key: readability-identifier-naming.ConstantHungarianPrefix , value: true }, \ +// RUN: { key: readability-identifier-naming.ConstantMemberHungarianPrefix , value: true }, \ +// RUN: { key: readability-identifier-naming.ConstantParameterHungarianPrefix , value: true }, \ +// RUN: { key: readability-identifier-naming.ConstantPointerParameterHungarianPrefix , value: true }, \ +// RUN: { key: readability-identifier-naming.ConstexprVariableHungarianPrefix , value: true }, \ +// RUN: { key: readability-identifier-naming.GlobalConstantHungarianPrefix , value: true }, \ +// RUN: { key: readability-identifier-naming.GlobalConstantPointerHungarianPrefix , value: true }, \ +// RUN: { key: readability-identifier-naming.GlobalVariableHungarianPrefix , value: true }, \ +// RUN: { key: readability-identifier-naming.LocalConstantHungarianPrefix , value: true }, \ +// RUN: { key: readability-identifier-naming.LocalConstantPointerHungarianPrefix , value: true }, \ +// RUN: { key: readability-identifier-naming.LocalPointerHungarianPrefix , value: true }, \ +// RUN: { key: readability-identifier-naming.LocalVariableHungarianPrefix , value: true }, \ +// RUN: { key: readability-identifier-naming.MemberHungarianPrefix , value: true }, \ +// RUN: { key: readability-identifier-naming.ParameterHungarianPrefix , value: true }, \ +// RUN: { key: readability-identifier-naming.PointerParameterHungarianPrefix , value: true }, \ +// RUN: { key: readability-identifier-naming.PrivateMemberHungarianPrefix , value: true }, \ +// RUN: { key: readability-identifier-naming.StaticConstantHungarianPrefix , value: true }, \ +// RUN: { key: readability-identifier-naming.StaticVariableHungarianPrefix , value: true }, \ +// RUN: { key: readability-identifier-naming.StructHungarianPrefix , value: true }, \ +// RUN: { key: readability-identifier-naming.UnionHungarianPrefix , value: true }, \ +// RUN: { key: readability-identifier-naming.VariableHungarianPrefix , value: true }, \ +// RUN: ]}' + +// clang-format off typedef signed char int8_t; // NOLINT typedef short int16_t; // NOLINT typedef long int32_t; // NOLINT @@ -16,112 +69,396 @@ typedef unsigned short WORD; // NOLINT typedef unsigned long DWORD; // NOLINT typedef int BOOL; // NOLINT -typedef BYTE BOOLEAN; // NOLINT +typedef int BOOLEAN; // NOLINT +typedef float FLOAT; // NOLINT +typedef int INT; // NOLINT +typedef unsigned int UINT; // NOLINT +typedef unsigned long ULONG; // NOLINT +typedef short SHORT; // NOLINT +typedef unsigned short USHORT; // NOLINT +typedef char CHAR; // NOLINT +typedef unsigned char UCHAR; // NOLINT +typedef signed char INT8; // NOLINT +typedef signed short INT16; // NOLINT +typedef signed int INT32; // NOLINT +typedef signed long long INT64; // NOLINT +typedef unsigned char UINT8; // NOLINT +typedef unsigned short UINT16; // NOLINT +typedef unsigned int UINT32; // NOLINT +typedef unsigned long long UINT64; // NOLINT +typedef long LONG; // NOLINT +typedef signed int LONG32; // NOLINT +typedef unsigned int ULONG32; // NOLINT +typedef uint64_t ULONG64; // NOLINT +typedef unsigned int DWORD32; // NOLINT +typedef uint64_t DWORD64; // NOLINT +typedef uint64_t ULONGLONG; // NOLINT +typedef void* PVOID; // NOLINT +typedef void* HANDLE; // NOLINT +typedef void* FILE; // NOLINT #define NULL (0) // NOLINT +// clang-format on + +// clang-format off +//===----------------------------------------------------------------------===// +// Cases to CheckOptions +//===----------------------------------------------------------------------===// +class CMyClass1 { +public: + static int ClassMemberCase; + // CHECK-MESSAGES: :[[@LINE-1]]:14: warning: invalid case style for class member 'ClassMemberCase' [readability-identifier-naming] + // CHECK-FIXES: {{^}} static int iClassMemberCase; + + char const ConstantMemberCase = 0; + // CHECK-MESSAGES: :[[@LINE-1]]:14: warning: invalid case style for constant member 'ConstantMemberCase' [readability-identifier-naming] + // CHECK-FIXES: {{^}} char const cConstantMemberCase = 0; + + void MyFunc1(const int ConstantParameterCase); + // CHECK-MESSAGES: :[[@LINE-1]]:26: warning: invalid case style for constant parameter 'ConstantParameterCase' [readability-identifier-naming] + // CHECK-FIXES: {{^}} void MyFunc1(const int iConstantParameterCase); + + void MyFunc2(const int* ConstantPointerParameterCase); + // CHECK-MESSAGES: :[[@LINE-1]]:27: warning: invalid case style for pointer parameter 'ConstantPointerParameterCase' [readability-identifier-naming] + // CHECK-FIXES: {{^}} void MyFunc2(const int* piConstantPointerParameterCase); + + static constexpr int ConstexprVariableCase = 123; + // CHECK-MESSAGES: :[[@LINE-1]]:24: warning: invalid case style for constexpr variable 'ConstexprVariableCase' [readability-identifier-naming] + // CHECK-FIXES: {{^}} static constexpr int iConstexprVariableCase = 123; +}; -// RUN: clang-tidy %s -checks=readability-identifier-naming \ -// RUN: -config="{CheckOptions: [\ -// RUN: {key: readability-identifier-naming.FunctionCase , value: CamelCase }, \ -// RUN: {key: readability-identifier-naming.ClassCase , value: szHungarianNotation }, \ -// RUN: {key: readability-identifier-naming.TypedefCase , value: szHungarianNotation }, \ -// RUN: {key: readability-identifier-naming.MemberCase , value: szHungarianNotation }, \ -// RUN: {key: readability-identifier-naming.ClassMemberCase , value: szHungarianNotation }, \ -// RUN: {key: readability-identifier-naming.ConstantMemberCase , value: szHungarianNotation }, \ -// RUN: {key: readability-identifier-naming.VariableCase , value: szHungarianNotation }, \ -// RUN: {key: readability-identifier-naming.ParameterCase , value: szHungarianNotation }, \ -// RUN: {key: readability-identifier-naming.GlobalPointerCase , value: szHungarianNotation }, \ -// RUN: {key: readability-identifier-naming.GlobalVariableCase , value: szHungarianNotation }, \ -// RUN: {key: readability-identifier-naming.GlobalFunctionCase , value: CamelCase } \ -// RUN: ]}" - -class UnlistedClass { public: mutable int ValInt; }; -// CHECK-MESSAGES: :[[@LINE-1]]:43: warning: invalid case style for member 'ValInt' [readability-identifier-naming] -// CHECK-FIXES: {{^}}class UnlistedClass { public: mutable int iValInt; }; - -UnlistedClass cUnlisted2; -// CHECK-MESSAGES: :[[@LINE-1]]:15: warning: invalid case style for global variable 'cUnlisted2' [readability-identifier-naming] -// CHECK-FIXES: {{^}}UnlistedClass Unlisted2; - -UnlistedClass objUnlistedClass3; -// CHECK-MESSAGES: :[[@LINE-1]]:15: warning: invalid case style for global variable 'objUnlistedClass3' [readability-identifier-naming] -// CHECK-FIXES: {{^}}UnlistedClass UnlistedClass3; +const int GlobalConstantCase = 0; +// CHECK-MESSAGES: :[[@LINE-1]]:11: warning: invalid case style for global constant 'GlobalConstantCase' [readability-identifier-naming] +// CHECK-FIXES: {{^}}const int iGlobalConstantCase = 0; -typedef int INDEX; -INDEX iIndex = 0; -// CHECK-MESSAGES: :[[@LINE-1]]:7: warning: invalid case style for global variable 'iIndex' [readability-identifier-naming] -// CHECK-FIXES: {{^}}INDEX Index = 0; +const int* GlobalConstantPointerCase = nullptr; +// CHECK-MESSAGES: :[[@LINE-1]]:12: warning: invalid case style for global variable 'GlobalConstantPointerCase' [readability-identifier-naming] +// CHECK-FIXES: {{^}}const int* piGlobalConstantPointerCase = nullptr; -struct DataBuffer { - mutable size_t Size; +int GlobalVariableCase = 0; +// CHECK-MESSAGES: :[[@LINE-1]]:5: warning: invalid case style for global variable 'GlobalVariableCase' [readability-identifier-naming] +// CHECK-FIXES: {{^}}int iGlobalVariableCase = 0; + +void Func1(){ + int const LocalConstantCase = 3; + // CHECK-MESSAGES: :[[@LINE-1]]:13: warning: invalid case style for local constant 'LocalConstantCase' [readability-identifier-naming] + // CHECK-FIXES: {{^}} int const iLocalConstantCase = 3; + + int* const LocalConstantPointerCase = nullptr; + // CHECK-MESSAGES: :[[@LINE-1]]:14: warning: invalid case style for local constant pointer 'LocalConstantPointerCase' [readability-identifier-naming] + // CHECK-FIXES: {{^}} int* const piLocalConstantPointerCase = nullptr; + + int *LocalPointerCase = nullptr; + // CHECK-MESSAGES: :[[@LINE-1]]:8: warning: invalid case style for local pointer 'LocalPointerCase' [readability-identifier-naming] + // CHECK-FIXES: {{^}} int *piLocalPointerCase = nullptr; + + int LocalVariableCase = 0; + // CHECK-MESSAGES: :[[@LINE-1]]:7: warning: invalid case style for local variable 'LocalVariableCase' [readability-identifier-naming] + // CHECK-FIXES: {{^}} int iLocalVariableCase = 0; +} + +class CMyClass2 { + char MemberCase; + // CHECK-MESSAGES: :[[@LINE-1]]:8: warning: invalid case style for private member 'MemberCase' [readability-identifier-naming] + // CHECK-FIXES: {{^}} char cMemberCase; + + void Func1(int ParameterCase); + // CHECK-MESSAGES: :[[@LINE-1]]:18: warning: invalid case style for parameter 'ParameterCase' [readability-identifier-naming] + // CHECK-FIXES: {{^}} void Func1(int iParameterCase); + + void Func2(const int ParameterCase); + // CHECK-MESSAGES: :[[@LINE-1]]:24: warning: invalid case style for constant parameter 'ParameterCase' [readability-identifier-naming] + // CHECK-FIXES: {{^}} void Func2(const int iParameterCase); + + void Func3(const int *PointerParameterCase); + // CHECK-MESSAGES: :[[@LINE-1]]:25: warning: invalid case style for pointer parameter 'PointerParameterCase' [readability-identifier-naming] + // CHECK-FIXES: {{^}} void Func3(const int *piPointerParameterCase); }; -// CHECK-MESSAGES: :[[@LINE-2]]:20: warning: invalid case style for member 'Size' [readability-identifier-naming] -// CHECK-FIXES: {{^}} mutable size_t nSize; -int &RefValueIndex = iIndex; -// CHECK-MESSAGES: :[[@LINE-1]]:6: warning: invalid case style for global variable 'RefValueIndex' [readability-identifier-naming] -// CHECK-FIXES: {{^}}int &iRefValueIndex = Index; +class CMyClass3 { +private: + char PrivateMemberCase; + // CHECK-MESSAGES: :[[@LINE-1]]:8: warning: invalid case style for private member 'PrivateMemberCase' [readability-identifier-naming] + // CHECK-FIXES: {{^}} char cPrivateMemberCase; +}; -typedef void (*FUNC_PTR_HELLO)(); -FUNC_PTR_HELLO Hello = NULL; -// CHECK-MESSAGES: :[[@LINE-1]]:16: warning: invalid case style for global pointer 'Hello' [readability-identifier-naming] -// CHECK-FIXES: {{^}}FUNC_PTR_HELLO fnHello = NULL; +static const int StaticConstantCase = 3; +// CHECK-MESSAGES: :[[@LINE-1]]:18: warning: invalid case style for global constant 'StaticConstantCase' [readability-identifier-naming] +// CHECK-FIXES: {{^}}static const int iStaticConstantCase = 3; -void *ValueVoidPtr = NULL; -// CHECK-MESSAGES: :[[@LINE-1]]:7: warning: invalid case style for global pointer 'ValueVoidPtr' [readability-identifier-naming] -// CHECK-FIXES: {{^}}void *pValueVoidPtr = NULL; +static int StaticVariableCase = 3; +// CHECK-MESSAGES: :[[@LINE-1]]:12: warning: invalid case style for global variable 'StaticVariableCase' [readability-identifier-naming] +// CHECK-FIXES: {{^}}static int iStaticVariableCase = 3; -ptrdiff_t PtrDiff = NULL; -// CHECK-MESSAGES: :[[@LINE-1]]:11: warning: invalid case style for global variable 'PtrDiff' [readability-identifier-naming] -// CHECK-FIXES: {{^}}ptrdiff_t pPtrDiff = NULL; +struct MyStruct { int StructCase; }; +// CHECK-MESSAGES: :[[@LINE-1]]:23: warning: invalid case style for member 'StructCase' [readability-identifier-naming] +// CHECK-FIXES: {{^}}struct MyStruct { int iStructCase; }; + +union MyUnion { int UnionCase1; long lUnionCase2; }; +// CHECK-MESSAGES: :[[@LINE-1]]:21: warning: invalid case style for member 'UnionCase1' [readability-identifier-naming] +// CHECK-FIXES: {{^}}union MyUnion { int iUnionCase1; long lUnionCase2; }; +//===----------------------------------------------------------------------===// +// C string +//===----------------------------------------------------------------------===// const char *NamePtr = "Name"; -// CHECK-MESSAGES: :[[@LINE-1]]:13: warning: invalid case style for global pointer 'NamePtr' [readability-identifier-naming] +// CHECK-MESSAGES: :[[@LINE-1]]:13: warning: invalid case style for global variable 'NamePtr' [readability-identifier-naming] // CHECK-FIXES: {{^}}const char *szNamePtr = "Name"; const char NameArray[] = "Name"; -// CHECK-MESSAGES: :[[@LINE-1]]:12: warning: invalid case style for global variable 'NameArray' [readability-identifier-naming] +// CHECK-MESSAGES: :[[@LINE-1]]:12: warning: invalid case style for global constant 'NameArray' [readability-identifier-naming] // CHECK-FIXES: {{^}}const char szNameArray[] = "Name"; const char *NamePtrArray[] = {"AA", "BB"}; // CHECK-MESSAGES: :[[@LINE-1]]:13: warning: invalid case style for global variable 'NamePtrArray' [readability-identifier-naming] // CHECK-FIXES: {{^}}const char *pszNamePtrArray[] = {"AA", "BB"}; +const wchar_t *WideNamePtr = L"Name"; +// CHECK-MESSAGES: :[[@LINE-1]]:16: warning: invalid case style for global variable 'WideNamePtr' [readability-identifier-naming] +// CHECK-FIXES: {{^}}const wchar_t *wszWideNamePtr = L"Name"; + +const wchar_t WideNameArray[] = L"Name"; +// CHECK-MESSAGES: :[[@LINE-1]]:15: warning: invalid case style for global constant 'WideNameArray' [readability-identifier-naming] +// CHECK-FIXES: {{^}}const wchar_t wszWideNameArray[] = L"Name"; + +const wchar_t *WideNamePtrArray[] = {L"AA", L"BB"}; +// CHECK-MESSAGES: :[[@LINE-1]]:16: warning: invalid case style for global variable 'WideNamePtrArray' [readability-identifier-naming] +// CHECK-FIXES: {{^}}const wchar_t *pwszWideNamePtrArray[] = {L"AA", L"BB"}; + +class CMyClass4 { +private: + char *Name = "Text"; + // CHECK-MESSAGES: :[[@LINE-1]]:9: warning: invalid case style for private member 'Name' [readability-identifier-naming] + // CHECK-FIXES: {{^}} char *szName = "Text"; + + const char *ConstName = "Text"; + // CHECK-MESSAGES: :[[@LINE-1]]:15: warning: invalid case style for private member 'ConstName' [readability-identifier-naming] + // CHECK-FIXES: {{^}} const char *szConstName = "Text"; + +public: + const char* DuplicateString(const char* Input, size_t nRequiredSize); + // CHECK-MESSAGES: :[[@LINE-1]]:43: warning: invalid case style for pointer parameter 'Input' [readability-identifier-naming] + // CHECK-FIXES: {{^}} const char* DuplicateString(const char* szInput, size_t nRequiredSize); + + size_t UpdateText(const char* Buffer, size_t nBufferSize); + // CHECK-MESSAGES: :[[@LINE-1]]:33: warning: invalid case style for pointer parameter 'Buffer' [readability-identifier-naming] + // CHECK-FIXES: {{^}} size_t UpdateText(const char* szBuffer, size_t nBufferSize); +}; + + +//===----------------------------------------------------------------------===// +// Microsoft Windows data types +//===----------------------------------------------------------------------===// +DWORD MsDword = 0; +// CHECK-MESSAGES: :[[@LINE-1]]:7: warning: invalid case style for global variable 'MsDword' [readability-identifier-naming] +// CHECK-FIXES: {{^}}DWORD dwMsDword = 0; + +BYTE MsByte = 0; +// CHECK-MESSAGES: :[[@LINE-1]]:6: warning: invalid case style for global variable 'MsByte' [readability-identifier-naming] +// CHECK-FIXES: {{^}}BYTE byMsByte = 0; + +WORD MsWord = 0; +// CHECK-MESSAGES: :[[@LINE-1]]:6: warning: invalid case style for global variable 'MsWord' [readability-identifier-naming] +// CHECK-FIXES: {{^}}WORD wMsWord = 0; + +BOOL MsBool = 0; +// CHECK-MESSAGES: :[[@LINE-1]]:6: warning: invalid case style for global variable 'MsBool' [readability-identifier-naming] +// CHECK-FIXES: {{^}}BOOL bMsBool = 0; + +BOOLEAN MsBoolean = 0; +// CHECK-MESSAGES: :[[@LINE-1]]:9: warning: invalid case style for global variable 'MsBoolean' [readability-identifier-naming] +// CHECK-FIXES: {{^}}BOOLEAN bMsBoolean = 0; + +CHAR MsValueChar = 0; +// CHECK-MESSAGES: :[[@LINE-1]]:6: warning: invalid case style for global variable 'MsValueChar' [readability-identifier-naming] +// CHECK-FIXES: {{^}}CHAR cMsValueChar = 0; + +UCHAR MsValueUchar = 0; +// CHECK-MESSAGES: :[[@LINE-1]]:7: warning: invalid case style for global variable 'MsValueUchar' [readability-identifier-naming] +// CHECK-FIXES: {{^}}UCHAR ucMsValueUchar = 0; + +SHORT MsValueShort = 0; +// CHECK-MESSAGES: :[[@LINE-1]]:7: warning: invalid case style for global variable 'MsValueShort' [readability-identifier-naming] +// CHECK-FIXES: {{^}}SHORT sMsValueShort = 0; + +USHORT MsValueUshort = 0; +// CHECK-MESSAGES: :[[@LINE-1]]:8: warning: invalid case style for global variable 'MsValueUshort' [readability-identifier-naming] +// CHECK-FIXES: {{^}}USHORT usMsValueUshort = 0; + +WORD MsValueWord = 0; +// CHECK-MESSAGES: :[[@LINE-1]]:6: warning: invalid case style for global variable 'MsValueWord' [readability-identifier-naming] +// CHECK-FIXES: {{^}}WORD wMsValueWord = 0; + +DWORD MsValueDword = 0; +// CHECK-MESSAGES: :[[@LINE-1]]:7: warning: invalid case style for global variable 'MsValueDword' [readability-identifier-naming] +// CHECK-FIXES: {{^}}DWORD dwMsValueDword = 0; + +DWORD32 MsValueDword32 = 0; +// CHECK-MESSAGES: :[[@LINE-1]]:9: warning: invalid case style for global variable 'MsValueDword32' [readability-identifier-naming] +// CHECK-FIXES: {{^}}DWORD32 dw32MsValueDword32 = 0; + +DWORD64 MsValueDword64 = 0; +// CHECK-MESSAGES: :[[@LINE-1]]:9: warning: invalid case style for global variable 'MsValueDword64' [readability-identifier-naming] +// CHECK-FIXES: {{^}}DWORD64 dw64MsValueDword64 = 0; + +LONG MsValueLong = 0; +// CHECK-MESSAGES: :[[@LINE-1]]:6: warning: invalid case style for global variable 'MsValueLong' [readability-identifier-naming] +// CHECK-FIXES: {{^}}LONG lMsValueLong = 0; + +ULONG MsValueUlong = 0; +// CHECK-MESSAGES: :[[@LINE-1]]:7: warning: invalid case style for global variable 'MsValueUlong' [readability-identifier-naming] +// CHECK-FIXES: {{^}}ULONG ulMsValueUlong = 0; + +ULONG32 MsValueUlong32 = 0; +// CHECK-MESSAGES: :[[@LINE-1]]:9: warning: invalid case style for global variable 'MsValueUlong32' [readability-identifier-naming] +// CHECK-FIXES: {{^}}ULONG32 ul32MsValueUlong32 = 0; + +ULONG64 MsValueUlong64 = 0; +// CHECK-MESSAGES: :[[@LINE-1]]:9: warning: invalid case style for global variable 'MsValueUlong64' [readability-identifier-naming] +// CHECK-FIXES: {{^}}ULONG64 ul64MsValueUlong64 = 0; + +ULONGLONG MsValueUlongLong = 0; +// CHECK-MESSAGES: :[[@LINE-1]]:11: warning: invalid case style for global variable 'MsValueUlongLong' [readability-identifier-naming] +// CHECK-FIXES: {{^}}ULONGLONG ullMsValueUlongLong = 0; + +HANDLE MsValueHandle = 0; +// CHECK-MESSAGES: :[[@LINE-1]]:8: warning: invalid case style for global variable 'MsValueHandle' [readability-identifier-naming] +// CHECK-FIXES: {{^}}HANDLE hMsValueHandle = 0; + +INT MsValueInt = 0; +// CHECK-MESSAGES: :[[@LINE-1]]:5: warning: invalid case style for global variable 'MsValueInt' [readability-identifier-naming] +// CHECK-FIXES: {{^}}INT iMsValueInt = 0; + +INT8 MsValueInt8 = 0; +// CHECK-MESSAGES: :[[@LINE-1]]:6: warning: invalid case style for global variable 'MsValueInt8' [readability-identifier-naming] +// CHECK-FIXES: {{^}}INT8 i8MsValueInt8 = 0; + +INT16 MsValueInt16 = 0; +// CHECK-MESSAGES: :[[@LINE-1]]:7: warning: invalid case style for global variable 'MsValueInt16' [readability-identifier-naming] +// CHECK-FIXES: {{^}}INT16 i16MsValueInt16 = 0; + +INT32 MsValueInt32 = 0; +// CHECK-MESSAGES: :[[@LINE-1]]:7: warning: invalid case style for global variable 'MsValueInt32' [readability-identifier-naming] +// CHECK-FIXES: {{^}}INT32 i32MsValueInt32 = 0; + +INT64 MsValueINt64 = 0; +// CHECK-MESSAGES: :[[@LINE-1]]:7: warning: invalid case style for global variable 'MsValueINt64' [readability-identifier-naming] +// CHECK-FIXES: {{^}}INT64 i64MsValueINt64 = 0; + +UINT MsValueUint = 0; +// CHECK-MESSAGES: :[[@LINE-1]]:6: warning: invalid case style for global variable 'MsValueUint' [readability-identifier-naming] +// CHECK-FIXES: {{^}}UINT uiMsValueUint = 0; + +UINT8 MsValueUint8 = 0; +// CHECK-MESSAGES: :[[@LINE-1]]:7: warning: invalid case style for global variable 'MsValueUint8' [readability-identifier-naming] +// CHECK-FIXES: {{^}}UINT8 u8MsValueUint8 = 0; + +UINT16 MsValueUint16 = 0; +// CHECK-MESSAGES: :[[@LINE-1]]:8: warning: invalid case style for global variable 'MsValueUint16' [readability-identifier-naming] +// CHECK-FIXES: {{^}}UINT16 u16MsValueUint16 = 0; + +UINT32 MsValueUint32 = 0; +// CHECK-MESSAGES: :[[@LINE-1]]:8: warning: invalid case style for global variable 'MsValueUint32' [readability-identifier-naming] +// CHECK-FIXES: {{^}}UINT32 u32MsValueUint32 = 0; + +UINT64 MsValueUint64 = 0; +// CHECK-MESSAGES: :[[@LINE-1]]:8: warning: invalid case style for global variable 'MsValueUint64' [readability-identifier-naming] +// CHECK-FIXES: {{^}}UINT64 u64MsValueUint64 = 0; + +PVOID MsValuePvoid = NULL; +// CHECK-MESSAGES: :[[@LINE-1]]:7: warning: invalid case style for global variable 'MsValuePvoid' [readability-identifier-naming] +// CHECK-FIXES: {{^}}PVOID pMsValuePvoid = NULL; + + +//===----------------------------------------------------------------------===// +// Array +//===----------------------------------------------------------------------===// +unsigned GlobalUnsignedArray[] = {1, 2, 3}; +// CHECK-MESSAGES: :[[@LINE-1]]:10: warning: invalid case style for global variable 'GlobalUnsignedArray' [readability-identifier-naming] +// CHECK-FIXES: {{^}}unsigned aGlobalUnsignedArray[] = {1, 2, 3}; + +int GlobalIntArray[] = {1, 2, 3}; +// CHECK-MESSAGES: :[[@LINE-1]]:5: warning: invalid case style for global variable 'GlobalIntArray' [readability-identifier-naming] +// CHECK-FIXES: {{^}}int aGlobalIntArray[] = {1, 2, 3}; + int DataInt[1] = {0}; // CHECK-MESSAGES: :[[@LINE-1]]:5: warning: invalid case style for global variable 'DataInt' [readability-identifier-naming] // CHECK-FIXES: {{^}}int aDataInt[1] = {0}; +int DataArray[2] = {0}; +// CHECK-MESSAGES: :[[@LINE-1]]:5: warning: invalid case style for global variable 'DataArray' [readability-identifier-naming] +// CHECK-FIXES: {{^}}int aDataArray[2] = {0}; + + +//===----------------------------------------------------------------------===// +// Pointer +//===----------------------------------------------------------------------===// int *DataIntPtr[1] = {0}; // CHECK-MESSAGES: :[[@LINE-1]]:6: warning: invalid case style for global variable 'DataIntPtr' [readability-identifier-naming] // CHECK-FIXES: {{^}}int *paDataIntPtr[1] = {0}; void *BufferPtr1; -// CHECK-MESSAGES: :[[@LINE-1]]:7: warning: invalid case style for global pointer 'BufferPtr1' [readability-identifier-naming] +// CHECK-MESSAGES: :[[@LINE-1]]:7: warning: invalid case style for global variable 'BufferPtr1' [readability-identifier-naming] // CHECK-FIXES: {{^}}void *pBufferPtr1; void **BufferPtr2; -// CHECK-MESSAGES: :[[@LINE-1]]:8: warning: invalid case style for global pointer 'BufferPtr2' [readability-identifier-naming] +// CHECK-MESSAGES: :[[@LINE-1]]:8: warning: invalid case style for global variable 'BufferPtr2' [readability-identifier-naming] // CHECK-FIXES: {{^}}void **ppBufferPtr2; void **pBufferPtr3; -// CHECK-MESSAGES: :[[@LINE-1]]:8: warning: invalid case style for global pointer 'pBufferPtr3' [readability-identifier-naming] +// CHECK-MESSAGES: :[[@LINE-1]]:8: warning: invalid case style for global variable 'pBufferPtr3' [readability-identifier-naming] // CHECK-FIXES: {{^}}void **ppBufferPtr3; int *pBufferPtr4; -// CHECK-MESSAGES: :[[@LINE-1]]:6: warning: invalid case style for global pointer 'pBufferPtr4' [readability-identifier-naming] +// CHECK-MESSAGES: :[[@LINE-1]]:6: warning: invalid case style for global variable 'pBufferPtr4' [readability-identifier-naming] // CHECK-FIXES: {{^}}int *piBufferPtr4; -int DataArray[2] = {0}; -// CHECK-MESSAGES: :[[@LINE-1]]:5: warning: invalid case style for global variable 'DataArray' [readability-identifier-naming] -// CHECK-FIXES: {{^}}int aDataArray[2] = {0}; +typedef void (*FUNC_PTR_HELLO)(); +FUNC_PTR_HELLO Hello = NULL; +// CHECK-MESSAGES: :[[@LINE-1]]:16: warning: invalid case style for global variable 'Hello' [readability-identifier-naming] +// CHECK-FIXES: {{^}}FUNC_PTR_HELLO fnHello = NULL; + +void *ValueVoidPtr = NULL; +// CHECK-MESSAGES: :[[@LINE-1]]:7: warning: invalid case style for global variable 'ValueVoidPtr' [readability-identifier-naming] +// CHECK-FIXES: {{^}}void *pValueVoidPtr = NULL; + +ptrdiff_t PtrDiff = NULL; +// CHECK-MESSAGES: :[[@LINE-1]]:11: warning: invalid case style for global variable 'PtrDiff' [readability-identifier-naming] +// CHECK-FIXES: {{^}}ptrdiff_t pPtrDiff = NULL; int8_t *ValueI8Ptr; -// CHECK-MESSAGES: :[[@LINE-1]]:9: warning: invalid case style for global pointer 'ValueI8Ptr' [readability-identifier-naming] +// CHECK-MESSAGES: :[[@LINE-1]]:9: warning: invalid case style for global variable 'ValueI8Ptr' [readability-identifier-naming] // CHECK-FIXES: {{^}}int8_t *pi8ValueI8Ptr; uint8_t *ValueU8Ptr; -// CHECK-MESSAGES: :[[@LINE-1]]:10: warning: invalid case style for global pointer 'ValueU8Ptr' [readability-identifier-naming] +// CHECK-MESSAGES: :[[@LINE-1]]:10: warning: invalid case style for global variable 'ValueU8Ptr' [readability-identifier-naming] // CHECK-FIXES: {{^}}uint8_t *pu8ValueU8Ptr; +void MyFunc2(void* Val){} +// CHECK-MESSAGES: :[[@LINE-1]]:20: warning: invalid case style for pointer parameter 'Val' [readability-identifier-naming] +// CHECK-FIXES: {{^}}void MyFunc2(void* pVal){} + + +//===----------------------------------------------------------------------===// +// Reference +//===----------------------------------------------------------------------===// +int iValueIndex = 1; +int &RefValueIndex = iValueIndex; +// CHECK-MESSAGES: :[[@LINE-1]]:6: warning: invalid case style for global variable 'RefValueIndex' [readability-identifier-naming] +// CHECK-FIXES: {{^}}int &iRefValueIndex = iValueIndex; + +const int &ConstRefValue = iValueIndex; +// CHECK-MESSAGES: :[[@LINE-1]]:12: warning: invalid case style for global variable 'ConstRefValue' [readability-identifier-naming] +// CHECK-FIXES: {{^}}const int &iConstRefValue = iValueIndex; + +long long llValueLongLong = 2; +long long &RefValueLongLong = llValueLongLong; +// CHECK-MESSAGES: :[[@LINE-1]]:12: warning: invalid case style for global variable 'RefValueLongLong' [readability-identifier-naming] +// CHECK-FIXES: {{^}}long long &llRefValueLongLong = llValueLongLong; + + +//===----------------------------------------------------------------------===// +// Various types +//===----------------------------------------------------------------------===// int8_t ValueI8; // CHECK-MESSAGES: :[[@LINE-1]]:8: warning: invalid case style for global variable 'ValueI8' [readability-identifier-naming] // CHECK-FIXES: {{^}}int8_t i8ValueI8; @@ -174,10 +511,6 @@ // CHECK-MESSAGES: :[[@LINE-1]]:5: warning: invalid case style for global variable 'ValueInt' [readability-identifier-naming] // CHECK-FIXES: {{^}}int iValueInt = 0; -int &RefValueInt = ValueInt; -// CHECK-MESSAGES: :[[@LINE-1]]:6: warning: invalid case style for global variable 'RefValueInt' [readability-identifier-naming] -// CHECK-FIXES: {{^}}int &iRefValueInt = iValueInt; - size_t ValueSize = 0; // CHECK-MESSAGES: :[[@LINE-1]]:8: warning: invalid case style for global variable 'ValueSize' [readability-identifier-naming] // CHECK-FIXES: {{^}}size_t nValueSize = 0; @@ -196,7 +529,7 @@ signed ValueSigned = 0; // CHECK-MESSAGES: :[[@LINE-1]]:8: warning: invalid case style for global variable 'ValueSigned' [readability-identifier-naming] -// CHECK-FIXES: {{^}}signed iValueSigned = 0; +// CHECK-FIXES: {{^}}signed sValueSigned = 0; long ValueLong = 0; // CHECK-MESSAGES: :[[@LINE-1]]:6: warning: invalid case style for global variable 'ValueLong' [readability-identifier-naming] @@ -206,22 +539,78 @@ // CHECK-MESSAGES: :[[@LINE-1]]:11: warning: invalid case style for global variable 'ValueLongLong' [readability-identifier-naming] // CHECK-FIXES: {{^}}long long llValueLongLong = 0; -long long &RefValueLongLong = ValueLongLong; -// CHECK-MESSAGES: :[[@LINE-1]]:12: warning: invalid case style for global variable 'RefValueLongLong' [readability-identifier-naming] -// CHECK-FIXES: {{^}}long long &llRefValueLongLong = llValueLongLong; +long long int ValueLongLongInt = 0; +// CHECK-MESSAGES: :[[@LINE-1]]:15: warning: invalid case style for global variable 'ValueLongLongInt' [readability-identifier-naming] +// CHECK-FIXES: {{^}}long long int lliValueLongLongInt = 0; long double ValueLongDouble = 0; // CHECK-MESSAGES: :[[@LINE-1]]:13: warning: invalid case style for global variable 'ValueLongDouble' [readability-identifier-naming] // CHECK-FIXES: {{^}}long double ldValueLongDouble = 0; +signed int ValueSignedInt = 0; +// CHECK-MESSAGES: :[[@LINE-1]]:12: warning: invalid case style for global variable 'ValueSignedInt' [readability-identifier-naming] +// CHECK-FIXES: {{^}}signed int siValueSignedInt = 0; + +signed short ValueSignedShort = 0; +// CHECK-MESSAGES: :[[@LINE-1]]:14: warning: invalid case style for global variable 'ValueSignedShort' [readability-identifier-naming] +// CHECK-FIXES: {{^}}signed short ssValueSignedShort = 0; + +signed short int ValueSignedShortInt = 0; +// CHECK-MESSAGES: :[[@LINE-1]]:18: warning: invalid case style for global variable 'ValueSignedShortInt' [readability-identifier-naming] +// CHECK-FIXES: {{^}}signed short int ssiValueSignedShortInt = 0; + +signed long long ValueSignedLongLong = 0; +// CHECK-MESSAGES: :[[@LINE-1]]:18: warning: invalid case style for global variable 'ValueSignedLongLong' [readability-identifier-naming] +// CHECK-FIXES: {{^}}signed long long sllValueSignedLongLong = 0; + +signed long int ValueSignedLongInt = 0; +// CHECK-MESSAGES: :[[@LINE-1]]:17: warning: invalid case style for global variable 'ValueSignedLongInt' [readability-identifier-naming] +// CHECK-FIXES: {{^}}signed long int sliValueSignedLongInt = 0; + +signed long ValueSignedLong = 0; +// CHECK-MESSAGES: :[[@LINE-1]]:13: warning: invalid case style for global variable 'ValueSignedLong' [readability-identifier-naming] +// CHECK-FIXES: {{^}}signed long slValueSignedLong = 0; + +unsigned long long int ValueUnsignedLongLongInt = 0; +// CHECK-MESSAGES: :[[@LINE-1]]:24: warning: invalid case style for global variable 'ValueUnsignedLongLongInt' [readability-identifier-naming] +// CHECK-FIXES: {{^}}unsigned long long int ulliValueUnsignedLongLongInt = 0; + +unsigned long long ValueUnsignedLongLong = 0; +// CHECK-MESSAGES: :[[@LINE-1]]:20: warning: invalid case style for global variable 'ValueUnsignedLongLong' [readability-identifier-naming] +// CHECK-FIXES: {{^}}unsigned long long ullValueUnsignedLongLong = 0; + +unsigned long int ValueUnsignedLongInt = 0; +// CHECK-MESSAGES: :[[@LINE-1]]:19: warning: invalid case style for global variable 'ValueUnsignedLongInt' [readability-identifier-naming] +// CHECK-FIXES: {{^}}unsigned long int uliValueUnsignedLongInt = 0; + +unsigned long ValueUnsignedLong = 0; +// CHECK-MESSAGES: :[[@LINE-1]]:15: warning: invalid case style for global variable 'ValueUnsignedLong' [readability-identifier-naming] +// CHECK-FIXES: {{^}}unsigned long ulValueUnsignedLong = 0; + +unsigned short int ValueUnsignedShortInt = 0; +// CHECK-MESSAGES: :[[@LINE-1]]:20: warning: invalid case style for global variable 'ValueUnsignedShortInt' [readability-identifier-naming] +// CHECK-FIXES: {{^}}unsigned short int usiValueUnsignedShortInt = 0; + +unsigned short ValueUnsignedShort = 0; +// CHECK-MESSAGES: :[[@LINE-1]]:16: warning: invalid case style for global variable 'ValueUnsignedShort' [readability-identifier-naming] +// CHECK-FIXES: {{^}}unsigned short usValueUnsignedShort = 0; + +unsigned int ValueUnsignedInt = 0; +// CHECK-MESSAGES: :[[@LINE-1]]:14: warning: invalid case style for global variable 'ValueUnsignedInt' [readability-identifier-naming] +// CHECK-FIXES: {{^}}unsigned int uiValueUnsignedInt = 0; + +long int ValueLongInt = 0; +// CHECK-MESSAGES: :[[@LINE-1]]:10: warning: invalid case style for global variable 'ValueLongInt' [readability-identifier-naming] +// CHECK-FIXES: {{^}}long int liValueLongInt = 0; + + +//===----------------------------------------------------------------------===// +// Specifier, Qualifier, Other keywords +//===----------------------------------------------------------------------===// volatile int VolatileInt = 0; // CHECK-MESSAGES: :[[@LINE-1]]:14: warning: invalid case style for global variable 'VolatileInt' [readability-identifier-naming] // CHECK-FIXES: {{^}}volatile int iVolatileInt = 0; -const int &ConstRefValue = ValueInt; -// CHECK-MESSAGES: :[[@LINE-1]]:12: warning: invalid case style for global variable 'ConstRefValue' [readability-identifier-naming] -// CHECK-FIXES: {{^}}const int &iConstRefValue = iValueInt; - thread_local int ThreadLocalValueInt = 0; // CHECK-MESSAGES: :[[@LINE-1]]:18: warning: invalid case style for global variable 'ThreadLocalValueInt' [readability-identifier-naming] // CHECK-FIXES: {{^}}thread_local int iThreadLocalValueInt = 0; @@ -230,34 +619,113 @@ // CHECK-MESSAGES: :[[@LINE-1]]:12: warning: invalid case style for global variable 'ExternValueInt' [readability-identifier-naming] // CHECK-FIXES: {{^}}extern int iExternValueInt; -void MyFunc1(int Val){} -// CHECK-MESSAGES: :[[@LINE-1]]:18: warning: invalid case style for parameter 'Val' [readability-identifier-naming] -// CHECK-FIXES: {{^}}void MyFunc1(int iVal){} - -void MyFunc2(void* Val){} -// CHECK-MESSAGES: :[[@LINE-1]]:20: warning: invalid case style for parameter 'Val' [readability-identifier-naming] -// CHECK-FIXES: {{^}}void MyFunc2(void* pVal){} +struct DataBuffer { + mutable size_t Size; +}; +// CHECK-MESSAGES: :[[@LINE-2]]:20: warning: invalid case style for member 'Size' [readability-identifier-naming] +// CHECK-FIXES: {{^}} mutable size_t nSize; static constexpr int const &ConstExprInt = 42; -// CHECK-MESSAGES: :[[@LINE-1]]:29: warning: invalid case style for global variable 'ConstExprInt' [readability-identifier-naming] +// CHECK-MESSAGES: :[[@LINE-1]]:29: warning: invalid case style for constexpr variable 'ConstExprInt' [readability-identifier-naming] // CHECK-FIXES: {{^}}static constexpr int const &iConstExprInt = 42; -DWORD MsDword = 0; -// CHECK-MESSAGES: :[[@LINE-1]]:7: warning: invalid case style for global variable 'MsDword' [readability-identifier-naming] -// CHECK-FIXES: {{^}}DWORD dwMsDword = 0; - -BYTE MsByte = 0; -// CHECK-MESSAGES: :[[@LINE-1]]:6: warning: invalid case style for global variable 'MsByte' [readability-identifier-naming] -// CHECK-FIXES: {{^}}BYTE byMsByte = 0; -WORD MsWord = 0; -// CHECK-MESSAGES: :[[@LINE-1]]:6: warning: invalid case style for global variable 'MsWord' [readability-identifier-naming] -// CHECK-FIXES: {{^}}WORD wMsWord = 0; +//===----------------------------------------------------------------------===// +// Redefined types +//===----------------------------------------------------------------------===// +typedef int INDEX; +INDEX iIndex = 0; +// CHECK-MESSAGES: :[[@LINE-1]]:7: warning: invalid case style for global variable 'iIndex' [readability-identifier-naming] +// CHECK-FIXES: {{^}}INDEX Index = 0; -BOOL MsBool = 0; -// CHECK-MESSAGES: :[[@LINE-1]]:6: warning: invalid case style for global variable 'MsBool' [readability-identifier-naming] -// CHECK-FIXES: {{^}}BOOL bMsBool = 0; -BOOLEAN MsBoolean = 0; -// CHECK-MESSAGES: :[[@LINE-1]]:9: warning: invalid case style for global variable 'MsBoolean' [readability-identifier-naming] -// CHECK-FIXES: {{^}}BOOLEAN bMsBoolean = 0; +//===----------------------------------------------------------------------===// +// Class +//===----------------------------------------------------------------------===// +class GenericClass { int Func(); }; +// CHECK-MESSAGES: :[[@LINE-1]]:7: warning: invalid case style for class 'GenericClass' [readability-identifier-naming] +// CHECK-FIXES: {{^}}class CGenericClass { int Func(); }; + +class AbstractClass { virtual int Func() = 0; }; +// CHECK-MESSAGES: :[[@LINE-1]]:7: warning: invalid case style for abstract class 'AbstractClass' [readability-identifier-naming] +// CHECK-FIXES: {{^}}class IAbstractClass { virtual int Func() = 0; }; + +class AbstractClass1 { virtual int Func1() = 0; int Func2(); }; +// CHECK-MESSAGES: :[[@LINE-1]]:7: warning: invalid case style for abstract class 'AbstractClass1' [readability-identifier-naming] +// CHECK-FIXES: {{^}}class IAbstractClass1 { virtual int Func1() = 0; int Func2(); }; + + +//===----------------------------------------------------------------------===// +// Other Cases +//===----------------------------------------------------------------------===// +int lower_case = 0; +// CHECK-MESSAGES: :[[@LINE-1]]:5: warning: invalid case style for global variable 'lower_case' [readability-identifier-naming] +// CHECK-FIXES: {{^}}int iLowerCase = 0; + +int lower_case1 = 0; +// CHECK-MESSAGES: :[[@LINE-1]]:5: warning: invalid case style for global variable 'lower_case1' [readability-identifier-naming] +// CHECK-FIXES: {{^}}int iLowerCase1 = 0; + +int lower_case_2 = 0; +// CHECK-MESSAGES: :[[@LINE-1]]:5: warning: invalid case style for global variable 'lower_case_2' [readability-identifier-naming] +// CHECK-FIXES: {{^}}int iLowerCase2 = 0; + +int UPPER_CASE = 0; +// CHECK-MESSAGES: :[[@LINE-1]]:5: warning: invalid case style for global variable 'UPPER_CASE' [readability-identifier-naming] +// CHECK-FIXES: {{^}}int iUpperCase = 0; + +int UPPER_CASE_1 = 0; +// CHECK-MESSAGES: :[[@LINE-1]]:5: warning: invalid case style for global variable 'UPPER_CASE_1' [readability-identifier-naming] +// CHECK-FIXES: {{^}}int iUpperCase1 = 0; + +int camelBack = 0; +// CHECK-MESSAGES: :[[@LINE-1]]:5: warning: invalid case style for global variable 'camelBack' [readability-identifier-naming] +// CHECK-FIXES: {{^}}int iCamelBack = 0; + +int camelBack_1 = 0; +// CHECK-MESSAGES: :[[@LINE-1]]:5: warning: invalid case style for global variable 'camelBack_1' [readability-identifier-naming] +// CHECK-FIXES: {{^}}int iCamelBack1 = 0; + +int camelBack2 = 0; +// CHECK-MESSAGES: :[[@LINE-1]]:5: warning: invalid case style for global variable 'camelBack2' [readability-identifier-naming] +// CHECK-FIXES: {{^}}int iCamelBack2 = 0; + +int CamelCase = 0; +// CHECK-MESSAGES: :[[@LINE-1]]:5: warning: invalid case style for global variable 'CamelCase' [readability-identifier-naming] +// CHECK-FIXES: {{^}}int iCamelCase = 0; + +int CamelCase_1 = 0; +// CHECK-MESSAGES: :[[@LINE-1]]:5: warning: invalid case style for global variable 'CamelCase_1' [readability-identifier-naming] +// CHECK-FIXES: {{^}}int iCamelCase1 = 0; + +int CamelCase2 = 0; +// CHECK-MESSAGES: :[[@LINE-1]]:5: warning: invalid case style for global variable 'CamelCase2' [readability-identifier-naming] +// CHECK-FIXES: {{^}}int iCamelCase2 = 0; + +int camel_Snake_Back = 0; +// CHECK-MESSAGES: :[[@LINE-1]]:5: warning: invalid case style for global variable 'camel_Snake_Back' [readability-identifier-naming] +// CHECK-FIXES: {{^}}int iCamelSnakeBack = 0; + +int camel_Snake_Back_1 = 0; +// CHECK-MESSAGES: :[[@LINE-1]]:5: warning: invalid case style for global variable 'camel_Snake_Back_1' [readability-identifier-naming] +// CHECK-FIXES: {{^}}int iCamelSnakeBack1 = 0; + +int Camel_Snake_Case = 0; +// CHECK-MESSAGES: :[[@LINE-1]]:5: warning: invalid case style for global variable 'Camel_Snake_Case' [readability-identifier-naming] +// CHECK-FIXES: {{^}}int iCamelSnakeCase = 0; + +int Camel_Snake_Case_1 = 0; +// CHECK-MESSAGES: :[[@LINE-1]]:5: warning: invalid case style for global variable 'Camel_Snake_Case_1' [readability-identifier-naming] +// CHECK-FIXES: {{^}}int iCamelSnakeCase1 = 0; + +//===----------------------------------------------------------------------===// +// Enum +//===----------------------------------------------------------------------===// +enum REVINFO_TYPE { RevValid }; +// CHECK-MESSAGES: :[[@LINE-1]]:21: warning: invalid case style for constant 'RevValid' [readability-identifier-naming] +// CHECK-FIXES: {{^}}enum REVINFO_TYPE { rtRevValid }; + +enum DataType { OneByte }; +// CHECK-MESSAGES: :[[@LINE-1]]:17: warning: invalid case style for constant 'OneByte' [readability-identifier-naming] +// CHECK-FIXES: {{^}}enum DataType { dtOneByte }; +// clang-format on