diff options
author | Fariborz Jahanian <fjahanian@apple.com> | 2011-07-07 23:04:17 +0000 |
---|---|---|
committer | Fariborz Jahanian <fjahanian@apple.com> | 2011-07-07 23:04:17 +0000 |
commit | 7a084ec568f8336ec6f10011d0118a6b19e253cb (patch) | |
tree | 1c49bba913aae0ad3cdb8d6187df00c335b06740 /lib/Sema/SemaExpr.cpp | |
parent | 7c9adf9113b1d1dfeca1d265a7c3bedb3671cfab (diff) |
objc++-arc: diagnose assignment/cast of a weak-unavailable
object to a __weak object/type. // rdar://9732636.
One item is yet todo.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@134655 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Sema/SemaExpr.cpp')
-rw-r--r-- | lib/Sema/SemaExpr.cpp | 32 |
1 files changed, 11 insertions, 21 deletions
diff --git a/lib/Sema/SemaExpr.cpp b/lib/Sema/SemaExpr.cpp index cf03684c67..fea31aa046 100644 --- a/lib/Sema/SemaExpr.cpp +++ b/lib/Sema/SemaExpr.cpp @@ -4066,22 +4066,12 @@ ExprResult Sema::CheckCastTypes(SourceLocation CastStartLoc, SourceRange TyR, } } } - else { - QualType canCastType = - Context.getCanonicalType(castType).getUnqualifiedType(); - if (isa<ObjCObjectPointerType>(canCastType) && - castType.getObjCLifetime() == Qualifiers::OCL_Weak && - castExprType->isObjCObjectPointerType()) { - if (const ObjCObjectPointerType *ObjT = - castExprType->getAs<ObjCObjectPointerType>()) - if (ObjT->getInterfaceDecl()->isArcWeakrefUnavailable()) { - Diag(castExpr->getLocStart(), - diag::err_arc_cast_of_weak_unavailable) + else if (!CheckObjCARCUnavailableWeakConversion(castType, castExprType)) { + Diag(castExpr->getLocStart(), + diag::err_arc_cast_of_weak_unavailable) << castExprType << castType << castExpr->getSourceRange(); - return ExprError(); - } - } + return ExprError(); } } @@ -5300,12 +5290,8 @@ Sema::CheckAssignmentConstraints(QualType lhsType, ExprResult &rhs, checkObjCPointerTypesForAssignment(*this, lhsType, rhsType); if (getLangOptions().ObjCAutoRefCount && result == Compatible && - origLhsType.getObjCLifetime() == Qualifiers::OCL_Weak) { - if (const ObjCObjectPointerType *ObjT = - rhsType->getAs<ObjCObjectPointerType>()) - if (ObjT->getInterfaceDecl()->isArcWeakrefUnavailable()) - result = IncompatibleObjCWeakRef; - } + !CheckObjCARCUnavailableWeakConversion(origLhsType, rhsType)) + result = IncompatibleObjCWeakRef; return result; } @@ -5474,8 +5460,12 @@ Sema::CheckSingleAssignmentConstraints(QualType lhsType, ExprResult &rExpr) { AA_Assigning); if (Res.isInvalid()) return Incompatible; + Sema::AssignConvertType result = Compatible; + if (getLangOptions().ObjCAutoRefCount && + !CheckObjCARCUnavailableWeakConversion(lhsType, rExpr.get()->getType())) + result = IncompatibleObjCWeakRef; rExpr = move(Res); - return Compatible; + return result; } // FIXME: Currently, we fall through and treat C++ classes like C |