njames93 created this revision. njames93 added reviewers: aaron.ballman, alexfh, LegalizeAdulthood. Herald added subscribers: carlosgalvezp, xazax.hun. Herald added a project: All. njames93 requested review of this revision. Herald added a project: clang-tools-extra. Herald added a subscriber: cfe-commits.
Fixed an issue where specifying empty strings for prefix or suffix would be ignored preventing using those to override a different style. Fixes https://github.com/llvm/llvm-project/issues/56358. Repository: rG LLVM Github Monorepo https://reviews.llvm.org/D129070 Files: clang-tools-extra/clang-tidy/readability/IdentifierNamingCheck.cpp clang-tools-extra/clang-tidy/readability/IdentifierNamingCheck.h clang-tools-extra/docs/ReleaseNotes.rst clang-tools-extra/test/clang-tidy/checkers/readability/identifier-naming-empty-options.cpp
Index: clang-tools-extra/test/clang-tidy/checkers/readability/identifier-naming-empty-options.cpp =================================================================== --- /dev/null +++ clang-tools-extra/test/clang-tidy/checkers/readability/identifier-naming-empty-options.cpp @@ -0,0 +1,13 @@ +// RUN: %check_clang_tidy %s readability-identifier-naming %t -- \ +// RUN: -config='{CheckOptions: {\ +// RUN: readability-identifier-naming.GlobalConstantPrefix: "", \ +// RUN: readability-identifier-naming.GlobalVariablePrefix: g_ \ +// RUN: }}' + +int BadGlobalVariable; +// CHECK-MESSAGES: :[[@LINE-1]]:5: warning: invalid case style for global variable 'BadGlobalVariable' [readability-identifier-naming] +// CHECK-FIXES: int g_BadGlobalVariable; +int g_GoodGlobalVariable; + +const int GoodGlobalConstant = 0; +const int g_IgnoreGlobalConstant = 0; Index: clang-tools-extra/docs/ReleaseNotes.rst =================================================================== --- clang-tools-extra/docs/ReleaseNotes.rst +++ clang-tools-extra/docs/ReleaseNotes.rst @@ -217,6 +217,11 @@ - Fixed incorrect suggestions for :doc:`readability-container-size-empty <clang-tidy/checks/readability/container-size-empty>` when smart pointers are involved. +- Fixed an issue in :doc:`readability-identifier-naming + <clang-tidy/checks/readability/identifier-naming>` when specifying an empty + string for ``Prefix`` or ``Suffix`` options could result in the style not + being used. + - Fixed a false positive in :doc:`readability-non-const-parameter <clang-tidy/checks/readability/non-const-parameter>` when the parameter is referenced by an lvalue. Index: clang-tools-extra/clang-tidy/readability/IdentifierNamingCheck.h =================================================================== --- clang-tools-extra/clang-tidy/readability/IdentifierNamingCheck.h +++ clang-tools-extra/clang-tidy/readability/IdentifierNamingCheck.h @@ -69,20 +69,20 @@ struct NamingStyle { NamingStyle() = default; - NamingStyle(llvm::Optional<CaseType> Case, const std::string &Prefix, - const std::string &Suffix, const std::string &IgnoredRegexpStr, + NamingStyle(llvm::Optional<CaseType> Case, StringRef Prefix, + StringRef Suffix, StringRef IgnoredRegexpStr, HungarianPrefixType HPType); NamingStyle(const NamingStyle &O) = delete; NamingStyle &operator=(NamingStyle &&O) = default; NamingStyle(NamingStyle &&O) = default; llvm::Optional<CaseType> Case; - std::string Prefix; - std::string Suffix; + StringRef Prefix; + StringRef Suffix; // Store both compiled and non-compiled forms so original value can be // serialized llvm::Regex IgnoredRegexp; - std::string IgnoredRegexpStr; + StringRef IgnoredRegexpStr; HungarianPrefixType HPType; }; Index: clang-tools-extra/clang-tidy/readability/IdentifierNamingCheck.cpp =================================================================== --- clang-tools-extra/clang-tidy/readability/IdentifierNamingCheck.cpp +++ clang-tools-extra/clang-tidy/readability/IdentifierNamingCheck.cpp @@ -228,9 +228,8 @@ // clang-format on IdentifierNamingCheck::NamingStyle::NamingStyle( - llvm::Optional<IdentifierNamingCheck::CaseType> Case, - const std::string &Prefix, const std::string &Suffix, - const std::string &IgnoredRegexpStr, HungarianPrefixType HPType) + llvm::Optional<IdentifierNamingCheck::CaseType> Case, StringRef Prefix, + StringRef Suffix, StringRef IgnoredRegexpStr, HungarianPrefixType HPType) : Case(Case), Prefix(Prefix), Suffix(Suffix), IgnoredRegexpStr(IgnoredRegexpStr), HPType(HPType) { if (!IgnoredRegexpStr.empty()) { @@ -263,22 +262,21 @@ memcpy(&StyleString[StyleSize], "IgnoredRegexp", 13); StyleString.truncate(StyleSize + 13); - StringRef IgnoredRegexpStr = Options.get(StyleString, ""); + Optional<StringRef> IgnoredRegexpStr = Options.get(StyleString); memcpy(&StyleString[StyleSize], "Prefix", 6); StyleString.truncate(StyleSize + 6); - std::string Prefix(Options.get(StyleString, "")); + Optional<StringRef> Prefix(Options.get(StyleString)); // Fast replacement of [Pre]fix -> [Suf]fix. memcpy(&StyleString[StyleSize], "Suf", 3); - std::string Postfix(Options.get(StyleString, "")); + Optional<StringRef> Postfix(Options.get(StyleString)); memcpy(&StyleString[StyleSize], "Case", 4); StyleString.pop_back_n(2); - auto CaseOptional = + llvm::Optional<CaseType> CaseOptional = Options.get<IdentifierNamingCheck::CaseType>(StyleString); - if (CaseOptional || !Prefix.empty() || !Postfix.empty() || - !IgnoredRegexpStr.empty() || HPTOpt) - Styles[I].emplace(std::move(CaseOptional), std::move(Prefix), - std::move(Postfix), IgnoredRegexpStr.str(), + if (CaseOptional || Prefix || Postfix || IgnoredRegexpStr || HPTOpt) + Styles[I].emplace(std::move(CaseOptional), Prefix.getValueOr(""), + Postfix.getValueOr(""), IgnoredRegexpStr.getValueOr(""), HPTOpt.value_or(IdentifierNamingCheck::HPT_Off)); } bool IgnoreMainLike = Options.get("IgnoreMainLikeFunctions", false);
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits