summaryrefslogtreecommitdiff
path: root/clang/lib/Sema/SemaCast.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'clang/lib/Sema/SemaCast.cpp')
-rw-r--r--clang/lib/Sema/SemaCast.cpp37
1 files changed, 20 insertions, 17 deletions
diff --git a/clang/lib/Sema/SemaCast.cpp b/clang/lib/Sema/SemaCast.cpp
index da43848a1a7d..d986e3b2b7ac 100644
--- a/clang/lib/Sema/SemaCast.cpp
+++ b/clang/lib/Sema/SemaCast.cpp
@@ -595,13 +595,11 @@ static void diagnoseBadCast(Sema &S, unsigned msg, CastType castType,
DifferentPtrness--;
}
if (!DifferentPtrness) {
- auto RecFrom = From->getAs<RecordType>();
- auto RecTo = To->getAs<RecordType>();
- if (RecFrom && RecTo) {
- auto DeclFrom = RecFrom->getAsCXXRecordDecl();
+ if (auto *DeclFrom = From->getAsCXXRecordDecl(),
+ *DeclTo = To->getAsCXXRecordDecl();
+ DeclFrom && DeclTo) {
if (!DeclFrom->isCompleteDefinition())
S.Diag(DeclFrom->getLocation(), diag::note_type_incomplete) << DeclFrom;
- auto DeclTo = RecTo->getAsCXXRecordDecl();
if (!DeclTo->isCompleteDefinition())
S.Diag(DeclTo->getLocation(), diag::note_type_incomplete) << DeclTo;
}
@@ -865,7 +863,7 @@ void CastOperation::CheckDynamicCast() {
return;
}
- const RecordType *DestRecord = DestPointee->getAs<RecordType>();
+ const auto *DestRecord = DestPointee->getAsCanonical<RecordType>();
if (DestPointee->isVoidType()) {
assert(DestPointer && "Reference to void is not possible");
} else if (DestRecord) {
@@ -912,7 +910,7 @@ void CastOperation::CheckDynamicCast() {
SrcPointee = SrcType;
}
- const RecordType *SrcRecord = SrcPointee->getAs<RecordType>();
+ const auto *SrcRecord = SrcPointee->getAsCanonical<RecordType>();
if (SrcRecord) {
if (Self.RequireCompleteType(OpRange.getBegin(), SrcPointee,
diag::err_bad_cast_incomplete,
@@ -1454,7 +1452,7 @@ static TryCastResult TryStaticCast(Sema &Self, ExprResult &SrcExpr,
// C++0x 5.2.9p9: A value of a scoped enumeration type can be explicitly
// converted to an integral type. [...] A value of a scoped enumeration type
// can also be explicitly converted to a floating-point type [...].
- if (const EnumType *Enum = SrcType->getAs<EnumType>()) {
+ if (const EnumType *Enum = dyn_cast<EnumType>(SrcType)) {
if (Enum->getOriginalDecl()->isScoped()) {
if (DestType->isBooleanType()) {
Kind = CK_IntegralToBoolean;
@@ -1486,8 +1484,7 @@ static TryCastResult TryStaticCast(Sema &Self, ExprResult &SrcExpr,
if (SrcType->isIntegralOrEnumerationType()) {
// [expr.static.cast]p10 If the enumeration type has a fixed underlying
// type, the value is first converted to that type by integral conversion
- const EnumType *Enum = DestType->castAs<EnumType>();
- const EnumDecl *ED = Enum->getOriginalDecl()->getDefinitionOrSelf();
+ const auto *ED = DestType->castAsEnumDecl();
Kind = ED->isFixed() && ED->getIntegerType()->isBooleanType()
? CK_IntegralToBoolean
: CK_IntegralCast;
@@ -1581,11 +1578,11 @@ static TryCastResult TryStaticCast(Sema &Self, ExprResult &SrcExpr,
// See if it looks like the user is trying to convert between
// related record types, and select a better diagnostic if so.
- if (auto SrcPointer = SrcType->getAs<PointerType>())
- if (auto DestPointer = DestType->getAs<PointerType>())
- if (SrcPointer->getPointeeType()->getAs<RecordType>() &&
- DestPointer->getPointeeType()->getAs<RecordType>())
- msg = diag::err_bad_cxx_cast_unrelated_class;
+ if (const auto *SrcPointer = SrcType->getAs<PointerType>())
+ if (const auto *DestPointer = DestType->getAs<PointerType>())
+ if (SrcPointer->getPointeeType()->isRecordType() &&
+ DestPointer->getPointeeType()->isRecordType())
+ msg = diag::err_bad_cxx_cast_unrelated_class;
if (SrcType->isMatrixType() && DestType->isMatrixType()) {
if (Self.CheckMatrixCast(OpRange, DestType, SrcType, Kind)) {
@@ -3097,7 +3094,8 @@ void CastOperation::CheckCStyleCast() {
if (!DestType->isScalarType() && !DestType->isVectorType() &&
!DestType->isMatrixType()) {
- if (const RecordType *DestRecordTy = DestType->getAs<RecordType>()) {
+ if (const RecordType *DestRecordTy =
+ DestType->getAsCanonical<RecordType>()) {
if (Self.Context.hasSameUnqualifiedType(DestType, SrcType)) {
// GCC struct/union extension: allow cast to self.
Self.Diag(OpRange.getBegin(), diag::ext_typecheck_cast_nonscalar)
@@ -3173,7 +3171,12 @@ void CastOperation::CheckCStyleCast() {
SrcExpr = ExprError();
return;
}
- if (!DestType->isNullPtrType()) {
+ if (DestType->isBooleanType()) {
+ SrcExpr = ImplicitCastExpr::Create(
+ Self.Context, DestType, CK_PointerToBoolean, SrcExpr.get(), nullptr,
+ VK_PRValue, Self.CurFPFeatureOverrides());
+
+ } else if (!DestType->isNullPtrType()) {
// Implicitly cast from the null pointer type to the type of the
// destination.
CastKind CK = DestType->isPointerType() ? CK_NullToPointer : CK_BitCast;