diff --git a/expr.cpp b/expr.cpp index 5be578eb..1b739a9a 100644 --- a/expr.cpp +++ b/expr.cpp @@ -6962,9 +6962,9 @@ TypeCastExpr::GetValue(FunctionEmitContext *ctx) const { return ctx->BitCastInst(v, ptype); //, "array_cast_0size"); } - AssertPos(pos, Type::Equal(toTarget, fromTarget) || - Type::Equal(toTarget, fromTarget->GetAsConstType())); - return expr->GetValue(ctx); + // Just bitcast it. See Issue #721 + llvm::Value *value = expr->GetValue(ctx); + return ctx->BitCastInst(value, toType->LLVMType(g->ctx), "refcast"); } const StructType *toStruct = CastType(toType); @@ -7170,6 +7170,14 @@ TypeCastExpr::TypeCheck() { // allow explicit typecasts between any two different pointer types return this; + const ReferenceType *fromRef = CastType(fromType); + const ReferenceType *toRef = CastType(toType); + if (fromRef != NULL && toRef != NULL) { + // allow explicit typecasts between any two different reference types + // Issues #721 + return this; + } + const AtomicType *fromAtomic = CastType(fromType); const AtomicType *toAtomic = CastType(toType); const EnumType *fromEnum = CastType(fromType);