[clang-tools-extra] [clang-tidy] Fix false negative in `readability-simplify-subscript-expr` when subscripting substituted types (PR #185570)

Victor Chernyakin via cfe-commits cfe-commits at lists.llvm.org
Tue Mar 10 05:51:02 PDT 2026


================
@@ -15,30 +15,27 @@ using namespace clang::ast_matchers;
 
 namespace clang::tidy::readability {
 
-static constexpr char KDefaultTypes[] =
+static constexpr char DefaultTypes[] =
     "::std::basic_string;::std::basic_string_view;::std::vector;::std::array;::"
     "std::span";
 
 SimplifySubscriptExprCheck::SimplifySubscriptExprCheck(
     StringRef Name, ClangTidyContext *Context)
     : ClangTidyCheck(Name, Context), Types(utils::options::parseStringList(
-                                         Options.get("Types", KDefaultTypes))) {
-}
+                                         Options.get("Types", DefaultTypes))) {}
 
 void SimplifySubscriptExprCheck::registerMatchers(MatchFinder *Finder) {
   const auto TypesMatcher = hasUnqualifiedDesugaredType(
       recordType(hasDeclaration(cxxRecordDecl(hasAnyName(Types)))));
 
   Finder->addMatcher(
-      arraySubscriptExpr(hasBase(
-          cxxMemberCallExpr(
-              has(memberExpr().bind("member")),
-              on(hasType(qualType(
-                  unless(anyOf(substTemplateTypeParmType(),
-                               hasDescendant(substTemplateTypeParmType()))),
----------------
localspook wrote:

My best guess is that these checks predate `IgnoreUnlessSpelledInSource` traversal, and this was how they emulated it back then

https://github.com/llvm/llvm-project/pull/185570


More information about the cfe-commits mailing list