https://github.com/zeyi2 created https://github.com/llvm/llvm-project/pull/230353
None >From 34b224954f45c9fc93072aba93ee72ed15d2d409 Mon Sep 17 00:00:00 2001 From: Zeyi Xu <[email protected]> Date: Fri, 9 Oct 2026 12:37:30 +0800 Subject: [PATCH] [clang-tidy] Support special names in matchesAnyListedRegexName --- clang-tools-extra/clang-tidy/utils/Matchers.h | 19 +++++++++++-------- clang-tools-extra/docs/ReleaseNotes.md | 4 ++++ ...spicious-stringview-data-usage-options.cpp | 1 - 3 files changed, 15 insertions(+), 9 deletions(-) diff --git a/clang-tools-extra/clang-tidy/utils/Matchers.h b/clang-tools-extra/clang-tidy/utils/Matchers.h index e04da473226239..7263339213033c 100644 --- a/clang-tools-extra/clang-tidy/utils/Matchers.h +++ b/clang-tools-extra/clang-tidy/utils/Matchers.h @@ -74,9 +74,8 @@ AST_MATCHER(Expr, hasUnevaluatedContext) { return false; } -// A matcher implementation that matches a list of type name regular expressions -// against a NamedDecl. If a regular expression contains the substring "::" -// matching will occur against the qualified name, otherwise only the typename. +// A matcher implementation that matches a list of name regular expressions +// against a NamedDecl. class MatchesAnyListedRegexNameMatcher : public ast_matchers::internal::MatcherInterface<NamedDecl> { public: @@ -95,8 +94,8 @@ class MatchesAnyListedRegexNameMatcher // Match against the qualified name because the regular expression // contains ":" suggesting name and namespace should be matched. MatchQualified, - // Match against the fully qualified name because the regular expression - // starts with ":". + // Match against the qualified name prefixed with "::" because the regular + // expression starts with ":" or "^:". MatchFullyQualified, }; MatchMode Mode; @@ -114,6 +113,8 @@ class MatchesAnyListedRegexNameMatcher default: if (const IdentifierInfo *II = ND.getIdentifier()) return Regex.match(II->getName()); + if (ND.getDeclName()) + return Regex.match(ND.getNameAsString()); return false; } } @@ -139,9 +140,11 @@ class MatchesAnyListedRegexNameMatcher std::vector<NameMatcher> NameMatchers; }; -// Returns a matcher that matches NamedDecl's against a list of provided regular -// expressions. If a regular expression contains starts ':' the NamedDecl's -// qualified name will be used for matching, otherwise its name will be used. +// Returns a matcher that matches NamedDecls against a list of provided regular +// expressions. A regular expression starting with ":" or "^:" is matched +// against the qualified name prefixed with "::". A regular expression +// containing ":" is matched against the qualified name; otherwise, the +// unqualified name is used. inline ::clang::ast_matchers::internal::Matcher<NamedDecl> matchesAnyListedRegexName(llvm::ArrayRef<StringRef> NameList) { return ::clang::ast_matchers::internal::Matcher( diff --git a/clang-tools-extra/docs/ReleaseNotes.md b/clang-tools-extra/docs/ReleaseNotes.md index 41aa783cabd248..68efb68f201a5c 100644 --- a/clang-tools-extra/docs/ReleaseNotes.md +++ b/clang-tools-extra/docs/ReleaseNotes.md @@ -194,6 +194,10 @@ infrastructure are described first, followed by tool-specific sections. <clang-tidy/checks/bugprone/std-namespace-modification>` when checking lambda closure types used as template arguments. +- Improved {doc}`bugprone-suspicious-stringview-data-usage + <clang-tidy/checks/bugprone/suspicious-stringview-data-usage>` by allowing + unqualified patterns in the `AllowedCallees` option to match constructor names. + - Improved {doc}`cppcoreguidelines-missing-std-forward <clang-tidy/checks/cppcoreguidelines/missing-std-forward>` check by diagnosing unforwarded `auto&&` parameters in C++20 abbreviated function templates. diff --git a/clang-tools-extra/test/clang-tidy/checkers/bugprone/suspicious-stringview-data-usage-options.cpp b/clang-tools-extra/test/clang-tidy/checkers/bugprone/suspicious-stringview-data-usage-options.cpp index 5c1a7f4341f808..dad59aec933bd2 100644 --- a/clang-tools-extra/test/clang-tidy/checkers/bugprone/suspicious-stringview-data-usage-options.cpp +++ b/clang-tools-extra/test/clang-tidy/checkers/bugprone/suspicious-stringview-data-usage-options.cpp @@ -29,7 +29,6 @@ void TestStringViewTypes(custom::StrView sv) { void TestAllowedCallees(custom::StrView sv) { safe_func(sv.data()); SafeClass sc(sv.data()); - // CHECK-MESSAGES: :[[@LINE-1]]:19: warning: result of a `data()` call may not be null terminated, provide size information to the callee to prevent potential issues [bugprone-suspicious-stringview-data-usage] } void TestNotAllowed(custom::StrView sv) { _______________________________________________ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
