[Sema][ObjC] Avoid the "type of property does not match type of accessor"
authorAlex Lorenz <arphaman@gmail.com>
Thu, 30 Mar 2017 13:33:51 +0000 (13:33 +0000)
committerAlex Lorenz <arphaman@gmail.com>
Thu, 30 Mar 2017 13:33:51 +0000 (13:33 +0000)
warning for methods that resemble the setters of readonly properties

rdar://30415679

llvm-svn: 299078

clang/lib/Sema/SemaObjCProperty.cpp
clang/test/SemaObjC/property-typecheck-1.m

index b950615..6c57164 100644 (file)
@@ -2185,12 +2185,9 @@ void Sema::ProcessPropertyDecl(ObjCPropertyDecl *property) {
   DiagnosePropertyAccessorMismatch(property, GetterMethod,
                                    property->getLocation());
 
-  if (SetterMethod) {
-    ObjCPropertyDecl::PropertyAttributeKind CAttr =
-      property->getPropertyAttributes();
-    if ((!(CAttr & ObjCPropertyDecl::OBJC_PR_readonly)) &&
-        Context.getCanonicalType(SetterMethod->getReturnType()) !=
-            Context.VoidTy)
+  if (!property->isReadOnly() && SetterMethod) {
+    if (Context.getCanonicalType(SetterMethod->getReturnType()) !=
+        Context.VoidTy)
       Diag(SetterMethod->getLocation(), diag::err_setter_type_void);
     if (SetterMethod->param_size() != 1 ||
         !Context.hasSameUnqualifiedType(
index 5fb05c8..85e8d46 100644 (file)
@@ -78,6 +78,11 @@ typedef void (F)(void);
 
 - (NSMutableArray*) pieces; // expected-note 2 {{declared here}}
 - (NSArray*) first;
+
+// Don't warn about setter-like methods for readonly properties.
+- (void)setFirst:(char)val;
+- (void)setPieces:(char)val;
+
 @end
 
 @interface Class2  {