clang-tools 6.0.0

Classes | Functions
clang::tidy::bugprone Namespace Reference

## Classes
class | ArgumentCommentCheck
class | AssertSideEffectCheck
| Finds `assert()` with side effect. More...
class | BoolPointerImplicitConversionCheck
| Checks for conditions based on implicit conversion from a bool pointer to bool. More...
class | BugproneModule
class | CopyConstructorInitCheck
| Finds copy constructors where the ctor don't call the copy constructor of the base class. More...
class | DanglingHandleCheck
| Detect dangling references in value handlers like std::experimental::string_view. More...
class | FoldInitTypeCheck
| Find and flag invalid initializer values in folds, e.g. More...
class | ForwardDeclarationNamespaceCheck
| Checks if an unused forward declaration is in a wrong namespace. More...
class | InaccurateEraseCheck
| Checks for inaccurate use of the `erase()` method. More...
class | IntegerDivisionCheck
| Finds cases where integer division in a floating point context is likely to cause unintended loss of precision. More...
class | MisplacedOperatorInStrlenInAllocCheck
| Finds cases where `1` is added to the string in the argument to a function in the `strlen()` family instead of the result and value is used as an argument to a memory allocation function. More...
class | MoveForwardingReferenceCheck
| The check warns if std::move is applied to a forwarding reference (i.e. More...
class | MultipleStatementMacroCheck
| Detect multiple statement macros that are used in unbraced conditionals. More...
class | StringConstructorCheck
| Finds suspicious string constructor and check their parameters. More...
class | SuspiciousMemsetUsageCheck
| Finds memset calls with potential mistakes in their arguments. More...
class | UndefinedMemoryManipulationCheck
| Finds calls of memory manipulation functions `memset()`, `memcpy()` and `memmove()` on not TriviallyCopyable objects resulting in undefined behavior. More...
class | UseAfterMoveCheck
| The check warns if an object is used after it has been moved, without an intervening reinitialization. More...
class | VirtualNearMissCheck
| Checks for near miss of virtual methods. More...

## Functions
static std::vector< std::pair< SourceLocation, StringRef > > | getCommentsInRange (ASTContext *Ctx, CharSourceRange Range)
static std::vector< std::pair< SourceLocation, StringRef > > | getCommentsBeforeLoc (ASTContext *Ctx, SourceLocation Loc)
static bool | isLikelyTypo (llvm::ArrayRef< ParmVarDecl *> Params, StringRef ArgName, unsigned ArgIndex)
static bool | sameName (StringRef InComment, StringRef InDecl, bool StrictMode)
static bool | looksLikeExpectMethod (const CXXMethodDecl *Expect)
static bool | areMockAndExpectMethods (const CXXMethodDecl *Mock, const CXXMethodDecl *Expect)
static const CXXMethodDecl * | findMockedMethod (const CXXMethodDecl *Method)
static const FunctionDecl * | resolveMocks (const FunctionDecl *Func)
*that are placed right before the argument **code *void | f (bool foo)
| Checks that argument comments match parameter names. More...
*** | f (true)
static bool | isValidBuiltinFold (const BuiltinType &ValueType, const BuiltinType &InitType, const ASTContext &Context)
| Returns true if ValueType is allowed to fold into InitType, i.e. More...
static bool | haveSameNamespaceOrTranslationUnit (const CXXRecordDecl *Decl1, const CXXRecordDecl *Decl2)
static std::string | getNameOfNamespace (const CXXRecordDecl *Decl)
static void | replaceMoveWithForward (const UnresolvedLookupExpr *Callee, const ParmVarDecl *ParmVar, const TemplateTypeParmDecl *TypeParmDecl, DiagnosticBuilder &Diag, const ASTContext &Context)
| AST_MATCHER_P (IntegerLiteral, isBiggerThan, unsigned, N)
static StatementMatcher | inDecltypeOrTemplateArg ()
bool | isStandardSmartPointer (const ValueDecl *VD)
static void | emitDiagnostic (const Expr *MovingCall, const DeclRefExpr *MoveArg, const UseAfterMove &Use, ClangTidyCheck *Check, ASTContext *Context)
| AST_MATCHER (CXXMethodDecl, isStatic)
| AST_MATCHER (CXXMethodDecl, isOverloadedOperator)
static bool | isOverrideMethod (const CXXMethodDecl *MD)
| Finds out if the given method overrides some method. More...
static bool | checkOverridingFunctionReturnType (const ASTContext *Context, const CXXMethodDecl *BaseMD, const CXXMethodDecl *DerivedMD)
| Checks whether the return types are covariant, according to C++[class.virtual]p7. More...
static QualType | getDecayedType (QualType Type)
static bool | checkParamTypes (const CXXMethodDecl *BaseMD, const CXXMethodDecl *DerivedMD)
static bool | checkOverrideWithoutName (const ASTContext *Context, const CXXMethodDecl *BaseMD, const CXXMethodDecl *DerivedMD)
static bool | checkOverrideByDerivedMethod (const CXXMethodDecl *BaseMD, const CXXMethodDecl *DerivedMD)
| Check whether BaseMD overrides DerivedMD. More...

## Function Documentation

## ◆ areMockAndExpectMethods()

static bool clang::tidy::bugprone::areMockAndExpectMethods | ( | const CXXMethodDecl * | Mock,
|  | const CXXMethodDecl * | Expect
| ) |  |
| static

Definition at line 155 of file ArgumentCommentCheck.cpp.

References looksLikeExpectMethod().

Referenced by findMockedMethod().

## ◆ AST_MATCHER() [1/2]

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

Definition at line 22 of file VirtualNearMissCheck.cpp.

## ◆ AST_MATCHER() [2/2]

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

Definition at line 24 of file VirtualNearMissCheck.cpp.

## ◆ AST_MATCHER_P()

clang::tidy::bugprone::AST_MATCHER_P | ( | IntegerLiteral | ,
|  | isBiggerThan | ,
|  | unsigned | ,
|  | N |
| ) |  |

Definition at line 21 of file StringConstructorCheck.cpp.

## ◆ checkOverrideByDerivedMethod()

static bool clang::tidy::bugprone::checkOverrideByDerivedMethod | ( | const CXXMethodDecl * | BaseMD,
|  | const CXXMethodDecl * | DerivedMD
| ) |  |
| static

Check whether BaseMD overrides DerivedMD.

Prerequisite: the class which BaseMD is in should be a base class of that DerivedMD is in.

Definition at line 168 of file VirtualNearMissCheck.cpp.

References isOverrideMethod().

## ◆ checkOverrideWithoutName()

static bool clang::tidy::bugprone::checkOverrideWithoutName | ( | const ASTContext * | Context,
|  | const CXXMethodDecl * | BaseMD,
|  | const CXXMethodDecl * | DerivedMD
| ) |  |
| static

Returns
  true if derived method can override base method except for the name.

Definition at line 148 of file VirtualNearMissCheck.cpp.

## ◆ checkOverridingFunctionReturnType()

static bool clang::tidy::bugprone::checkOverridingFunctionReturnType | ( | const ASTContext * | Context,
|  | const CXXMethodDecl * | BaseMD,
|  | const CXXMethodDecl * | DerivedMD
| ) |  |
| static

Checks whether the return types are covariant, according to C++[class.virtual]p7.

Similar with clang::Sema::CheckOverridingFunctionReturnType.

Returns
  true if the return types of BaseMD and DerivedMD are covariant.

Check if the return types are covariant.

BTy is the class type in return type of BaseMD. For example, B* Base::md() While BRD is the declaration of B.

Definition at line 38 of file VirtualNearMissCheck.cpp.

## ◆ checkParamTypes()

static bool clang::tidy::bugprone::checkParamTypes | ( | const CXXMethodDecl * | BaseMD,
|  | const CXXMethodDecl * | DerivedMD
| ) |  |
| static

Returns
  true if the param types are the same.

Definition at line 130 of file VirtualNearMissCheck.cpp.

References getDecayedType().

## ◆ emitDiagnostic()

static void clang::tidy::bugprone::emitDiagnostic | ( | const Expr * | MovingCall,
|  | const DeclRefExpr * | MoveArg,
|  | const UseAfterMove & | Use,
|  | ClangTidyCheck * | Check,
|  | ASTContext * | Context
| ) |  |
| static

Definition at line 351 of file UseAfterMoveCheck.cpp.

Referenced by clang::tidy::bugprone::UseAfterMoveCheck::check().

## ◆ f() [1/2]

* that are placed right before the argument* * code* void clang::tidy::bugprone::f | ( | bool | foo | ) |

Checks that argument comments match parameter names.

The check understands argument comments in the form `/*parameter_name=

## ◆ f() [2/2]

* * * clang::tidy::bugprone::f | ( | true |  | ) |

## ◆ findMockedMethod()

static const CXXMethodDecl* clang::tidy::bugprone::findMockedMethod | ( | const CXXMethodDecl * | Method | ) |
| static

Definition at line 170 of file ArgumentCommentCheck.cpp.

References areMockAndExpectMethods(), and looksLikeExpectMethod().

Referenced by resolveMocks().

## ◆ getCommentsBeforeLoc()

static std::vector<std::pair<SourceLocation, StringRef> > clang::tidy::bugprone::getCommentsBeforeLoc | ( | ASTContext * | Ctx,
|  | SourceLocation | Loc
| ) |  |
| static

Definition at line 91 of file ArgumentCommentCheck.cpp.

References clang::tidy::utils::lexer::getPreviousToken().

Referenced by resolveMocks().

## ◆ getCommentsInRange()

static std::vector<std::pair<SourceLocation, StringRef> > clang::tidy::bugprone::getCommentsInRange | ( | ASTContext * | Ctx,
|  | CharSourceRange | Range
| ) |  |
| static

Definition at line 47 of file ArgumentCommentCheck.cpp.

Referenced by resolveMocks().

## ◆ getDecayedType()

static QualType clang::tidy::bugprone::getDecayedType | ( | QualType | Type | ) |
| static

Returns
  decayed type for arrays and functions.

Definition at line 123 of file VirtualNearMissCheck.cpp.

Referenced by checkParamTypes().

## ◆ getNameOfNamespace()

static std::string clang::tidy::bugprone::getNameOfNamespace | ( | const CXXRecordDecl * | Decl | ) |
| static

Definition at line 104 of file ForwardDeclarationNamespaceCheck.cpp.

Referenced by clang::tidy::bugprone::ForwardDeclarationNamespaceCheck::onEndOfTranslationUnit().

## ◆ haveSameNamespaceOrTranslationUnit()

static bool clang::tidy::bugprone::haveSameNamespaceOrTranslationUnit | ( | const CXXRecordDecl * | Decl1,
|  | const CXXRecordDecl * | Decl2
| ) |  |
| static

Definition at line 83 of file ForwardDeclarationNamespaceCheck.cpp.

Referenced by clang::tidy::bugprone::ForwardDeclarationNamespaceCheck::onEndOfTranslationUnit().

## ◆ inDecltypeOrTemplateArg()

static StatementMatcher clang::tidy::bugprone::inDecltypeOrTemplateArg | ( |  | ) |
| static

Definition at line 78 of file UseAfterMoveCheck.cpp.

## ◆ isLikelyTypo()

static bool clang::tidy::bugprone::isLikelyTypo | ( | llvm::ArrayRef< ParmVarDecl *> | Params,
|  | StringRef | ArgName,
|  | unsigned | ArgIndex
| ) |  |
| static

Definition at line 108 of file ArgumentCommentCheck.cpp.

Referenced by resolveMocks().

## ◆ isOverrideMethod()

static bool clang::tidy::bugprone::isOverrideMethod | ( | const CXXMethodDecl * | MD | ) |
| static

Finds out if the given method overrides some method.

Definition at line 29 of file VirtualNearMissCheck.cpp.

Referenced by checkOverrideByDerivedMethod().

## ◆ isStandardSmartPointer()

bool clang::tidy::bugprone::isStandardSmartPointer | ( | const ValueDecl * | VD | ) |

Definition at line 208 of file UseAfterMoveCheck.cpp.

References DeclRef, and Name.

## ◆ isValidBuiltinFold()

static bool clang::tidy::bugprone::isValidBuiltinFold | ( | const BuiltinType & | ValueType,
|  | const BuiltinType & | InitType,
|  | const ASTContext & | Context
| ) |  |
| static

Returns true if ValueType is allowed to fold into InitType, i.e.

if: static_cast<InitType>(ValueType{some_value}) does not result in trucation.

Definition at line 80 of file FoldInitTypeCheck.cpp.

## ◆ looksLikeExpectMethod()

static bool clang::tidy::bugprone::looksLikeExpectMethod | ( | const CXXMethodDecl * | Expect | ) |
| static

Definition at line 150 of file ArgumentCommentCheck.cpp.

Referenced by areMockAndExpectMethods(), and findMockedMethod().

## ◆ replaceMoveWithForward()

static void clang::tidy::bugprone::replaceMoveWithForward | ( | const UnresolvedLookupExpr * | Callee,
|  | const ParmVarDecl * | ParmVar,
|  | const TemplateTypeParmDecl * | TypeParmDecl,
|  | DiagnosticBuilder & | Diag,
|  | const ASTContext & | Context
| ) |  |
| static

Definition at line 22 of file MoveForwardingReferenceCheck.cpp.

Referenced by clang::tidy::bugprone::MoveForwardingReferenceCheck::check().

## ◆ resolveMocks()

static const FunctionDecl* clang::tidy::bugprone::resolveMocks | ( | const FunctionDecl * | Func | ) |
| static

Definition at line 195 of file ArgumentCommentCheck.cpp.

References clang::tidy::ClangTidyCheck::diag(), findMockedMethod(), getCommentsBeforeLoc(), getCommentsInRange(), isLikelyTypo(), and sameName().

## ◆ sameName()

static bool clang::tidy::bugprone::sameName | ( | StringRef | InComment,
|  | StringRef | InDecl,
|  | bool | StrictMode
| ) |  |
| static

Definition at line 141 of file ArgumentCommentCheck.cpp.

Referenced by resolveMocks().