10#include "../utils/OptionsUtils.h"
11#include "clang/AST/ASTContext.h"
12#include "clang/ASTMatchers/ASTMatchFinder.h"
19 "::std::basic_string;::std::basic_string_view;::std::vector;::std::array;::"
29 const auto TypesMatcher = hasUnqualifiedDesugaredType(
30 recordType(hasDeclaration(cxxRecordDecl(hasAnyName(Types)))));
33 arraySubscriptExpr(hasBase(
35 has(memberExpr().bind(
"member")),
37 unless(anyOf(substTemplateTypeParmType(),
38 hasDescendant(substTemplateTypeParmType()))),
39 anyOf(TypesMatcher, pointerType(pointee(TypesMatcher)))))),
40 callee(namedDecl(hasName(
"data"))))
46 const auto *Call = Result.Nodes.getNodeAs<CXXMemberCallExpr>(
"call");
47 if (Result.Context->getSourceManager().isMacroBodyExpansion(
51 const auto *Member = Result.Nodes.getNodeAs<MemberExpr>(
"member");
53 diag(Member->getMemberLoc(),
54 "accessing an element of the container does not require a call to "
55 "'data()'; did you mean to use 'operator[]'?");
56 if (Member->isArrow())
57 DiagBuilder << FixItHint::CreateInsertion(Member->getBeginLoc(),
"(*")
58 << FixItHint::CreateInsertion(Member->getOperatorLoc(),
")");
59 DiagBuilder << FixItHint::CreateRemoval(
60 {Member->getOperatorLoc(), Call->getEndLoc()});
llvm::SmallString< 256U > Name
void store(ClangTidyOptions::OptionMap &Options, StringRef LocalName, StringRef Value) const
Stores an option with the check-local name LocalName with string value Value to Options.
Base class for all clang-tidy checks.
DiagnosticBuilder diag(SourceLocation Loc, StringRef Description, DiagnosticIDs::Level Level=DiagnosticIDs::Warning)
Add a diagnostic with the check's name.
Every ClangTidyCheck reports errors through a DiagnosticsEngine provided by this context.
void registerMatchers(ast_matchers::MatchFinder *Finder) override
Override this to register AST matchers with Finder.
void check(const ast_matchers::MatchFinder::MatchResult &Result) override
ClangTidyChecks that register ASTMatchers should do the actual work in here.
SimplifySubscriptExprCheck(StringRef Name, ClangTidyContext *Context)
void storeOptions(ClangTidyOptions::OptionMap &Opts) override
Should store all options supported by this check with their current values or default values for opti...
static const char KDefaultTypes[]
std::string serializeStringList(ArrayRef< StringRef > Strings)
Serialize a sequence of names that can be parsed by parseStringList.
llvm::StringMap< ClangTidyValue > OptionMap