diff --git a/clang/lib/AST/DeclObjC.cpp b/clang/lib/AST/DeclObjC.cpp index 194544f9fa81a0f0693cff6a77eed0cda14d8755..cf3bd0abeaf43288bb293643212001eda1a6ede7 100644 --- a/clang/lib/AST/DeclObjC.cpp +++ b/clang/lib/AST/DeclObjC.cpp @@ -252,24 +252,26 @@ void ObjCMethodDecl::setMethodParams(ParmVarDecl **NewParamInfo, } } -/// isPropertyReadonly - Return true if property is a readonly, by seaching +/// isPropertyReadonly - Return true if property is readonly, by searching /// for the property in the class and in its categories. /// bool ObjCInterfaceDecl::isPropertyReadonly(ObjCPropertyDecl *PDecl) const { - if (PDecl->isReadOnly()) { - // Main class has the property as 'readyonly'. Must search - // through the category list to see if the property's - // attribute has been over-ridden to 'readwrite'. - for (ObjCCategoryDecl *Category = getCategoryList(); - Category; Category = Category->getNextClassCategory()) { - PDecl= Category->FindPropertyDeclaration(PDecl->getIdentifier()); - if (PDecl && !PDecl->isReadOnly()) - return false; - } - return true; + if (!PDecl->isReadOnly()) + return false; + + // Main class has the property as 'readonly'. Must search + // through the category list to see if the property's + // attribute has been over-ridden to 'readwrite'. + for (ObjCCategoryDecl *Category = getCategoryList(); + Category; Category = Category->getNextClassCategory()) { + ObjCPropertyDecl *P = + Category->FindPropertyDeclaration(PDecl->getIdentifier()); + if (P && !P->isReadOnly()) + return false; } - return false; + + return true; } /// FindPropertyDeclaration - Finds declaration of the property given its name diff --git a/clang/test/SemaObjC/property-category-1.m b/clang/test/SemaObjC/property-category-1.m index 32e14f00c19ddda78a2d2f251c2c94bc845d2a47..926f964202508ba05b7e39e533551ce04eb45b3e 100644 --- a/clang/test/SemaObjC/property-category-1.m +++ b/clang/test/SemaObjC/property-category-1.m @@ -33,3 +33,20 @@ int main(int argc, char **argv) { return test.object - 12345 + test.Anotherobject - 200; } +/// + +@interface I0 +@property(readonly) int p0; +@end + +@interface I0 (Cat0) +@end + +@interface I0 (Cat1) +@end + +@implementation I0 +- (void) foo { + self.p0 = 0; // expected-error {{assigning to property with 'readonly' attribute not allowed}} +} +@end