ExprResult CXXCheckCStyleCast(SourceRange R, QualType CastTy, ExprValueKind &VK,
Expr *CastExpr, CastKind &Kind,
CXXCastPath &BasePath, bool FunctionalStyle);
-
+
+ /// \brief Checks for valid expressions which can be cast to an ObjC
+ /// pointer without needing a bridge cast.
+ bool ValidObjCARCNoBridgeCastExpr(const Expr *Exp);
+
/// \brief Checks for invalid conversions and casts between
/// retainable pointers and other pointer kinds.
void CheckObjCARCConversion(SourceRange castRange, QualType castType,
};
}
+bool
+Sema::ValidObjCARCNoBridgeCastExpr(const Expr *Exp) {
+ Exp = Exp->IgnoreParenImpCasts();
+ return isa<ObjCMessageExpr>(Exp) || isa<ObjCPropertyRefExpr>(Exp);
+}
+
void
Sema::CheckObjCARCConversion(SourceRange castRange, QualType castType,
Expr *castExpr, CheckedConversionKind CCK) {
if (castType->isObjCARCBridgableType() &&
castExprType->isCARCBridgableType()) {
+ // explicit unbridged casts are allowed if the source of the cast is a
+ // message sent to an objc method (or property access)
+ if (ValidObjCARCNoBridgeCastExpr(castExpr))
+ return;
Diag(loc, diag::err_arc_cast_requires_bridge)
<< 2
<< castExprType
--- /dev/null
+// // RUN: %clang_cc1 -triple x86_64-apple-darwin11 -fobjc-nonfragile-abi -fsyntax-only -fobjc-arc -verify %s
+// rdar://9744349
+
+typedef const struct __CFString * CFStringRef;
+
+@interface I
+@property CFStringRef P;
+@end
+
+@implementation I
+@synthesize P;
+- (id) Meth {
+ I* p1 = (id)[p1 P];
+ id p2 = (__bridge_transfer id)[p1 P];
+ id p3 = (__bridge I*)[p1 P];
+ return (id) p1.P;
+}
+@end