clang-tools  16.0.0git
Classes | Enumerations | Functions | Variables
clang::tidy::readability Namespace Reference

Classes

class  AvoidConstParamsInDecls
 
class  BracesAroundStatementsCheck
 Checks that bodies of if statements and loops (for, range-for, do-while, and while) are inside braces. More...
 
class  ConstReturnTypeCheck
 For any function whose return type is const-qualified, suggests removal of the const qualifier from that return type. More...
 
class  ContainerContainsCheck
 Finds usages of container.count() and find() == end() which should be replaced by a call to the container.contains() method introduced in C++20. More...
 
class  ContainerDataPointerCheck
 Checks whether a call to operator[] and & can be replaced with a call to data(). More...
 
class  ContainerSizeEmptyCheck
 Checks whether a call to the size() method can be replaced with a call to empty(). More...
 
class  ConvertMemberFunctionsToStatic
 This check finds C++ class methods than can be made static because they don't use the 'this' pointer. More...
 
class  DeleteNullPointerCheck
 Check whether the 'if' statement is unnecessary before calling 'delete' on a pointer. More...
 
class  DuplicateIncludeCheck
 Find and remove duplicate #include directives. More...
 
class  ElseAfterReturnCheck
 Flags the usages of else after return. More...
 
class  FindUsageOfThis
 
class  FunctionCognitiveComplexityCheck
 Checks function Cognitive Complexity metric. More...
 
class  FunctionSizeCheck
 Checks for large functions based on various metrics. More...
 
class  IdentifierLengthCheck
 Warns about identifiers names whose length is too short. More...
 
class  IdentifierNamingCheck
 Checks for identifiers naming style mismatch. More...
 
class  ImplicitBoolConversionCheck
 Checks for use of implicit bool conversions in expressions. More...
 
class  InconsistentDeclarationParameterNameCheck
 Checks for declarations of functions which differ in parameter names. More...
 
class  IsolateDeclarationCheck
 This check diagnoses all DeclStmt's declaring more than one variable and tries to refactor the code to one statement per declaration. More...
 
class  MagicNumbersCheck
 Detects magic numbers, integer and floating point literals embedded in code. More...
 
class  MakeMemberFunctionConstCheck
 Finds non-static member functions that can be made 'const'. More...
 
class  MisleadingIndentationCheck
 Checks the code for dangling else, and possible misleading indentations due to missing braces. More...
 
class  MisplacedArrayIndexCheck
 Warn about unusual array index syntax (index[array] instead of array[index]). More...
 
class  NamedParameterCheck
 Find functions with unnamed arguments. More...
 
class  NamespaceCommentCheck
 Checks that long namespaces have a closing comment. More...
 
class  NonConstParameterCheck
 Warn when a pointer function parameter can be const. More...
 
class  QualifiedAutoCheck
 Finds variables declared as auto that could be declared as: 'auto*' or 'const auto *' and reference variables declared as: 'const auto &'. More...
 
class  ReadabilityModule
 
class  RedundantAccessSpecifiersCheck
 Detects redundant access specifiers inside classes, structs, and unions. More...
 
class  RedundantControlFlowCheck
 Eliminates redundant return statements at the end of a function that returns void. More...
 
class  RedundantDeclarationCheck
 Find redundant variable declarations. More...
 
class  RedundantFunctionPtrDereferenceCheck
 Eliminate redundant dereferences of a function pointer. More...
 
class  RedundantMemberInitCheck
 Finds member initializations that are unnecessary because the same default constructor would be called if they were not present. More...
 
class  RedundantPreprocessorCheck
 This check flags redundant preprocessor directives: nested directives with the same condition. More...
 
class  RedundantSmartptrGetCheck
 Find and remove redundant calls to smart pointer's .get() method. More...
 
class  RedundantStringCStrCheck
 Finds unnecessary calls to std::string::c_str(). More...
 
class  RedundantStringInitCheck
 Finds unnecessary string initializations. More...
 
class  SimplifyBooleanExprCheck
 Looks for boolean expressions involving boolean constants and simplifies them to use the appropriate boolean expression directly. More...
 
class  SimplifySubscriptExprCheck
 Simplifies subscript expressions. More...
 
class  StaticAccessedThroughInstanceCheck
 Checks for member expressions that access static members through instances and replaces them with uses of the appropriate qualified-id. More...
 
class  StaticDefinitionInAnonymousNamespaceCheck
 Finds static function and variable definitions in anonymous namespace. More...
 
class  StringCompareCheck
 This check flags all calls compare when used to check for string equality or inequality. More...
 
class  SuspiciousCallArgumentCheck
 Finds function calls where the arguments passed are provided out of order, based on the difference between the argument name and the parameter names of the function. More...
 
class  UniqueptrDeleteReleaseCheck
 Flags statements of the form delete <unique_ptr expr>.release(); and replaces them with: <unique_ptr expr> = nullptr; More...
 
class  UppercaseLiteralSuffixCheck
 Detects when the integral literal or floating point literal has non-uppercase suffix, and suggests to make the suffix uppercase. More...
 
class  UseAnyOfAllOfCheck
 Finds ranged-based for loops that can be replaced by a call to std::any_of or std::all_of. More...
 

Enumerations

enum  StyleKind : int { SK_Count, SK_Invalid }
 
enum  UsageKind { Unused, Const, NonConst }
 

Functions

static tok::TokenKind getTokenKind (SourceLocation Loc, const SourceManager &SM, const ASTContext *Context)
 
static SourceLocation forwardSkipWhitespaceAndComments (SourceLocation Loc, const SourceManager &SM, const ASTContext *Context)
 
static SourceLocation findEndLocation (const Stmt &S, const SourceManager &SM, const ASTContext *Context)
 
static llvm::Optional< Token > findConstToRemove (const FunctionDecl *Def, const MatchFinder::MatchResult &Result)
 
static CheckResult checkDef (const clang::FunctionDecl *Def, const MatchFinder::MatchResult &MatchResult)
 
 AST_MATCHER (CXXMethodDecl, isStatic)
 
 AST_MATCHER (CXXMethodDecl, hasTrivialBody)
 
 AST_MATCHER (CXXMethodDecl, isOverloadedOperator)
 
 AST_MATCHER (CXXRecordDecl, hasAnyDependentBases)
 
 AST_MATCHER (CXXMethodDecl, isTemplate)
 
 AST_MATCHER (CXXMethodDecl, isDependentContext)
 
 AST_MATCHER (CXXMethodDecl, isInsideMacroDefinition)
 
 AST_MATCHER_P (CXXMethodDecl, hasCanonicalDecl, ast_matchers::internal::Matcher< CXXMethodDecl >, InnerMatcher)
 
 AST_MATCHER (CXXMethodDecl, usesThis)
 
static StringRef getStringFromRange (SourceManager &SourceMgr, const LangOptions &LangOpts, SourceRange Range)
 Obtain the original source code text from a SourceRange. More...
 
static SourceRange getLocationOfConst (const TypeSourceInfo *TSI, SourceManager &SourceMgr, const LangOptions &LangOpts)
 
static SourceLocation advanceBeyondCurrentLine (const SourceManager &SM, SourceLocation Start, int Offset)
 
static const DeclRefExpr * findUsage (const Stmt *Node, int64_t DeclIdentifier)
 
static const DeclRefExpr * findUsageRange (const Stmt *Node, const llvm::ArrayRef< int64_t > &DeclIdentifiers)
 
static const DeclRefExpr * checkInitDeclUsageInElse (const IfStmt *If)
 
static const DeclRefExpr * checkConditionVarUsageInElse (const IfStmt *If)
 
static bool containsDeclInScope (const Stmt *Node)
 
static void removeElseAndBrackets (DiagnosticBuilder &Diag, ASTContext &Context, const Stmt *Else, SourceLocation ElseLoc)
 
static bool hasPreprocessorBranchEndBetweenLocations (const ElseAfterReturnCheck::ConditionalBranchMap &ConditionalBranchMap, const SourceManager &SM, SourceLocation StartLoc, SourceLocation EndLoc)
 
static StringRef getControlFlowString (const Stmt &Stmt)
 
static SourceLocation findStartOfIndirection (SourceLocation Start, int Indirections, const SourceManager &SM, const LangOptions &LangOpts)
 
static bool isMacroID (SourceRange R)
 
static int countIndirections (const Type *T, int Indirections=0)
 This function counts the number of written indirections for the given Type T. More...
 
static bool typeIsMemberPointer (const Type *T)
 
static Optional< std::vector< SourceRange > > declRanges (const DeclStmt *DS, const SourceManager &SM, const LangOptions &LangOpts)
 This function tries to extract the SourceRanges that make up all declarations in this DeclStmt. More...
 
static Optional< std::vector< StringRef > > collectSourceRanges (llvm::ArrayRef< SourceRange > Ranges, const SourceManager &SM, const LangOptions &LangOpts)
 
static std::vector< std::string > createIsolatedDecls (llvm::ArrayRef< StringRef > Snippets)
 Expects a vector {TypeSnippet, Firstdecl, SecondDecl, ...}. More...
 
 AST_MATCHER (CXXMethodDecl, usesThisAsConst)
 
static SourceLocation getConstInsertionPoint (const CXXMethodDecl *M)
 
static const IfStmt * getPrecedingIf (const SourceManager &SM, ASTContext *Context, const IfStmt *If)
 
static bool locationsInSameFile (const SourceManager &Sources, SourceLocation Loc1, SourceLocation Loc2)
 
static llvm::Optional< std::string > getNamespaceNameAsWritten (SourceLocation &Loc, const SourceManager &Sources, const LangOptions &LangOpts)
 
static ClangTidyModuleRegistry::Add< ReadabilityModuleX ("readability-module", "Adds readability-related checks.")
 
 AST_MATCHER (FunctionDecl, doesDeclarationForceExternallyVisibleDefinition)
 
static std::vector< StringRef > removeNamespaces (ArrayRef< StringRef > Names)
 
static const CXXConstructExpr * getConstructExpr (const CXXCtorInitializer &CtorInit)
 
static llvm::Optional< SourceRange > getConstructExprArgRange (const CXXConstructExpr &Construct)
 
static bool needsParensAfterUnaryNegation (const Expr *E)
 
static StringRef negatedOperator (const BinaryOperator *BinOp)
 
static StringRef getOperatorName (OverloadedOperatorKind OpKind)
 
static StringRef negatedOperator (const CXXOperatorCallExpr *OpCall)
 
static std::string asBool (StringRef Text, bool NeedsStaticCast)
 
static bool needsNullPtrComparison (const Expr *E)
 
static bool needsZeroComparison (const Expr *E)
 
static bool needsStaticCast (const Expr *E)
 
static std::string compareExpressionToConstant (const ASTContext &Context, const Expr *E, bool Negated, const char *Constant)
 
static std::string compareExpressionToNullPtr (const ASTContext &Context, const Expr *E, bool Negated)
 
static std::string compareExpressionToZero (const ASTContext &Context, const Expr *E, bool Negated)
 
static std::string replacementExpression (const ASTContext &Context, bool Negated, const Expr *E)
 
static bool containsDiscardedTokens (const ASTContext &Context, CharSourceRange CharRange)
 
static bool containsBoolLiteral (const Expr *E)
 
static bool flipDemorganOperator (llvm::SmallVectorImpl< FixItHint > &Output, const BinaryOperator *BO)
 Swaps a BinaryOperator opcode from && to || or vice-versa. More...
 
static BinaryOperatorKind getDemorganFlippedOperator (BinaryOperatorKind BO)
 
static bool flipDemorganSide (SmallVectorImpl< FixItHint > &Fixes, const ASTContext &Ctx, const Expr *E, Optional< BinaryOperatorKind > OuterBO)
 
static bool flipDemorganBinaryOperator (SmallVectorImpl< FixItHint > &Fixes, const ASTContext &Ctx, const BinaryOperator *BinOp, Optional< BinaryOperatorKind > OuterBO, const ParenExpr *Parens=nullptr)
 Inverts BinOp, Removing Parens if they exist and are safe to remove. More...
 
static bool shouldRemoveParens (const Stmt *Parent, BinaryOperatorKind NewOuterBinary, const ParenExpr *Parens)
 
static unsigned getNameSpecifierNestingLevel (const QualType &QType)
 
 AST_MATCHER (NamedDecl, isInAnonymousNamespace)
 
static double percentage (double X, double Y)
 Returns how many % X is of Y. More...
 
static bool applyEqualityHeuristic (StringRef Arg, StringRef Param)
 
static bool applyAbbreviationHeuristic (const llvm::StringMap< std::string > &AbbreviationDictionary, StringRef Arg, StringRef Param)
 
static bool applyPrefixHeuristic (StringRef Arg, StringRef Param, int8_t Threshold)
 Check whether the shorter String is a prefix of the longer String. More...
 
static bool applySuffixHeuristic (StringRef Arg, StringRef Param, int8_t Threshold)
 Check whether the shorter String is a suffix of the longer String. More...
 
static bool applySubstringHeuristic (StringRef Arg, StringRef Param, int8_t Threshold)
 
static bool applyLevenshteinHeuristic (StringRef Arg, StringRef Param, int8_t Threshold)
 
static bool applyJaroWinklerHeuristic (StringRef Arg, StringRef Param, int8_t Threshold)
 
static bool applyDiceHeuristic (StringRef Arg, StringRef Param, int8_t Threshold)
 
static bool areRefAndQualCompatible (QualType ArgType, QualType ParamType)
 Checks if ArgType binds to ParamType regarding reference-ness and cv-qualifiers. More...
 
static bool isPointerOrArray (QualType TypeToCheck)
 
static bool isCompatibleWithArrayReference (QualType ArgType, QualType ParamType)
 Checks whether ArgType is an array type identical to ParamType's array type. More...
 
static QualType convertToPointeeOrArrayElementQualType (QualType TypeToConvert)
 
static bool arePointersStillQualCompatible (QualType ArgType, QualType ParamType, bool &IsParamContinuouslyConst)
 Checks if multilevel pointers' qualifiers compatibility continues on the current pointer level. More...
 
static bool arePointerTypesCompatible (QualType ArgType, QualType ParamType, bool IsParamContinuouslyConst)
 Checks whether multilevel pointers are compatible in terms of levels, qualifiers and pointee type. More...
 
static bool areTypesCompatible (QualType ArgType, QualType ParamType, const ASTContext &Ctx)
 Checks whether ArgType converts implicitly to ParamType. More...
 
static bool isOverloadedUnaryOrBinarySymbolOperator (const FunctionDecl *FD)
 
static bool isViableLoop (const CXXForRangeStmt &S, ASTContext &Context)
 

Variables

constexpr llvm::StringLiteral ContainerExprName = "container-expr"
 
constexpr llvm::StringLiteral DerefContainerExprName = "deref-container-expr"
 
constexpr llvm::StringLiteral AddrOfContainerExprName
 
constexpr llvm::StringLiteral AddressOfName = "address-of"
 
static const char InterruptingStr [] = "interrupting"
 
static const char WarningMessage [] = "do not use 'else' after '%0'"
 
static const char WarnOnUnfixableStr [] = "WarnOnUnfixable"
 
static const char WarnOnConditionVariablesStr [] = "WarnOnConditionVariables"
 
const unsigned DefaultMinimumVariableNameLength = 3
 
const unsigned DefaultMinimumLoopCounterNameLength = 2
 
const unsigned DefaultMinimumExceptionNameLength = 2
 
const unsigned DefaultMinimumParameterNameLength = 3
 
const char DefaultIgnoredLoopCounterNames [] = "^[ijk_]$"
 
const char DefaultIgnoredVariableNames [] = ""
 
const char DefaultIgnoredExceptionVariableNames [] = "^[e]$"
 
const char DefaultIgnoredParameterNames [] = "^[n]$"
 
const char ErrorMessage []
 
static const StringRef StyleNames []
 
static const StringRef HungarainNotationPrimitiveTypes []
 
static const StringRef HungarainNotationUserDefinedTypes []
 
const char DefaultIgnoredIntegerValues [] = "1;2;3;4;"
 
const char DefaultIgnoredFloatingPointValues [] = "1.0;100.0;"
 
const char DefaultStringNames []
 
static constexpr char SimplifyOperatorDiagnostic []
 
static constexpr char SimplifyConditionDiagnostic []
 
static constexpr char SimplifyConditionalReturnDiagnostic []
 
static std::pair< BinaryOperatorKind, BinaryOperatorKind > Opposites []
 
static std::pair< OverloadedOperatorKind, StringRef > OperatorNames []
 
static std::pair< OverloadedOperatorKind, OverloadedOperatorKind > OppositeOverloads []
 
static const char KDefaultTypes []
 
static const StringRef CompareMessage
 
static constexpr std::size_t DefaultMinimumIdentifierNameLength = 3
 
static constexpr StringRef HeuristicToString []
 
static constexpr DefaultHeuristicConfiguration Defaults []
 
static constexpr llvm::StringLiteral DefaultAbbreviations
 
static constexpr std::size_t SmallVectorSize
 

Enumeration Type Documentation

◆ StyleKind

Enumerator
SK_Count 
SK_Invalid 

Definition at line 125 of file IdentifierNamingCheck.cpp.

◆ UsageKind

Enumerator
Unused 
Const 
NonConst 

Definition at line 52 of file MakeMemberFunctionConstCheck.cpp.

Function Documentation

◆ advanceBeyondCurrentLine()

static SourceLocation clang::tidy::readability::advanceBeyondCurrentLine ( const SourceManager &  SM,
SourceLocation  Start,
int  Offset 
)
static

Definition at line 20 of file DuplicateIncludeCheck.cpp.

◆ applyAbbreviationHeuristic()

static bool clang::tidy::readability::applyAbbreviationHeuristic ( const llvm::StringMap< std::string > &  AbbreviationDictionary,
StringRef  Arg,
StringRef  Param 
)
static

Definition at line 138 of file SuspiciousCallArgumentCheck.cpp.

◆ applyDiceHeuristic()

static bool clang::tidy::readability::applyDiceHeuristic ( StringRef  Arg,
StringRef  Param,
int8_t  Threshold 
)
static

Definition at line 275 of file SuspiciousCallArgumentCheck.cpp.

References percentage().

◆ applyEqualityHeuristic()

static bool clang::tidy::readability::applyEqualityHeuristic ( StringRef  Arg,
StringRef  Param 
)
static

Definition at line 134 of file SuspiciousCallArgumentCheck.cpp.

◆ applyJaroWinklerHeuristic()

static bool clang::tidy::readability::applyJaroWinklerHeuristic ( StringRef  Arg,
StringRef  Param,
int8_t  Threshold 
)
static

Definition at line 214 of file SuspiciousCallArgumentCheck.cpp.

References Range.

◆ applyLevenshteinHeuristic()

static bool clang::tidy::readability::applyLevenshteinHeuristic ( StringRef  Arg,
StringRef  Param,
int8_t  Threshold 
)
static

Definition at line 205 of file SuspiciousCallArgumentCheck.cpp.

References Dist.

◆ applyPrefixHeuristic()

static bool clang::tidy::readability::applyPrefixHeuristic ( StringRef  Arg,
StringRef  Param,
int8_t  Threshold 
)
static

Check whether the shorter String is a prefix of the longer String.

Definition at line 153 of file SuspiciousCallArgumentCheck.cpp.

References percentage().

◆ applySubstringHeuristic()

static bool clang::tidy::readability::applySubstringHeuristic ( StringRef  Arg,
StringRef  Param,
int8_t  Threshold 
)
static

Definition at line 176 of file SuspiciousCallArgumentCheck.cpp.

References percentage().

◆ applySuffixHeuristic()

static bool clang::tidy::readability::applySuffixHeuristic ( StringRef  Arg,
StringRef  Param,
int8_t  Threshold 
)
static

Check whether the shorter String is a suffix of the longer String.

Definition at line 165 of file SuspiciousCallArgumentCheck.cpp.

References percentage().

◆ arePointersStillQualCompatible()

static bool clang::tidy::readability::arePointersStillQualCompatible ( QualType  ArgType,
QualType  ParamType,
bool &  IsParamContinuouslyConst 
)
static

Checks if multilevel pointers' qualifiers compatibility continues on the current pointer level.

For multilevel pointers, C++ permits conversion, if every cv-qualifier in ArgType also appears in the corresponding position in ParamType, and if PramType has a cv-qualifier that's not in ArgType, then every * in ParamType to the right of that cv-qualifier, except the last one, must also be const-qualified.

Definition at line 345 of file SuspiciousCallArgumentCheck.cpp.

Referenced by arePointerTypesCompatible().

◆ arePointerTypesCompatible()

static bool clang::tidy::readability::arePointerTypesCompatible ( QualType  ArgType,
QualType  ParamType,
bool  IsParamContinuouslyConst 
)
static

Checks whether multilevel pointers are compatible in terms of levels, qualifiers and pointee type.

Definition at line 362 of file SuspiciousCallArgumentCheck.cpp.

References arePointersStillQualCompatible(), and convertToPointeeOrArrayElementQualType().

Referenced by areTypesCompatible().

◆ areRefAndQualCompatible()

static bool clang::tidy::readability::areRefAndQualCompatible ( QualType  ArgType,
QualType  ParamType 
)
static

Checks if ArgType binds to ParamType regarding reference-ness and cv-qualifiers.

Definition at line 303 of file SuspiciousCallArgumentCheck.cpp.

Referenced by areTypesCompatible().

◆ areTypesCompatible()

static bool clang::tidy::readability::areTypesCompatible ( QualType  ArgType,
QualType  ParamType,
const ASTContext &  Ctx 
)
static

◆ asBool()

static std::string clang::tidy::readability::asBool ( StringRef  Text,
bool  NeedsStaticCast 
)
static

Definition at line 99 of file SimplifyBooleanExprCheck.cpp.

References Text.

◆ AST_MATCHER() [1/11]

clang::tidy::readability::AST_MATCHER ( CXXMethodDecl  ,
hasTrivialBody   
)

Definition at line 25 of file ConvertMemberFunctionsToStatic.cpp.

◆ AST_MATCHER() [2/11]

clang::tidy::readability::AST_MATCHER ( CXXMethodDecl  ,
isDependentContext   
)

Definition at line 39 of file ConvertMemberFunctionsToStatic.cpp.

◆ AST_MATCHER() [3/11]

clang::tidy::readability::AST_MATCHER ( CXXMethodDecl  ,
isInsideMacroDefinition   
)

Definition at line 43 of file ConvertMemberFunctionsToStatic.cpp.

◆ AST_MATCHER() [4/11]

clang::tidy::readability::AST_MATCHER ( CXXMethodDecl  ,
isOverloadedOperator   
)

Definition at line 27 of file ConvertMemberFunctionsToStatic.cpp.

◆ AST_MATCHER() [5/11]

clang::tidy::readability::AST_MATCHER ( CXXMethodDecl  ,
isStatic   
)

Definition at line 23 of file ConvertMemberFunctionsToStatic.cpp.

◆ AST_MATCHER() [6/11]

clang::tidy::readability::AST_MATCHER ( CXXMethodDecl  ,
isTemplate   
)

Definition at line 35 of file ConvertMemberFunctionsToStatic.cpp.

◆ AST_MATCHER() [7/11]

clang::tidy::readability::AST_MATCHER ( CXXMethodDecl  ,
usesThis   
)

Definition at line 57 of file ConvertMemberFunctionsToStatic.cpp.

References E.

◆ AST_MATCHER() [8/11]

clang::tidy::readability::AST_MATCHER ( CXXMethodDecl  ,
usesThisAsConst   
)

Definition at line 210 of file MakeMemberFunctionConstCheck.cpp.

◆ AST_MATCHER() [9/11]

clang::tidy::readability::AST_MATCHER ( CXXRecordDecl  ,
hasAnyDependentBases   
)

Definition at line 31 of file ConvertMemberFunctionsToStatic.cpp.

◆ AST_MATCHER() [10/11]

clang::tidy::readability::AST_MATCHER ( FunctionDecl  ,
doesDeclarationForceExternallyVisibleDefinition   
)

Definition at line 20 of file RedundantDeclarationCheck.cpp.

◆ AST_MATCHER() [11/11]

clang::tidy::readability::AST_MATCHER ( NamedDecl  ,
isInAnonymousNamespace   
)

◆ AST_MATCHER_P()

clang::tidy::readability::AST_MATCHER_P ( CXXMethodDecl  ,
hasCanonicalDecl  ,
ast_matchers::internal::Matcher< CXXMethodDecl >  ,
InnerMatcher   
)

Definition at line 52 of file ConvertMemberFunctionsToStatic.cpp.

◆ checkConditionVarUsageInElse()

static const DeclRefExpr* clang::tidy::readability::checkConditionVarUsageInElse ( const IfStmt *  If)
static

Definition at line 101 of file ElseAfterReturnCheck.cpp.

◆ checkDef()

static CheckResult clang::tidy::readability::checkDef ( const clang::FunctionDecl *  Def,
const MatchFinder::MatchResult &  MatchResult 
)
static

Definition at line 82 of file ConstReturnTypeCheck.cpp.

◆ checkInitDeclUsageInElse()

static const DeclRefExpr* clang::tidy::readability::checkInitDeclUsageInElse ( const IfStmt *  If)
static

Definition at line 84 of file ElseAfterReturnCheck.cpp.

◆ collectSourceRanges()

static Optional<std::vector<StringRef> > clang::tidy::readability::collectSourceRanges ( llvm::ArrayRef< SourceRange >  Ranges,
const SourceManager &  SM,
const LangOptions &  LangOpts 
)
static

Definition at line 204 of file IsolateDeclarationCheck.cpp.

◆ compareExpressionToConstant()

static std::string clang::tidy::readability::compareExpressionToConstant ( const ASTContext &  Context,
const Expr *  E,
bool  Negated,
const char *  Constant 
)
static

Definition at line 140 of file SimplifyBooleanExprCheck.cpp.

◆ compareExpressionToNullPtr()

static std::string clang::tidy::readability::compareExpressionToNullPtr ( const ASTContext &  Context,
const Expr *  E,
bool  Negated 
)
static

Definition at line 151 of file SimplifyBooleanExprCheck.cpp.

◆ compareExpressionToZero()

static std::string clang::tidy::readability::compareExpressionToZero ( const ASTContext &  Context,
const Expr *  E,
bool  Negated 
)
static

Definition at line 157 of file SimplifyBooleanExprCheck.cpp.

◆ containsBoolLiteral()

static bool clang::tidy::readability::containsBoolLiteral ( const Expr *  E)
static

Definition at line 596 of file SimplifyBooleanExprCheck.cpp.

◆ containsDeclInScope()

static bool clang::tidy::readability::containsDeclInScope ( const Stmt *  Node)
static

Definition at line 107 of file ElseAfterReturnCheck.cpp.

◆ containsDiscardedTokens()

static bool clang::tidy::readability::containsDiscardedTokens ( const ASTContext &  Context,
CharSourceRange  CharRange 
)
static

Definition at line 240 of file SimplifyBooleanExprCheck.cpp.

◆ convertToPointeeOrArrayElementQualType()

static QualType clang::tidy::readability::convertToPointeeOrArrayElementQualType ( QualType  TypeToConvert)
static

◆ countIndirections()

static int clang::tidy::readability::countIndirections ( const Type *  T,
int  Indirections = 0 
)
static

This function counts the number of written indirections for the given Type T.

It does NOT resolve typedefs as it's a helper for lexing the source code.

See also
declRanges

Definition at line 60 of file IsolateDeclarationCheck.cpp.

◆ createIsolatedDecls()

static std::vector<std::string> clang::tidy::readability::createIsolatedDecls ( llvm::ArrayRef< StringRef >  Snippets)
static

Expects a vector {TypeSnippet, Firstdecl, SecondDecl, ...}.

Definition at line 232 of file IsolateDeclarationCheck.cpp.

◆ declRanges()

static Optional<std::vector<SourceRange> > clang::tidy::readability::declRanges ( const DeclStmt *  DS,
const SourceManager &  SM,
const LangOptions &  LangOpts 
)
static

This function tries to extract the SourceRanges that make up all declarations in this DeclStmt.

The resulting vector has the structure {UnderlyingType, Decl1, Decl2, ...}. Each SourceRange is of the form [Begin, End). If any of the create ranges is invalid or in a macro the result will be None. If the DeclStmt contains only one declaration, the result is None. If the DeclStmt contains declarations other than VarDecl the result is None.

int * ptr1 = nullptr, value = 42;
// [ ][ ] [ ] - The ranges here are inclusive
Todo:
Generalize this function to take other declarations than VarDecl.

Definition at line 109 of file IsolateDeclarationCheck.cpp.

◆ findConstToRemove()

static llvm::Optional<Token> clang::tidy::readability::findConstToRemove ( const FunctionDecl *  Def,
const MatchFinder::MatchResult &  Result 
)
static

Definition at line 28 of file ConstReturnTypeCheck.cpp.

◆ findEndLocation()

static SourceLocation clang::tidy::readability::findEndLocation ( const Stmt &  S,
const SourceManager &  SM,
const ASTContext *  Context 
)
static

Definition at line 53 of file BracesAroundStatementsCheck.cpp.

◆ findStartOfIndirection()

static SourceLocation clang::tidy::readability::findStartOfIndirection ( SourceLocation  Start,
int  Indirections,
const SourceManager &  SM,
const LangOptions &  LangOpts 
)
static

Definition at line 34 of file IsolateDeclarationCheck.cpp.

◆ findUsage()

static const DeclRefExpr* clang::tidy::readability::findUsage ( const Stmt *  Node,
int64_t  DeclIdentifier 
)
static

Definition at line 51 of file ElseAfterReturnCheck.cpp.

◆ findUsageRange()

static const DeclRefExpr* clang::tidy::readability::findUsageRange ( const Stmt *  Node,
const llvm::ArrayRef< int64_t > &  DeclIdentifiers 
)
static

Definition at line 67 of file ElseAfterReturnCheck.cpp.

◆ flipDemorganBinaryOperator()

static bool clang::tidy::readability::flipDemorganBinaryOperator ( SmallVectorImpl< FixItHint > &  Fixes,
const ASTContext &  Ctx,
const BinaryOperator *  BinOp,
Optional< BinaryOperatorKind >  OuterBO,
const ParenExpr *  Parens = nullptr 
)
static

Inverts BinOp, Removing Parens if they exist and are safe to remove.

returns true if there is any issue building the Fixes, false otherwise.

Definition at line 790 of file SimplifyBooleanExprCheck.cpp.

References Ctx, flipDemorganOperator(), flipDemorganSide(), and getDemorganFlippedOperator().

◆ flipDemorganOperator()

static bool clang::tidy::readability::flipDemorganOperator ( llvm::SmallVectorImpl< FixItHint > &  Output,
const BinaryOperator *  BO 
)
static

Swaps a BinaryOperator opcode from && to || or vice-versa.

Definition at line 768 of file SimplifyBooleanExprCheck.cpp.

References Output.

Referenced by flipDemorganBinaryOperator().

◆ flipDemorganSide()

static bool clang::tidy::readability::flipDemorganSide ( SmallVectorImpl< FixItHint > &  Fixes,
const ASTContext &  Ctx,
const Expr *  E,
Optional< BinaryOperatorKind >  OuterBO 
)
static

Definition at line 869 of file SimplifyBooleanExprCheck.cpp.

Referenced by flipDemorganBinaryOperator().

◆ forwardSkipWhitespaceAndComments()

static SourceLocation clang::tidy::readability::forwardSkipWhitespaceAndComments ( SourceLocation  Loc,
const SourceManager &  SM,
const ASTContext *  Context 
)
static

Definition at line 37 of file BracesAroundStatementsCheck.cpp.

◆ getConstInsertionPoint()

static SourceLocation clang::tidy::readability::getConstInsertionPoint ( const CXXMethodDecl *  M)
static

Definition at line 241 of file MakeMemberFunctionConstCheck.cpp.

References M.

◆ getConstructExpr()

static const CXXConstructExpr* clang::tidy::readability::getConstructExpr ( const CXXCtorInitializer &  CtorInit)
static

Definition at line 36 of file RedundantStringInitCheck.cpp.

◆ getConstructExprArgRange()

static llvm::Optional<SourceRange> clang::tidy::readability::getConstructExprArgRange ( const CXXConstructExpr &  Construct)
static

Definition at line 44 of file RedundantStringInitCheck.cpp.

References ns1::ns2::B, and E.

◆ getControlFlowString()

static StringRef clang::tidy::readability::getControlFlowString ( const Stmt &  Stmt)
static

Definition at line 227 of file ElseAfterReturnCheck.cpp.

◆ getDemorganFlippedOperator()

static BinaryOperatorKind clang::tidy::readability::getDemorganFlippedOperator ( BinaryOperatorKind  BO)
static

Definition at line 778 of file SimplifyBooleanExprCheck.cpp.

Referenced by flipDemorganBinaryOperator().

◆ getLocationOfConst()

static SourceRange clang::tidy::readability::getLocationOfConst ( const TypeSourceInfo *  TSI,
SourceManager &  SourceMgr,
const LangOptions &  LangOpts 
)
static

◆ getNamespaceNameAsWritten()

static llvm::Optional<std::string> clang::tidy::readability::getNamespaceNameAsWritten ( SourceLocation &  Loc,
const SourceManager &  Sources,
const LangOptions &  LangOpts 
)
static

Definition at line 49 of file NamespaceCommentCheck.cpp.

◆ getNameSpecifierNestingLevel()

static unsigned clang::tidy::readability::getNameSpecifierNestingLevel ( const QualType &  QType)
static

Definition at line 20 of file StaticAccessedThroughInstanceCheck.cpp.

◆ getOperatorName()

static StringRef clang::tidy::readability::getOperatorName ( OverloadedOperatorKind  OpKind)
static

◆ getPrecedingIf()

static const IfStmt* clang::tidy::readability::getPrecedingIf ( const SourceManager &  SM,
ASTContext *  Context,
const IfStmt *  If 
)
static

Definition at line 19 of file MisleadingIndentationCheck.cpp.

◆ getStringFromRange()

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

Obtain the original source code text from a SourceRange.

Definition at line 95 of file ConvertMemberFunctionsToStatic.cpp.

References clang::tidy::cppcoreguidelines::getSourceText(), LangOpts, Range, and SourceMgr.

Referenced by getLocationOfConst().

◆ getTokenKind()

static tok::TokenKind clang::tidy::readability::getTokenKind ( SourceLocation  Loc,
const SourceManager &  SM,
const ASTContext *  Context 
)
static

Definition at line 21 of file BracesAroundStatementsCheck.cpp.

◆ hasPreprocessorBranchEndBetweenLocations()

static bool clang::tidy::readability::hasPreprocessorBranchEndBetweenLocations ( const ElseAfterReturnCheck::ConditionalBranchMap ConditionalBranchMap,
const SourceManager &  SM,
SourceLocation  StartLoc,
SourceLocation  EndLoc 
)
static

Definition at line 187 of file ElseAfterReturnCheck.cpp.

◆ isCompatibleWithArrayReference()

static bool clang::tidy::readability::isCompatibleWithArrayReference ( QualType  ArgType,
QualType  ParamType 
)
static

Checks whether ArgType is an array type identical to ParamType's array type.

Enforces array elements' qualifier compatibility as well.

Definition at line 315 of file SuspiciousCallArgumentCheck.cpp.

Referenced by areTypesCompatible().

◆ isMacroID()

static bool clang::tidy::readability::isMacroID ( SourceRange  R)
static

Definition at line 52 of file IsolateDeclarationCheck.cpp.

◆ isOverloadedUnaryOrBinarySymbolOperator()

static bool clang::tidy::readability::isOverloadedUnaryOrBinarySymbolOperator ( const FunctionDecl *  FD)
static

Definition at line 480 of file SuspiciousCallArgumentCheck.cpp.

◆ isPointerOrArray()

static bool clang::tidy::readability::isPointerOrArray ( QualType  TypeToCheck)
static

Definition at line 309 of file SuspiciousCallArgumentCheck.cpp.

Referenced by areTypesCompatible().

◆ isViableLoop()

static bool clang::tidy::readability::isViableLoop ( const CXXForRangeStmt &  S,
ASTContext &  Context 
)
static

Definition at line 74 of file UseAnyOfAllOfCheck.cpp.

◆ locationsInSameFile()

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

Definition at line 42 of file NamespaceCommentCheck.cpp.

◆ needsNullPtrComparison()

static bool clang::tidy::readability::needsNullPtrComparison ( const Expr *  E)
static

Definition at line 106 of file SimplifyBooleanExprCheck.cpp.

◆ needsParensAfterUnaryNegation()

static bool clang::tidy::readability::needsParensAfterUnaryNegation ( const Expr *  E)
static

Definition at line 44 of file SimplifyBooleanExprCheck.cpp.

◆ needsStaticCast()

static bool clang::tidy::readability::needsStaticCast ( const Expr *  E)
static

Definition at line 121 of file SimplifyBooleanExprCheck.cpp.

◆ needsZeroComparison()

static bool clang::tidy::readability::needsZeroComparison ( const Expr *  E)
static

Definition at line 114 of file SimplifyBooleanExprCheck.cpp.

◆ negatedOperator() [1/2]

static StringRef clang::tidy::readability::negatedOperator ( const BinaryOperator *  BinOp)
static

Definition at line 59 of file SimplifyBooleanExprCheck.cpp.

References Opposites.

◆ negatedOperator() [2/2]

static StringRef clang::tidy::readability::negatedOperator ( const CXXOperatorCallExpr *  OpCall)
static

Definition at line 88 of file SimplifyBooleanExprCheck.cpp.

References getOperatorName(), and OppositeOverloads.

◆ percentage()

static double clang::tidy::readability::percentage ( double  X,
double  Y 
)
inlinestatic

Returns how many % X is of Y.

Definition at line 132 of file SuspiciousCallArgumentCheck.cpp.

References X.

Referenced by applyDiceHeuristic(), applyPrefixHeuristic(), applySubstringHeuristic(), and applySuffixHeuristic().

◆ removeElseAndBrackets()

static void clang::tidy::readability::removeElseAndBrackets ( DiagnosticBuilder &  Diag,
ASTContext &  Context,
const Stmt *  Else,
SourceLocation  ElseLoc 
)
static

Definition at line 117 of file ElseAfterReturnCheck.cpp.

◆ removeNamespaces()

static std::vector<StringRef> clang::tidy::readability::removeNamespaces ( ArrayRef< StringRef >  Names)
static

Definition at line 24 of file RedundantStringInitCheck.cpp.

◆ replacementExpression()

static std::string clang::tidy::readability::replacementExpression ( const ASTContext &  Context,
bool  Negated,
const Expr *  E 
)
static

Definition at line 162 of file SimplifyBooleanExprCheck.cpp.

◆ shouldRemoveParens()

static bool clang::tidy::readability::shouldRemoveParens ( const Stmt *  Parent,
BinaryOperatorKind  NewOuterBinary,
const ParenExpr *  Parens 
)
static

Definition at line 895 of file SimplifyBooleanExprCheck.cpp.

References Parent.

◆ typeIsMemberPointer()

static bool clang::tidy::readability::typeIsMemberPointer ( const Type *  T)
static

Definition at line 81 of file IsolateDeclarationCheck.cpp.

◆ X()

static ClangTidyModuleRegistry::Add<ReadabilityModule> clang::tidy::readability::X ( "readability-module"  ,
"Adds readability-related checks."   
)
static

Variable Documentation

◆ AddressOfName

constexpr llvm::StringLiteral clang::tidy::readability::AddressOfName = "address-of"
constexpr

Definition at line 24 of file ContainerDataPointerCheck.cpp.

◆ AddrOfContainerExprName

constexpr llvm::StringLiteral clang::tidy::readability::AddrOfContainerExprName
constexpr
Initial value:
=
"addr-of-container-expr"

Definition at line 22 of file ContainerDataPointerCheck.cpp.

◆ CompareMessage

const StringRef clang::tidy::readability::CompareMessage
static
Initial value:
= "do not use 'compare' to test equality "
"of strings; use the string equality "
"operator instead"

Definition at line 21 of file StringCompareCheck.cpp.

◆ ContainerExprName

constexpr llvm::StringLiteral clang::tidy::readability::ContainerExprName = "container-expr"
constexpr

Definition at line 20 of file ContainerDataPointerCheck.cpp.

◆ DefaultAbbreviations

constexpr llvm::StringLiteral clang::tidy::readability::DefaultAbbreviations
staticconstexpr

Definition at line 96 of file SuspiciousCallArgumentCheck.cpp.

◆ DefaultIgnoredExceptionVariableNames

const char clang::tidy::readability::DefaultIgnoredExceptionVariableNames[] = "^[e]$"

Definition at line 27 of file IdentifierLengthCheck.cpp.

◆ DefaultIgnoredFloatingPointValues

const char clang::tidy::readability::DefaultIgnoredFloatingPointValues[] = "1.0;100.0;"

Definition at line 61 of file MagicNumbersCheck.cpp.

◆ DefaultIgnoredIntegerValues

const char clang::tidy::readability::DefaultIgnoredIntegerValues[] = "1;2;3;4;"

Definition at line 60 of file MagicNumbersCheck.cpp.

◆ DefaultIgnoredLoopCounterNames

const char clang::tidy::readability::DefaultIgnoredLoopCounterNames[] = "^[ijk_]$"

Definition at line 25 of file IdentifierLengthCheck.cpp.

◆ DefaultIgnoredParameterNames

const char clang::tidy::readability::DefaultIgnoredParameterNames[] = "^[n]$"

Definition at line 28 of file IdentifierLengthCheck.cpp.

◆ DefaultIgnoredVariableNames

const char clang::tidy::readability::DefaultIgnoredVariableNames[] = ""

Definition at line 26 of file IdentifierLengthCheck.cpp.

◆ DefaultMinimumExceptionNameLength

const unsigned clang::tidy::readability::DefaultMinimumExceptionNameLength = 2

Definition at line 23 of file IdentifierLengthCheck.cpp.

◆ DefaultMinimumIdentifierNameLength

constexpr std::size_t clang::tidy::readability::DefaultMinimumIdentifierNameLength = 3
staticconstexpr

Definition at line 45 of file SuspiciousCallArgumentCheck.cpp.

◆ DefaultMinimumLoopCounterNameLength

const unsigned clang::tidy::readability::DefaultMinimumLoopCounterNameLength = 2

Definition at line 22 of file IdentifierLengthCheck.cpp.

◆ DefaultMinimumParameterNameLength

const unsigned clang::tidy::readability::DefaultMinimumParameterNameLength = 3

Definition at line 24 of file IdentifierLengthCheck.cpp.

◆ DefaultMinimumVariableNameLength

const unsigned clang::tidy::readability::DefaultMinimumVariableNameLength = 3

Definition at line 21 of file IdentifierLengthCheck.cpp.

◆ Defaults

constexpr DefaultHeuristicConfiguration clang::tidy::readability::Defaults[]
staticconstexpr
Initial value:
= {
{true, -1, -1},
{true, -1, -1},
{true, 25, 30},
{true, 25, 30},
{true, 40, 50},
{true, 50, 66},
{true, 75, 85},
{true, 60, 70},
}

Definition at line 51 of file SuspiciousCallArgumentCheck.cpp.

◆ DefaultStringNames

const char clang::tidy::readability::DefaultStringNames[]
Initial value:
=
"::std::basic_string_view;::std::basic_string"

Definition at line 21 of file RedundantStringInitCheck.cpp.

◆ DerefContainerExprName

constexpr llvm::StringLiteral clang::tidy::readability::DerefContainerExprName = "deref-container-expr"
constexpr

Definition at line 21 of file ContainerDataPointerCheck.cpp.

◆ ErrorMessage

const char clang::tidy::readability::ErrorMessage[]
Initial value:
=
"%select{variable|exception variable|loop variable|"
"parameter}0 name %1 is too short, expected at least %2 characters"

Definition at line 30 of file IdentifierLengthCheck.cpp.

◆ HeuristicToString

constexpr StringRef clang::tidy::readability::HeuristicToString[]
staticconstexpr
Initial value:
= {
"Equality", "Abbreviation", "Prefix", "Suffix",
"Substring", "Levenshtein", "JaroWinkler", "Dice"}

Definition at line 47 of file SuspiciousCallArgumentCheck.cpp.

◆ HungarainNotationPrimitiveTypes

const StringRef clang::tidy::readability::HungarainNotationPrimitiveTypes[]
static
Initial value:
= {
#define STRINGIZE(v)
}

Definition at line 184 of file IdentifierNamingCheck.cpp.

Referenced by clang::tidy::readability::IdentifierNamingCheck::HungarianNotation::loadFileConfig().

◆ HungarainNotationUserDefinedTypes

const StringRef clang::tidy::readability::HungarainNotationUserDefinedTypes[]
static
Initial value:
= {
#define STRINGIZE(v)
}

Definition at line 220 of file IdentifierNamingCheck.cpp.

Referenced by clang::tidy::readability::IdentifierNamingCheck::HungarianNotation::loadFileConfig().

◆ InterruptingStr

const char clang::tidy::readability::InterruptingStr[] = "interrupting"
static

Definition at line 46 of file ElseAfterReturnCheck.cpp.

◆ KDefaultTypes

const char clang::tidy::readability::KDefaultTypes[]
static
Initial value:
=
"::std::basic_string;::std::basic_string_view;::std::vector;::std::array"

Definition at line 20 of file SimplifySubscriptExprCheck.cpp.

◆ OperatorNames

std::pair<OverloadedOperatorKind, StringRef> clang::tidy::readability::OperatorNames[]
static
Initial value:
= {
{OO_EqualEqual, "=="}, {OO_ExclaimEqual, "!="}, {OO_Less, "<"},
{OO_GreaterEqual, ">="}, {OO_Greater, ">"}, {OO_LessEqual, "<="}}

Definition at line 70 of file SimplifyBooleanExprCheck.cpp.

Referenced by getOperatorName().

◆ OppositeOverloads

std::pair<OverloadedOperatorKind, OverloadedOperatorKind> clang::tidy::readability::OppositeOverloads[]
static
Initial value:
= {{OO_EqualEqual, OO_ExclaimEqual},
{OO_Less, OO_GreaterEqual},
{OO_Greater, OO_LessEqual}}

Definition at line 84 of file SimplifyBooleanExprCheck.cpp.

Referenced by negatedOperator().

◆ Opposites

std::pair<BinaryOperatorKind, BinaryOperatorKind> clang::tidy::readability::Opposites[]
static
Initial value:
= {
{BO_LT, BO_GE}, {BO_GT, BO_LE}, {BO_EQ, BO_NE}}

Definition at line 56 of file SimplifyBooleanExprCheck.cpp.

Referenced by negatedOperator().

◆ SimplifyConditionalReturnDiagnostic

constexpr char clang::tidy::readability::SimplifyConditionalReturnDiagnostic[]
staticconstexpr
Initial value:
=
"redundant boolean literal in conditional return statement"

Definition at line 41 of file SimplifyBooleanExprCheck.cpp.

◆ SimplifyConditionDiagnostic

constexpr char clang::tidy::readability::SimplifyConditionDiagnostic[]
staticconstexpr
Initial value:
=
"redundant boolean literal in if statement condition"

Definition at line 39 of file SimplifyBooleanExprCheck.cpp.

◆ SimplifyOperatorDiagnostic

constexpr char clang::tidy::readability::SimplifyOperatorDiagnostic[]
staticconstexpr
Initial value:
=
"redundant boolean literal supplied to boolean operator"

Definition at line 37 of file SimplifyBooleanExprCheck.cpp.

◆ SmallVectorSize

constexpr std::size_t clang::tidy::readability::SmallVectorSize
staticconstexpr

◆ StyleNames

const StringRef clang::tidy::readability::StyleNames[]
static
Initial value:
= {
#define STRINGIZE(v)
}

Definition at line 133 of file IdentifierNamingCheck.cpp.

Referenced by clang::tidy::readability::IdentifierNamingCheck::getFileStyleFromOptions().

◆ WarningMessage

const char clang::tidy::readability::WarningMessage[] = "do not use 'else' after '%0'"
static

Definition at line 47 of file ElseAfterReturnCheck.cpp.

◆ WarnOnConditionVariablesStr

const char clang::tidy::readability::WarnOnConditionVariablesStr[] = "WarnOnConditionVariables"
static

Definition at line 49 of file ElseAfterReturnCheck.cpp.

◆ WarnOnUnfixableStr

const char clang::tidy::readability::WarnOnUnfixableStr[] = "WarnOnUnfixable"
static

Definition at line 48 of file ElseAfterReturnCheck.cpp.

clang::tidy::readability::SmallVectorSize
static constexpr std::size_t SmallVectorSize
Definition: SuspiciousCallArgumentCheck.cpp:128