]> granicus.if.org Git - clang/commitdiff
Fix <rdar://problem/6574319> clang issues error on 'readonly' property with a defaul...
authorSteve Naroff <snaroff@apple.com>
Thu, 26 Feb 2009 19:11:32 +0000 (19:11 +0000)
committerSteve Naroff <snaroff@apple.com>
Thu, 26 Feb 2009 19:11:32 +0000 (19:11 +0000)
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.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@65562 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Sema/Sema.h
lib/Sema/SemaDeclObjC.cpp
test/SemaObjC/property-13.m [new file with mode: 0644]

index 533386cab55993dcc52ddd966125356c26c1a111..25f2164ed071cda9e983dd4876db8302751ec4ff 100644 (file)
@@ -887,7 +887,7 @@ public:
   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.
index b3644a5ab9c0e7d9c9843f0a6ef9d579e6aefcc8..cb35890b3f1c96d52e476050b41bb059f5d6999b 100644 (file)
@@ -720,7 +720,7 @@ void Sema::WarnConflictingTypedMethods(ObjCMethodDecl *ImpMethodDecl,
 /// 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 @@ bool Sema::isPropertyReadonly(ObjCPropertyDecl *PDecl,
         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;
 }
 
diff --git a/test/SemaObjC/property-13.m b/test/SemaObjC/property-13.m
new file mode 100644 (file)
index 0000000..bcf8299
--- /dev/null
@@ -0,0 +1,77 @@
+// RUN: clang -fsyntax-only -verify %s
+
+@interface NSObject 
++ alloc;
+- init;
+@end
+
+@protocol Test
+  @property int required;
+
+@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;
+@required
+  @property int required1;
+@optional
+  @property int optional_to_be_defined;
+  @property (readonly, getter = optional_preexisting_setter_getter) int optional_getter_attr;
+@end
+
+@interface Test : NSObject <Test> {
+  int ivar;
+  int ivar1;
+  int ivar2;
+}
+@property int required;
+@property int optional_to_be_defined;
+- (int) optional_preexisting_setter_getter;
+- (void) setOptional_preexisting_setter_getter:(int)value;
+@end
+
+@implementation Test
+@synthesize required = ivar;
+@synthesize required1 = ivar1;
+@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; }
+@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;
+}
+