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.

llvm-svn: 255943
This commit is contained in:
Douglas Gregor 2015-12-18 00:52:31 +00:00
parent 545304d323
commit 0253543c92
2 changed files with 23 additions and 0 deletions

View File

@ -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;
}

View File

@ -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<P>
@end
@interface I2()
@property (readwrite) id prop;
@end
@implementation I2
@synthesize prop;
@end