clang-tools 19.0.0git
Classes | Typedefs | Enumerations | Functions | Variables
clang::tidy::modernize Namespace Reference

Classes

class  AvoidBindCheck
 Replace simple uses of std::bind with a lambda. More...
 
class  AvoidCArraysCheck
 Find C-style array types and recommend to use std::array<> / std::vector<>. More...
 
struct  ClassifiedToken
 
class  ComponentFinderASTVisitor
 Class used to find the variables and member expressions on which an arbitrary expression depends. More...
 
class  ConcatNestedNamespacesCheck
 
class  Confidence
 A class to encapsulate lowering of the tool's confidence level. More...
 
struct  ContainerCall
 
class  DeclFinderASTVisitor
 Class used to determine if any declarations used in a Stmt would conflict with a particular identifier. More...
 
class  DependencyFinderASTVisitor
 Class used to determine if an expression is dependent on a variable declared inside of the loop where it would be used. More...
 
class  DeprecatedHeadersCheck
 This check replaces deprecated C library headers with their C++ STL alternatives. More...
 
class  DeprecatedIosBaseAliasesCheck
 This check warns the uses of the deprecated member types of std::ios_base and replaces those that have a non-deprecated equivalent. More...
 
struct  EnableIfData
 
class  ForLoopIndexUseVisitor
 Discover usages of expressions consisting of index or iterator access. More...
 
class  IntegralLiteralExpressionMatcher
 
class  LoopConvertCheck
 
class  MacroToEnumCallbacks
 
class  MacroToEnumCheck
 Replaces groups of related macros with an unscoped anonymous enum. More...
 
class  MakeSharedCheck
 Replace the pattern: More...
 
class  MakeSmartPtrCheck
 Base class for MakeSharedCheck and MakeUniqueCheck. More...
 
class  MakeUniqueCheck
 Replace the pattern: More...
 
class  MinMaxUseInitializerListCheck
 Replaces nested std::min and std::max calls with an initializer list where applicable. More...
 
class  ModernizeModule
 
class  NS
 
class  PassByValueCheck
 
class  RawStringLiteralCheck
 This check replaces string literals with escaped characters to raw string literals. More...
 
class  RedundantVoidArgCheck
 Find and remove redundant void argument lists. More...
 
class  ReplaceAutoPtrCheck
 Transforms the deprecated std::auto_ptr into the C++11 std::unique_ptr. More...
 
class  ReplaceDisallowCopyAndAssignMacroCheck
 This check finds macro expansions of DISALLOW_COPY_AND_ASSIGN(Type) and replaces them with a deleted copy constructor and a deleted assignment operator. More...
 
class  ReplaceRandomShuffleCheck
 std::random_shuffle will be removed as of C++17. More...
 
class  ReturnBracedInitListCheck
 Use a braced init list for return statements rather than unnecessary repeating the return type name. More...
 
class  ShrinkToFitCheck
 Replace copy and swap tricks on shrinkable containers with the shrink_to_fit() method call. More...
 
class  StmtAncestorASTVisitor
 Class used build the reverse AST properties needed to detect name conflicts and free variables. More...
 
struct  TUTrackingInfo
 
class  TypeTraitsCheck
 Converts standard library type traits of the form traits<...>::type and traits<...>::value into traits_t<...> and traits_v<...> respectively. More...
 
class  UnaryStaticAssertCheck
 Replaces a static_assert declaration with an empty message with the unary version. More...
 
struct  Usage
 The information needed to describe a valid convertible usage of an array index or iterator. More...
 
class  UseAutoCheck
 
class  UseBoolLiteralsCheck
 Finds integer literals which are cast to bool. More...
 
class  UseConstraintsCheck
 Replace enable_if with C++20 requires clauses. More...
 
class  UseDefaultMemberInitCheck
 Convert a default constructor's member initializers into default member initializers. More...
 
class  UseDesignatedInitializersCheck
 Finds initializer lists for aggregate type that could be written as designated initializers instead. More...
 
class  UseEmplaceCheck
 This check looks for cases when inserting new element into std::vector but the element is constructed temporarily. More...
 
class  UseEqualsDefaultCheck
 Replace default bodies of special member functions with '= default;'. More...
 
class  UseEqualsDeleteCheck
 Identifies unimplemented private special member functions, and recommends using = delete for them. More...
 
class  UseNodiscardCheck
 Add [[nodiscard]] to non-void const-member functions with no arguments or pass-by-value or pass by const-reference arguments. More...
 
class  UseNoexceptCheck
 Replace dynamic exception specifications, with noexcept (or user-defined macro) or noexcept(false). More...
 
class  UseNullptrCheck
 
class  UseOverrideCheck
 Use C++11's override and remove virtual where applicable. More...
 
class  UseRangesCheck
 Detects calls to standard library iterator algorithms that could be replaced with a ranges version instead. More...
 
class  UseStartsEndsWithCheck
 Checks for common roundabout ways to express starts_with and ends_with and suggests replacing with starts_with when the method is available. More...
 
class  UseStdFormatCheck
 Converts calls to absl::StrFormat, or other functions via configuration options, to C++20's std::format, or another function via a configuration option, modifying the format string appropriately and removing now-unnecessary calls to std::string::c_str() and std::string::data(). More...
 
class  UseStdNumbersCheck
 Finds constants and function calls to math functions that can be replaced with c++20's mathematical constants from the numbers header and offers fix-it hints. More...
 
class  UseStdPrintCheck
 Convert calls to printf-like functions to std::print and std::println. More...
 
class  UseTrailingReturnTypeCheck
 Rewrites function signatures to use a trailing return type. More...
 
class  UseTransparentFunctorsCheck
 Prefer using transparent functors to non-transparent ones. More...
 
class  UseUncaughtExceptionsCheck
 This check will warn on calls to std::uncaught_exception and replace them with calls to std::uncaught_exceptions, since std::uncaught_exception was deprecated in C++17. More...
 
class  UseUsingCheck
 Check finds typedefs and replaces it with usings. More...
 
class  VariableNamer
 Create names for generated variables within a particular statement. More...
 

Typedefs

using NamespaceName = llvm::SmallString< 40 >
 
using StmtParentMap = llvm::DenseMap< const clang::Stmt *, const clang::Stmt * >
 A map used to walk the AST in reverse: maps child Stmt to parent Stmt.
 
using DeclParentMap = llvm::DenseMap< const clang::VarDecl *, const clang::DeclStmt * >
 A map used to walk the AST in reverse: maps VarDecl to the to parent DeclStmt.
 
using ReplacedVarsMap = llvm::DenseMap< const clang::ForStmt *, const clang::VarDecl * >
 A map used to track which variables have been removed by a refactoring pass.
 
using StmtGeneratedVarNameMap = llvm::DenseMap< const clang::Stmt *, std::string >
 A map used to remember the variable names generated in a Stmt.
 
using ComponentVector = llvm::SmallVector< const clang::Expr *, 16 >
 A vector used to store the AST subtrees of an Expr.
 
using UsageResult = llvm::SmallVector< Usage, 8 >
 
using CharsBitSet = std::bitset< 1<< CHAR_BIT >
 

Enumerations

enum class  LiteralSize {
  Unknown = 0 , Int , UnsignedInt , Long ,
  UnsignedLong , LongLong , UnsignedLongLong
}
 
enum class  IteratorCallKind { ICK_Member , ICK_ADL , ICK_Std }
 
enum  LoopFixerKind { LFK_Array , LFK_Iterator , LFK_ReverseIterator , LFK_PseudoArray }
 

Functions

static bool tryCaptureAsLocalVariable (const MatchFinder::MatchResult &Result, BindArgument &B, const Expr *E)
 
static bool tryCaptureAsMemberVariable (const MatchFinder::MatchResult &Result, BindArgument &B, const Expr *E)
 
static const Expr * ignoreTemporariesAndPointers (const Expr *E)
 
static const Expr * ignoreTemporariesAndConstructors (const Expr *E)
 
static StringRef getSourceTextForExpr (const MatchFinder::MatchResult &Result, const Expr *E)
 
static bool isCallExprNamed (const Expr *E, StringRef Name)
 
static void initializeBindArgumentForCallExpr (const MatchFinder::MatchResult &Result, BindArgument &B, const CallExpr *CE, unsigned &CaptureIndex)
 
static bool anyDescendantIsLocal (const Stmt *Statement)
 
static SmallVector< BindArgument, 4 > buildBindArguments (const MatchFinder::MatchResult &Result, const CallableInfo &Callable)
 
static int findPositionOfPlaceholderUse (ArrayRef< BindArgument > Args, size_t PlaceholderIndex)
 
static void addPlaceholderArgs (const LambdaProperties &LP, llvm::raw_ostream &Stream, bool PermissiveParameterList)
 
static void addFunctionCallArgs (ArrayRef< BindArgument > Args, llvm::raw_ostream &Stream)
 
static bool isPlaceHolderIndexRepeated (const ArrayRef< BindArgument > Args)
 
static std::vector< const FunctionDecl * > findCandidateCallOperators (const CXXRecordDecl *RecordDecl, size_t NumArgs)
 
static bool isFixitSupported (const CallableInfo &Callee, ArrayRef< BindArgument > Args)
 
const FunctionDecl * getCallOperator (const CXXRecordDecl *Callable, size_t NumArgs)
 
const FunctionDecl * getCallMethodDecl (const MatchFinder::MatchResult &Result, CallableType Type, CallableMaterializationKind Materialization)
 
static CallableType getCallableType (const MatchFinder::MatchResult &Result)
 
static CallableMaterializationKind getCallableMaterialization (const MatchFinder::MatchResult &Result)
 
static LambdaProperties getLambdaProperties (const MatchFinder::MatchResult &Result)
 
static bool emitCapture (llvm::StringSet<> &CaptureSet, StringRef Delimiter, CaptureMode CM, CaptureExpr CE, StringRef Identifier, StringRef InitExpression, raw_ostream &Stream)
 
static void emitCaptureList (const LambdaProperties &LP, const MatchFinder::MatchResult &Result, raw_ostream &Stream)
 
static ArrayRef< BindArgument > getForwardedArgumentList (const LambdaProperties &P)
 
static bool locationsInSameFile (const SourceManager &Sources, SourceLocation Loc1, SourceLocation Loc2)
 
static StringRef getRawStringRef (const SourceRange &Range, const SourceManager &Sources, const LangOptions &LangOpts)
 
static std::optional< const char * > getReplacementType (StringRef Type)
 
static bool isIntegralConstant (const Token &Token)
 
static LiteralSize literalTokenSize (const Token &Tok)
 
static bool operator< (LiteralSize LHS, LiteralSize RHS)
 
static StatementMatcher integerComparisonMatcher ()
 
static DeclarationMatcher initToZeroMatcher ()
 
static StatementMatcher incrementVarMatcher ()
 
static StatementMatcher arrayConditionMatcher (internal::Matcher< Expr > LimitExpr)
 
StatementMatcher makeArrayLoopMatcher ()
 The matcher for loops over arrays.
 
StatementMatcher makeIteratorLoopMatcher (bool IsReverse)
 The matcher used for iterator-based for loops.
 
StatementMatcher makePseudoArrayLoopMatcher ()
 The matcher used for array-like containers (pseudoarrays).
 
static std::optional< ContainerCallgetContainerExpr (const Expr *Call)
 
static std::pair< const Expr *, IteratorCallKindgetContainerFromBeginEndCall (const Expr *Init, bool IsBegin, bool *IsArrow, bool IsReverse)
 Determine whether Init appears to be an initializing an iterator.
 
static const Expr * findContainer (ASTContext *Context, const Expr *BeginExpr, const Expr *EndExpr, bool *ContainerNeedsDereference, bool IsReverse)
 Determines the container whose begin() and end() functions are called for an iterator-based loop.
 
static StringRef getStringFromRange (SourceManager &SourceMgr, const LangOptions &LangOpts, SourceRange Range)
 Obtain the original source code text from a SourceRange.
 
static const ValueDecl * getReferencedVariable (const Expr *E)
 If the given expression is actually a DeclRefExpr or a MemberExpr, find and return the underlying ValueDecl; otherwise, return NULL.
 
static bool isDirectMemberExpr (const Expr *E)
 Returns true when the given expression is a member expression whose base is this (implicitly or not).
 
static bool canBeModified (ASTContext *Context, const Expr *E)
 Given an expression that represents an usage of an element from the containter that we are iterating over, returns false when it can be guaranteed this element cannot be modified as a result of this usage.
 
static bool usagesAreConst (ASTContext *Context, const UsageResult &Usages)
 Returns true when it can be guaranteed that the elements of the container are not being modified.
 
static bool usagesReturnRValues (const UsageResult &Usages)
 Returns true if the elements of the container are never accessed by reference.
 
static bool containerIsConst (const Expr *ContainerExpr, bool Dereference)
 Returns true if the container is const-qualified.
 
const Expr * digThroughConstructorsConversions (const Expr *E)
 Look through conversion/copy constructors and member functions to find the explicit initialization expression, returning it is found.
 
bool areSameExpr (ASTContext *Context, const Expr *First, const Expr *Second)
 Returns true when two Exprs are equivalent.
 
const DeclRefExpr * getDeclRef (const Expr *E)
 Returns the DeclRefExpr represented by E, or NULL if there isn't one.
 
bool areSameVariable (const ValueDecl *First, const ValueDecl *Second)
 Returns true when two ValueDecls are the same variable.
 
static bool exprReferencesVariable (const ValueDecl *Target, const Expr *E)
 Determines if an expression is a declaration reference to a particular variable.
 
static const Expr * getDereferenceOperand (const Expr *E)
 If the expression is a dereference or call to operator*(), return the operand.
 
template<typename ContainerT >
static bool containsExpr (ASTContext *Context, const ContainerT *Container, const Expr *E)
 Returns true when the Container contains an Expr equivalent to E.
 
static bool isIndexInSubscriptExpr (const Expr *IndexExpr, const VarDecl *IndexVar)
 Returns true when the index expression is a declaration reference to IndexVar.
 
static bool isIndexInSubscriptExpr (ASTContext *Context, const Expr *IndexExpr, const VarDecl *IndexVar, const Expr *Obj, const Expr *SourceExpr, bool PermitDeref)
 Returns true when the index expression is a declaration reference to IndexVar, Obj is the same expression as SourceExpr after all parens and implicit casts are stripped off.
 
static bool isDereferenceOfOpCall (const CXXOperatorCallExpr *OpCall, const VarDecl *IndexVar)
 Returns true when Opcall is a call a one-parameter dereference of IndexVar.
 
static bool isDereferenceOfUop (const UnaryOperator *Uop, const VarDecl *IndexVar)
 Returns true when Uop is a dereference of IndexVar.
 
static bool isAliasDecl (ASTContext *Context, const Decl *TheDecl, const VarDecl *IndexVar)
 Determines whether the given Decl defines a variable initialized to the loop object.
 
static bool arrayMatchesBoundExpr (ASTContext *Context, const QualType &ArrayType, const Expr *ConditionExpr)
 Determines whether the bound of a for loop condition expression is the same as the statically computable size of ArrayType.
 
static bool hasOnlyComments (SourceLocation Loc, const LangOptions &Options, StringRef Text)
 
static StringRef getTokenName (const Token &Tok)
 
static bool isValid (SourceRange Range)
 
static bool empty (SourceRange Range)
 
static FindArgsResult findArgs (const CallExpr *Call)
 
static SmallVector< FixItHint > generateReplacements (const MatchFinder::MatchResult &Match, const CallExpr *TopCall, const FindArgsResult &Result, const bool IgnoreNonTrivialTypes, const std::uint64_t IgnoreTrivialTypesOfSizeAbove)
 
static ClangTidyModuleRegistry::Add< ModernizeModuleX ("modernize-module", "Add modernize checks.")
 
static TypeMatcher notTemplateSpecConstRefType ()
 
static TypeMatcher nonConstValueType ()
 
static bool paramReferredExactlyOnce (const CXXConstructorDecl *Ctor, const ParmVarDecl *ParamDecl)
 Whether or not ParamDecl is used exactly one time in Ctor.
 
static bool hasRValueOverload (const CXXConstructorDecl *Ctor, const ParmVarDecl *Param)
 Returns true if the given constructor is part of a lvalue/rvalue reference pair, i.e.
 
static SmallVector< const ParmVarDecl *, 2 > collectParamDecls (const CXXConstructorDecl *Ctor, const ParmVarDecl *ParamDecl)
 Find all references to ParamDecl across all of the redeclarations of Ctor.
 
bool isMacroIdentifier (const IdentifierTable &Idents, const Token &ProtoToken)
 
static DeclarationName getName (const DependentScopeDeclRefExpr &D)
 
static DeclarationName getName (const DeclRefExpr &D)
 
static bool isNamedType (const ElaboratedTypeLoc &ETL)
 
static bool isNamedType (const DependentNameTypeLoc &DTL)
 
static bool isNamedDeclInStdTraitsSet (const NamedDecl *ND, const llvm::StringSet<> &Set)
 
static bool checkTemplatedDecl (const NestedNameSpecifier *NNS, const llvm::StringSet<> &Set)
 
static void ignoreTypeLocClasses (TypeLoc &Loc, std::initializer_list< TypeLoc::TypeLocClass > const &LocClasses)
 
static bool isMutliLevelPointerToTypeLocClasses (TypeLoc Loc, std::initializer_list< TypeLoc::TypeLocClass > const &LocClasses)
 
static std::optional< TemplateSpecializationTypeLoc > matchEnableIfSpecializationImplTypename (TypeLoc TheType)
 
static std::optional< TemplateSpecializationTypeLoc > matchEnableIfSpecializationImplTrait (TypeLoc TheType)
 
static std::optional< TemplateSpecializationTypeLoc > matchEnableIfSpecializationImpl (TypeLoc TheType)
 
static std::optional< EnableIfDatamatchEnableIfSpecialization (TypeLoc TheType)
 
static std::pair< std::optional< EnableIfData >, const Decl * > matchTrailingTemplateParam (const FunctionTemplateDecl *FunctionTemplate)
 
template<typename T >
static SourceLocation getRAngleFileLoc (const SourceManager &SM, const T &Element)
 
static SourceRange getConditionRange (ASTContext &Context, const TemplateSpecializationTypeLoc &EnableIf)
 
static SourceRange getTypeRange (ASTContext &Context, const TemplateSpecializationTypeLoc &EnableIf)
 
static std::optional< StringRef > getTypeText (ASTContext &Context, const TemplateSpecializationTypeLoc &EnableIf)
 
static std::optional< SourceLocation > findInsertionForConstraint (const FunctionDecl *Function, ASTContext &Context)
 
bool isPrimaryExpression (const Expr *Expression)
 
static std::optional< std::string > getConditionText (const Expr *ConditionExpr, SourceRange ConditionRange, ASTContext &Context)
 
static std::vector< FixItHint > handleReturnType (const FunctionDecl *Function, const TypeLoc &ReturnType, const EnableIfData &EnableIf, ASTContext &Context)
 
static std::vector< FixItHint > handleTrailingTemplateType (const FunctionTemplateDecl *FunctionTemplate, const FunctionDecl *Function, const Decl *LastTemplateParam, const EnableIfData &EnableIf, ASTContext &Context)
 
static StringRef getValueOfValueInit (const QualType InitType)
 
static bool isZero (const Expr *E)
 
static const Expr * ignoreUnaryPlus (const Expr *E)
 
static const Expr * getInitializer (const Expr *E)
 
static bool sameValue (const Expr *E1, const Expr *E2)
 
static std::set< const FieldDecl * > getAllNamedFields (const CXXRecordDecl *Record)
 Finds all the named non-static fields of Record.
 
static std::set< const Type * > getAllDirectBases (const CXXRecordDecl *Record)
 Returns the names of the direct bases of Record, both virtual and non-virtual.
 
internal::Matcher< Expr > accessToFieldInVar (const FieldDecl *Field, const ValueDecl *Var)
 Returns a matcher that matches member expressions where the base is the variable declared as Var and the accessed member is the one declared as Field.
 
static bool isCopyConstructorAndCanBeDefaulted (ASTContext *Context, const CXXConstructorDecl *Ctor)
 Check that the given constructor has copy signature and that it copy-initializes all its bases and members.
 
static bool isCopyAssignmentAndCanBeDefaulted (ASTContext *Context, const CXXMethodDecl *Operator)
 Checks that the given method is an overloading of the assignment operator, has copy signature, returns a reference to "*this" and copies all its members and subobjects.
 
static bool bodyEmpty (const ASTContext *Context, const CompoundStmt *Body)
 Returns false if the body has any non-whitespace character.
 
static bool doesNoDiscardMacroExist (ASTContext &Context, const llvm::StringRef &MacroId)
 
static SmallVector< Token, 16 > parseTokens (CharSourceRange Range, const MatchFinder::MatchResult &Result)
 
static StringRef getText (const Token &Tok, const SourceManager &Sources)
 
static clang::ast_matchers::StatementMatcher unusedReturnValue (clang::ast_matchers::StatementMatcher MatchedCallExpr)
 
static SourceLocation expandIfMacroId (SourceLocation Loc, const SourceManager &SM)
 
static bool isCvr (Token T)
 
static bool isSpecifier (Token T)
 
static std::optional< ClassifiedTokenclassifyToken (const FunctionDecl &F, Preprocessor &PP, Token Tok)
 
static bool hasAnyNestedLocalQualifiers (QualType Type)
 
template<typename T >
static T getInnerTypeLocAs (TypeLoc Loc)
 

Variables

static constexpr std::array< StringRef, 5 > DeprecatedTypes
 
static const char LoopNameArray [] = "forLoopArray"
 
static const char LoopNameIterator [] = "forLoopIterator"
 
static const char LoopNameReverseIterator [] = "forLoopReverseIterator"
 
static const char LoopNamePseudoArray [] = "forLoopPseudoArray"
 
static const char ConditionBoundName [] = "conditionBound"
 
static const char InitVarName [] = "initVar"
 
static const char BeginCallName [] = "beginCall"
 
static const char EndCallName [] = "endCall"
 
static const char EndVarName [] = "endVar"
 
static const char DerefByValueResultName [] = "derefByValueResult"
 
static const char DerefByRefResultName [] = "derefByRefResult"
 
static const llvm::StringSet MemberNames
 
static const llvm::StringSet ADLNames
 
static const llvm::StringSet StdNames
 
static const llvm::StringSet ValueTraits
 
static const llvm::StringSet TypeTraits
 
static constexpr char Bind [] = ""
 
static constexpr char IgnoreSingleElementAggregatesName []
 
static constexpr bool IgnoreSingleElementAggregatesDefault = true
 
static constexpr char RestrictToPODTypesName [] = "RestrictToPODTypes"
 
static constexpr bool RestrictToPODTypesDefault = false
 
static constexpr char IgnoreMacrosName [] = "IgnoreMacros"
 
static constexpr bool IgnoreMacrosDefault = true
 
static constexpr char StrictCStandardComplianceName []
 
static constexpr bool StrictCStandardComplianceDefault = true
 
static constexpr char StrictCppStandardComplianceName []
 
static constexpr bool StrictCppStandardComplianceDefault = true
 
static const char SpecialFunction [] = "SpecialFunction"
 
static const char SpecialFunction [] = "SpecialFunction"
 
static const char DeletedNotPublic [] = "DeletedNotPublic"
 
static constexpr const char * SingleRangeNames []
 
static constexpr const char * TwoRangeNames []
 
constexpr llvm::StringLiteral Message
 
static constexpr llvm::StringLiteral ExternCDeclName = "extern-c-decl"
 
static constexpr llvm::StringLiteral ParentDeclName = "parent-decl"
 
static constexpr llvm::StringLiteral TagDeclName = "tag-decl"
 
static constexpr llvm::StringLiteral TypedefName = "typedef"
 
static constexpr llvm::StringLiteral DeclStmtName = "decl-stmt"
 

Typedef Documentation

◆ CharsBitSet

using clang::tidy::modernize::CharsBitSet = typedef std::bitset<1 << CHAR_BIT>

Definition at line 17 of file RawStringLiteralCheck.h.

◆ ComponentVector

using clang::tidy::modernize::ComponentVector = typedef llvm::SmallVector<const clang::Expr *, 16>

A vector used to store the AST subtrees of an Expr.

Definition at line 52 of file LoopConvertUtils.h.

◆ DeclParentMap

using clang::tidy::modernize::DeclParentMap = typedef llvm::DenseMap<const clang::VarDecl *, const clang::DeclStmt *>

A map used to walk the AST in reverse: maps VarDecl to the to parent DeclStmt.

Definition at line 39 of file LoopConvertUtils.h.

◆ NamespaceName

using clang::tidy::modernize::NamespaceName = typedef llvm::SmallString<40>

Definition at line 18 of file ConcatNestedNamespacesCheck.h.

◆ ReplacedVarsMap

using clang::tidy::modernize::ReplacedVarsMap = typedef llvm::DenseMap<const clang::ForStmt *, const clang::VarDecl *>

A map used to track which variables have been removed by a refactoring pass.

It maps the parent ForStmt to the removed index variable's VarDecl.

Definition at line 44 of file LoopConvertUtils.h.

◆ StmtGeneratedVarNameMap

using clang::tidy::modernize::StmtGeneratedVarNameMap = typedef llvm::DenseMap<const clang::Stmt *, std::string>

A map used to remember the variable names generated in a Stmt.

Definition at line 48 of file LoopConvertUtils.h.

◆ StmtParentMap

using clang::tidy::modernize::StmtParentMap = typedef llvm::DenseMap<const clang::Stmt *, const clang::Stmt *>

A map used to walk the AST in reverse: maps child Stmt to parent Stmt.

Definition at line 35 of file LoopConvertUtils.h.

◆ UsageResult

using clang::tidy::modernize::UsageResult = typedef llvm::SmallVector<Usage, 8>

Definition at line 273 of file LoopConvertUtils.h.

Enumeration Type Documentation

◆ IteratorCallKind

Enumerator
ICK_Member 
ICK_ADL 
ICK_Std 

Definition at line 336 of file LoopConvertCheck.cpp.

◆ LiteralSize

Enumerator
Unknown 
Int 
UnsignedInt 
Long 
UnsignedLong 
LongLong 
UnsignedLongLong 

Definition at line 17 of file IntegralLiteralExpressionMatcher.h.

◆ LoopFixerKind

Enumerator
LFK_Array 
LFK_Iterator 
LFK_ReverseIterator 
LFK_PseudoArray 

Definition at line 27 of file LoopConvertUtils.h.

Function Documentation

◆ accessToFieldInVar()

internal::Matcher< Expr > clang::tidy::modernize::accessToFieldInVar ( const FieldDecl *  Field,
const ValueDecl *  Var 
)

Returns a matcher that matches member expressions where the base is the variable declared as Var and the accessed member is the one declared as Field.

Definition at line 51 of file UseEqualsDefaultCheck.cpp.

References Field.

Referenced by isCopyAssignmentAndCanBeDefaulted(), and isCopyConstructorAndCanBeDefaulted().

◆ addFunctionCallArgs()

static void clang::tidy::modernize::addFunctionCallArgs ( ArrayRef< BindArgument >  Args,
llvm::raw_ostream &  Stream 
)
static

Definition at line 364 of file AvoidBindCheck.cpp.

References Args.

Referenced by clang::tidy::modernize::AvoidBindCheck::check().

◆ addPlaceholderArgs()

static void clang::tidy::modernize::addPlaceholderArgs ( const LambdaProperties &  LP,
llvm::raw_ostream &  Stream,
bool  PermissiveParameterList 
)
static

◆ anyDescendantIsLocal()

static bool clang::tidy::modernize::anyDescendantIsLocal ( const Stmt *  Statement)
static

Definition at line 184 of file AvoidBindCheck.cpp.

References anyDescendantIsLocal(), Decl, and DeclRef.

Referenced by anyDescendantIsLocal(), and buildBindArguments().

◆ areSameExpr()

bool clang::tidy::modernize::areSameExpr ( ASTContext *  Context,
const Expr *  First,
const Expr *  Second 
)

Returns true when two Exprs are equivalent.

Definition at line 193 of file LoopConvertUtils.cpp.

References clang::tidy::utils::areStatementsIdentical().

Referenced by findContainer(), and isIndexInSubscriptExpr().

◆ areSameVariable()

bool clang::tidy::modernize::areSameVariable ( const ValueDecl *  First,
const ValueDecl *  Second 
)

Returns true when two ValueDecls are the same variable.

Definition at line 203 of file LoopConvertUtils.cpp.

Referenced by exprReferencesVariable(), and isIndexInSubscriptExpr().

◆ arrayConditionMatcher()

static StatementMatcher clang::tidy::modernize::arrayConditionMatcher ( internal::Matcher< Expr >  LimitExpr)
static

Definition at line 97 of file LoopConvertCheck.cpp.

References integerComparisonMatcher().

Referenced by makeArrayLoopMatcher(), and makePseudoArrayLoopMatcher().

◆ arrayMatchesBoundExpr()

static bool clang::tidy::modernize::arrayMatchesBoundExpr ( ASTContext *  Context,
const QualType &  ArrayType,
const Expr *  ConditionExpr 
)
static

Determines whether the bound of a for loop condition expression is the same as the statically computable size of ArrayType.

Given

const int N = 5;
int arr[N];

This is intended to permit

for (int i = 0; i < N; ++i) { /* use arr[i] */ }
for (int i = 0; i < arraysize(arr); ++i) { /* use arr[i] */ }

Definition at line 432 of file LoopConvertUtils.cpp.

◆ bodyEmpty()

static bool clang::tidy::modernize::bodyEmpty ( const ASTContext *  Context,
const CompoundStmt *  Body 
)
static

Returns false if the body has any non-whitespace character.

Definition at line 201 of file UseEqualsDefaultCheck.cpp.

References Text.

Referenced by clang::tidy::modernize::UseEqualsDefaultCheck::check().

◆ buildBindArguments()

static SmallVector< BindArgument, 4 > clang::tidy::modernize::buildBindArguments ( const MatchFinder::MatchResult &  Result,
const CallableInfo &  Callable 
)
static

◆ canBeModified()

static bool clang::tidy::modernize::canBeModified ( ASTContext *  Context,
const Expr *  E 
)
static

Given an expression that represents an usage of an element from the containter that we are iterating over, returns false when it can be guaranteed this element cannot be modified as a result of this usage.

Definition at line 496 of file LoopConvertCheck.cpp.

References E.

Referenced by usagesAreConst().

◆ checkTemplatedDecl()

static bool clang::tidy::modernize::checkTemplatedDecl ( const NestedNameSpecifier *  NNS,
const llvm::StringSet<> &  Set 
)
static

◆ classifyToken()

static std::optional< ClassifiedToken > clang::tidy::modernize::classifyToken ( const FunctionDecl &  F,
Preprocessor &  PP,
Token  Tok 
)
static

◆ collectParamDecls()

static SmallVector< const ParmVarDecl *, 2 > clang::tidy::modernize::collectParamDecls ( const CXXConstructorDecl *  Ctor,
const ParmVarDecl *  ParamDecl 
)
static

Find all references to ParamDecl across all of the redeclarations of Ctor.

Definition at line 179 of file PassByValueCheck.cpp.

References Results.

Referenced by clang::tidy::modernize::PassByValueCheck::check().

◆ containerIsConst()

static bool clang::tidy::modernize::containerIsConst ( const Expr *  ContainerExpr,
bool  Dereference 
)
static

Returns true if the container is const-qualified.

Definition at line 540 of file LoopConvertCheck.cpp.

References getReferencedVariable().

◆ containsExpr()

template<typename ContainerT >
static bool clang::tidy::modernize::containsExpr ( ASTContext *  Context,
const ContainerT *  Container,
const Expr *  E 
)
static

Returns true when the Container contains an Expr equivalent to E.

Definition at line 234 of file LoopConvertUtils.cpp.

References Container, E, and ID.

◆ digThroughConstructorsConversions()

const Expr * clang::tidy::modernize::digThroughConstructorsConversions ( const Expr *  E)

Look through conversion/copy constructors and member functions to find the explicit initialization expression, returning it is found.

The main idea is that given vector<int> v; we consider either of these initializations vector<int>::iterator it = v.begin(); vector<int>::iterator it(v.begin()); vector<int>::const_iterator it(v.begin()); and retrieve v.begin() as the expression used to initialize it but do not include vector<int>::iterator it; vector<int>::iterator it(v.begin(), 0); // if this constructor existed as being initialized from v.begin()

Definition at line 169 of file LoopConvertUtils.cpp.

References digThroughConstructorsConversions(), and E.

Referenced by digThroughConstructorsConversions(), getContainerExpr(), and isAliasDecl().

◆ doesNoDiscardMacroExist()

static bool clang::tidy::modernize::doesNoDiscardMacroExist ( ASTContext &  Context,
const llvm::StringRef &  MacroId 
)
static

◆ emitCapture()

static bool clang::tidy::modernize::emitCapture ( llvm::StringSet<> &  CaptureSet,
StringRef  Delimiter,
CaptureMode  CM,
CaptureExpr  CE,
StringRef  Identifier,
StringRef  InitExpression,
raw_ostream &  Stream 
)
static

Definition at line 585 of file AvoidBindCheck.cpp.

References CE, and CM.

Referenced by emitCaptureList().

◆ emitCaptureList()

static void clang::tidy::modernize::emitCaptureList ( const LambdaProperties &  LP,
const MatchFinder::MatchResult &  Result,
raw_ostream &  Stream 
)
static

Definition at line 607 of file AvoidBindCheck.cpp.

References emitCapture().

Referenced by clang::tidy::modernize::AvoidBindCheck::check().

◆ empty()

static bool clang::tidy::modernize::empty ( SourceRange  Range)
static

◆ expandIfMacroId()

static SourceLocation clang::tidy::modernize::expandIfMacroId ( SourceLocation  Loc,
const SourceManager &  SM 
)
static

Definition at line 119 of file UseTrailingReturnTypeCheck.cpp.

References expandIfMacroId(), and Loc.

Referenced by expandIfMacroId().

◆ exprReferencesVariable()

static bool clang::tidy::modernize::exprReferencesVariable ( const ValueDecl *  Target,
const Expr *  E 
)
static

Determines if an expression is a declaration reference to a particular variable.

Definition at line 210 of file LoopConvertUtils.cpp.

References areSameVariable(), Decl, E, and getDeclRef().

Referenced by isDereferenceOfOpCall(), and isDereferenceOfUop().

◆ findArgs()

static FindArgsResult clang::tidy::modernize::findArgs ( const CallExpr *  Call)
static

◆ findCandidateCallOperators()

static std::vector< const FunctionDecl * > clang::tidy::modernize::findCandidateCallOperators ( const CXXRecordDecl *  RecordDecl,
size_t  NumArgs 
)
static

Definition at line 395 of file AvoidBindCheck.cpp.

Referenced by getCallOperator().

◆ findContainer()

static const Expr * clang::tidy::modernize::findContainer ( ASTContext *  Context,
const Expr *  BeginExpr,
const Expr *  EndExpr,
bool *  ContainerNeedsDereference,
bool  IsReverse 
)
static

Determines the container whose begin() and end() functions are called for an iterator-based loop.

BeginExpr must be a member call to a function named "begin()", and EndExpr must be a member.

Definition at line 434 of file LoopConvertCheck.cpp.

References areSameExpr(), and getContainerFromBeginEndCall().

Referenced by clang::tidy::modernize::LoopConvertCheck::check().

◆ findInsertionForConstraint()

static std::optional< SourceLocation > clang::tidy::modernize::findInsertionForConstraint ( const FunctionDecl *  Function,
ASTContext &  Context 
)
static

◆ findPositionOfPlaceholderUse()

static int clang::tidy::modernize::findPositionOfPlaceholderUse ( ArrayRef< BindArgument >  Args,
size_t  PlaceholderIndex 
)
static

Definition at line 321 of file AvoidBindCheck.cpp.

References Args, and PlaceHolderIndex.

Referenced by addPlaceholderArgs().

◆ generateReplacements()

static SmallVector< FixItHint > clang::tidy::modernize::generateReplacements ( const MatchFinder::MatchResult &  Match,
const CallExpr *  TopCall,
const FindArgsResult &  Result,
const bool  IgnoreNonTrivialTypes,
const std::uint64_t  IgnoreTrivialTypesOfSizeAbove 
)
static

◆ getAllDirectBases()

static std::set< const Type * > clang::tidy::modernize::getAllDirectBases ( const CXXRecordDecl *  Record)
static

Returns the names of the direct bases of Record, both virtual and non-virtual.

Definition at line 38 of file UseEqualsDefaultCheck.cpp.

Referenced by isCopyAssignmentAndCanBeDefaulted(), and isCopyConstructorAndCanBeDefaulted().

◆ getAllNamedFields()

static std::set< const FieldDecl * > clang::tidy::modernize::getAllNamedFields ( const CXXRecordDecl *  Record)
static

Finds all the named non-static fields of Record.

Definition at line 25 of file UseEqualsDefaultCheck.cpp.

References Field.

Referenced by isCopyAssignmentAndCanBeDefaulted(), and isCopyConstructorAndCanBeDefaulted().

◆ getCallableMaterialization()

static CallableMaterializationKind clang::tidy::modernize::getCallableMaterialization ( const MatchFinder::MatchResult &  Result)
static

Definition at line 515 of file AvoidBindCheck.cpp.

References CE, and ignoreTemporariesAndPointers().

Referenced by getLambdaProperties().

◆ getCallableType()

static CallableType clang::tidy::modernize::getCallableType ( const MatchFinder::MatchResult &  Result)
static

Definition at line 492 of file AvoidBindCheck.cpp.

References Decl.

Referenced by getLambdaProperties().

◆ getCallMethodDecl()

const FunctionDecl * clang::tidy::modernize::getCallMethodDecl ( const MatchFinder::MatchResult &  Result,
CallableType  Type,
CallableMaterializationKind  Materialization 
)

◆ getCallOperator()

const FunctionDecl * clang::tidy::modernize::getCallOperator ( const CXXRecordDecl *  Callable,
size_t  NumArgs 
)

Definition at line 459 of file AvoidBindCheck.cpp.

References Callable, and findCandidateCallOperators().

Referenced by getCallMethodDecl().

◆ getConditionRange()

static SourceRange clang::tidy::modernize::getConditionRange ( ASTContext &  Context,
const TemplateSpecializationTypeLoc &  EnableIf 
)
static

◆ getConditionText()

static std::optional< std::string > clang::tidy::modernize::getConditionText ( const Expr *  ConditionExpr,
SourceRange  ConditionRange,
ASTContext &  Context 
)
static

◆ getContainerExpr()

static std::optional< ContainerCall > clang::tidy::modernize::getContainerExpr ( const Expr *  Call)
static

◆ getContainerFromBeginEndCall()

static std::pair< const Expr *, IteratorCallKind > clang::tidy::modernize::getContainerFromBeginEndCall ( const Expr *  Init,
bool  IsBegin,
bool *  IsArrow,
bool  IsReverse 
)
static

Determine whether Init appears to be an initializing an iterator.

If it is, returns the object whose begin() or end() method is called, and the output parameter isArrow is set to indicate whether the initialization is called via . or ->.

Definition at line 411 of file LoopConvertCheck.cpp.

References getContainerExpr().

Referenced by findContainer().

◆ getDeclRef()

const DeclRefExpr * clang::tidy::modernize::getDeclRef ( const Expr *  E)

Returns the DeclRefExpr represented by E, or NULL if there isn't one.

Definition at line 198 of file LoopConvertUtils.cpp.

References E.

Referenced by exprReferencesVariable(), getReferencedVariable(), and isIndexInSubscriptExpr().

◆ getDereferenceOperand()

static const Expr * clang::tidy::modernize::getDereferenceOperand ( const Expr *  E)
static

If the expression is a dereference or call to operator*(), return the operand.

Otherwise, return NULL.

Definition at line 219 of file LoopConvertUtils.cpp.

References E.

Referenced by isIndexInSubscriptExpr().

◆ getForwardedArgumentList()

static ArrayRef< BindArgument > clang::tidy::modernize::getForwardedArgumentList ( const LambdaProperties &  P)
static

Definition at line 630 of file AvoidBindCheck.cpp.

References Args.

Referenced by clang::tidy::modernize::AvoidBindCheck::check().

◆ getInitializer()

static const Expr * clang::tidy::modernize::getInitializer ( const Expr *  E)
static

Definition at line 141 of file UseDefaultMemberInitCheck.cpp.

References E.

Referenced by sameValue().

◆ getInnerTypeLocAs()

template<typename T >
static T clang::tidy::modernize::getInnerTypeLocAs ( TypeLoc  Loc)
static

Definition at line 67 of file UseTransparentFunctorsCheck.cpp.

References Loc.

◆ getLambdaProperties()

static LambdaProperties clang::tidy::modernize::getLambdaProperties ( const MatchFinder::MatchResult &  Result)
static

◆ getName() [1/2]

static DeclarationName clang::tidy::modernize::getName ( const DeclRefExpr &  D)
static

Definition at line 139 of file TypeTraitsCheck.cpp.

◆ getName() [2/2]

static DeclarationName clang::tidy::modernize::getName ( const DependentScopeDeclRefExpr &  D)
static

Definition at line 135 of file TypeTraitsCheck.cpp.

Referenced by clang::tidy::modernize::NS::appendCloseComment().

◆ getRAngleFileLoc()

template<typename T >
static SourceLocation clang::tidy::modernize::getRAngleFileLoc ( const SourceManager &  SM,
const T &  Element 
)
static

◆ getRawStringRef()

static StringRef clang::tidy::modernize::getRawStringRef ( const SourceRange &  Range,
const SourceManager &  Sources,
const LangOptions &  LangOpts 
)
static

Definition at line 26 of file ConcatNestedNamespacesCheck.cpp.

References Range.

Referenced by clang::tidy::modernize::NS::getNamespaceBackRange().

◆ getReferencedVariable()

static const ValueDecl * clang::tidy::modernize::getReferencedVariable ( const Expr *  E)
static

If the given expression is actually a DeclRefExpr or a MemberExpr, find and return the underlying ValueDecl; otherwise, return NULL.

Definition at line 477 of file LoopConvertCheck.cpp.

References E, and getDeclRef().

Referenced by clang::tidy::modernize::LoopConvertCheck::check(), and containerIsConst().

◆ getReplacementType()

static std::optional< const char * > clang::tidy::modernize::getReplacementType ( StringRef  Type)
static

◆ getSourceTextForExpr()

static StringRef clang::tidy::modernize::getSourceTextForExpr ( const MatchFinder::MatchResult &  Result,
const Expr *  E 
)
static

◆ getStringFromRange()

static StringRef clang::tidy::modernize::getStringFromRange ( SourceManager &  SourceMgr,
const LangOptions &  LangOpts,
SourceRange  Range 
)
static

Obtain the original source code text from a SourceRange.

Definition at line 463 of file LoopConvertCheck.cpp.

References Range.

◆ getText()

static StringRef clang::tidy::modernize::getText ( const Token &  Tok,
const SourceManager &  Sources 
)
static

◆ getTokenName()

static StringRef clang::tidy::modernize::getTokenName ( const Token &  Tok)
static

◆ getTypeRange()

static SourceRange clang::tidy::modernize::getTypeRange ( ASTContext &  Context,
const TemplateSpecializationTypeLoc &  EnableIf 
)
static

◆ getTypeText()

static std::optional< StringRef > clang::tidy::modernize::getTypeText ( ASTContext &  Context,
const TemplateSpecializationTypeLoc &  EnableIf 
)
static

Definition at line 233 of file UseConstraintsCheck.cpp.

References getTypeRange(), and Text.

Referenced by handleReturnType().

◆ getValueOfValueInit()

static StringRef clang::tidy::modernize::getValueOfValueInit ( const QualType  InitType)
static

Definition at line 24 of file UseDefaultMemberInitCheck.cpp.

References getValueOfValueInit().

Referenced by getValueOfValueInit().

◆ handleReturnType()

static std::vector< FixItHint > clang::tidy::modernize::handleReturnType ( const FunctionDecl *  Function,
const TypeLoc &  ReturnType,
const EnableIfData EnableIf,
ASTContext &  Context 
)
static

◆ handleTrailingTemplateType()

static std::vector< FixItHint > clang::tidy::modernize::handleTrailingTemplateType ( const FunctionTemplateDecl *  FunctionTemplate,
const FunctionDecl *  Function,
const Decl LastTemplateParam,
const EnableIfData EnableIf,
ASTContext &  Context 
)
static

◆ hasAnyNestedLocalQualifiers()

static bool clang::tidy::modernize::hasAnyNestedLocalQualifiers ( QualType  Type)
static

◆ hasOnlyComments()

static bool clang::tidy::modernize::hasOnlyComments ( SourceLocation  Loc,
const LangOptions &  Options,
StringRef  Text 
)
static

Definition at line 23 of file MacroToEnumCheck.cpp.

References C, Loc, and Text.

◆ hasRValueOverload()

static bool clang::tidy::modernize::hasRValueOverload ( const CXXConstructorDecl *  Ctor,
const ParmVarDecl *  Param 
)
static

Returns true if the given constructor is part of a lvalue/rvalue reference pair, i.e.

Param is of lvalue reference type, and there exists another constructor such that:

  • it has the same number of parameters as Ctor.
  • the parameter at the same index as Param is an rvalue reference of the same pointee type
  • all other parameters have the same type as the corresponding parameter in Ctor or are rvalue references with the same pointee type. Examples: A::A(const B& Param) A::A(B&&)

A::A(const B& Param, const C&) A::A(B&& Param, C&&)

A::A(const B&, const C& Param) A::A(B&&, C&& Param)

A::A(const B&, const C& Param) A::A(const B&, C&& Param)

A::A(const B& Param, int) A::A(B&& Param, int)

Definition at line 130 of file PassByValueCheck.cpp.

References C, Candidate, and E.

Referenced by clang::tidy::modernize::PassByValueCheck::check().

◆ ignoreTemporariesAndConstructors()

static const Expr * clang::tidy::modernize::ignoreTemporariesAndConstructors ( const Expr *  E)
static

◆ ignoreTemporariesAndPointers()

static const Expr * clang::tidy::modernize::ignoreTemporariesAndPointers ( const Expr *  E)
static

◆ ignoreTypeLocClasses()

static void clang::tidy::modernize::ignoreTypeLocClasses ( TypeLoc &  Loc,
std::initializer_list< TypeLoc::TypeLocClass > const &  LocClasses 
)
static

Definition at line 338 of file UseAutoCheck.cpp.

References Loc.

Referenced by isMutliLevelPointerToTypeLocClasses().

◆ ignoreUnaryPlus()

static const Expr * clang::tidy::modernize::ignoreUnaryPlus ( const Expr *  E)
static

Definition at line 134 of file UseDefaultMemberInitCheck.cpp.

References E.

Referenced by sameValue().

◆ incrementVarMatcher()

static StatementMatcher clang::tidy::modernize::incrementVarMatcher ( )
static

Definition at line 92 of file LoopConvertCheck.cpp.

References InitVarName.

Referenced by makeArrayLoopMatcher(), and makePseudoArrayLoopMatcher().

◆ initializeBindArgumentForCallExpr()

static void clang::tidy::modernize::initializeBindArgumentForCallExpr ( const MatchFinder::MatchResult &  Result,
BindArgument &  B,
const CallExpr *  CE,
unsigned &  CaptureIndex 
)
static

◆ initToZeroMatcher()

static DeclarationMatcher clang::tidy::modernize::initToZeroMatcher ( )
static

Definition at line 86 of file LoopConvertCheck.cpp.

References InitVarName.

Referenced by makeArrayLoopMatcher(), and makePseudoArrayLoopMatcher().

◆ integerComparisonMatcher()

static StatementMatcher clang::tidy::modernize::integerComparisonMatcher ( )
static

Definition at line 81 of file LoopConvertCheck.cpp.

References InitVarName.

Referenced by arrayConditionMatcher().

◆ isAliasDecl()

static bool clang::tidy::modernize::isAliasDecl ( ASTContext *  Context,
const Decl TheDecl,
const VarDecl *  IndexVar 
)
static

Determines whether the given Decl defines a variable initialized to the loop object.

This is intended to find cases such as

for (int i = 0; i < arraySize(arr); ++i) {
T t = arr[i];
// use t, do not use i
}

and

for (iterator i = container.begin(), e = container.end(); i != e; ++i) {
T t = *i;
// use t, do not use i
}

Definition at line 349 of file LoopConvertUtils.cpp.

References digThroughConstructorsConversions(), E, isDereferenceOfOpCall(), isDereferenceOfUop(), isIndexInSubscriptExpr(), and TheDecl.

◆ isCallExprNamed()

static bool clang::tidy::modernize::isCallExprNamed ( const Expr *  E,
StringRef  Name 
)
static

Definition at line 146 of file AvoidBindCheck.cpp.

References CE, E, and Name.

Referenced by initializeBindArgumentForCallExpr(), and isFixitSupported().

◆ isCopyAssignmentAndCanBeDefaulted()

static bool clang::tidy::modernize::isCopyAssignmentAndCanBeDefaulted ( ASTContext *  Context,
const CXXMethodDecl *  Operator 
)
static

Checks that the given method is an overloading of the assignment operator, has copy signature, returns a reference to "*this" and copies all its members and subobjects.

Definition at line 124 of file UseEqualsDefaultCheck.cpp.

References accessToFieldInVar(), empty(), Field, getAllDirectBases(), and getAllNamedFields().

Referenced by clang::tidy::modernize::UseEqualsDefaultCheck::check().

◆ isCopyConstructorAndCanBeDefaulted()

static bool clang::tidy::modernize::isCopyConstructorAndCanBeDefaulted ( ASTContext *  Context,
const CXXConstructorDecl *  Ctor 
)
static

Check that the given constructor has copy signature and that it copy-initializes all its bases and members.

Definition at line 60 of file UseEqualsDefaultCheck.cpp.

References accessToFieldInVar(), empty(), Field, getAllDirectBases(), and getAllNamedFields().

Referenced by clang::tidy::modernize::UseEqualsDefaultCheck::check().

◆ isCvr()

static bool clang::tidy::modernize::isCvr ( Token  T)
static

Definition at line 171 of file UseTrailingReturnTypeCheck.cpp.

Referenced by classifyToken().

◆ isDereferenceOfOpCall()

static bool clang::tidy::modernize::isDereferenceOfOpCall ( const CXXOperatorCallExpr *  OpCall,
const VarDecl *  IndexVar 
)
static

Returns true when Opcall is a call a one-parameter dereference of IndexVar.

For example, if the index variable is index, returns true for *index but not index *notIndex

Definition at line 313 of file LoopConvertUtils.cpp.

References exprReferencesVariable().

Referenced by isAliasDecl().

◆ isDereferenceOfUop()

static bool clang::tidy::modernize::isDereferenceOfUop ( const UnaryOperator *  Uop,
const VarDecl *  IndexVar 
)
static

Returns true when Uop is a dereference of IndexVar.

For example, if the index variable is index, returns true for *index but not index *notIndex

Definition at line 326 of file LoopConvertUtils.cpp.

References exprReferencesVariable().

Referenced by isAliasDecl().

◆ isDirectMemberExpr()

static bool clang::tidy::modernize::isDirectMemberExpr ( const Expr *  E)
static

Returns true when the given expression is a member expression whose base is this (implicitly or not).

Definition at line 487 of file LoopConvertCheck.cpp.

References E.

Referenced by clang::tidy::modernize::LoopConvertCheck::check().

◆ isFixitSupported()

static bool clang::tidy::modernize::isFixitSupported ( const CallableInfo &  Callee,
ArrayRef< BindArgument >  Args 
)
static

Definition at line 430 of file AvoidBindCheck.cpp.

References Args, isCallExprNamed(), and isPlaceHolderIndexRepeated().

Referenced by getLambdaProperties().

◆ isIndexInSubscriptExpr() [1/2]

static bool clang::tidy::modernize::isIndexInSubscriptExpr ( ASTContext *  Context,
const Expr *  IndexExpr,
const VarDecl *  IndexVar,
const Expr *  Obj,
const Expr *  SourceExpr,
bool  PermitDeref 
)
static

Returns true when the index expression is a declaration reference to IndexVar, Obj is the same expression as SourceExpr after all parens and implicit casts are stripped off.

If PermitDeref is true, IndexExpression may be a dereference (overloaded or builtin operator*).

This function is intended for array-like containers, as it makes sure that both the container and the index match. If the loop has index variable index and iterates over container, then isIndexInSubscriptExpr returns true for

container[index]
container.at(index)
container->at(index)

but not for

container[notIndex]
notContainer[index]

If PermitDeref is true, then isIndexInSubscriptExpr additionally returns true on these expressions:

(*container)[index]
(*container).at(index)

Definition at line 287 of file LoopConvertUtils.cpp.

References areSameExpr(), getDereferenceOperand(), and isIndexInSubscriptExpr().

◆ isIndexInSubscriptExpr() [2/2]

static bool clang::tidy::modernize::isIndexInSubscriptExpr ( const Expr *  IndexExpr,
const VarDecl *  IndexVar 
)
static

Returns true when the index expression is a declaration reference to IndexVar.

If the index variable is index, this function returns true on arrayExpression[index]; containerExpression[index]; but not containerExpression[notIndex];

Definition at line 253 of file LoopConvertUtils.cpp.

References areSameVariable(), and getDeclRef().

Referenced by isAliasDecl(), and isIndexInSubscriptExpr().

◆ isIntegralConstant()

static bool clang::tidy::modernize::isIntegralConstant ( const Token &  Token)
static

Definition at line 20 of file IntegralLiteralExpressionMatcher.cpp.

References C.

◆ isMacroIdentifier()

bool clang::tidy::modernize::isMacroIdentifier ( const IdentifierTable &  Idents,
const Token &  ProtoToken 
)

Definition at line 115 of file RedundantVoidArgCheck.cpp.

◆ isMutliLevelPointerToTypeLocClasses()

static bool clang::tidy::modernize::isMutliLevelPointerToTypeLocClasses ( TypeLoc  Loc,
std::initializer_list< TypeLoc::TypeLocClass > const &  LocClasses 
)
static

Definition at line 345 of file UseAutoCheck.cpp.

References ignoreTypeLocClasses(), and Loc.

◆ isNamedDeclInStdTraitsSet()

static bool clang::tidy::modernize::isNamedDeclInStdTraitsSet ( const NamedDecl *  ND,
const llvm::StringSet<> &  Set 
)
static

◆ isNamedType() [1/2]

static bool clang::tidy::modernize::isNamedType ( const DependentNameTypeLoc &  DTL)
static

Definition at line 152 of file TypeTraitsCheck.cpp.

◆ isNamedType() [2/2]

static bool clang::tidy::modernize::isNamedType ( const ElaboratedTypeLoc &  ETL)
static

Definition at line 143 of file TypeTraitsCheck.cpp.

References Decl.

◆ isPlaceHolderIndexRepeated()

static bool clang::tidy::modernize::isPlaceHolderIndexRepeated ( const ArrayRef< BindArgument >  Args)
static

Definition at line 383 of file AvoidBindCheck.cpp.

References Args.

Referenced by isFixitSupported().

◆ isPrimaryExpression()

bool clang::tidy::modernize::isPrimaryExpression ( const Expr *  Expression)

Definition at line 278 of file UseConstraintsCheck.cpp.

Referenced by getConditionText().

◆ isSpecifier()

static bool clang::tidy::modernize::isSpecifier ( Token  T)
static

Definition at line 175 of file UseTrailingReturnTypeCheck.cpp.

Referenced by classifyToken().

◆ isValid()

static bool clang::tidy::modernize::isValid ( SourceRange  Range)
static

◆ isZero()

static bool clang::tidy::modernize::isZero ( const Expr *  E)
static

Definition at line 112 of file UseDefaultMemberInitCheck.cpp.

References E.

Referenced by sameValue().

◆ literalTokenSize()

static LiteralSize clang::tidy::modernize::literalTokenSize ( const Token &  Tok)
static

◆ locationsInSameFile()

static bool clang::tidy::modernize::locationsInSameFile ( const SourceManager &  Sources,
SourceLocation  Loc1,
SourceLocation  Loc2 
)
static

◆ makeArrayLoopMatcher()

StatementMatcher clang::tidy::modernize::makeArrayLoopMatcher ( )

The matcher for loops over arrays.

for (int i = 0; i < 3 + 2; ++i) { ... }

The following string identifiers are bound to these parts of the AST: ConditionBoundName: '3 + 2' (as an Expr) InitVarName: 'i' (as a VarDecl) LoopName: The entire for loop (as a ForStmt)

Client code will need to make sure that:

  • The index variable is only used as an array index.
  • All arrays indexed by the loop are the same.

Definition at line 119 of file LoopConvertCheck.cpp.

References arrayConditionMatcher(), ConditionBoundName, incrementVarMatcher(), initToZeroMatcher(), and LoopNameArray.

Referenced by clang::tidy::modernize::LoopConvertCheck::registerMatchers().

◆ makeIteratorLoopMatcher()

StatementMatcher clang::tidy::modernize::makeIteratorLoopMatcher ( bool  IsReverse)

The matcher used for iterator-based for loops.

This matcher is more flexible than array-based loops. It will match catch loops of the following textual forms (regardless of whether the iterator type is actually a pointer type or a class type):

for (containerType::iterator it = container.begin(),
e = createIterator(); it != e; ++it) { ... }
for (containerType::iterator it = container.begin();
it != anotherContainer.end(); ++it) { ... }
for (containerType::iterator it = begin(container),
e = end(container); it != e; ++it) { ... }
for (containerType::iterator it = std::begin(container),
e = std::end(container); it != e; ++it) { ... }

The following string identifiers are bound to the parts of the AST: InitVarName: 'it' (as a VarDecl) LoopName: The entire for loop (as a ForStmt) In the first example only: EndVarName: 'e' (as a VarDecl) In the second example only: EndCallName: 'container.end()' (as a CXXMemberCallExpr) In the third/fourth examples: 'end(container)' or 'std::end(container)' (as a CallExpr)

Client code will need to make sure that:

  • The two containers on which 'begin' and 'end' are called are the same.

Definition at line 160 of file LoopConvertCheck.cpp.

References BeginCallName, DerefByRefResultName, DerefByValueResultName, EndCallName, EndVarName, InitVarName, LoopNameIterator, and LoopNameReverseIterator.

Referenced by clang::tidy::modernize::LoopConvertCheck::registerMatchers().

◆ makePseudoArrayLoopMatcher()

StatementMatcher clang::tidy::modernize::makePseudoArrayLoopMatcher ( )

The matcher used for array-like containers (pseudoarrays).

This matcher is more flexible than array-based loops. It will match loops of the following textual forms (regardless of whether the iterator type is actually a pointer type or a class type):

for (int i = 0, j = container.size(); i < j; ++i) { ... }
for (int i = 0; i < container.size(); ++i) { ... }
for (int i = 0; i < size(container); ++i) { ... }

The following string identifiers are bound to the parts of the AST: InitVarName: 'i' (as a VarDecl) LoopName: The entire for loop (as a ForStmt) In the first example only: EndVarName: 'j' (as a VarDecl) In the second example only: EndCallName: 'container.size()' (as a CXXMemberCallExpr) or 'size(contaner)' (as a CallExpr)

Client code will need to make sure that:

  • The containers on which 'size()' is called is the container indexed.
  • The index variable is only used in overloaded operator[] or container.at().
  • The container's iterators would not be invalidated during the loop.

Definition at line 272 of file LoopConvertCheck.cpp.

References arrayConditionMatcher(), EndCallName, EndVarName, incrementVarMatcher(), initToZeroMatcher(), and LoopNamePseudoArray.

Referenced by clang::tidy::modernize::LoopConvertCheck::registerMatchers().

◆ matchEnableIfSpecialization()

static std::optional< EnableIfData > clang::tidy::modernize::matchEnableIfSpecialization ( TypeLoc  TheType)
static

◆ matchEnableIfSpecializationImpl()

static std::optional< TemplateSpecializationTypeLoc > clang::tidy::modernize::matchEnableIfSpecializationImpl ( TypeLoc  TheType)
static

◆ matchEnableIfSpecializationImplTrait()

static std::optional< TemplateSpecializationTypeLoc > clang::tidy::modernize::matchEnableIfSpecializationImplTrait ( TypeLoc  TheType)
static

Definition at line 89 of file UseConstraintsCheck.cpp.

Referenced by matchEnableIfSpecializationImpl().

◆ matchEnableIfSpecializationImplTypename()

static std::optional< TemplateSpecializationTypeLoc > clang::tidy::modernize::matchEnableIfSpecializationImplTypename ( TypeLoc  TheType)
static

Definition at line 54 of file UseConstraintsCheck.cpp.

Referenced by matchEnableIfSpecializationImpl().

◆ matchTrailingTemplateParam()

static std::pair< std::optional< EnableIfData >, const Decl * > clang::tidy::modernize::matchTrailingTemplateParam ( const FunctionTemplateDecl *  FunctionTemplate)
static

◆ nonConstValueType()

static TypeMatcher clang::tidy::modernize::nonConstValueType ( )
static

◆ notTemplateSpecConstRefType()

static TypeMatcher clang::tidy::modernize::notTemplateSpecConstRefType ( )
static

◆ operator<()

static bool clang::tidy::modernize::operator< ( LiteralSize  LHS,
LiteralSize  RHS 
)
static

Definition at line 137 of file IntegralLiteralExpressionMatcher.cpp.

◆ paramReferredExactlyOnce()

static bool clang::tidy::modernize::paramReferredExactlyOnce ( const CXXConstructorDecl *  Ctor,
const ParmVarDecl *  ParamDecl 
)
static

Whether or not ParamDecl is used exactly one time in Ctor.

Checks both in the init-list and the body of the constructor.

clang::RecursiveASTVisitor that checks that the given ParmVarDecl is used exactly one time.

See also
ExactlyOneUsageVisitor::hasExactlyOneUsageIn()

Whether or not the parameter variable is referred only once in the given constructor.

Counts the number of references to a variable.

Stops the AST traversal if more than one usage is found.

Definition at line 60 of file PassByValueCheck.cpp.

Referenced by clang::tidy::modernize::PassByValueCheck::check().

◆ parseTokens()

static SmallVector< Token, 16 > clang::tidy::modernize::parseTokens ( CharSourceRange  Range,
const MatchFinder::MatchResult &  Result 
)
static

Definition at line 56 of file UseOverrideCheck.cpp.

References Info, and Range.

Referenced by clang::tidy::modernize::UseOverrideCheck::check().

◆ sameValue()

static bool clang::tidy::modernize::sameValue ( const Expr *  E1,
const Expr *  E2 
)
static

Definition at line 148 of file UseDefaultMemberInitCheck.cpp.

References getInitializer(), ignoreUnaryPlus(), isZero(), and sameValue().

Referenced by sameValue().

◆ tryCaptureAsLocalVariable()

static bool clang::tidy::modernize::tryCaptureAsLocalVariable ( const MatchFinder::MatchResult &  Result,
BindArgument &  B,
const Expr *  E 
)
static

◆ tryCaptureAsMemberVariable()

static bool clang::tidy::modernize::tryCaptureAsMemberVariable ( const MatchFinder::MatchResult &  Result,
BindArgument &  B,
const Expr *  E 
)
static

◆ unusedReturnValue()

static clang::ast_matchers::StatementMatcher clang::tidy::modernize::unusedReturnValue ( clang::ast_matchers::StatementMatcher  MatchedCallExpr)
static

◆ usagesAreConst()

static bool clang::tidy::modernize::usagesAreConst ( ASTContext *  Context,
const UsageResult Usages 
)
static

Returns true when it can be guaranteed that the elements of the container are not being modified.

Definition at line 515 of file LoopConvertCheck.cpp.

References canBeModified(), clang::tidy::modernize::Usage::UK_CaptureByCopy, and clang::tidy::modernize::Usage::UK_CaptureByRef.

◆ usagesReturnRValues()

static bool clang::tidy::modernize::usagesReturnRValues ( const UsageResult Usages)
static

Returns true if the elements of the container are never accessed by reference.

Definition at line 531 of file LoopConvertCheck.cpp.

◆ X()

static ClangTidyModuleRegistry::Add< ModernizeModule > clang::tidy::modernize::X ( "modernize-module"  ,
"Add modernize checks."   
)
static

Variable Documentation

◆ ADLNames

const llvm::StringSet clang::tidy::modernize::ADLNames
static
Initial value:
{"begin", "cbegin", "rbegin",
"crbegin", "end", "cend",
"rend", "crend", "size"}

Definition at line 74 of file LoopConvertCheck.cpp.

Referenced by getContainerExpr().

◆ BeginCallName

const char clang::tidy::modernize::BeginCallName[] = "beginCall"
static

Definition at line 66 of file LoopConvertCheck.cpp.

Referenced by makeIteratorLoopMatcher().

◆ Bind

constexpr char clang::tidy::modernize::Bind[] = ""
staticconstexpr

◆ ConditionBoundName

const char clang::tidy::modernize::ConditionBoundName[] = "conditionBound"
static

◆ DeclStmtName

constexpr llvm::StringLiteral clang::tidy::modernize::DeclStmtName = "decl-stmt"
staticconstexpr

◆ DeletedNotPublic

const char clang::tidy::modernize::DeletedNotPublic[] = "DeletedNotPublic"
static

◆ DeprecatedTypes

constexpr std::array<StringRef, 5> clang::tidy::modernize::DeprecatedTypes
staticconstexpr
Initial value:
= {
"::std::ios_base::io_state", "::std::ios_base::open_mode",
"::std::ios_base::seek_dir", "::std::ios_base::streamoff",
"::std::ios_base::streampos"}

Definition at line 18 of file DeprecatedIosBaseAliasesCheck.cpp.

Referenced by clang::tidy::modernize::DeprecatedIosBaseAliasesCheck::registerMatchers().

◆ DerefByRefResultName

const char clang::tidy::modernize::DerefByRefResultName[] = "derefByRefResult"
static

Definition at line 70 of file LoopConvertCheck.cpp.

Referenced by makeIteratorLoopMatcher().

◆ DerefByValueResultName

const char clang::tidy::modernize::DerefByValueResultName[] = "derefByValueResult"
static

Definition at line 69 of file LoopConvertCheck.cpp.

Referenced by makeIteratorLoopMatcher().

◆ EndCallName

const char clang::tidy::modernize::EndCallName[] = "endCall"
static

◆ EndVarName

const char clang::tidy::modernize::EndVarName[] = "endVar"
static

◆ ExternCDeclName

constexpr llvm::StringLiteral clang::tidy::modernize::ExternCDeclName = "extern-c-decl"
staticconstexpr

◆ IgnoreMacrosDefault

constexpr bool clang::tidy::modernize::IgnoreMacrosDefault = true
staticconstexpr

Definition at line 33 of file UseDesignatedInitializersCheck.cpp.

◆ IgnoreMacrosName

constexpr char clang::tidy::modernize::IgnoreMacrosName[] = "IgnoreMacros"
staticconstexpr

◆ IgnoreSingleElementAggregatesDefault

constexpr bool clang::tidy::modernize::IgnoreSingleElementAggregatesDefault = true
staticconstexpr

Definition at line 27 of file UseDesignatedInitializersCheck.cpp.

◆ IgnoreSingleElementAggregatesName

constexpr char clang::tidy::modernize::IgnoreSingleElementAggregatesName[]
staticconstexpr
Initial value:
=
"IgnoreSingleElementAggregates"

Definition at line 25 of file UseDesignatedInitializersCheck.cpp.

Referenced by clang::tidy::modernize::UseDesignatedInitializersCheck::storeOptions().

◆ InitVarName

const char clang::tidy::modernize::InitVarName[] = "initVar"
static

◆ LoopNameArray

const char clang::tidy::modernize::LoopNameArray[] = "forLoopArray"
static

◆ LoopNameIterator

const char clang::tidy::modernize::LoopNameIterator[] = "forLoopIterator"
static

◆ LoopNamePseudoArray

const char clang::tidy::modernize::LoopNamePseudoArray[] = "forLoopPseudoArray"
static

◆ LoopNameReverseIterator

const char clang::tidy::modernize::LoopNameReverseIterator[] = "forLoopReverseIterator"
static

◆ MemberNames

const llvm::StringSet clang::tidy::modernize::MemberNames
static
Initial value:
{"begin", "cbegin", "rbegin",
"crbegin", "end", "cend",
"rend", "crend", "size"}

Definition at line 71 of file LoopConvertCheck.cpp.

Referenced by getContainerExpr().

◆ Message

static const StringRef clang::tidy::modernize::Message
constexpr

◆ ParentDeclName

constexpr llvm::StringLiteral clang::tidy::modernize::ParentDeclName = "parent-decl"
staticconstexpr

◆ RestrictToPODTypesDefault

constexpr bool clang::tidy::modernize::RestrictToPODTypesDefault = false
staticconstexpr

Definition at line 30 of file UseDesignatedInitializersCheck.cpp.

◆ RestrictToPODTypesName

constexpr char clang::tidy::modernize::RestrictToPODTypesName[] = "RestrictToPODTypes"
staticconstexpr

◆ SingleRangeNames

constexpr const char* clang::tidy::modernize::SingleRangeNames[]
staticconstexpr

◆ SpecialFunction [1/2]

const char clang::tidy::modernize::SpecialFunction[] = "SpecialFunction"
static

◆ SpecialFunction [2/2]

const char clang::tidy::modernize::SpecialFunction[] = "SpecialFunction"
static

Definition at line 44 of file UseEqualsDeleteCheck.cpp.

◆ StdNames

const llvm::StringSet clang::tidy::modernize::StdNames
static
Initial value:
{
"std::begin", "std::cbegin", "std::rbegin", "std::crbegin", "std::end",
"std::cend", "std::rend", "std::crend", "std::size"}

Definition at line 77 of file LoopConvertCheck.cpp.

Referenced by getContainerExpr().

◆ StrictCppStandardComplianceDefault

constexpr bool clang::tidy::modernize::StrictCppStandardComplianceDefault = true
staticconstexpr

Definition at line 41 of file UseDesignatedInitializersCheck.cpp.

◆ StrictCppStandardComplianceName

constexpr char clang::tidy::modernize::StrictCppStandardComplianceName[]
staticconstexpr
Initial value:
=
"StrictCppStandardCompliance"

Definition at line 39 of file UseDesignatedInitializersCheck.cpp.

Referenced by clang::tidy::modernize::UseDesignatedInitializersCheck::storeOptions().

◆ StrictCStandardComplianceDefault

constexpr bool clang::tidy::modernize::StrictCStandardComplianceDefault = true
staticconstexpr

Definition at line 37 of file UseDesignatedInitializersCheck.cpp.

◆ StrictCStandardComplianceName

constexpr char clang::tidy::modernize::StrictCStandardComplianceName[]
staticconstexpr
Initial value:
=
"StrictCStandardCompliance"

Definition at line 35 of file UseDesignatedInitializersCheck.cpp.

Referenced by clang::tidy::modernize::UseDesignatedInitializersCheck::storeOptions().

◆ TagDeclName

constexpr llvm::StringLiteral clang::tidy::modernize::TagDeclName = "tag-decl"
staticconstexpr

◆ TwoRangeNames

constexpr const char* clang::tidy::modernize::TwoRangeNames[]
staticconstexpr
Initial value:
= {
"equal",
"mismatch",
"partial_sort_copy",
"includes",
"set_union",
"set_intersection",
"set_difference",
"set_symmetric_difference",
"merge",
"lexicographical_compare",
"find_end",
"search",
"is_permutation",
}

Definition at line 83 of file modernize/UseRangesCheck.cpp.

Referenced by clang::tidy::modernize::UseRangesCheck::getReplacerMap().

◆ TypedefName

constexpr llvm::StringLiteral clang::tidy::modernize::TypedefName = "typedef"
staticconstexpr

◆ TypeTraits

const llvm::StringSet clang::tidy::modernize::TypeTraits
static
Initial value:
= {
"remove_cv",
"remove_const",
"remove_volatile",
"add_cv",
"add_const",
"add_volatile",
"remove_reference",
"add_lvalue_reference",
"add_rvalue_reference",
"remove_pointer",
"add_pointer",
"make_signed",
"make_unsigned",
"remove_extent",
"remove_all_extents",
"aligned_storage",
"aligned_union",
"decay",
"remove_cvref",
"enable_if",
"conditional",
"common_type",
"common_reference",
"underlying_type",
"result_of",
"invoke_result",
"type_identity",
}

Definition at line 105 of file TypeTraitsCheck.cpp.

Referenced by clang::tidy::modernize::TypeTraitsCheck::check().

◆ ValueTraits

const llvm::StringSet clang::tidy::modernize::ValueTraits
static

Definition at line 18 of file TypeTraitsCheck.cpp.

Referenced by clang::tidy::modernize::TypeTraitsCheck::check().