]> granicus.if.org Git - clang/commitdiff
[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

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

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

index b950615210412415bf475eeececc859e86b1f423..6c571645487426b7d1205c4b7a4eea7118d8dee2 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 5fb05c8bd3840be48fdd3fe85e5117d4bde09f84..85e8d4624be1d9171d4b026d6f5ac4e738baa31b 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  {