From: Fariborz Jahanian Date: Sat, 10 Jan 2009 18:43:55 +0000 (+0000) Subject: Explicit declaration of property setters over-ride X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=212921261b9904d5b21c85c68a57c2b0d3f72b14;p=clang Explicit declaration of property setters over-ride prohibition of 'readonly' properties in an assignment. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@62028 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/AST/DeclObjC.cpp b/lib/AST/DeclObjC.cpp index 56da9a6dfa..f39eec3dc5 100644 --- a/lib/AST/DeclObjC.cpp +++ b/lib/AST/DeclObjC.cpp @@ -257,7 +257,9 @@ void ObjCMethodDecl::setMethodParams(ParmVarDecl **NewParamInfo, /// bool ObjCInterfaceDecl::isPropertyReadonly(ObjCPropertyDecl *PDecl) const { - if (!PDecl->isReadOnly()) + // Even if property is ready only, if interface has a user defined setter, + // it is not considered read only. + if (!PDecl->isReadOnly() || getInstanceMethod(PDecl->getSetterName())) return false; // Main class has the property as 'readonly'. Must search @@ -265,6 +267,10 @@ bool ObjCInterfaceDecl::isPropertyReadonly(ObjCPropertyDecl *PDecl) const // attribute has been over-ridden to 'readwrite'. for (ObjCCategoryDecl *Category = getCategoryList(); Category; Category = Category->getNextClassCategory()) { + // Even if property is ready only, if a category has a user defined setter, + // it is not considered read only. + if (Category->getInstanceMethod(PDecl->getSetterName())) + return false; ObjCPropertyDecl *P = Category->FindPropertyDeclaration(PDecl->getIdentifier()); if (P && !P->isReadOnly()) diff --git a/test/SemaObjC/property-user-setter.m b/test/SemaObjC/property-user-setter.m new file mode 100644 index 0000000000..cb2091e8ce --- /dev/null +++ b/test/SemaObjC/property-user-setter.m @@ -0,0 +1,25 @@ +// RUN: clang -fsyntax-only -verify %s + +@interface I0 +@property(readonly) int x; +@property(readonly) int y; +@property(readonly) int z; +-(void) setY: (int) y0; +@end + +@interface I0 (Cat0) +-(void) setX: (int) a0; +@end + +@implementation I0 +@dynamic x; +@dynamic y; +@dynamic z; +-(void) setY: (int) y0{} + +-(void) im0 { + self.x = 0; + self.y = 2; + self.z = 2; // expected-error {{assigning to property with 'readonly' attribute not allowed}} +} +@end