]> granicus.if.org Git - clang/commitdiff
objective-C arc: don't issue no explicit ownership warning when
authorFariborz Jahanian <fjahanian@apple.com>
Wed, 12 Sep 2012 20:34:47 +0000 (20:34 +0000)
committerFariborz Jahanian <fjahanian@apple.com>
Wed, 12 Sep 2012 20:34:47 +0000 (20:34 +0000)
__autoreleasing is explicitely added to param type.
// rdar://12280826

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@163738 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Sema/SemaDeclObjC.cpp
test/SemaObjC/arc-objc-lifetime.m

index e81429cc4c77538a19538926e1b300c68d639452..2dc2b0cba1b4206fa37eccb2cc1da586316cc493 100644 (file)
@@ -282,11 +282,10 @@ void Sema::AddAnyMethodToGlobalPool(Decl *D) {
     AddFactoryMethodToGlobalPool(MDecl, true);
 }
 
-/// StrongPointerToObjCPointer - returns true when pointer to ObjC pointer
-/// is __strong, or when it is any other type. It returns false when
-/// pointer to ObjC pointer is not __strong.
+/// HasExplicitOwnershipAttr - returns true when pointer to ObjC pointer
+/// has explicit ownership attribute; false otherwise.
 static bool
-StrongPointerToObjCPointer(Sema &S, ParmVarDecl *Param) {
+HasExplicitOwnershipAttr(Sema &S, ParmVarDecl *Param) {
   QualType T = Param->getType();
   if (!T->isObjCIndirectLifetimeType())
     return true;
@@ -296,8 +295,11 @@ StrongPointerToObjCPointer(Sema &S, ParmVarDecl *Param) {
         ? T->getAs<PointerType>()->getPointeeType() 
         : T->getAs<ReferenceType>()->getPointeeType();
   if (T->isObjCLifetimeType()) {
-    Qualifiers::ObjCLifetime lifetime = T.getObjCLifetime();
-    return lifetime == Qualifiers::OCL_Strong;
+    // when lifetime is Qualifiers::OCL_None it means that it has
+    // no implicit ownership qualifier (which means it is explicit).
+    Qualifiers::ObjCLifetime lifetime = 
+      T.getLocalQualifiers().getObjCLifetime();
+    return lifetime == Qualifiers::OCL_None;
   }
   return true;
 }
@@ -335,7 +337,7 @@ void Sema::ActOnStartOfObjCMethodDef(Scope *FnBodyScope, Decl *D) {
           Param->setInvalidDecl();
     if (!Param->isInvalidDecl() &&
         getLangOpts().ObjCAutoRefCount &&
-        !StrongPointerToObjCPointer(*this, Param))
+        !HasExplicitOwnershipAttr(*this, Param))
       Diag(Param->getLocation(), diag::warn_arc_strong_pointer_objc_pointer) <<
             Param->getType();
     
index d47428d1d60729e4435e51655b62bb953e4efcba..08d2dbe16c87479496a979fe5c7dd84db07208c9 100644 (file)
@@ -56,3 +56,14 @@ typedef void (^T) ();
 - (void) N : (__strong NSObject***) arg0 : (__strong NSObject<P>***)arg : (float**) arg1 : (double) arg2 {} 
 - (void) BLOCK : (T*) arg0 : (T)arg  : (__strong T*) arg1 {} // expected-warning {{method parameter of type '__autoreleasing T *' (aka 'void (^__autoreleasing *)()') with no explicit ownership}}
 @end
+
+// rdar://12280826
+@class NSMutableDictionary, NSError;
+@interface Radar12280826
+- (void)createInferiorTransportAndSetEnvironment:(NSMutableDictionary*)environment error:(__autoreleasing NSError**)error;
+@end
+
+@implementation Radar12280826
+- (void)createInferiorTransportAndSetEnvironment:(NSMutableDictionary*)environment error:(__autoreleasing NSError**)error {}
+@end
+