]> granicus.if.org Git - clang/commitdiff
ObjectiveC arc. Warn when an implicitly 'strong' property
authorFariborz Jahanian <fjahanian@apple.com>
Sat, 26 Oct 2013 00:35:39 +0000 (00:35 +0000)
committerFariborz Jahanian <fjahanian@apple.com>
Sat, 26 Oct 2013 00:35:39 +0000 (00:35 +0000)
is redeclared as 'weak' in class extension.
// rdar://15304886

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

include/clang/Basic/DiagnosticSemaKinds.td
lib/Sema/SemaObjCProperty.cpp
test/SemaObjC/arc-decls.m

index e2fedbbbab8ea3b3ef7d5d2608473a4363b7520e..c90b54600a4c26da95e13822505b6991533f16ca 100644 (file)
@@ -678,6 +678,10 @@ def warn_objc_property_default_assign_on_object : Warning<
   InGroup<ObjCPropertyNoAttribute>;
 def warn_property_attr_mismatch : Warning<
   "property attribute in class extension does not match the primary class">;
+def warn_property_implicitly_mismatched : Warning <
+  "primary property declaration is implicitly strong while redeclaration "
+  "in class extension is weak">,
+  InGroup<DiagGroup<"objc-property-implicit-mismatch">>;
 def warn_objc_property_copy_missing_on_block : Warning<
     "'copy' attribute must be specified for the block property "
     "when -fobjc-gc-only is specified">;
index 8658b687c1cc29ad504d55488b05ded8b6fa19fa..9d18c659c27eced3f364c0dd158e24e8bbf48b9f 100644 (file)
@@ -459,6 +459,20 @@ Sema::HandlePropertyInClassExtension(Scope *S,
       Diag(AtLoc, diag::warn_property_attr_mismatch);
       Diag(PIDecl->getLocation(), diag::note_property_declare);
     }
+    else if (getLangOpts().ObjCAutoRefCount) {
+      QualType PrimaryPropertyQT =
+        Context.getCanonicalType(PIDecl->getType()).getUnqualifiedType();
+      if (isa<ObjCObjectPointerType>(PrimaryPropertyQT)) {
+        Qualifiers::ObjCLifetime PrimaryPropertyLifeTime =
+          PrimaryPropertyQT.getObjCLifetime();
+        if (PrimaryPropertyLifeTime == Qualifiers::OCL_None &&
+            (Attributes & ObjCDeclSpec::DQ_PR_weak)) {
+              Diag(AtLoc, diag::warn_property_implicitly_mismatched);
+              Diag(PIDecl->getLocation(), diag::note_property_declare);
+            }
+        }
+    }
+    
     DeclContext *DC = cast<DeclContext>(CCPrimary);
     if (!ObjCPropertyDecl::findPropertyDecl(DC,
                                  PIDecl->getDeclName().getAsIdentifierInfo())) {
index 3d0ef686f96b765a73b73864922e604e9538e36c..f8e80c781945acb0260ad99bc0b0333068bf9730 100644 (file)
@@ -105,3 +105,16 @@ struct __attribute__((objc_ownership(none))) S2 {}; // expected-error {{'objc_ow
 @interface I2
     @property __attribute__((objc_ownership(frob))) id i; // expected-warning {{'objc_ownership' attribute argument not supported: 'frob'}}
 @end
+
+// rdar://15304886
+@interface NSObject @end
+
+@interface ControllerClass : NSObject @end
+
+@interface SomeClassOwnedByController
+@property (readonly) ControllerClass *controller; // expected-note {{property declared here}}
+@end
+
+@interface SomeClassOwnedByController ()
+@property (readwrite, weak) ControllerClass *controller; // expected-warning {{primary property declaration is implicitly strong while redeclaration in class extension is weak}}
+@end