clang 8.0.0

Enumerations | Functions
SemaCast.cpp File Reference
`#include "clang/Sema/SemaInternal.h"`
`#include "clang/AST/ASTContext.h"`
`#include "clang/AST/CXXInheritance.h"`
`#include "clang/AST/ExprCXX.h"`
`#include "clang/AST/ExprObjC.h"`
`#include "clang/AST/RecordLayout.h"`
`#include "clang/Basic/PartialDiagnostic.h"`
`#include "clang/Basic/TargetInfo.h"`
`#include "clang/Lex/Preprocessor.h"`
`#include "clang/Sema/Initialization.h"`
`#include "llvm/ADT/SmallVector.h"`
`#include <set>`
Include dependency graph for SemaCast.cpp:

Go to the source code of this file.

## Enumerations
enum | TryCastResult { TC_NotApplicable, TC_Success, TC_Extension, TC_Failed }
enum | CastType { CT_Const, CT_Static, CT_Reinterpret, CT_Dynamic, CT_CStyle, CT_Functional }
enum | CastAwayConstnessKind
| The kind of unwrapping we did when determining whether a conversion casts away constness. More...

## Functions
static bool | isValidCast (TryCastResult TCR)
static void | DiagnoseCastQual (Sema &Self, const ExprResult &SrcExpr, QualType DestType)
| DiagnoseCastQual - Warn whenever casts discards a qualifiers, be it either const, volatile or both. More...
static TryCastResult | TryLValueToRValueCast (Sema &Self, Expr *SrcExpr, QualType DestType, bool CStyle, CastKind &Kind, CXXCastPath &BasePath, unsigned &msg)
| Tests whether a conversion according to N2844 is valid. More...
static TryCastResult | TryStaticReferenceDowncast (Sema &Self, Expr *SrcExpr, QualType DestType, bool CStyle, SourceRange OpRange, unsigned &msg, CastKind &Kind, CXXCastPath &BasePath)
| Tests whether a conversion according to C++ 5.2.9p5 is valid. More...
static TryCastResult | TryStaticPointerDowncast (Sema &Self, QualType SrcType, QualType DestType, bool CStyle, SourceRange OpRange, unsigned &msg, CastKind &Kind, CXXCastPath &BasePath)
| Tests whether a conversion according to C++ 5.2.9p8 is valid. More...
static TryCastResult | TryStaticDowncast (Sema &Self, CanQualType SrcType, CanQualType DestType, bool CStyle, SourceRange OpRange, QualType OrigSrcType, QualType OrigDestType, unsigned &msg, CastKind &Kind, CXXCastPath &BasePath)
| TryStaticDowncast - Common functionality of TryStaticReferenceDowncast and TryStaticPointerDowncast. More...
static TryCastResult | TryStaticMemberPointerUpcast (Sema &Self, ExprResult &SrcExpr, QualType SrcType, QualType DestType, bool CStyle, SourceRange OpRange, unsigned &msg, CastKind &Kind, CXXCastPath &BasePath)
| TryStaticMemberPointerUpcast - Tests whether a conversion according to C++ 5.2.9p9 is valid: More...
static TryCastResult | TryStaticImplicitCast (Sema &Self, ExprResult &SrcExpr, QualType DestType, Sema::CheckedConversionKind CCK, SourceRange OpRange, unsigned &msg, CastKind &Kind, bool ListInitialization)
| TryStaticImplicitCast - Tests whether a conversion according to C++ 5.2.9p2 is valid: More...
static TryCastResult | TryStaticCast (Sema &Self, ExprResult &SrcExpr, QualType DestType, Sema::CheckedConversionKind CCK, SourceRange OpRange, unsigned &msg, CastKind &Kind, CXXCastPath &BasePath, bool ListInitialization)
| TryStaticCast - Check if a static cast can be performed, and do so if possible. More...
static TryCastResult | TryConstCast (Sema &Self, ExprResult &SrcExpr, QualType DestType, bool CStyle, unsigned &msg)
| TryConstCast - See if a const_cast from source to destination is allowed, and perform it if it is. More...
static TryCastResult | TryReinterpretCast (Sema &Self, ExprResult &SrcExpr, QualType DestType, bool CStyle, SourceRange OpRange, unsigned &msg, CastKind &Kind)
static bool | tryDiagnoseOverloadedCast (Sema &S, CastType CT, SourceRange range, Expr *src, QualType destType, bool listInitialization)
| Try to diagnose a failed overloaded cast. More...
static void | diagnoseBadCast (Sema &S, unsigned msg, CastType castType, SourceRange opRange, Expr *src, QualType destType, bool listInitialization)
| Diagnose a failed cast. More...
static CastAwayConstnessKind | unwrapCastAwayConstnessLevel (ASTContext &Context, QualType &T1, QualType &T2)
| Unwrap one level of types for CastsAwayConstness. More...
static CastAwayConstnessKind | CastsAwayConstness (Sema &Self, QualType SrcType, QualType DestType, bool CheckCVR, bool CheckObjCLifetime, QualType *TheOffendingSrcType=nullptr, QualType *TheOffendingDestType=nullptr, Qualifiers *CastAwayQualifiers=nullptr)
| Check if the pointer conversion from SrcType to DestType casts away constness as defined in C++ [expr.const.cast]. More...
static TryCastResult | getCastAwayConstnessCastKind (CastAwayConstnessKind CACK, unsigned &DiagID)
static void | DiagnoseReinterpretUpDownCast (Sema &Self, const Expr *SrcExpr, QualType DestType, SourceRange OpRange)
| Check that a reinterpret_cast<DestType>(SrcExpr) is not used as upcast or downcast between respective pointers or references. More...
static bool | IsAddressSpaceConversion (QualType SrcType, QualType DestType)
static void | DiagnoseCastOfObjCSEL (Sema &Self, const ExprResult &SrcExpr, QualType DestType)
static void | DiagnoseCallingConvCast (Sema &Self, const ExprResult &SrcExpr, QualType DstType, SourceRange OpRange)
| Diagnose casts that change the calling convention of a pointer to a function defined in the current TU. More...
static void | checkIntToPointerCast (bool CStyle, SourceLocation Loc, const Expr *SrcExpr, QualType DestType, Sema &Self)
static bool | fixOverloadedReinterpretCastExpr (Sema &Self, QualType DestType, ExprResult &Result)
static void | DiagnoseBadFunctionCast (Sema &Self, const ExprResult &SrcExpr, QualType DestType)
| DiagnoseBadFunctionCast - Warn whenever a function call is cast to a non-matching type. More...

## Enumeration Type Documentation

## ◆ CastAwayConstnessKind

enum CastAwayConstnessKind

The kind of unwrapping we did when determining whether a conversion casts away constness.

Definition at line 455 of file SemaCast.cpp.

## ◆ CastType

enum CastType

Enumerator
CT_Const | const_cast
CT_Static | static_cast
CT_Reinterpret | reinterpret_cast
CT_Dynamic | dynamic_cast
CT_CStyle | (Type)expr
CT_Functional | Type(expr)

Definition at line 46 of file SemaCast.cpp.

## ◆ TryCastResult

enum TryCastResult

Enumerator
TC_NotApplicable | The cast method is not applicable.
TC_Success | The cast method is appropriate and successful.
TC_Extension | The cast method is appropriate and accepted as a language extension.
TC_Failed | The cast method is appropriate, but failed. A diagnostic has been emitted.

Definition at line 33 of file SemaCast.cpp.

## Function Documentation

## ◆ CastsAwayConstness()

static CastAwayConstnessKind CastsAwayConstness | ( | Sema & | Self,
|  | QualType | SrcType,
|  | QualType | DestType,
|  | bool | CheckCVR,
|  | bool | CheckObjCLifetime,
|  | QualType * | TheOffendingSrcType = `nullptr`,
|  | QualType * | TheOffendingDestType = `nullptr`,
|  | Qualifiers * | CastAwayQualifiers = `nullptr`
| ) |  |
| static

Check if the pointer conversion from SrcType to DestType casts away constness as defined in C++ [expr.const.cast].

This is used by the cast checkers. Both arguments must denote pointer (possibly to member) types.

Parameters

  CheckCVR | Whether to check for const/volatile/restrict qualifiers.
  CheckObjCLifetime | Whether to check Objective-C lifetime qualifiers.

Definition at line 560 of file SemaCast.cpp.

References clang::Qualifiers::compatiblyIncludesObjCLifetime(), clang::Sema::Context, clang::Qualifiers::fromCVRMask(), clang::ASTContext::getCanonicalType(), clang::Qualifiers::getCVRQualifiers(), clang::ASTContext::getLangOpts(), clang::ASTContext::getUnqualifiedArrayType(), clang::Qualifiers::hasConst(), clang::Type::isAnyPointerType(), clang::Type::isBlockPointerType(), clang::Type::isMemberPointerType(), clang::Type::isObjCObjectType(), clang::Type::isReferenceType(), clang::Qualifiers::removeConst(), and unwrapCastAwayConstnessLevel().

Referenced by DiagnoseCastQual(), and TryReinterpretCast().

## ◆ checkIntToPointerCast()

static void checkIntToPointerCast | ( | bool | CStyle,
|  | SourceLocation | Loc,
|  | const Expr * | SrcExpr,
|  | QualType | DestType,
|  | Sema & | Self
| ) |  |
| static

Definition at line 1930 of file SemaCast.cpp.

References clang::Sema::Context, Diag(), clang::Sema::Diag(), clang::Expr::getType(), clang::ASTContext::getTypeSize(), clang::Type::isBooleanType(), clang::Type::isEnumeralType(), clang::Expr::isIntegerConstantExpr(), clang::Type::isIntegralType(), and clang::Type::isVoidPointerType().

Referenced by DiagnoseBadFunctionCast(), and TryReinterpretCast().

## ◆ diagnoseBadCast()

static void diagnoseBadCast | ( | Sema & | S,
|  | unsigned | msg,
|  | CastType | castType,
|  | SourceRange | opRange,
|  | Expr * | src,
|  | QualType | destType,
|  | bool | listInitialization
| ) |  |
| static

Diagnose a failed cast.

Definition at line 413 of file SemaCast.cpp.

Referenced by DiagnoseReinterpretUpDownCast(), and TryReinterpretCast().

## ◆ DiagnoseBadFunctionCast()

static void DiagnoseBadFunctionCast | ( | Sema & | Self,
|  | const ExprResult & | SrcExpr,
|  | QualType | DestType
| ) |  |
| static

DiagnoseBadFunctionCast - Warn whenever a function call is cast to a non-matching type.

Such as enum function call to int, int call to pointer; etc. Cast to 'void' is an exception.

Definition at line 2443 of file SemaCast.cpp.

References clang::Sema::AA_Casting, clang::LangOptions::allowsNonTrivialObjCLifetimeQualifiers(), clang::VectorType::AltiVecVector, clang::Sema::CCK_CStyleCast, clang::Sema::CheckExtVectorCast(), checkIntToPointerCast(), clang::Sema::CheckObjCARCUnavailableWeakConversion(), clang::Sema::checkUnknownAnyCast(), clang::Sema::CheckVectorCast(), clang::Qualifiers::compatiblyIncludesObjCLifetime(), clang::Sema::Context, clang::Sema::DefaultFunctionArrayLvalueConversion(), clang::Sema::Diag(), DiagnoseCallingConvCast(), DiagnoseCastOfObjCSEL(), clang::Sema::Diags, clang::ExprError(), clang::Sema::FixOverloadedFunctionReference(), clang::ActionResult< PtrTy, CompressInvalid >::get(), clang::Type::getAs(), clang::SourceRange::getBegin(), clang::RecordType::getDecl(), clang::APValue::getInt(), clang::Sema::getLangOpts(), clang::Sema::getOpenCLOptions(), clang::PointerType::getPointeeType(), clang::QualType::getQualifiers(), clang::CastExpr::getTargetFieldForToUnionCast(), clang::QualType::getUnqualifiedType(), clang::ASTContext::hasSameUnqualifiedType(), clang::Sema::IgnoredValueConversions(), clang::Type::isAnyPointerType(), clang::Type::isArithmeticType(), clang::Type::isBlockPointerType(), clang::Type::isBooleanType(), clang::Type::isComplexIntegerType(), clang::Type::isComplexType(), clang::OpenCLOptions::isEnabled(), clang::Type::isEnumeralType(), clang::Type::isEventT(), clang::Type::isExtVectorType(), clang::Type::isFloatingType(), clang::Type::isHalfType(), clang::DiagnosticsEngine::isIgnored(), clang::Type::isIntegerType(), clang::Type::isIntegralType(), clang::ActionResult< PtrTy, CompressInvalid >::isInvalid(), clang::Type::isObjCLifetimeType(), clang::Type::isPlaceholderType(), clang::Type::isRealFloatingType(), clang::Type::isScalarType(), clang::TagDecl::isUnion(), clang::ActionResult< PtrTy, CompressInvalid >::isUsable(), clang::Type::isVectorType(), clang::Type::isVoidType(), clang::ASTContext::OverloadTy, clang::Sema::PrepareScalarCast(), clang::Sema::prepareVectorSplat(), clang::Sema::RequireCompleteType(), clang::Sema::ResolveAddressOfOverloadedFunction(), clang::Result, and clang::Expr::EvalResult::Val.

## ◆ DiagnoseCallingConvCast()

static void DiagnoseCallingConvCast | ( | Sema & | Self,
|  | const ExprResult & | SrcExpr,
|  | QualType | DstType,
|  | SourceRange | OpRange
| ) |  |
| static

Diagnose casts that change the calling convention of a pointer to a function defined in the current TU.

Definition at line 1842 of file SemaCast.cpp.

References clang::Type::castAs(), clang::Sema::Context, clang::FixItHint::CreateInsertion(), clang::Sema::Diag(), clang::Sema::Diags, clang::ActionResult< PtrTy, CompressInvalid >::get(), clang::Sema::getASTContext(), clang::SourceRange::getBegin(), clang::FunctionType::getCallConv(), clang::ASTContext::getDefaultCallingConvention(), clang::Preprocessor::getIdentifierInfo(), clang::Sema::getLangOpts(), clang::Preprocessor::getLastMacroWithSpelling(), clang::FunctionType::getNameForCallConv(), clang::Sema::getPreprocessor(), clang::IdentifierInfo::getTokenID(), clang::ASTContext::hasSameType(), clang::Expr::IgnoreParenImpCasts(), clang::Type::isFunctionPointerType(), clang::DiagnosticsEngine::isIgnored(), and clang::IdentifierInfo::isKeyword().

Referenced by DiagnoseBadFunctionCast(), and TryReinterpretCast().

## ◆ DiagnoseCastOfObjCSEL()

static void DiagnoseCastOfObjCSEL | ( | Sema & | Self,
|  | const ExprResult & | SrcExpr,
|  | QualType | DestType
| ) |  |
| static

Definition at line 1823 of file SemaCast.cpp.

References clang::Sema::Context, clang::Sema::Diag(), clang::ActionResult< PtrTy, CompressInvalid >::get(), clang::Type::getAs(), clang::Type::getPointeeType(), clang::QualType::getUnqualifiedType(), clang::ASTContext::hasSameType(), and clang::Type::isVoidType().

Referenced by DiagnoseBadFunctionCast(), and TryReinterpretCast().

## ◆ DiagnoseCastQual()

static void DiagnoseCastQual | ( | Sema & | Self,
|  | const ExprResult & | SrcExpr,
|  | QualType | DestType
| ) |  |
| static

DiagnoseCastQual - Warn whenever casts discards a qualifiers, be it either const, volatile or both.

Definition at line 2700 of file SemaCast.cpp.

References CastsAwayConstness(), clang::Sema::Diag(), clang::ActionResult< PtrTy, CompressInvalid >::get(), clang::Qualifiers::hasConst(), clang::Qualifiers::hasVolatile(), clang::Type::isAnyPointerType(), clang::ActionResult< PtrTy, CompressInvalid >::isInvalid(), and clang::Type::isLValueReferenceType().

Referenced by clang::Sema::BuildCStyleCastExpr().

## ◆ DiagnoseReinterpretUpDownCast()

static void DiagnoseReinterpretUpDownCast | ( | Sema & | Self,
|  | const Expr * | SrcExpr,
|  | QualType | DestType,
|  | SourceRange | OpRange
| ) |  |
| static

Check that a reinterpret_cast<DestType>(SrcExpr) is not used as upcast or downcast between respective pointers or references.

Definition at line 851 of file SemaCast.cpp.

References clang::LangOptions::allowsNonTrivialObjCLifetimeQualifiers(), clang::CXXBasePaths::begin(), clang::Sema::CCK_OtherCast, clang::Sema::Context, clang::FixItHint::CreateReplacement(), CT_Reinterpret, CT_Static, clang::Sema::DefaultFunctionArrayLvalueConversion(), clang::Sema::Diag(), diagnoseBadCast(), clang::CXXBasePaths::end(), clang::ExprError(), clang::OverloadExpr::find(), clang::ActionResult< PtrTy, CompressInvalid >::get(), clang::Type::getAsCXXRecordDecl(), clang::ASTContext::getASTRecordLayout(), clang::ASTRecordLayout::getBaseClassOffset(), clang::SourceRange::getBegin(), clang::CXXRecordDecl::getDefinition(), clang::Sema::getLangOpts(), clang::OverloadExpr::getName(), clang::Type::getPointeeCXXRecordDecl(), clang::OverloadExpr::getQualifierLoc(), clang::NestedNameSpecifierLoc::getSourceRange(), clang::Expr::getType(), clang::Sema::IgnoredValueConversions(), clang::TagDecl::isCompleteDefinition(), clang::CXXRecordDecl::isDerivedFrom(), clang::ActionResult< PtrTy, CompressInvalid >::isInvalid(), clang::Decl::isInvalidDecl(), clang::Type::isRecordType(), isValidCast(), clang::Type::isVoidType(), clang::CharUnits::isZero(), clang::Sema::NoteAllOverloadCandidates(), Offset, clang::ASTContext::OverloadTy, clang::Sema::ResolveAndFixSingleFunctionTemplateSpecialization(), TC_Success, TryReinterpretCast(), TryStaticCast(), clang::VK_RValue, and clang::CharUnits::Zero().

## ◆ fixOverloadedReinterpretCastExpr()

static bool fixOverloadedReinterpretCastExpr | ( | Sema & | Self,
|  | QualType | DestType,
|  | ExprResult & | Result
| ) |  |
| static

Definition at line 1956 of file SemaCast.cpp.

References clang::ActionResult< PtrTy, CompressInvalid >::get(), clang::Expr::getValueKindForType(), clang::ActionResult< PtrTy, CompressInvalid >::isUsable(), clang::Sema::resolveAndFixAddressOfOnlyViableOverloadCandidate(), clang::Sema::ResolveAndFixSingleFunctionTemplateSpecialization(), and clang::VK_RValue.

Referenced by TryReinterpretCast().

## ◆ getCastAwayConstnessCastKind()

static TryCastResult getCastAwayConstnessCastKind | ( | CastAwayConstnessKind | CACK,
|  | unsigned & | DiagID
| ) |  |
| static

Definition at line 655 of file SemaCast.cpp.

References clang::Sema::CheckDerivedToBaseConversion(), clang::Sema::CheckPlaceholderExpr(), clang::Sema::Context, clang::Sema::CreateMaterializeTemporaryExpr(), CT_Const, CT_Dynamic, clang::Sema::DefaultFunctionArrayLvalueConversion(), clang::Sema::Diag(), clang::ExprError(), clang::ActionResult< PtrTy, CompressInvalid >::get(), clang::Type::getAs(), clang::SourceRange::getBegin(), clang::ASTContext::getCanonicalType(), clang::RecordType::getDecl(), clang::RecordDecl::getDefinition(), clang::Sema::getLangOpts(), clang::Type::getPointeeType(), clang::PointerType::getPointeeType(), clang::QualType::getUnqualifiedType(), clang::QualType::isAtLeastAsQualifiedAs(), clang::Sema::IsDerivedFrom(), clang::ActionResult< PtrTy, CompressInvalid >::isInvalid(), isValidCast(), clang::Type::isVoidType(), clang::Sema::RequireCompleteType(), TC_Extension, TC_Failed, TC_Success, TryConstCast(), and clang::VK_RValue.

Referenced by TryReinterpretCast().

## ◆ IsAddressSpaceConversion()

static bool IsAddressSpaceConversion | ( | QualType | SrcType,
|  | QualType | DestType
| ) |  |
| static

Definition at line 1050 of file SemaCast.cpp.

References clang::QualType::getAddressSpace(), clang::Type::getAs(), and clang::PointerType::getPointeeType().

Referenced by TryReinterpretCast(), and TryStaticCast().

## ◆ isValidCast()

static bool isValidCast | ( | TryCastResult | TCR | ) |
| static

Definition at line 42 of file SemaCast.cpp.

References TC_Extension, and TC_Success.

Referenced by DiagnoseReinterpretUpDownCast(), getCastAwayConstnessCastKind(), and TryReinterpretCast().

## ◆ TryConstCast()

static TryCastResult TryConstCast | ( | Sema & | Self,
|  | ExprResult & | SrcExpr,
|  | QualType | DestType,
|  | bool | CStyle,
|  | unsigned & | msg
| ) |  |
| static

TryConstCast - See if a const_cast from source to destination is allowed, and perform it if it is.

Definition at line 1670 of file SemaCast.cpp.

References clang::Sema::Context, clang::Sema::CreateMaterializeTemporaryExpr(), clang::ActionResult< PtrTy, CompressInvalid >::get(), clang::Type::getAs(), clang::ASTContext::getCanonicalType(), clang::ASTContext::getPointerType(), clang::ASTContext::hasCvrSimilarType(), clang::Type::isFunctionPointerType(), clang::Type::isMemberFunctionPointerType(), clang::Type::isMemberPointerType(), clang::Type::isObjCObjectPointerType(), clang::Type::isPointerType(), clang::Type::isRecordType(), TC_NotApplicable, and TC_Success.

Referenced by getCastAwayConstnessCastKind(), and TryReinterpretCast().

## ◆ tryDiagnoseOverloadedCast()

static bool tryDiagnoseOverloadedCast | ( | Sema & | S,
|  | CastType | CT,
|  | SourceRange | range,
|  | Expr * | src,
|  | QualType | destType,
|  | bool | listInitialization
| ) |  |
| static

Try to diagnose a failed overloaded cast.

Returns true if diagnostics were emitted.

Definition at line 337 of file SemaCast.cpp.

## ◆ TryLValueToRValueCast()

TryCastResult TryLValueToRValueCast | ( | Sema & | Self,
|  | Expr * | SrcExpr,
|  | QualType | DestType,
|  | bool | CStyle,
|  | CastKind & | Kind,
|  | CXXCastPath & | BasePath,
|  | unsigned & | msg
| ) |  |
| static

Tests whether a conversion according to N2844 is valid.

Definition at line 1255 of file SemaCast.cpp.

References clang::Sema::CompareReferenceRelationship(), clang::Type::getAs(), clang::Stmt::getBeginLoc(), clang::ReferenceType::getPointeeType(), clang::Expr::getType(), clang::QualType::getUnqualifiedType(), clang::Expr::isGLValue(), clang::Expr::isLValue(), clang::Sema::Ref_Compatible, clang::Sema::Ref_Incompatible, TC_Failed, and TC_NotApplicable.

Referenced by TryStaticCast().

## ◆ TryReinterpretCast()

static TryCastResult TryReinterpretCast | ( | Sema & | Self,
|  | ExprResult & | SrcExpr,
|  | QualType | DestType,
|  | bool | CStyle,
|  | SourceRange | OpRange,
|  | unsigned & | msg,
|  | CastKind & | Kind
| ) |  |
| static

Definition at line 1983 of file SemaCast.cpp.

References clang::Sema::AA_Casting, clang::LangOptions::allowsNonTrivialObjCLifetimeQualifiers(), clang::VectorType::AltiVecVector, clang::Sema::areLaxCompatibleVectorTypes(), CastsAwayConstness(), clang::Sema::CCK_CStyleCast, clang::Sema::CCK_FunctionalCast, clang::Sema::CheckCompatibleReinterpretCast(), checkIntToPointerCast(), clang::Sema::checkUnknownAnyCast(), clang::Sema::Context, CT_CStyle, CT_Functional, clang::Sema::DefaultFunctionArrayLvalueConversion(), clang::Sema::Diag(), diagnoseBadCast(), DiagnoseCallingConvCast(), DiagnoseCastOfObjCSEL(), clang::ExprError(), clang::OverloadExpr::find(), fixOverloadedReinterpretCastExpr(), clang::ActionResult< PtrTy, CompressInvalid >::get(), clang::Type::getAs(), clang::SourceRange::getBegin(), clang::ASTContext::getCanonicalType(), getCastAwayConstnessCastKind(), clang::TargetInfo::getCXXABI(), clang::Sema::getLangOpts(), clang::OverloadExpr::getName(), clang::ASTContext::getPointerType(), clang::OverloadExpr::getQualifierLoc(), clang::NestedNameSpecifierLoc::getSourceRange(), clang::ASTContext::getTargetInfo(), clang::ASTContext::getTypeSize(), clang::Sema::IgnoredValueConversions(), IsAddressSpaceConversion(), clang::Type::isAnyPointerType(), clang::Type::isBlockPointerType(), clang::Type::isBooleanType(), clang::Sema::isCompleteType(), clang::Type::isDependentType(), clang::Type::isFunctionPointerType(), clang::Type::isIntegralOrEnumerationType(), clang::Type::isIntegralType(), clang::ActionResult< PtrTy, CompressInvalid >::isInvalid(), clang::MemberPointerType::isMemberFunctionPointer(), clang::Type::isMemberPointerType(), clang::TargetCXXABI::isMicrosoft(), clang::Type::isNullPtrType(), clang::Type::isObjCObjectPointerType(), clang::Type::isRecordType(), clang::ActionResult< PtrTy, CompressInvalid >::isUsable(), isValidCast(), clang::Type::isVectorType(), clang::Type::isVoidType(), clang::Sema::NoteAllOverloadCandidates(), clang::OK_BitField, clang::OK_ObjCProperty, clang::OK_ObjCSubscript, clang::OK_Ordinary, clang::OK_VectorComponent, clang::ASTContext::OverloadTy, clang::Sema::PrepareCastToObjCObjectPointer(), clang::Sema::prepareVectorSplat(), clang::Sema::ResolveAddressOfOverloadedFunction(), clang::Sema::ResolveAndFixSingleFunctionTemplateSpecialization(), clang::Result, TC_Failed, TC_NotApplicable, TC_Success, TryConstCast(), TryStaticCast(), and clang::VK_RValue.

Referenced by DiagnoseReinterpretUpDownCast().

## ◆ TryStaticCast()

static TryCastResult TryStaticCast | ( | Sema & | Self,
|  | ExprResult & | SrcExpr,
|  | QualType | DestType,
|  | Sema::CheckedConversionKind | CCK,
|  | SourceRange | OpRange,
|  | unsigned & | msg,
|  | CastKind & | Kind,
|  | CXXCastPath & | BasePath,
|  | bool | ListInitialization
| ) |  |
| static

TryStaticCast - Check if a static cast can be performed, and do so if possible.

If `CStyle`, ignore access restrictions on hierarchy casting and casting away constness.

Definition at line 1064 of file SemaCast.cpp.

References clang::Sema::CCK_CStyleCast, clang::Sema::CCK_FunctionalCast, clang::Sema::CheckTollFreeBridgeStaticCast(), clang::Qualifiers::compatiblyIncludes(), clang::Sema::Context, clang::Sema::Diag(), clang::ActionResult< PtrTy, CompressInvalid >::get(), clang::Type::getAs(), clang::ASTContext::getCanonicalType(), clang::Sema::getLangOpts(), clang::Type::getPointeeType(), clang::QualType::getQualifiers(), IsAddressSpaceConversion(), clang::Type::isBlockPointerType(), clang::Type::isBooleanType(), clang::Type::isEnumeralType(), clang::Type::isFunctionType(), clang::Type::isIncompleteOrObjectType(), clang::Type::isIntegralOrEnumerationType(), clang::Type::isIntegralType(), clang::ActionResult< PtrTy, CompressInvalid >::isInvalid(), clang::Type::isObjCObjectPointerType(), clang::Type::isRealFloatingType(), clang::Type::isVoidType(), clang::Qualifiers::removeObjCGCAttr(), clang::Qualifiers::removeObjCLifetime(), TC_Failed, TC_NotApplicable, TC_Success, TryLValueToRValueCast(), TryStaticImplicitCast(), TryStaticMemberPointerUpcast(), TryStaticPointerDowncast(), and TryStaticReferenceDowncast().

Referenced by DiagnoseReinterpretUpDownCast(), and TryReinterpretCast().

## ◆ TryStaticDowncast()

TryCastResult TryStaticDowncast | ( | Sema & | Self,
|  | CanQualType | SrcType,
|  | CanQualType | DestType,
|  | bool | CStyle,
|  | SourceRange | OpRange,
|  | QualType | OrigSrcType,
|  | QualType | OrigDestType,
|  | unsigned & | msg,
|  | CastKind & | Kind,
|  | CXXCastPath & | BasePath
| ) |  |
| static

TryStaticDowncast - Common functionality of TryStaticReferenceDowncast and TryStaticPointerDowncast.

Tests whether a static downcast from SrcType to DestType is possible and allowed.

Definition at line 1385 of file SemaCast.cpp.

References clang::CanQual< T >::getAs(), clang::SourceRange::getBegin(), clang::Sema::isCompleteType(), and TC_NotApplicable.

Referenced by TryStaticPointerDowncast(), and TryStaticReferenceDowncast().

## ◆ TryStaticImplicitCast()

TryCastResult TryStaticImplicitCast | ( | Sema & | Self,
|  | ExprResult & | SrcExpr,
|  | QualType | DestType,
|  | Sema::CheckedConversionKind | CCK,
|  | SourceRange | OpRange,
|  | unsigned & | msg,
|  | CastKind & | Kind,
|  | bool | ListInitialization
| ) |  |
| static

TryStaticImplicitCast - Tests whether a conversion according to C++ 5.2.9p2 is valid:

An expression e can be explicitly converted to a type T using a `static_cast` if the declaration "T t(e);" is well-formed [...].

Definition at line 1615 of file SemaCast.cpp.

References clang::Sema::CCK_CStyleCast, clang::Sema::CCK_FunctionalCast, clang::InitializationKind::CreateCast(), clang::InitializationKind::CreateCStyleCast(), clang::InitializationKind::CreateFunctionalCast(), clang::InitializationSequence::Failed(), clang::ActionResult< PtrTy, CompressInvalid >::get(), clang::SourceRange::getBegin(), clang::InitializedEntity::InitializeTemporary(), clang::InitializationSequence::isConstructorInitialization(), clang::ActionResult< PtrTy, CompressInvalid >::isInvalid(), clang::Type::isRecordType(), clang::Type::isReferenceType(), clang::InitializationSequence::Perform(), clang::Sema::RequireCompleteType(), clang::Sema::RequireNonAbstractType(), clang::Result, TC_Failed, TC_NotApplicable, and TC_Success.

Referenced by TryStaticCast().

## ◆ TryStaticMemberPointerUpcast()

TryCastResult TryStaticMemberPointerUpcast | ( | Sema & | Self,
|  | ExprResult & | SrcExpr,
|  | QualType | SrcType,
|  | QualType | DestType,
|  | bool | CStyle,
|  | SourceRange | OpRange,
|  | unsigned & | msg,
|  | CastKind & | Kind,
|  | CXXCastPath & | BasePath
| ) |  |
| static

TryStaticMemberPointerUpcast - Tests whether a conversion according to C++ 5.2.9p9 is valid:

An rvalue of type "pointer to member of D of type cv1 T" can be converted to an rvalue of type "pointer to member of B of type cv2 T", where B is a base class of D [...].

Definition at line 1497 of file SemaCast.cpp.

References clang::Sema::Context, clang::ActionResult< PtrTy, CompressInvalid >::get(), clang::Type::getAs(), clang::SourceRange::getBegin(), clang::MemberPointerType::getClass(), clang::TargetInfo::getCXXABI(), clang::ASTContext::getMemberPointerType(), clang::CXXMethodDecl::getParent(), clang::MemberPointerType::getPointeeType(), clang::ASTContext::getTargetInfo(), clang::ASTContext::getTypeDeclType(), clang::ASTContext::hasSameUnqualifiedType(), clang::Sema::isCompleteType(), clang::TargetCXXABI::isMicrosoft(), clang::ASTContext::OverloadTy, clang::Sema::ResolveAddressOfOverloadedFunction(), and TC_NotApplicable.

Referenced by TryStaticCast().

## ◆ TryStaticPointerDowncast()

TryCastResult TryStaticPointerDowncast | ( | Sema & | Self,
|  | QualType | SrcType,
|  | QualType | DestType,
|  | bool | CStyle,
|  | SourceRange | OpRange,
|  | unsigned & | msg,
|  | CastKind & | Kind,
|  | CXXCastPath & | BasePath
| ) |  |
| static

Tests whether a conversion according to C++ 5.2.9p8 is valid.

Definition at line 1351 of file SemaCast.cpp.

References clang::Sema::Context, clang::Type::getAs(), clang::ASTContext::getCanonicalType(), clang::PointerType::getPointeeType(), TC_NotApplicable, and TryStaticDowncast().

Referenced by TryStaticCast().

## ◆ TryStaticReferenceDowncast()

TryCastResult TryStaticReferenceDowncast | ( | Sema & | Self,
|  | Expr * | SrcExpr,
|  | QualType | DestType,
|  | bool | CStyle,
|  | SourceRange | OpRange,
|  | unsigned & | msg,
|  | CastKind & | Kind,
|  | CXXCastPath & | BasePath
| ) |  |
| static

Tests whether a conversion according to C++ 5.2.9p5 is valid.

Definition at line 1313 of file SemaCast.cpp.

References clang::Sema::Context, clang::Type::getAs(), clang::ASTContext::getCanonicalType(), clang::ReferenceType::getPointeeType(), clang::Expr::getType(), clang::Expr::isLValue(), clang::Type::isRValueReferenceType(), TC_NotApplicable, and TryStaticDowncast().

Referenced by TryStaticCast().

## ◆ unwrapCastAwayConstnessLevel()

static CastAwayConstnessKind unwrapCastAwayConstnessLevel | ( | ASTContext & | Context,
|  | QualType & | T1,
|  | QualType & | T2
| ) |  |
| static

Unwrap one level of types for CastsAwayConstness.

Like Sema::UnwrapSimilarTypes, this removes one level of indirection from both types, provided that they're both pointer-like or array-like. Unlike the Sema function, doesn't care if the unwrapped pieces are related.

This function may remove additional levels as necessary for correctness: the resulting T1 is unwrapped sufficiently that it is never an array type, so that its qualifiers can be directly compared to those of T2 (which will have the combined set of qualifiers from all indermediate levels of T2), as (effectively) required by [expr.const.cast]p7 replacing T1's qualifiers with those from T2.

Definition at line 482 of file SemaCast.cpp.

Referenced by CastsAwayConstness().