clang-tools 20.0.0git
Classes | Public Types | Public Member Functions | Public Attributes | List of all members
clang::tidy::bugprone::model::ConversionSequence Struct Reference

The results of the steps of an Implicit Conversion Sequence is saved in an instance of this record. More...

Classes

struct  UserDefinedConversionOperator
 
struct  UserDefinedConvertingConstructor
 

Public Types

enum  UserDefinedConversionKind { UDCK_None , UDCK_Ctor , UDCK_Oper }
 

Public Member Functions

 ConversionSequence ()
 
 ConversionSequence (QualType From, QualType To)
 
 operator bool () const
 
SmallVector< QualType, 4 > getInvolvedTypesInSequence () const
 Returns all the "steps" (non-unique and non-similar) types involved in the conversion sequence.
 
ConversionSequenceupdate (const ConversionSequence &RHS)
 Updates the steps of the conversion sequence with the steps from the other instance.
 
void setConversion (const UserDefinedConvertingConstructor &UDCC)
 Sets the user-defined conversion to the given constructor.
 
void setConversion (const UserDefinedConversionOperator &UDCO)
 Sets the user-defined conversion to the given operator.
 
QualType getTypeAfterUserDefinedConversion () const
 Returns the type in the conversion that's formally "in our hands" once the user-defined conversion is executed.
 
const CXXMethodDecl * getUserDefinedConversionFunction () const
 
SourceRange getUserDefinedConversionHighlight () const
 Returns the SourceRange in the text that corresponds to the interesting part of the user-defined conversion.
 

Public Attributes

QualType Begin
 The type the conversion stared from.
 
QualType AfterFirstStandard
 The intermediate type after the first Standard Conversion Sequence.
 
union {
   char   None
 
   UserDefinedConvertingConstructor   UDConvCtor
 
   UserDefinedConversionOperator   UDConvOp
 
}; 
 The details of the user-defined conversion involved, as a tagged union.
 
UserDefinedConversionKind UDConvKind
 
QualType AfterSecondStandard
 The intermediate type after performing the second Standard Conversion Sequence.
 
QualType End
 The result type the conversion targeted.
 

Detailed Description

The results of the steps of an Implicit Conversion Sequence is saved in an instance of this record.

A ConversionSequence maps the steps of the conversion with a member for each type involved in the conversion. Imagine going from a hypothetical Complex class to projecting it to the real part as a const double.

I.e., given:

struct Complex { operator double() const; };

void functionBeingAnalysed(Complex C, const double R);

we will get the following sequence:

(Begin=) Complex

The first standard conversion is a qualification adjustment.

(AfterFirstStandard=) const Complex

Then the user-defined conversion is executed.

(UDConvOp.ConversionOperatorResultType=) double

Then this 'double' is qualifier-adjusted to 'const double'.

(AfterSecondStandard=) double

The conversion's result has now been calculated, so it ends here. (End=) double.

Explicit storing of Begin and End in this record is needed, because getting to what Begin and End here are needs further resolution of types, e.g. in the case of typedefs:

using Comp = Complex;
using CD = const double;
void functionBeingAnalysed2(Comp C, CD R);

In this case, the user will be diagnosed with a potential conversion between the two typedefs as written in the code, but to elaborate the reasoning behind this conversion, we also need to show what the typedefs mean. See FormattedConversionSequence towards the bottom of this file!

Definition at line 225 of file EasilySwappableParametersCheck.cpp.

Member Enumeration Documentation

◆ UserDefinedConversionKind

Enumerator
UDCK_None 
UDCK_Ctor 
UDCK_Oper 

Definition at line 226 of file EasilySwappableParametersCheck.cpp.

Constructor & Destructor Documentation

◆ ConversionSequence() [1/2]

clang::tidy::bugprone::model::ConversionSequence::ConversionSequence ( )
inline

Definition at line 261 of file EasilySwappableParametersCheck.cpp.

◆ ConversionSequence() [2/2]

clang::tidy::bugprone::model::ConversionSequence::ConversionSequence ( QualType  From,
QualType  To 
)
inline

Definition at line 262 of file EasilySwappableParametersCheck.cpp.

Member Function Documentation

◆ getInvolvedTypesInSequence()

SmallVector< QualType, 4 > clang::tidy::bugprone::model::ConversionSequence::getInvolvedTypesInSequence ( ) const
inline

◆ getTypeAfterUserDefinedConversion()

QualType clang::tidy::bugprone::model::ConversionSequence::getTypeAfterUserDefinedConversion ( ) const
inline

◆ getUserDefinedConversionFunction()

const CXXMethodDecl * clang::tidy::bugprone::model::ConversionSequence::getUserDefinedConversionFunction ( ) const
inline

◆ getUserDefinedConversionHighlight()

SourceRange clang::tidy::bugprone::model::ConversionSequence::getUserDefinedConversionHighlight ( ) const
inline

Returns the SourceRange in the text that corresponds to the interesting part of the user-defined conversion.

This is either the parameter type in a converting constructor, or the conversion result type in a conversion operator.

Definition at line 369 of file EasilySwappableParametersCheck.cpp.

References clang::tidy::bugprone::model::ConversionSequence::UserDefinedConvertingConstructor::Fun, clang::tidy::bugprone::model::ConversionSequence::UserDefinedConversionOperator::Fun, UDCK_Ctor, UDCK_None, UDCK_Oper, UDConvCtor, UDConvKind, and UDConvOp.

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

◆ operator bool()

clang::tidy::bugprone::model::ConversionSequence::operator bool ( ) const
inlineexplicit

◆ setConversion() [1/2]

void clang::tidy::bugprone::model::ConversionSequence::setConversion ( const UserDefinedConversionOperator UDCO)
inline

Sets the user-defined conversion to the given operator.

Definition at line 334 of file EasilySwappableParametersCheck.cpp.

References UDCK_Oper, UDConvKind, and UDConvOp.

◆ setConversion() [2/2]

void clang::tidy::bugprone::model::ConversionSequence::setConversion ( const UserDefinedConvertingConstructor UDCC)
inline

Sets the user-defined conversion to the given constructor.

Definition at line 328 of file EasilySwappableParametersCheck.cpp.

References UDCK_Ctor, UDConvCtor, and UDConvKind.

◆ update()

ConversionSequence & clang::tidy::bugprone::model::ConversionSequence::update ( const ConversionSequence RHS)
inline

Updates the steps of the conversion sequence with the steps from the other instance.

Note
This method does not check if the resulting conversion sequence is sensible!

Definition at line 306 of file EasilySwappableParametersCheck.cpp.

References AfterFirstStandard, AfterSecondStandard, UDCK_Ctor, UDCK_None, UDCK_Oper, UDConvCtor, UDConvKind, and UDConvOp.

Member Data Documentation

◆ 

union { ... } clang::tidy::bugprone::model::ConversionSequence::@1

The details of the user-defined conversion involved, as a tagged union.

◆ AfterFirstStandard

QualType clang::tidy::bugprone::model::ConversionSequence::AfterFirstStandard

◆ AfterSecondStandard

QualType clang::tidy::bugprone::model::ConversionSequence::AfterSecondStandard

The intermediate type after performing the second Standard Conversion Sequence.

Definition at line 256 of file EasilySwappableParametersCheck.cpp.

Referenced by clang::tidy::bugprone::model::calculateMixability(), getInvolvedTypesInSequence(), operator bool(), and update().

◆ Begin

QualType clang::tidy::bugprone::model::ConversionSequence::Begin

The type the conversion stared from.

Definition at line 241 of file EasilySwappableParametersCheck.cpp.

◆ End

QualType clang::tidy::bugprone::model::ConversionSequence::End

The result type the conversion targeted.

Definition at line 259 of file EasilySwappableParametersCheck.cpp.

◆ None

char clang::tidy::bugprone::model::ConversionSequence::None

Definition at line 248 of file EasilySwappableParametersCheck.cpp.

◆ UDConvCtor

UserDefinedConvertingConstructor clang::tidy::bugprone::model::ConversionSequence::UDConvCtor

◆ UDConvKind

UserDefinedConversionKind clang::tidy::bugprone::model::ConversionSequence::UDConvKind

◆ UDConvOp

UserDefinedConversionOperator clang::tidy::bugprone::model::ConversionSequence::UDConvOp

The documentation for this struct was generated from the following file: