r315093 - [ObjC] Don't warn on readwrite properties with custom setters that
Alex Lorenz via cfe-commits
cfe-commits at lists.llvm.org
Fri Oct 6 12:24:27 PDT 2017
Author: arphaman
Date: Fri Oct 6 12:24:26 2017
New Revision: 315093
URL: http://llvm.org/viewvc/llvm-project?rev=315093&view=rev
Log:
[ObjC] Don't warn on readwrite properties with custom setters that
override readonly properties from protocols
rdar://34192541
Added:
cfe/trunk/test/SemaObjC/property-implement-readonly-with-custom-setter.m
Modified:
cfe/trunk/lib/Sema/SemaObjCProperty.cpp
Modified: cfe/trunk/lib/Sema/SemaObjCProperty.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaObjCProperty.cpp?rev=315093&r1=315092&r2=315093&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaObjCProperty.cpp (original)
+++ cfe/trunk/lib/Sema/SemaObjCProperty.cpp Fri Oct 6 12:24:26 2017
@@ -1599,7 +1599,11 @@ Sema::DiagnosePropertyMismatch(ObjCPrope
// 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);
Added: cfe/trunk/test/SemaObjC/property-implement-readonly-with-custom-setter.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaObjC/property-implement-readonly-with-custom-setter.m?rev=315093&view=auto
==============================================================================
--- cfe/trunk/test/SemaObjC/property-implement-readonly-with-custom-setter.m (added)
+++ cfe/trunk/test/SemaObjC/property-implement-readonly-with-custom-setter.m Fri Oct 6 12:24:26 2017
@@ -0,0 +1,21 @@
+// RUN: %clang_cc1 -fsyntax-only -verify -Wno-objc-root-class %s
+// rdar://34192541
+
+ at class NSString;
+
+ at protocol MyProtocol
+ at property (nonatomic, strong, readonly) NSString *myString;
+ at end
+
+ at interface MyClass <MyProtocol>
+// Don't warn about this setter:
+ at property (nonatomic, strong, setter=setMYString:) NSString *myString;
+
+
+ at property (nonatomic, strong, readonly) NSString *overridenInClass; // expected-note {{property declared here}}
+ at end
+
+ at interface MySubClass: MyClass
+ at property (nonatomic, strong, setter=setMYOverride:) NSString *overridenInClass;
+// expected-warning at -1 {{'setter' attribute on property 'overridenInClass' does not match the property inherited from 'MyClass'}}
+ at end
More information about the cfe-commits
mailing list