clang API Documentation

SemaCXXCast.cpp File Reference

#include "clang/Sema/SemaInternal.h"
#include "clang/Sema/Initialization.h"
#include "clang/AST/ExprCXX.h"
#include "clang/AST/ExprObjC.h"
#include "clang/AST/ASTContext.h"
#include "clang/AST/CXXInheritance.h"
#include "clang/Basic/PartialDiagnostic.h"
#include "llvm/ADT/SmallVector.h"
#include <set>
Include dependency graph for SemaCXXCast.cpp:

Go to the source code of this file.

Enumerations

enum  TryCastResult { TC_NotApplicable, TC_Success, TC_Failed }
enum  CastType {
  CT_Const, CT_Static, CT_Reinterpret, CT_Dynamic,
  CT_CStyle, CT_Functional
}

Functions

static bool CastsAwayConstness (Sema &Self, QualType SrcType, QualType DestType, bool CheckCVR, bool CheckObjCLifetime)
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.
static TryCastResult TryStaticReferenceDowncast (Sema &Self, Expr *SrcExpr, QualType DestType, bool CStyle, const SourceRange &OpRange, unsigned &msg, CastKind &Kind, CXXCastPath &BasePath)
 Tests whether a conversion according to C++ 5.2.9p5 is valid.
static TryCastResult TryStaticPointerDowncast (Sema &Self, QualType SrcType, QualType DestType, bool CStyle, const SourceRange &OpRange, unsigned &msg, CastKind &Kind, CXXCastPath &BasePath)
 Tests whether a conversion according to C++ 5.2.9p8 is valid.
static TryCastResult TryStaticDowncast (Sema &Self, CanQualType SrcType, CanQualType DestType, bool CStyle, const SourceRange &OpRange, QualType OrigSrcType, QualType OrigDestType, unsigned &msg, CastKind &Kind, CXXCastPath &BasePath)
static TryCastResult TryStaticMemberPointerUpcast (Sema &Self, ExprResult &SrcExpr, QualType SrcType, QualType DestType, bool CStyle, const SourceRange &OpRange, unsigned &msg, CastKind &Kind, CXXCastPath &BasePath)
static TryCastResult TryStaticImplicitCast (Sema &Self, ExprResult &SrcExpr, QualType DestType, Sema::CheckedConversionKind CCK, const SourceRange &OpRange, unsigned &msg, CastKind &Kind)
static TryCastResult TryStaticCast (Sema &Self, ExprResult &SrcExpr, QualType DestType, Sema::CheckedConversionKind CCK, const SourceRange &OpRange, unsigned &msg, CastKind &Kind, CXXCastPath &BasePath)
static TryCastResult TryConstCast (Sema &Self, Expr *SrcExpr, QualType DestType, bool CStyle, unsigned &msg)
static TryCastResult TryReinterpretCast (Sema &Self, ExprResult &SrcExpr, QualType DestType, bool CStyle, const SourceRange &OpRange, unsigned &msg, CastKind &Kind)
static bool tryDiagnoseOverloadedCast (Sema &S, CastType CT, SourceRange range, Expr *src, QualType destType)
static void diagnoseBadCast (Sema &S, unsigned msg, CastType castType, SourceRange opRange, Expr *src, QualType destType)
 Diagnose a failed cast.
static bool UnwrapDissimilarPointerTypes (QualType &T1, QualType &T2)

Enumeration Type Documentation

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 34 of file SemaCXXCast.cpp.

Enumerator:
TC_NotApplicable 

The cast method is not applicable.

TC_Success 

The cast method is appropriate and successful.

TC_Failed 

The cast method is appropriate, but failed. A diagnostic has been emitted.

Definition at line 27 of file SemaCXXCast.cpp.


Function Documentation

static bool CastsAwayConstness ( Sema Self,
QualType  SrcType,
QualType  DestType,
bool  CheckCVR,
bool  CheckObjCLifetime 
) [static]

CastsAwayConstness - Check if the pointer conversion from SrcType to DestType casts away constness as defined in C++ 5.2.11p8ff. 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 439 of file SemaCXXCast.cpp.

References clang::Qualifiers::compatiblyIncludesObjCLifetime(), clang::Sema::Context, clang::ASTContext::getCanonicalType(), clang::Qualifiers::getCVRQualifiers(), clang::ASTContext::getLangOptions(), clang::ASTContext::getPointerType(), clang::ASTContext::getQualifiedType(), clang::ASTContext::getUnqualifiedArrayType(), clang::Sema::IsQualificationConversion(), clang::Qualifiers::setCVRQualifiers(), UnwrapDissimilarPointerTypes(), and clang::ASTContext::VoidTy.

Referenced by TryReinterpretCast().

static void diagnoseBadCast ( Sema S,
unsigned  msg,
CastType  castType,
SourceRange  opRange,
Expr src,
QualType  destType 
) [static]
static TryCastResult TryConstCast ( Sema Self,
Expr SrcExpr,
QualType  DestType,
bool  CStyle,
unsigned &  msg 
) [static]
static bool tryDiagnoseOverloadedCast ( Sema S,
CastType  CT,
SourceRange  range,
Expr src,
QualType  destType 
) [static]
TryCastResult TryLValueToRValueCast ( Sema Self,
Expr SrcExpr,
QualType  DestType,
bool  CStyle,
CastKind Kind,
CXXCastPath BasePath,
unsigned &  msg 
) [static]
static TryCastResult TryReinterpretCast ( Sema Self,
ExprResult SrcExpr,
QualType  DestType,
bool  CStyle,
const SourceRange OpRange,
unsigned &  msg,
CastKind Kind 
) [static]
static TryCastResult TryStaticCast ( Sema Self,
ExprResult SrcExpr,
QualType  DestType,
Sema::CheckedConversionKind  CCK,
const SourceRange OpRange,
unsigned &  msg,
CastKind Kind,
CXXCastPath BasePath 
) [static]
TryCastResult TryStaticDowncast ( Sema Self,
CanQualType  SrcType,
CanQualType  DestType,
bool  CStyle,
const SourceRange OpRange,
QualType  OrigSrcType,
QualType  OrigDestType,
unsigned &  msg,
CastKind Kind,
CXXCastPath BasePath 
) [static]
TryCastResult TryStaticImplicitCast ( Sema Self,
ExprResult SrcExpr,
QualType  DestType,
Sema::CheckedConversionKind  CCK,
const SourceRange OpRange,
unsigned &  msg,
CastKind Kind 
) [static]
TryCastResult TryStaticMemberPointerUpcast ( Sema Self,
ExprResult SrcExpr,
QualType  SrcType,
QualType  DestType,
bool  CStyle,
const SourceRange OpRange,
unsigned &  msg,
CastKind Kind,
CXXCastPath BasePath 
) [static]
TryCastResult TryStaticPointerDowncast ( Sema Self,
QualType  SrcType,
QualType  DestType,
bool  CStyle,
const SourceRange OpRange,
unsigned &  msg,
CastKind Kind,
CXXCastPath BasePath 
) [static]

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

Definition at line 1007 of file SemaCXXCast.cpp.

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

Referenced by TryStaticCast().

TryCastResult TryStaticReferenceDowncast ( Sema Self,
Expr SrcExpr,
QualType  DestType,
bool  CStyle,
const SourceRange OpRange,
unsigned &  msg,
CastKind Kind,
CXXCastPath BasePath 
) [static]
static bool UnwrapDissimilarPointerTypes ( QualType T1,
QualType T2 
) [static]

UnwrapDissimilarPointerTypes - Like Sema::UnwrapSimilarPointerTypes, this removes one level of indirection from both types, provided that they're the same kind of pointer (plain or to-member). Unlike the Sema function, this one doesn't care if the two pointers-to-member don't point into the same class. This is because CastsAwayConstness doesn't care.

Definition at line 379 of file SemaCXXCast.cpp.

References clang::BlockPointerType::getPointeeType(), clang::MemberPointerType::getPointeeType(), clang::ObjCObjectPointerType::getPointeeType(), and clang::PointerType::getPointeeType().

Referenced by CastsAwayConstness().