clang-tools  14.0.0git
Classes | Enumerations | Functions
clang::tidy::bugprone::model Namespace Reference

Classes

struct  ConversionSequence
 The results of the steps of an Implicit Conversion Sequence is saved in an instance of this record. More...
 
struct  Mix
 A named tuple that contains the information for a mix between two concrete parameters. More...
 
struct  MixableParameterRange
 
struct  MixData
 Contains the metadata for the mixability result between two types, independently of which parameters they were calculated from. More...
 

Enumerations

enum  MixFlags : unsigned char {
  MixFlags::Invalid = 0, MixFlags::WorkaroundDisableCanonicalEquivalence = 1, MixFlags::None = 2, MixFlags::Trivial = 4,
  MixFlags::Canonical = 8, MixFlags::TypeAlias = 16, MixFlags::ReferenceBind = 32, MixFlags::Qualifiers = 64,
  MixFlags::ImplicitConversion = 128
}
 The language features involved in allowing the mix between two parameters. More...
 
enum  ImplicitConversionModellingMode : unsigned char { ImplicitConversionModellingMode::None, ImplicitConversionModellingMode::All, ImplicitConversionModellingMode::OneWaySingleStandardOnly }
 Helper enum for the recursive calls in the modelling that toggle what kinds of implicit conversions are to be modelled. More...
 

Functions

 LLVM_ENABLE_BITMASK_ENUMS_IN_NAMESPACE ()
 
static bool hasFlag (MixFlags Data, MixFlags SearchedFlag)
 Returns whether the SearchedFlag is turned on in the Data. More...
 
static std::string formatMixFlags (MixFlags F)
 Formats the MixFlags enum into a useful, user-readable representation. More...
 
static MixData isLRefEquallyBindingToType (const TheCheck &Check, const LValueReferenceType *LRef, QualType Ty, const ASTContext &Ctx, bool IsRefRHS, ImplicitConversionModellingMode ImplicitMode)
 Calculates if the reference binds an expression of the given type. More...
 
static MixData approximateImplicitConversion (const TheCheck &Check, QualType LType, QualType RType, const ASTContext &Ctx, ImplicitConversionModellingMode ImplicitMode)
 Returns whether an expression of LType can be used in an RType context, as per the implicit conversion rules. More...
 
static bool isUselessSugar (const Type *T)
 
static NonCVRQualifiersResult getNonCVRQualifiers (const ASTContext &Ctx, QualType LType, QualType RType)
 Returns if the two types are qualified in a way that ever after equating or removing local CVR qualification, even if the unqualified types would mix, the qualified ones don't, because there are some other local qualifiers that aren't equal. More...
 
static MixData calculateMixability (const TheCheck &Check, QualType LType, QualType RType, const ASTContext &Ctx, ImplicitConversionModellingMode ImplicitMode)
 Approximate the way how LType and RType might refer to "essentially the same" type, in a sense that at a particular call site, an expression of type LType and RType might be successfully passed to a variable (in our specific case, a parameter) of type RType and LType, respectively. More...
 
static bool isDerivedToBase (const CXXRecordDecl *Derived, const CXXRecordDecl *Base)
 
static Optional< QualType > approximateStandardConversionSequence (const TheCheck &Check, QualType From, QualType To, const ASTContext &Ctx)
 
static Optional< ConversionSequencetryConversionOperators (const TheCheck &Check, const CXXRecordDecl *RD, QualType ToType)
 
static Optional< ConversionSequencetryConvertingConstructors (const TheCheck &Check, QualType FromType, const CXXRecordDecl *RD)
 
static MixableParameterRange modelMixingRange (const TheCheck &Check, const FunctionDecl *FD, std::size_t StartIndex, const filter::SimilarlyUsedParameterPairSuppressor &UsageBasedSuppressor)
 

Enumeration Type Documentation

◆ ImplicitConversionModellingMode

Helper enum for the recursive calls in the modelling that toggle what kinds of implicit conversions are to be modelled.

Enumerator
None 

No implicit conversions are modelled.

The full implicit conversion sequence is modelled.

All 

Only model a unidirectional implicit conversion and within it only one standard conversion sequence.

OneWaySingleStandardOnly 

Definition at line 546 of file EasilySwappableParametersCheck.cpp.

◆ MixFlags

enum clang::tidy::bugprone::model::MixFlags : unsigned char
strong

The language features involved in allowing the mix between two parameters.

Enumerator
Invalid 

Sentinel bit pattern. DO NOT USE!

WorkaroundDisableCanonicalEquivalence 

Certain constructs (such as pointers to noexcept/non-noexcept functions) have the same CanonicalType, which would result in false positives.

During the recursive modelling call, this flag is set if a later diagnosed canonical type equivalence should be thrown away.

None 

Mix between the two parameters is not possible.

Trivial 

The two mix trivially, and are the exact same type.

Canonical 

The two mix because the types refer to the same CanonicalType, but we do not elaborate as to how.

TypeAlias 

The path from one type to the other involves desugaring type aliases.

ReferenceBind 

The mix involves the binding power of "const &".

Qualifiers 

The mix involves change in the qualifiers.

ImplicitConversion 

The mixing of the parameters is possible through implicit conversions between the types.

Definition at line 100 of file EasilySwappableParametersCheck.cpp.

Function Documentation

◆ approximateImplicitConversion()

static MixData clang::tidy::bugprone::model::approximateImplicitConversion ( const TheCheck Check,
QualType  LType,
QualType  RType,
const ASTContext &  Ctx,
ImplicitConversionModellingMode  ImplicitMode 
)
static

Returns whether an expression of LType can be used in an RType context, as per the implicit conversion rules.

Note: the result of this operation, unlike that of calculateMixability, is NOT symmetric.

Definition at line 1288 of file EasilySwappableParametersCheck.cpp.

◆ approximateStandardConversionSequence()

static Optional<QualType> clang::tidy::bugprone::model::approximateStandardConversionSequence ( const TheCheck Check,
QualType  From,
QualType  To,
const ASTContext &  Ctx 
)
static

Definition at line 945 of file EasilySwappableParametersCheck.cpp.

◆ calculateMixability()

static MixData clang::tidy::bugprone::model::calculateMixability ( const TheCheck Check,
QualType  LType,
QualType  RType,
const ASTContext &  Ctx,
ImplicitConversionModellingMode  ImplicitMode 
)
static

Approximate the way how LType and RType might refer to "essentially the same" type, in a sense that at a particular call site, an expression of type LType and RType might be successfully passed to a variable (in our specific case, a parameter) of type RType and LType, respectively.

Note the swapped order!

The returned data structure is not guaranteed to be properly set, as this function is potentially recursive. It is the caller's responsibility to call sanitize() on the result once the recursion is over.

Definition at line 634 of file EasilySwappableParametersCheck.cpp.

◆ formatMixFlags()

static std::string clang::tidy::bugprone::model::formatMixFlags ( MixFlags  F)
inlinestatic

Formats the MixFlags enum into a useful, user-readable representation.

Definition at line 141 of file EasilySwappableParametersCheck.cpp.

◆ getNonCVRQualifiers()

static NonCVRQualifiersResult clang::tidy::bugprone::model::getNonCVRQualifiers ( const ASTContext &  Ctx,
QualType  LType,
QualType  RType 
)
static

Returns if the two types are qualified in a way that ever after equating or removing local CVR qualification, even if the unqualified types would mix, the qualified ones don't, because there are some other local qualifiers that aren't equal.

Definition at line 593 of file EasilySwappableParametersCheck.cpp.

References Ctx, and Qualifiers.

◆ hasFlag()

static bool clang::tidy::bugprone::model::hasFlag ( MixFlags  Data,
MixFlags  SearchedFlag 
)
inlinestatic

Returns whether the SearchedFlag is turned on in the Data.

Definition at line 125 of file EasilySwappableParametersCheck.cpp.

Referenced by clang::tidy::bugprone::needsToElaborateImplicitConversion(), and clang::tidy::bugprone::model::MixData::sanitize().

◆ isDerivedToBase()

static bool clang::tidy::bugprone::model::isDerivedToBase ( const CXXRecordDecl *  Derived,
const CXXRecordDecl *  Base 
)
inlinestatic

Definition at line 938 of file EasilySwappableParametersCheck.cpp.

References Base.

◆ isLRefEquallyBindingToType()

static MixData clang::tidy::bugprone::model::isLRefEquallyBindingToType ( const TheCheck Check,
const LValueReferenceType *  LRef,
QualType  Ty,
const ASTContext &  Ctx,
bool  IsRefRHS,
ImplicitConversionModellingMode  ImplicitMode 
)
static

Calculates if the reference binds an expression of the given type.

This is true iff 'LRef' is some 'const T &' type, and the 'Ty' is 'T' or 'const T'.

Parameters
ImplicitModeis forwarded in the possible recursive call to calculateMixability.

Definition at line 882 of file EasilySwappableParametersCheck.cpp.

◆ isUselessSugar()

static bool clang::tidy::bugprone::model::isUselessSugar ( const Type *  T)
inlinestatic

Definition at line 569 of file EasilySwappableParametersCheck.cpp.

◆ LLVM_ENABLE_BITMASK_ENUMS_IN_NAMESPACE()

clang::tidy::bugprone::model::LLVM_ENABLE_BITMASK_ENUMS_IN_NAMESPACE ( )

◆ modelMixingRange()

static MixableParameterRange clang::tidy::bugprone::model::modelMixingRange ( const TheCheck Check,
const FunctionDecl *  FD,
std::size_t  StartIndex,
const filter::SimilarlyUsedParameterPairSuppressor UsageBasedSuppressor 
)
static

Definition at line 1401 of file EasilySwappableParametersCheck.cpp.

◆ tryConversionOperators()

static Optional<ConversionSequence> clang::tidy::bugprone::model::tryConversionOperators ( const TheCheck Check,
const CXXRecordDecl *  RD,
QualType  ToType 
)
static

Definition at line 1184 of file EasilySwappableParametersCheck.cpp.

◆ tryConvertingConstructors()

static Optional<ConversionSequence> clang::tidy::bugprone::model::tryConvertingConstructors ( const TheCheck Check,
QualType  FromType,
const CXXRecordDecl *  RD 
)
static

Definition at line 1235 of file EasilySwappableParametersCheck.cpp.