clang-tools 10.0.0

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 | 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 | DeletedDefaultCheck
| Checks when a constructor or an assignment operator is marked as '= default' but is actually deleted by the compiler. More...
class | DeleteNullPointerCheck
| Check whether the 'if' statement is unnecessary before calling 'delete' on a pointer. More...
class | ElseAfterReturnCheck
| Flags the usages of `else` after `return`. More...
class | FindUsageOfThis
class | FunctionSizeCheck
| Checks for large functions based on various metrics. 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 | 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...

## Enumerations
enum | StyleKind { SK_Count, SK_Invalid }
enum | UsageKind { Unused, Const, NonConst }

## Functions
static llvm::Optional< Token > | ConstTok (CharSourceRange Range, const MatchFinder::MatchResult &Result)
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 bool | matchesStyle (StringRef Name, IdentifierNamingCheck::NamingStyle Style)
static std::string | fixupWithCase (StringRef Name, IdentifierNamingCheck::CaseType Case)
static std::string | fixupWithStyle (StringRef Name, const IdentifierNamingCheck::NamingStyle &Style)
static StyleKind | findStyleKind (const NamedDecl *D, const std::vector< llvm::Optional< IdentifierNamingCheck::NamingStyle >> &NamingStyles)
static void | addUsage (IdentifierNamingCheck::NamingCheckFailureMap &Failures, const IdentifierNamingCheck::NamingCheckId &Decl, SourceRange Range, SourceManager *SourceMgr=nullptr)
static void | addUsage (IdentifierNamingCheck::NamingCheckFailureMap &Failures, const NamedDecl *Decl, SourceRange Range, SourceManager *SourceMgr=nullptr)
| Convenience method when the usage to be added is a NamedDecl. More...
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< ReadabilityModule > | X ("readability-module", "Adds readability-related checks.")
| AST_MATCHER (FunctionDecl, doesDeclarationForceExternallyVisibleDefinition)
bool | containsBoolLiteral (const Expr *E)
static unsigned | getNameSpecifierNestingLevel (const QualType &QType)

## Variables
static StringRef const | StyleNames []
const char | DefaultIgnoredIntegerValues [] = "1;2;3;4;"
const char | DefaultIgnoredFloatingPointValues [] = "1.0;100.0;"
const char | DefaultStringNames [] = "::std::basic_string"
static const char | kDefaultTypes []
static const StringRef | CompareMessage

## Enumeration Type Documentation

## ◆ StyleKind

enum clang::tidy::readability::StyleKind

Enumerator
SK_Count |
SK_Invalid |

Definition at line 121 of file IdentifierNamingCheck.cpp.

## ◆ UsageKind

enum clang::tidy::readability::UsageKind

Enumerator
Unused |
Const |
NonConst |

Definition at line 50 of file MakeMemberFunctionConstCheck.cpp.

## Function Documentation

## ◆ addUsage() [1/2]

static void clang::tidy::readability::addUsage | ( | IdentifierNamingCheck::NamingCheckFailureMap & | Failures,
|  | const IdentifierNamingCheck::NamingCheckId & | Decl,
|  | SourceRange | Range,
|  | SourceManager * | SourceMgr = `nullptr`
| ) |  |
| static

Definition at line 686 of file IdentifierNamingCheck.cpp.

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

## ◆ addUsage() [2/2]

static void clang::tidy::readability::addUsage | ( | IdentifierNamingCheck::NamingCheckFailureMap & | Failures,
|  | const NamedDecl * | Decl,
|  | SourceRange | Range,
|  | SourceManager * | SourceMgr = `nullptr`
| ) |  |
| static

Convenience method when the usage to be added is a NamedDecl.

Definition at line 717 of file IdentifierNamingCheck.cpp.

## ◆ AST_MATCHER() [1/10]

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

Definition at line 20 of file RedundantDeclarationCheck.cpp.

## ◆ AST_MATCHER() [2/10]

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

Definition at line 23 of file ConvertMemberFunctionsToStatic.cpp.

## ◆ AST_MATCHER() [3/10]

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

Definition at line 25 of file ConvertMemberFunctionsToStatic.cpp.

## ◆ AST_MATCHER() [4/10]

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

Definition at line 27 of file ConvertMemberFunctionsToStatic.cpp.

## ◆ AST_MATCHER() [5/10]

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

Definition at line 31 of file ConvertMemberFunctionsToStatic.cpp.

## ◆ AST_MATCHER() [6/10]

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

Definition at line 35 of file ConvertMemberFunctionsToStatic.cpp.

## ◆ AST_MATCHER() [7/10]

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

Definition at line 39 of file ConvertMemberFunctionsToStatic.cpp.

## ◆ AST_MATCHER() [8/10]

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

Definition at line 43 of file ConvertMemberFunctionsToStatic.cpp.

## ◆ AST_MATCHER() [9/10]

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

Definition at line 57 of file ConvertMemberFunctionsToStatic.cpp.

References E.

## ◆ AST_MATCHER() [10/10]

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

Definition at line 201 of file MakeMemberFunctionConstCheck.cpp.

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

## ◆ checkDef()

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

Definition at line 70 of file ConstReturnTypeCheck.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.

## ◆ ConstTok()

static llvm::Optional<Token> clang::tidy::readability::ConstTok | ( | CharSourceRange | Range,
|  | const MatchFinder::MatchResult & | Result
| ) |  |
| static

Definition at line 50 of file AvoidConstParamsInDecls.cpp.

## ◆ containsBoolLiteral()

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

Definition at line 344 of file SimplifyBooleanExprCheck.cpp.

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

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

## ◆ findStyleKind()

static StyleKind clang::tidy::readability::findStyleKind | ( | const NamedDecl * | D,
|  | const std::vector< llvm::Optional< IdentifierNamingCheck::NamingStyle >> & | NamingStyles
| ) |  |
| static

Definition at line 409 of file IdentifierNamingCheck.cpp.

References Decl, SK_Invalid, and Type.

## ◆ fixupWithCase()

static std::string clang::tidy::readability::fixupWithCase | ( | StringRef | Name,
|  | IdentifierNamingCheck::CaseType | Case
| ) |  |
| static

Definition at line 302 of file IdentifierNamingCheck.cpp.

References clang::tidy::readability::IdentifierNamingCheck::CT_AnyCase, clang::tidy::readability::IdentifierNamingCheck::CT_CamelBack, clang::tidy::readability::IdentifierNamingCheck::CT_CamelCase, clang::tidy::readability::IdentifierNamingCheck::CT_CamelSnakeBack, clang::tidy::readability::IdentifierNamingCheck::CT_CamelSnakeCase, clang::tidy::readability::IdentifierNamingCheck::CT_LowerCase, clang::tidy::readability::IdentifierNamingCheck::CT_UpperCase, Name, and Word.

## ◆ fixupWithStyle()

static std::string clang::tidy::readability::fixupWithStyle | ( | StringRef | Name,
|  | const IdentifierNamingCheck::NamingStyle & | Style
| ) |  |
| static

Definition at line 399 of file IdentifierNamingCheck.cpp.

## ◆ getConstInsertionPoint()

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

Definition at line 233 of file MakeMemberFunctionConstCheck.cpp.

## ◆ getLocationOfConst()

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

Definition at line 106 of file ConvertMemberFunctionsToStatic.cpp.

## ◆ getNamespaceNameAsWritten()

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

Definition at line 52 of file NamespaceCommentCheck.cpp.

## ◆ getNameSpecifierNestingLevel()

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

Definition at line 19 of file StaticAccessedThroughInstanceCheck.cpp.

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

## ◆ isMacroID()

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

Definition at line 52 of file IsolateDeclarationCheck.cpp.

## ◆ locationsInSameFile()

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

Definition at line 45 of file NamespaceCommentCheck.cpp.

## ◆ matchesStyle()

static bool clang::tidy::readability::matchesStyle | ( | StringRef | Name,
|  | IdentifierNamingCheck::NamingStyle | Style
| ) |  |
| static

Definition at line 269 of file IdentifierNamingCheck.cpp.

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

Referenced by clang::tidy::readability::ReadabilityModule::addCheckFactories().

## Variable Documentation

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

## ◆ DefaultIgnoredFloatingPointValues

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

Definition at line 62 of file MagicNumbersCheck.cpp.

## ◆ DefaultIgnoredIntegerValues

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

Definition at line 61 of file MagicNumbersCheck.cpp.

## ◆ DefaultStringNames

const char clang::tidy::readability::DefaultStringNames[] = "::std::basic_string"

Definition at line 21 of file RedundantStringInitCheck.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.

## ◆ StyleNames

StringRef const clang::tidy::readability::StyleNames[]
| static

Initial value:
= {
#define STRINGIZE(v)
}

Definition at line 129 of file IdentifierNamingCheck.cpp.