clang-tools 17.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 class  MixFlags : unsigned char {
  Invalid = 0 , WorkaroundDisableCanonicalEquivalence = 1 , None = 2 , Trivial = 4 ,
  Canonical = 8 , TypeAlias = 16 , ReferenceBind = 32 , Qualifiers = 64 ,
  ImplicitConversion = 128
}
 The language features involved in allowing the mix between two parameters. More...
 
enum class  ImplicitConversionModellingMode : unsigned char { None , All , 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.
 
static std::string formatMixFlags (MixFlags F)
 Formats the MixFlags enum into a useful, user-readable representation.
 
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.
 
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.
 
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.
 
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.
 
static bool isDerivedToBase (const CXXRecordDecl *Derived, const CXXRecordDecl *Base)
 
static std::optional< QualType > approximateStandardConversionSequence (const TheCheck &Check, QualType From, QualType To, const ASTContext &Ctx)
 
static std::optional< ConversionSequencetryConversionOperators (const TheCheck &Check, const CXXRecordDecl *RD, QualType ToType)
 
static std::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 556 of file EasilySwappableParametersCheck.cpp.

◆ MixFlags

enum class 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 110 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

◆ approximateStandardConversionSequence()

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

◆ 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 644 of file EasilySwappableParametersCheck.cpp.

References clang::tidy::bugprone::model::ConversionSequence::AfterFirstStandard, clang::tidy::bugprone::model::ConversionSequence::AfterSecondStandard, approximateImplicitConversion(), calculateMixability(), Canonical, clang::tidy::bugprone::model::MixData::Conversion, clang::tidy::bugprone::model::MixData::Flags, getNonCVRQualifiers(), hasFlag(), ImplicitConversion, clang::tidy::bugprone::model::MixData::indicatesMixability(), isLRefEquallyBindingToType(), isUselessSugar(), None, OneWaySingleStandardOnly, Qualifiers, ReferenceBind, clang::tidy::bugprone::model::MixData::sanitize(), Trivial, TypeAlias, clang::tidy::bugprone::model::ConversionSequence::UDCK_None, clang::tidy::bugprone::model::ConversionSequence::UDConvKind, clang::tidy::bugprone::model::MixData::withCommonTypeTransformed(), and WorkaroundDisableCanonicalEquivalence.

Referenced by approximateStandardConversionSequence(), calculateMixability(), isLRefEquallyBindingToType(), and modelMixingRange().

◆ 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 151 of file EasilySwappableParametersCheck.cpp.

References Canonical, hasFlag(), ImplicitConversion, Invalid, None, Qualifiers, ReferenceBind, Trivial, TypeAlias, and WorkaroundDisableCanonicalEquivalence.

Referenced by modelMixingRange().

◆ 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 603 of file EasilySwappableParametersCheck.cpp.

References Qualifiers.

Referenced by calculateMixability().

◆ 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 135 of file EasilySwappableParametersCheck.cpp.

References Invalid.

Referenced by approximateStandardConversionSequence(), calculateMixability(), formatMixFlags(), and clang::tidy::bugprone::model::MixData::sanitize().

◆ isDerivedToBase()

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

◆ 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 892 of file EasilySwappableParametersCheck.cpp.

References calculateMixability(), None, and Trivial.

Referenced by calculateMixability().

◆ isUselessSugar()

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

Definition at line 579 of file EasilySwappableParametersCheck.cpp.

Referenced by calculateMixability().

◆ 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

◆ tryConversionOperators()

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

◆ tryConvertingConstructors()

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