[arcmt] Allow -retain of an __unsafe_unretained receiver if the result gets used.

Keep the error if the result is unused. rdar://9552694.

llvm-svn: 135209
This commit is contained in:
Argyrios Kyrtzidis 2011-07-14 22:46:12 +00:00
parent 5143181ff9
commit 08903e4c16
2 changed files with 3 additions and 1 deletions

View File

@ -70,7 +70,8 @@ public:
if (E->getReceiverKind() == ObjCMessageExpr::Instance)
if (Expr *rec = E->getInstanceReceiver()) {
rec = rec->IgnoreParenImpCasts();
if (rec->getType().getObjCLifetime() == Qualifiers::OCL_ExplicitNone){
if (rec->getType().getObjCLifetime() == Qualifiers::OCL_ExplicitNone &&
(E->getMethodFamily() != OMF_retain || isRemovable(E))) {
std::string err = "it is not safe to remove '";
err += E->getSelector().getAsString() + "' message on "
"an __unsafe_unretained type";

View File

@ -39,6 +39,7 @@ struct UnsafeS {
void test1(A *a, BOOL b, struct UnsafeS *unsafeS) {
[unsafeS->unsafeObj retain]; // expected-error {{it is not safe to remove 'retain' message on an __unsafe_unretained type}} \
// expected-error {{ARC forbids explicit message send}}
id foo = [unsafeS->unsafeObj retain]; // no warning.
[a dealloc];
[a retain];
[a retainCount]; // expected-error {{ARC forbids explicit message send of 'retainCount'}}