aboutsummaryrefslogtreecommitdiff
path: root/lib/Sema/SemaExprObjC.cpp
diff options
context:
space:
mode:
authorFariborz Jahanian <fjahanian@apple.com>2011-10-29 00:06:10 +0000
committerFariborz Jahanian <fjahanian@apple.com>2011-10-29 00:06:10 +0000
commitfc2eff57d7497578e8f08a5ee520ad3886a51186 (patch)
treea9844f1898f90dca3915c2c713563e8426711b3b /lib/Sema/SemaExprObjC.cpp
parent839046a8c5f890f172b0a172ed6ec9e7d0275f2e (diff)
objc-arc: desugar certain type and improve on diagnostic for
ownership qualifier cast which won't work. // rdar://10244607 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@143258 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Sema/SemaExprObjC.cpp')
-rw-r--r--lib/Sema/SemaExprObjC.cpp30
1 files changed, 20 insertions, 10 deletions
diff --git a/lib/Sema/SemaExprObjC.cpp b/lib/Sema/SemaExprObjC.cpp
index edf8b72050..019dc81764 100644
--- a/lib/Sema/SemaExprObjC.cpp
+++ b/lib/Sema/SemaExprObjC.cpp
@@ -1937,17 +1937,27 @@ Sema::CheckObjCARCConversion(SourceRange castRange, QualType castType,
if (exprACTC == castACTC) {
// check for viablity and report error if casting an rvalue to a
// life-time qualifier.
- if ((castACTC == ACTC_retainable) &&
- isa<AttributedType>(castType) &&
- (castType.getObjCLifetime() != Qualifiers::OCL_None) &&
+ if ((castACTC == ACTC_retainable) &&
(CCK == CCK_CStyleCast || CCK == CCK_OtherCast) &&
- castType != castExprType) {
- SourceLocation loc =
- (castRange.isValid() ? castRange.getBegin()
- : castExpr->getExprLoc());
- Diag(loc, diag::err_arc_nolifetime_behavior)
- << effCastType << castExprType
- << castRange << castExpr->getSourceRange();
+ (castType != castExprType)) {
+ const Type *DT = castType.getTypePtr();
+ QualType QDT = castType;
+ // We desugar some types but not others. We ignore those
+ // that cannot happen in a cast; i.e. auto, and those which
+ // should not be de-sugared; i.e typedef.
+ if (const ParenType *PT = dyn_cast<ParenType>(DT))
+ QDT = PT->desugar();
+ else if (const TypeOfType *TP = dyn_cast<TypeOfType>(DT))
+ QDT = TP->desugar();
+ else if (const AttributedType *AT = dyn_cast<AttributedType>(DT))
+ QDT = AT->desugar();
+ if (QDT != castType &&
+ QDT.getObjCLifetime() != Qualifiers::OCL_None) {
+ SourceLocation loc =
+ (castRange.isValid() ? castRange.getBegin()
+ : castExpr->getExprLoc());
+ Diag(loc, diag::err_arc_nolifetime_behavior);
+ }
}
return ACR_okay;
}