[cfe-commits] r65562 - in /cfe/trunk: lib/Sema/Sema.h lib/Sema/SemaDeclObjC.cpp test/SemaObjC/property-13.m
Steve Naroff
snaroff at apple.com
Thu Feb 26 11:11:32 PST 2009
Author: snaroff
Date: Thu Feb 26 13:11:32 2009
New Revision: 65562
URL: http://llvm.org/viewvc/llvm-project?rev=65562&view=rev
Log:
Fix <rdar://problem/6574319> clang issues error on 'readonly' property with a defaul setter attribute.
Needed to make isPropertyReadonly() non-const (for this fix to compile). I imagine there's a way to retain the const-ness, however I have more important fish to fry.
Added:
cfe/trunk/test/SemaObjC/property-13.m
Modified:
cfe/trunk/lib/Sema/Sema.h
cfe/trunk/lib/Sema/SemaDeclObjC.cpp
Modified: cfe/trunk/lib/Sema/Sema.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/Sema.h?rev=65562&r1=65561&r2=65562&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/Sema.h (original)
+++ cfe/trunk/lib/Sema/Sema.h Thu Feb 26 13:11:32 2009
@@ -887,7 +887,7 @@
NamespaceDecl *GetStdNamespace();
bool isPropertyReadonly(ObjCPropertyDecl *PropertyDecl,
- ObjCInterfaceDecl *IDecl) const;
+ ObjCInterfaceDecl *IDecl);
/// CheckProtocolMethodDefs - This routine checks unimplemented
/// methods declared in protocol, and those referenced by it.
Modified: cfe/trunk/lib/Sema/SemaDeclObjC.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDeclObjC.cpp?rev=65562&r1=65561&r2=65562&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaDeclObjC.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDeclObjC.cpp Thu Feb 26 13:11:32 2009
@@ -720,7 +720,7 @@
/// for the property in the class and in its categories and implementations
///
bool Sema::isPropertyReadonly(ObjCPropertyDecl *PDecl,
- ObjCInterfaceDecl *IDecl) const {
+ ObjCInterfaceDecl *IDecl) {
// by far the most common case.
if (!PDecl->isReadOnly())
return false;
@@ -758,6 +758,11 @@
return false;
}
}
+ // Lastly, look through the implementation (if one is in scope).
+ if (ObjCImplementationDecl *ImpDecl =
+ ObjCImplementations[IDecl->getIdentifier()])
+ if (ImpDecl->getInstanceMethod(PDecl->getSetterName()))
+ return false;
return true;
}
Added: cfe/trunk/test/SemaObjC/property-13.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaObjC/property-13.m?rev=65562&view=auto
==============================================================================
--- cfe/trunk/test/SemaObjC/property-13.m (added)
+++ cfe/trunk/test/SemaObjC/property-13.m Thu Feb 26 13:11:32 2009
@@ -0,0 +1,77 @@
+// RUN: clang -fsyntax-only -verify %s
+
+ at interface NSObject
++ alloc;
+- init;
+ at end
+
+ at protocol Test
+ @property int required;
+
+ at optional
+ @property int optional;
+ @property int optional1;
+ @property int optional_preexisting_setter_getter;
+ @property (setter = setOptional_preexisting_setter_getter: ,
+ getter = optional_preexisting_setter_getter) int optional_with_setter_getter_attr;
+ at required
+ @property int required1;
+ at optional
+ @property int optional_to_be_defined;
+ @property (readonly, getter = optional_preexisting_setter_getter) int optional_getter_attr;
+ at end
+
+ at interface Test : NSObject <Test> {
+ int ivar;
+ int ivar1;
+ int ivar2;
+}
+ at property int required;
+ at property int optional_to_be_defined;
+- (int) optional_preexisting_setter_getter;
+- (void) setOptional_preexisting_setter_getter:(int)value;
+ at end
+
+ at implementation Test
+ at synthesize required = ivar;
+ at synthesize required1 = ivar1;
+ at synthesize optional_to_be_defined = ivar2;
+- (int) optional_preexisting_setter_getter { return ivar; }
+- (void) setOptional_preexisting_setter_getter:(int)value
+ {
+ ivar = value;
+ }
+- (void) setOptional_getter_attr:(int)value { ivar = value; }
+ at end
+
+int main ()
+{
+ Test *x = [[Test alloc] init];
+ /* 1. Test of a requred property */
+ x.required1 = 100;
+ if (x.required1 != 100)
+ abort ();
+
+ /* 2. Test of a synthesize optional property */
+ x.optional_to_be_defined = 123;
+ if (x.optional_to_be_defined != 123)
+ abort ();
+
+ /* 3. Test of optional property with pre-sxisting defined setter/getter */
+ x.optional_preexisting_setter_getter = 200;
+ if (x.optional_preexisting_setter_getter != 200)
+ abort ();
+
+ /* 4. Test of optional property with setter/getter attribute */
+ if (x.optional_with_setter_getter_attr != 200)
+ abort ();
+ return 0;
+
+ /* 5. Test of optional property with getter attribute and default setter method. */
+ x.optional_getter_attr = 1000;
+ if (x.optional_getter_attr != 1000)
+ abort ();
+
+ return 0;
+}
+
More information about the cfe-commits
mailing list