clang-tools 22.0.0git
clang::tidy::readability::ContainerDataPointerCheck Class Reference

Checks whether a call to operator[] and & can be replaced with a call to data(). More...

#include <ContainerDataPointerCheck.h>

Inheritance diagram for clang::tidy::readability::ContainerDataPointerCheck:
[legend]

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

Detailed Description

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.

Constructor & Destructor Documentation

◆ ContainerDataPointerCheck()

clang::tidy::readability::ContainerDataPointerCheck::ContainerDataPointerCheck ( StringRef Name,
ClangTidyContext * Context )

Definition at line 32 of file ContainerDataPointerCheck.cpp.

Member Function Documentation

◆ check()

void clang::tidy::readability::ContainerDataPointerCheck::check ( const ast_matchers::MatchFinder::MatchResult & Result)
override

◆ getCheckTraversalKind()

std::optional< TraversalKind > clang::tidy::readability::ContainerDataPointerCheck::getCheckTraversalKind ( ) const
inlineoverride

Definition at line 36 of file ContainerDataPointerCheck.h.

◆ isLanguageVersionSupported()

bool clang::tidy::readability::ContainerDataPointerCheck::isLanguageVersionSupported ( const LangOptions & LO) const
inlineoverride

Definition at line 27 of file ContainerDataPointerCheck.h.

◆ registerMatchers()

void clang::tidy::readability::ContainerDataPointerCheck::registerMatchers ( ast_matchers::MatchFinder * Finder)
override

◆ storeOptions()

void clang::tidy::readability::ContainerDataPointerCheck::storeOptions ( ClangTidyOptions::OptionMap & Opts)
override

The documentation for this class was generated from the following files: