]> granicus.if.org Git - clang/commitdiff
[ObjC] Don't warn on readwrite properties with custom setters that
authorAlex Lorenz <arphaman@gmail.com>
Fri, 6 Oct 2017 19:24:26 +0000 (19:24 +0000)
committerAlex Lorenz <arphaman@gmail.com>
Fri, 6 Oct 2017 19:24:26 +0000 (19:24 +0000)
override readonly properties from protocols

rdar://34192541

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

lib/Sema/SemaObjCProperty.cpp
test/SemaObjC/property-implement-readonly-with-custom-setter.m [new file with mode: 0644]

index 18f509caaa0c0f8df3c0e593831834ae800a5eca..9c61d45158af1d5338d0fdfe771fcacfa1db042e 100644 (file)
@@ -1599,7 +1599,11 @@ Sema::DiagnosePropertyMismatch(ObjCPropertyDecl *Property,
   // meaningless for readonly properties, so don't diagnose if the
   // atomic property is 'readonly'.
   checkAtomicPropertyMismatch(*this, SuperProperty, Property, false);
-  if (Property->getSetterName() != SuperProperty->getSetterName()) {
+  // Readonly properties from protocols can be implemented as "readwrite"
+  // with a custom setter name.
+  if (Property->getSetterName() != SuperProperty->getSetterName() &&
+      !(SuperProperty->isReadOnly() &&
+        isa<ObjCProtocolDecl>(SuperProperty->getDeclContext()))) {
     Diag(Property->getLocation(), diag::warn_property_attribute)
       << Property->getDeclName() << "setter" << inheritedName;
     Diag(SuperProperty->getLocation(), diag::note_property_declare);
diff --git a/test/SemaObjC/property-implement-readonly-with-custom-setter.m b/test/SemaObjC/property-implement-readonly-with-custom-setter.m
new file mode 100644 (file)
index 0000000..7ac1380
--- /dev/null
@@ -0,0 +1,21 @@
+// RUN: %clang_cc1  -fsyntax-only -verify -Wno-objc-root-class %s
+// rdar://34192541
+
+@class NSString;
+
+@protocol MyProtocol
+@property (nonatomic, strong, readonly) NSString *myString;
+@end
+
+@interface MyClass <MyProtocol>
+// Don't warn about this setter:
+@property (nonatomic, strong, setter=setMYString:) NSString *myString;
+
+
+@property (nonatomic, strong, readonly) NSString *overridenInClass; // expected-note {{property declared here}}
+@end
+
+@interface MySubClass: MyClass
+@property (nonatomic, strong, setter=setMYOverride:) NSString *overridenInClass;
+// expected-warning@-1 {{'setter' attribute on property 'overridenInClass' does not match the property inherited from 'MyClass'}}
+@end