clang-tools  14.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...

Collaboration diagram for clang::tidy::bugprone::model::ConversionSequence:
Collaboration graph
[legend]

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. More...
 
ConversionSequenceupdate (const ConversionSequence &RHS)
 Updates the steps of the conversion sequence with the steps from the other instance. More...
 
void setConversion (const UserDefinedConvertingConstructor &UDCC)
 Sets the user-defined conversion to the given constructor. More...
 
void setConversion (const UserDefinedConversionOperator &UDCO)
 Sets the user-defined conversion to the given operator. More...
 
QualType getTypeAfterUserDefinedConversion () const
 Returns the type in the conversion that's formally "in our hands" once the user-defined conversion is executed. More...
 
const CXXMethodDecl * getUserDefinedConversionFunction () const
 
SourceRange getUserDefinedConversionHighlight () const
 Returns the SourceRange in the text that corresponds to the interesting part of the user-defined conversion. More...
 

Public Attributes

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

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

Member Enumeration Documentation

◆ UserDefinedConversionKind

Enumerator
UDCK_None 
UDCK_Ctor 
UDCK_Oper 

Definition at line 216 of file EasilySwappableParametersCheck.cpp.

Constructor & Destructor Documentation

◆ ConversionSequence() [1/2]

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

◆ ConversionSequence() [2/2]

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

Definition at line 252 of file EasilySwappableParametersCheck.cpp.

Member Function Documentation

◆ getInvolvedTypesInSequence()

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

Returns all the "steps" (non-unique and non-similar) types involved in the conversion sequence.

This method does NOT return Begin and End.

Definition at line 262 of file EasilySwappableParametersCheck.cpp.

◆ getTypeAfterUserDefinedConversion()

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

Returns the type in the conversion that's formally "in our hands" once the user-defined conversion is executed.

Definition at line 331 of file EasilySwappableParametersCheck.cpp.

◆ getUserDefinedConversionFunction()

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

Definition at line 343 of file EasilySwappableParametersCheck.cpp.

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

◆ operator bool()

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

Definition at line 255 of file EasilySwappableParametersCheck.cpp.

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

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

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

References AfterFirstStandard, AfterSecondStandard, UDConvCtor, UDConvKind, and UDConvOp.

Member Data Documentation

◆ @1

union { ... }

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

◆ AfterFirstStandard

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

The intermediate type after the first Standard Conversion Sequence.

Definition at line 234 of file EasilySwappableParametersCheck.cpp.

Referenced by update().

◆ AfterSecondStandard

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

The intermediate type after performing the second Standard Conversion Sequence.

Definition at line 246 of file EasilySwappableParametersCheck.cpp.

Referenced by update().

◆ Begin

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

The type the conversion stared from.

Definition at line 231 of file EasilySwappableParametersCheck.cpp.

◆ End

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

The result type the conversion targeted.

Definition at line 249 of file EasilySwappableParametersCheck.cpp.

◆ None

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

Definition at line 238 of file EasilySwappableParametersCheck.cpp.

◆ UDConvCtor

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

Definition at line 239 of file EasilySwappableParametersCheck.cpp.

Referenced by update().

◆ UDConvKind

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

Definition at line 242 of file EasilySwappableParametersCheck.cpp.

Referenced by update().

◆ UDConvOp

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

Definition at line 240 of file EasilySwappableParametersCheck.cpp.

Referenced by update().


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