[cfe-commits] r62028 - in /cfe/trunk: lib/AST/DeclObjC.cpp test/SemaObjC/property-user-setter.m
Fariborz Jahanian
fjahanian at apple.com
Sat Jan 10 10:43:57 PST 2009
Author: fjahanian
Date: Sat Jan 10 12:43:55 2009
New Revision: 62028
URL: http://llvm.org/viewvc/llvm-project?rev=62028&view=rev
Log:
Explicit declaration of property setters over-ride
prohibition of 'readonly' properties in an assignment.
Added:
cfe/trunk/test/SemaObjC/property-user-setter.m
Modified:
cfe/trunk/lib/AST/DeclObjC.cpp
Modified: cfe/trunk/lib/AST/DeclObjC.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/DeclObjC.cpp?rev=62028&r1=62027&r2=62028&view=diff
==============================================================================
--- cfe/trunk/lib/AST/DeclObjC.cpp (original)
+++ cfe/trunk/lib/AST/DeclObjC.cpp Sat Jan 10 12:43:55 2009
@@ -257,7 +257,9 @@
///
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 @@
// 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())
Added: cfe/trunk/test/SemaObjC/property-user-setter.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaObjC/property-user-setter.m?rev=62028&view=auto
==============================================================================
--- cfe/trunk/test/SemaObjC/property-user-setter.m (added)
+++ cfe/trunk/test/SemaObjC/property-user-setter.m Sat Jan 10 12:43:55 2009
@@ -0,0 +1,25 @@
+// RUN: clang -fsyntax-only -verify %s
+
+ at interface I0
+ at property(readonly) int x;
+ at property(readonly) int y;
+ at property(readonly) int z;
+-(void) setY: (int) y0;
+ at end
+
+ at interface I0 (Cat0)
+-(void) setX: (int) a0;
+ at end
+
+ at implementation I0
+ at dynamic x;
+ at dynamic y;
+ at 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}}
+}
+ at end
More information about the cfe-commits
mailing list