From: Fariborz Jahanian Date: Sat, 26 Oct 2013 00:35:39 +0000 (+0000) Subject: ObjectiveC arc. Warn when an implicitly 'strong' property X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=9d9a9436246160fe1dc3fe768ba5f69874d4b6ed;p=clang ObjectiveC arc. Warn when an implicitly 'strong' property 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 --- diff --git a/include/clang/Basic/DiagnosticSemaKinds.td b/include/clang/Basic/DiagnosticSemaKinds.td index e2fedbbbab..c90b54600a 100644 --- a/include/clang/Basic/DiagnosticSemaKinds.td +++ b/include/clang/Basic/DiagnosticSemaKinds.td @@ -678,6 +678,10 @@ def warn_objc_property_default_assign_on_object : Warning< InGroup; 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>; def warn_objc_property_copy_missing_on_block : Warning< "'copy' attribute must be specified for the block property " "when -fobjc-gc-only is specified">; diff --git a/lib/Sema/SemaObjCProperty.cpp b/lib/Sema/SemaObjCProperty.cpp index 8658b687c1..9d18c659c2 100644 --- a/lib/Sema/SemaObjCProperty.cpp +++ b/lib/Sema/SemaObjCProperty.cpp @@ -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(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(CCPrimary); if (!ObjCPropertyDecl::findPropertyDecl(DC, PIDecl->getDeclName().getAsIdentifierInfo())) { diff --git a/test/SemaObjC/arc-decls.m b/test/SemaObjC/arc-decls.m index 3d0ef686f9..f8e80c7819 100644 --- a/test/SemaObjC/arc-decls.m +++ b/test/SemaObjC/arc-decls.m @@ -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