clang-tools 22.0.0git
|
Checks whether a call to operator[] and & can be replaced with a call to data(). More...
#include <ContainerDataPointerCheck.h>
Public Member Functions | |
ContainerDataPointerCheck (StringRef Name, ClangTidyContext *Context) | |
bool | isLanguageVersionSupported (const LangOptions &LO) const override |
void | storeOptions (ClangTidyOptions::OptionMap &Opts) override |
void | registerMatchers (ast_matchers::MatchFinder *Finder) override |
void | check (const ast_matchers::MatchFinder::MatchResult &Result) override |
std::optional< TraversalKind > | getCheckTraversalKind () const override |
Checks whether a call to operator[] and & can be replaced with a call to data().
This only replaces the case where the offset being accessed through the subscript operation is a known constant 0. This avoids a potential invalid memory access when the container is empty. Cases where the constant is not explicitly zero can be addressed through the clang static analyzer, and those which cannot be statically identified can be caught using UBSan.
Definition at line 23 of file ContainerDataPointerCheck.h.
clang::tidy::readability::ContainerDataPointerCheck::ContainerDataPointerCheck | ( | StringRef | Name, |
ClangTidyContext * | Context ) |
Definition at line 32 of file ContainerDataPointerCheck.cpp.
|
override |
|
inlineoverride |
Definition at line 36 of file ContainerDataPointerCheck.h.
|
inlineoverride |
Definition at line 27 of file ContainerDataPointerCheck.h.
|
override |
Definition at line 38 of file ContainerDataPointerCheck.cpp.
References clang::tidy::readability::AddressOfName, clang::tidy::readability::AddrOfContainerExprName, clang::tidy::readability::ContainerExprName, clang::tidy::readability::DerefContainerExprName, and clang::tidy::matchers::matchesAnyListedName().
|
override |
Definition at line 26 of file ContainerDataPointerCheck.cpp.
References clang::tidy::utils::options::serializeStringList().