[PATCH] D129070: [clang-tidy] Fixed an issue in readability-identifier-naming not using options specified.
Nathan James via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Mon Jul 4 08:06:53 PDT 2022
njames93 updated this revision to Diff 442101.
njames93 added a comment.
Small tweak.
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D129070/new/
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,12 @@
+// RUN: %check_clang_tidy %s readability-identifier-naming %t -- \
+// RUN: -config='{CheckOptions: { \
+// RUN: readability-identifier-naming.GlobalConstantPrefix: "", \
+// RUN: readability-identifier-naming.GlobalVariablePrefix: g_ }}'
+
+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
@@ -234,6 +234,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,8 +69,8 @@
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;
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 =
+ 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);
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D129070.442101.patch
Type: text/x-patch
Size: 4823 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20220704/8d197c2b/attachment-0001.bin>
More information about the cfe-commits
mailing list