From: Fariborz Jahanian Date: Fri, 9 Dec 2011 19:55:11 +0000 (+0000) Subject: objc-arc: diagnose synthesis of a 'weak unavailable' property. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=6dce88d9f71cd4be18554af94145a9147b363199;p=clang objc-arc: diagnose synthesis of a 'weak unavailable' property. // rdar://10535245 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@146272 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/include/clang/Basic/DiagnosticSemaKinds.td b/include/clang/Basic/DiagnosticSemaKinds.td index 15824849e7..9d3bccbb9e 100644 --- a/include/clang/Basic/DiagnosticSemaKinds.td +++ b/include/clang/Basic/DiagnosticSemaKinds.td @@ -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">; diff --git a/lib/Sema/SemaObjCProperty.cpp b/lib/Sema/SemaObjCProperty.cpp index c47a305b96..e754e73377 100644 --- a/lib/Sema/SemaObjCProperty.cpp +++ b/lib/Sema/SemaObjCProperty.cpp @@ -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()) + 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); diff --git a/test/SemaObjC/arc-unavailable-for-weakref.m b/test/SemaObjC/arc-unavailable-for-weakref.m index fdf850206c..97566809d9 100644 --- a/test/SemaObjC/arc-unavailable-for-weakref.m +++ b/test/SemaObjC/arc-unavailable-for-weakref.m @@ -48,3 +48,17 @@ NOWEAK * 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