From: Douglas Gregor Date: Fri, 18 Dec 2015 00:52:31 +0000 (+0000) Subject: ObjC properties: consider ownership of properties from protocols when synthesizing. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=1a3cb157e1a1fc24fc64d782b5c54b03f5c6313f;p=clang ObjC properties: consider ownership of properties from protocols when synthesizing. When determining whether ownership was explicitly written for a property when it is being synthesized, also consider that the original property might have come from a protocol. Fixes rdar://problem/23931441. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@255943 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Sema/SemaObjCProperty.cpp b/lib/Sema/SemaObjCProperty.cpp index f42daced86..1cb84e4480 100644 --- a/lib/Sema/SemaObjCProperty.cpp +++ b/lib/Sema/SemaObjCProperty.cpp @@ -868,6 +868,13 @@ static bool hasWrittenStorageAttribute(ObjCPropertyDecl *Prop) { return OrigProp->getPropertyAttributesAsWritten() & OwnershipMask; } + // Look through all of the protocols. + for (const auto *Proto : OrigClass->all_referenced_protocols()) { + if (ObjCPropertyDecl *OrigProp = + Proto->FindPropertyDeclaration(Prop->getIdentifier())) + return OrigProp->getPropertyAttributesAsWritten() & OwnershipMask; + } + return false; } diff --git a/test/SemaObjC/arc-property-decl-attrs.m b/test/SemaObjC/arc-property-decl-attrs.m index 408b270920..6c96ba481c 100644 --- a/test/SemaObjC/arc-property-decl-attrs.m +++ b/test/SemaObjC/arc-property-decl-attrs.m @@ -105,3 +105,19 @@ @property(nonatomic, weak, nonnull, readonly) id ROdelegate; // expected-error {{property attributes 'nonnull' and 'weak' are mutually exclusive}} @end +// rdar://problem/23931441 +@protocol P +@property(readonly, retain) id prop; +@end + +__attribute__((objc_root_class)) +@interface I2

+@end + +@interface I2() +@property (readwrite) id prop; +@end + +@implementation I2 +@synthesize prop; +@end