diff options
author | Fariborz Jahanian <fjahanian@apple.com> | 2011-10-29 00:06:10 +0000 |
---|---|---|
committer | Fariborz Jahanian <fjahanian@apple.com> | 2011-10-29 00:06:10 +0000 |
commit | 244b187d2221b8377295c311d2b79be5aa483af3 (patch) | |
tree | 3f6b9caf0b058577302ebe41c1bdfc7da6d52d17 /clang/lib/Sema/SemaExprObjC.cpp | |
parent | 53cafabac01e4d7000d48f2bb57aef32660f1ea0 (diff) | |
download | bcm5719-llvm-244b187d2221b8377295c311d2b79be5aa483af3.tar.gz bcm5719-llvm-244b187d2221b8377295c311d2b79be5aa483af3.zip |
objc-arc: desugar certain type and improve on diagnostic for
ownership qualifier cast which won't work.
// rdar://10244607
llvm-svn: 143258
Diffstat (limited to 'clang/lib/Sema/SemaExprObjC.cpp')
-rw-r--r-- | clang/lib/Sema/SemaExprObjC.cpp | 30 |
1 files changed, 20 insertions, 10 deletions
diff --git a/clang/lib/Sema/SemaExprObjC.cpp b/clang/lib/Sema/SemaExprObjC.cpp index edf8b720504..019dc817643 100644 --- a/clang/lib/Sema/SemaExprObjC.cpp +++ b/clang/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; } |