]> granicus.if.org Git - clang/commitdiff
objc-arc: diagnose synthesis of a 'weak unavailable' property.
authorFariborz Jahanian <fjahanian@apple.com>
Fri, 9 Dec 2011 19:55:11 +0000 (19:55 +0000)
committerFariborz Jahanian <fjahanian@apple.com>
Fri, 9 Dec 2011 19:55:11 +0000 (19:55 +0000)
// rdar://10535245

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

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

index 15824849e79581004d04f2400cc568246173175f..9d3bccbb9e03f13eadabadda0d501636280c39c9 100644 (file)
@@ -3066,6 +3066,9 @@ def err_arc_unsupported_weak_class : Error<
   "class is incompatible with __weak references">;
 def err_arc_weak_unavailable_assign : Error<
   "assignment of a weak-unavailable object to a __weak object">;
+def err_arc_weak_unavailable_property : Error<
+  "synthesis of a weak-unavailable property is disallowed "
+  "because it requires synthesis of an ivar of the __weak object">;
 def err_arc_convesion_of_weak_unavailable : Error<
   "%select{implicit conversion|cast}0 of weak-unavailable object of type %1 to"
   " a __weak object of type %2">;
index c47a305b9672dffcf1c1293a5fe4467e00b0dc16..e754e7337798e9313eeac2a40fb310b76f3d5e72 100644 (file)
@@ -648,13 +648,21 @@ Decl *Sema::ActOnPropertyImplDecl(Scope *S,
           Qualifiers::ObjCLifetime lifetime =
             getImpliedARCOwnership(kind, PropertyIvarType);
           assert(lifetime && "no lifetime for property?");
-
-          if (lifetime == Qualifiers::OCL_Weak &&
-              !getLangOptions().ObjCRuntimeHasWeak) {
-            Diag(PropertyLoc, diag::err_arc_weak_no_runtime);
-            Diag(property->getLocation(), diag::note_property_declare);
+          if (lifetime == Qualifiers::OCL_Weak) {
+            bool err = false;
+            if (const ObjCObjectPointerType *ObjT =
+                PropertyIvarType->getAs<ObjCObjectPointerType>())
+              if (ObjT->getInterfaceDecl()->isArcWeakrefUnavailable()) {
+                Diag(PropertyLoc, diag::err_arc_weak_unavailable_property);
+                Diag(property->getLocation(), diag::note_property_declare);
+                err = true;
+              }
+            if (!err && !getLangOptions().ObjCRuntimeHasWeak) {
+              Diag(PropertyLoc, diag::err_arc_weak_no_runtime);
+              Diag(property->getLocation(), diag::note_property_declare);
+            }
           }
-
+          
           Qualifiers qs;
           qs.addObjCLifetime(lifetime);
           PropertyIvarType = Context.getQualifiedType(PropertyIvarType, qs);   
index fdf850206c2deaa8b26652474d99c0fbaaa75102..97566809d9db7e77cd6a39ba74c76f0ba122892f 100644 (file)
@@ -48,3 +48,17 @@ NOWEAK<P, P1> * Test2() {
                                 // expected-error {{explicit ownership qualifier on cast result has no effect}}
 }
 
+// rdar://10535245
+__attribute__((objc_arc_weak_reference_unavailable))
+@interface NSFont
+@end
+
+@interface I
+{
+}
+@property (weak) NSFont *font; // expected-note {{property declared here}}
+@end
+
+@implementation I
+@synthesize font = _font; // expected-error {{synthesis of a weak-unavailable property is disallowed because it requires synthesis of an ivar of the __weak object}}
+@end