clang-tools 6.0.0

Classes | Typedefs | Enumerations | Functions | Variables
clang::tidy::modernize Namespace Reference

## Classes
class | AvoidBindCheck
| Replace simple uses of std::bind with a lambda. More...
class | ComponentFinderASTVisitor
| Class used to find the variables and member expressions on which an arbitrary expression depends. More...
class | Confidence
| A class to encapsulate lowering of the tool's confidence level. More...
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 | ForLoopIndexUseVisitor
| Discover usages of expressions consisting of index or iterator access. More...
class | LoopConvertCheck
class | MakeSharedCheck
| Replace the pattern: More...
class | MakeSmartPtrCheck
| Base class for MakeSharedCheck and MakeUniqueCheck. More...
class | MakeUniqueCheck
| Replace the pattern: More...
class | ModernizeModule
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 | 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 | 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 | UseDefaultMemberInitCheck
| Convert a default constructor's member initializers into default member initializers. 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
| Mark unimplemented private special member functions with '= delete'. 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 | UseTransparentFunctorsCheck
| Prefer using transparent functors to non-transparent ones. 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
typedef llvm::DenseMap< const clang::Stmt *, const clang::Stmt * > | StmtParentMap
| A map used to walk the AST in reverse: maps child Stmt to parent Stmt. More...
typedef llvm::DenseMap< const clang::VarDecl *, const clang::DeclStmt * > | DeclParentMap
| A map used to walk the AST in reverse: maps VarDecl to the to parent DeclStmt. More...
typedef llvm::DenseMap< const clang::ForStmt *, const clang::VarDecl * > | ReplacedVarsMap
| A map used to track which variables have been removed by a refactoring pass. More...
typedef llvm::DenseMap< const clang::Stmt *, std::string > | StmtGeneratedVarNameMap
| A map used to remember the variable names generated in a Stmt. More...
typedef llvm::SmallVector< const clang::Expr *, 16 > | ComponentVector
| A vector used to store the AST subtrees of an Expr. More...
typedef llvm::SmallVector< Usage, 8 > | UsageResult

## Enumerations
enum | LoopFixerKind { LFK_Array, LFK_Iterator, LFK_PseudoArray }

## Functions
static SmallVector< BindArgument, 4 > | buildBindArguments (const MatchFinder::MatchResult &Result, const CallExpr *C)
static void | addPlaceholderArgs (const ArrayRef< BindArgument > Args, llvm::raw_ostream &Stream)
static void | addFunctionCallArgs (const ArrayRef< BindArgument > Args, llvm::raw_ostream &Stream)
static bool | isPlaceHolderIndexRepeated (const ArrayRef< BindArgument > Args)
StatementMatcher | makeArrayLoopMatcher ()
| The matcher for loops over arrays. More...
StatementMatcher | makeIteratorLoopMatcher ()
| The matcher used for iterator-based for loops. More...
StatementMatcher | makePseudoArrayLoopMatcher ()
| The matcher used for array-like containers (pseudoarrays). More...
static const Expr * | getContainerFromBeginEndCall (const Expr *Init, bool IsBegin, bool *IsArrow)
| Determine whether Init appears to be an initializing an iterator. More...
static const Expr * | findContainer (ASTContext *Context, const Expr *BeginExpr, const Expr *EndExpr, bool *ContainerNeedsDereference)
| Determines the container whose begin() and end() functions are called for an iterator-based loop. More...
static StringRef | getStringFromRange (SourceManager &SourceMgr, const LangOptions &LangOpts, SourceRange Range)
| Obtain the original source code text from a SourceRange. More...
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. More...
static bool | isDirectMemberExpr (const Expr *E)
| Returns true when the given expression is a member expression whose base is `this` (implicitly or not). More...
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. More...
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. More...
static bool | usagesReturnRValues (const UsageResult &Usages)
| Returns true if the elements of the container are never accessed by reference. More...
static bool | containerIsConst (const Expr *ContainerExpr, bool Dereference)
| Returns true if the container is const-qualified. More...
const Expr * | digThroughConstructors (const Expr *E)
| Look through conversion/copy constructors to find the explicit initialization expression, returning it is found. More...
bool | areSameExpr (ASTContext *Context, const Expr *First, const Expr *Second)
| Returns true when two Exprs are equivalent. More...
const DeclRefExpr * | getDeclRef (const Expr *E)
| Returns the DeclRefExpr represented by E, or NULL if there isn't one. More...
bool | areSameVariable (const ValueDecl *First, const ValueDecl *Second)
| Returns true when two ValueDecls are the same variable. More...
static bool | exprReferencesVariable (const ValueDecl *Target, const Expr *E)
| Determines if an expression is a declaration reference to a particular variable. More...
static const Expr * | getDereferenceOperand (const Expr *E)
| If the expression is a dereference or call to operator*(), return the operand. More...
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. More...
static bool | isIndexInSubscriptExpr (const Expr *IndexExpr, const VarDecl *IndexVar)
| Returns true when the index expression is a declaration reference to IndexVar. More...
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. More...
static bool | isDereferenceOfOpCall (const CXXOperatorCallExpr *OpCall, const VarDecl *IndexVar)
| Returns true when Opcall is a call a one-parameter dereference of IndexVar. More...
static bool | isDereferenceOfUop (const UnaryOperator *Uop, const VarDecl *IndexVar)
| Returns true when Uop is a dereference of IndexVar. More...
static bool | isAliasDecl (ASTContext *Context, const Decl *TheDecl, const VarDecl *IndexVar)
| Determines whether the given Decl defines a variable initialized to the loop object. More...
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. More...
static ClangTidyModuleRegistry::Add< ModernizeModule > | X ("modernize-module", "Add modernize checks.")
| AST_MATCHER (CXXRecordDecl, isMoveConstructible)
| Matches move-constructible classes. More...
static TypeMatcher | constRefType ()
static TypeMatcher | nonConstValueType ()
static bool | paramReferredExactlyOnce (const CXXConstructorDecl *Ctor, const ParmVarDecl *ParamDecl)
| Whether or not `ParamDecl` is used exactly one time in `Ctor`. More...
static SmallVector< const ParmVarDecl *, 2 > | collectParamDecls (const CXXConstructorDecl *Ctor, const ParmVarDecl *ParamDecl)
| Find all references to `ParamDecl` across all of the redeclarations of `Ctor`. More...
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`. More...
static std::set< const Type * > | getAllDirectBases (const CXXRecordDecl *Record)
| Returns the names of the direct bases of `Record`, both virtual and non-virtual. More...
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`. More...
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. More...
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. More...
static bool | bodyEmpty (const ASTContext *Context, const CompoundStmt *Body)
| Returns false if the body has any non-whitespace character. More...
static SmallVector< Token, 16 > | ParseTokens (CharSourceRange Range, const MatchFinder::MatchResult &Result)
static StringRef | GetText (const Token &Tok, const SourceManager &Sources)
template<typename T >
static T | getInnerTypeLocAs (TypeLoc Loc)
static bool | CheckRemoval (SourceManager &SM, SourceLocation StartLoc, ASTContext &Context)

## Variables
static const char | LoopNameArray [] = "forLoopArray"
static const char | LoopNameIterator [] = "forLoopIterator"
static const char | LoopNamePseudoArray [] = "forLoopPseudoArray"
static const char | ConditionBoundName [] = "conditionBound"
static const char | ConditionVarName [] = "conditionVar"
static const char | IncrementVarName [] = "incrementVar"
static const char | InitVarName [] = "initVar"
static const char | BeginCallName [] = "beginCall"
static const char | EndCallName [] = "endCall"
static const char | ConditionEndVarName [] = "conditionEndVar"
static const char | EndVarName [] = "endVar"
static const char | DerefByValueResultName [] = "derefByValueResult"
static const char | DerefByRefResultName [] = "derefByRefResult"
static const TypeMatcher | AnyType = anything()
static const StatementMatcher | IntegerComparisonMatcher
static const DeclarationMatcher | InitToZeroMatcher
static const StatementMatcher | IncrementVarMatcher
static const char | SpecialFunction [] = "SpecialFunction"
static const char | SpecialFunction [] = "SpecialFunction"
static const char | DeletedNotPublic [] = "DeletedNotPublic"
static const StringRef | Message = "prefer transparent functors '%0'"

## Typedef Documentation

## ◆ ComponentVector

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

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

Definition at line 50 of file LoopConvertUtils.h.

## ◆ DeclParentMap

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

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

Definition at line 38 of file LoopConvertUtils.h.

## ◆ ReplacedVarsMap

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

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 43 of file LoopConvertUtils.h.

## ◆ StmtGeneratedVarNameMap

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

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

Definition at line 47 of file LoopConvertUtils.h.

## ◆ StmtParentMap

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

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

Definition at line 33 of file LoopConvertUtils.h.

## ◆ UsageResult

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

Definition at line 271 of file LoopConvertUtils.h.

## Enumeration Type Documentation

## ◆ LoopFixerKind

enum clang::tidy::modernize::LoopFixerKind

Enumerator
LFK_Array |
LFK_Iterator |
LFK_PseudoArray |

Definition at line 30 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.

## ◆ addFunctionCallArgs()

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

Definition at line 97 of file AvoidBindCheck.cpp.

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

## ◆ addPlaceholderArgs()

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

Definition at line 75 of file AvoidBindCheck.cpp.

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

## ◆ areSameExpr()

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

Returns true when two Exprs are equivalent.

Definition at line 188 of file LoopConvertUtils.cpp.

Referenced by clang::tidy::modernize::ForLoopIndexUseVisitor::addUsage().

## ◆ areSameVariable()

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

Returns true when two ValueDecls are the same variable.

Definition at line 204 of file LoopConvertUtils.cpp.

Referenced by clang::tidy::modernize::ForLoopIndexUseVisitor::addUsage(), exprReferencesVariable(), and isIndexInSubscriptExpr().

## ◆ 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 433 of file LoopConvertUtils.cpp.

Referenced by clang::tidy::modernize::ForLoopIndexUseVisitor::addUsage().

## ◆ AST_MATCHER()

clang::tidy::modernize::AST_MATCHER | ( | CXXRecordDecl | ,
|  | isMoveConstructible |
| ) |  |

Matches move-constructible classes.

Given

// POD types are trivially move constructible.
struct Foo { int a; };
struct Bar {
Bar(Bar &&) = deleted;
int a;
};

recordDecl(isMoveConstructible()) matches "Foo".

Definition at line 40 of file PassByValueCheck.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 191 of file UseEqualsDefaultCheck.cpp.

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

## ◆ buildBindArguments()

static SmallVector<BindArgument, 4> clang::tidy::modernize::buildBindArguments | ( | const MatchFinder::MatchResult & | Result,
|  | const CallExpr * | C
| ) |  |
| static

Definition at line 48 of file AvoidBindCheck.cpp.

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

## ◆ 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 389 of file LoopConvertCheck.cpp.

## ◆ CheckRemoval()

static bool clang::tidy::modernize::CheckRemoval | ( | SourceManager & | SM,
|  | SourceLocation | StartLoc,
|  | ASTContext & | Context
| ) |  |
| static

Definition at line 32 of file UseUsingCheck.cpp.

## ◆ 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 109 of file PassByValueCheck.cpp.

## ◆ constRefType()

static TypeMatcher clang::tidy::modernize::constRefType | ( |  | ) |
| static

Definition at line 48 of file PassByValueCheck.cpp.

## ◆ containerIsConst()

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

Returns true if the container is const-qualified.

Definition at line 433 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 235 of file LoopConvertUtils.cpp.

Referenced by clang::tidy::modernize::ForLoopIndexUseVisitor::addUsage().

## ◆ digThroughConstructors()

const Expr * clang::tidy::modernize::digThroughConstructors | ( | const Expr * | E | ) |

Look through conversion/copy constructors 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()); 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.

Referenced by getContainerFromBeginEndCall().

## ◆ 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 211 of file LoopConvertUtils.cpp.

References areSameVariable(), and getDeclRef().

Referenced by clang::tidy::modernize::ForLoopIndexUseVisitor::addUsage(), isDereferenceOfOpCall(), and isDereferenceOfUop().

## ◆ findContainer()

static const Expr* clang::tidy::modernize::findContainer | ( | ASTContext * | Context,
|  | const Expr * | BeginExpr,
|  | const Expr * | EndExpr,
|  | bool * | ContainerNeedsDereference
| ) |  |
| 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 331 of file LoopConvertCheck.cpp.

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

## ◆ 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.

## ◆ 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.

## ◆ getContainerFromBeginEndCall()

static const Expr* clang::tidy::modernize::getContainerFromBeginEndCall | ( | const Expr * | Init,
|  | bool | IsBegin,
|  | bool * | IsArrow
| ) |  |
| 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 301 of file LoopConvertCheck.cpp.

References digThroughConstructors(), and Name.

## ◆ 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 199 of file LoopConvertUtils.cpp.

Referenced by clang::tidy::modernize::ForLoopIndexUseVisitor::addUsage(), 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 220 of file LoopConvertUtils.cpp.

## ◆ getInitializer()

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

Definition at line 96 of file UseDefaultMemberInitCheck.cpp.

Referenced by sameValue().

## ◆ getInnerTypeLocAs()

template<typename T >

static T clang::tidy::modernize::getInnerTypeLocAs | ( | TypeLoc | Loc | ) |
| static

Definition at line 73 of file UseTransparentFunctorsCheck.cpp.

## ◆ 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 370 of file LoopConvertCheck.cpp.

References getDeclRef().

Referenced by containerIsConst().

## ◆ 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 356 of file LoopConvertCheck.cpp.

## ◆ GetText()

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

Definition at line 62 of file UseOverrideCheck.cpp.

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

## ◆ getValueOfValueInit()

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

Definition at line 21 of file UseDefaultMemberInitCheck.cpp.

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

## ◆ ignoreUnaryPlus()

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

Definition at line 89 of file UseDefaultMemberInitCheck.cpp.

Referenced by sameValue().

## ◆ 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 350 of file LoopConvertUtils.cpp.

Referenced by clang::tidy::modernize::ForLoopIndexUseVisitor::addUsage().

## ◆ 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 117 of file UseEqualsDefaultCheck.cpp.

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.

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

## ◆ 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 314 of file LoopConvertUtils.cpp.

References exprReferencesVariable().

Referenced by clang::tidy::modernize::ForLoopIndexUseVisitor::addUsage().

## ◆ 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 327 of file LoopConvertUtils.cpp.

References exprReferencesVariable().

Referenced by clang::tidy::modernize::ForLoopIndexUseVisitor::addUsage().

## ◆ 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 380 of file LoopConvertCheck.cpp.

## ◆ isIndexInSubscriptExpr() [1/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 254 of file LoopConvertUtils.cpp.

References areSameVariable(), and getDeclRef().

Referenced by clang::tidy::modernize::ForLoopIndexUseVisitor::addUsage().

## ◆ isIndexInSubscriptExpr() [2/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 288 of file LoopConvertUtils.cpp.

## ◆ isPlaceHolderIndexRepeated()

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

Definition at line 109 of file AvoidBindCheck.cpp.

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

## ◆ isZero()

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

Definition at line 67 of file UseDefaultMemberInitCheck.cpp.

Referenced by sameValue().

## ◆ makeArrayLoopMatcher()

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

The matcher for loops over arrays.

In this general example, assuming 'j' and 'k' are of integral type:

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

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

Client code will need to make sure that:

- The three index variables identified by the matcher are the same VarDecl.
- The index variable is only used as an array index.
- All arrays indexed by the loop are the same.

Definition at line 79 of file LoopConvertCheck.cpp.

## ◆ makeIteratorLoopMatcher()

StatementMatcher clang::tidy::modernize::makeIteratorLoopMatcher | ( |  | ) |

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):

Assuming f, g, and h are of type containerType::iterator,

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

The following string identifiers are bound to the parts of the AST: InitVarName: 'it' (as a VarDecl) ConditionVarName: 'f' (as a VarDecl) LoopName: The entire for loop (as a ForStmt) In the first example only: EndVarName: 'e' (as a VarDecl) ConditionEndVarName: 'g' (as a VarDecl) In the second example only: EndCallName: 'container.end()' (as a CXXMemberCallExpr)

Client code will need to make sure that:

- The iterator variables 'it', 'f', and 'h' are the same.
- The two containers on which 'begin' and 'end' are called are the same.
- If the end iterator variable 'g' is defined, it is the same as 'f'.

Definition at line 124 of file LoopConvertCheck.cpp.

## ◆ 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):

Assuming f, g, and h are of type containerType::iterator,

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

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

Client code will need to make sure that:

- The index variables 'i', 'f', and 'h' are the same.
- The containers on which 'size()' is called is the container indexed.
- The index variable is only used in overloaded operator[] or container.at().
- If the end iterator variable 'g' is defined, it is the same as 'j'.
- The container's iterators would not be invalidated during the loop.

Definition at line 232 of file LoopConvertCheck.cpp.

## ◆ nonConstValueType()

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

Definition at line 52 of file PassByValueCheck.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 59 of file PassByValueCheck.cpp.

## ◆ ParseTokens()

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

Definition at line 30 of file UseOverrideCheck.cpp.

References File, Info, and Tokens.

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

## ◆ sameValue()

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

Definition at line 103 of file UseDefaultMemberInitCheck.cpp.

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

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

## ◆ 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 408 of file LoopConvertCheck.cpp.

## ◆ 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 424 of file LoopConvertCheck.cpp.

## ◆ X()

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

## Variable Documentation

## ◆ AnyType

const TypeMatcher clang::tidy::modernize::AnyType = anything()
| static

Definition at line 48 of file LoopConvertCheck.cpp.

## ◆ BeginCallName

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

Definition at line 40 of file LoopConvertCheck.cpp.

## ◆ ConditionBoundName

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

Definition at line 36 of file LoopConvertCheck.cpp.

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

## ◆ ConditionEndVarName

const char clang::tidy::modernize::ConditionEndVarName[] = "conditionEndVar"
| static

Definition at line 42 of file LoopConvertCheck.cpp.

## ◆ ConditionVarName

const char clang::tidy::modernize::ConditionVarName[] = "conditionVar"
| static

Definition at line 37 of file LoopConvertCheck.cpp.

## ◆ DeletedNotPublic

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

Definition at line 22 of file UseEqualsDeleteCheck.cpp.

## ◆ DerefByRefResultName

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

Definition at line 45 of file LoopConvertCheck.cpp.

## ◆ DerefByValueResultName

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

Definition at line 44 of file LoopConvertCheck.cpp.

## ◆ EndCallName

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

Definition at line 41 of file LoopConvertCheck.cpp.

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

## ◆ EndVarName

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

Definition at line 43 of file LoopConvertCheck.cpp.

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

## ◆ IncrementVarMatcher

const StatementMatcher clang::tidy::modernize::IncrementVarMatcher
| static

Initial value:
=
declRefExpr(to(varDecl(hasType(isInteger())).bind(IncrementVarName)))
clang::tidy::modernize::IncrementVarName
static const char IncrementVarName[]
Definition: LoopConvertCheck.cpp:38

Definition at line 58 of file LoopConvertCheck.cpp.

## ◆ IncrementVarName

const char clang::tidy::modernize::IncrementVarName[] = "incrementVar"
| static

Definition at line 38 of file LoopConvertCheck.cpp.

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

## ◆ InitToZeroMatcher

const DeclarationMatcher clang::tidy::modernize::InitToZeroMatcher
| static

Initial value:
=
varDecl(hasInitializer(ignoringParenImpCasts(integerLiteral(equals(0)))))
.bind(InitVarName)
clang::tidy::modernize::InitVarName
static const char InitVarName[]
Definition: LoopConvertCheck.cpp:39

Definition at line 54 of file LoopConvertCheck.cpp.

## ◆ InitVarName

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

Definition at line 39 of file LoopConvertCheck.cpp.

## ◆ IntegerComparisonMatcher

const StatementMatcher clang::tidy::modernize::IntegerComparisonMatcher
| static

Initial value:
=
expr(ignoringParenImpCasts(
declRefExpr(to(varDecl(hasType(isInteger())).bind(ConditionVarName)))))
clang::tidy::modernize::ConditionVarName
static const char ConditionVarName[]
Definition: LoopConvertCheck.cpp:37

Definition at line 50 of file LoopConvertCheck.cpp.

## ◆ LoopNameArray

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

Definition at line 33 of file LoopConvertCheck.cpp.

## ◆ LoopNameIterator

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

Definition at line 34 of file LoopConvertCheck.cpp.

## ◆ LoopNamePseudoArray

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

Definition at line 35 of file LoopConvertCheck.cpp.

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

## ◆ Message

const StringRef clang::tidy::modernize::Message = "prefer transparent functors '%0'"
| static

Definition at line 71 of file UseTransparentFunctorsCheck.cpp.

Referenced by clang::tidy::modernize::UseOverrideCheck::check(), clang::tidy::modernize::UseTransparentFunctorsCheck::check(), clang::tidy::readability::DeletedDefaultCheck::check(), clang::tidy::readability::NamespaceCommentCheck::check(), clang::tidy::misc::UnconventionalAssignOperatorCheck::check(), and clang::tidy::ClangTidyDiagnosticConsumer::HandleDiagnostic().

## ◆ SpecialFunction [1/2]

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

Definition at line 21 of file UseEqualsDeleteCheck.cpp.

## ◆ SpecialFunction [2/2]

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

Definition at line 21 of file UseEqualsDefaultCheck.cpp.

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