diff options
| author | Alex Lorenz <arphaman@gmail.com> | 2017-10-06 19:24:26 +0000 |
|---|---|---|
| committer | Alex Lorenz <arphaman@gmail.com> | 2017-10-06 19:24:26 +0000 |
| commit | 05a63ee197a1e226ada83334491b91b231324b87 (patch) | |
| tree | 92cc5c16afb3ad517d732c62090ec51f5004af3b /clang | |
| parent | ba0f79af92f9a4ed19d58c81bd7d185f2263231a (diff) | |
| download | bcm5719-llvm-05a63ee197a1e226ada83334491b91b231324b87.tar.gz bcm5719-llvm-05a63ee197a1e226ada83334491b91b231324b87.zip | |
[ObjC] Don't warn on readwrite properties with custom setters that
override readonly properties from protocols
rdar://34192541
llvm-svn: 315093
Diffstat (limited to 'clang')
| -rw-r--r-- | clang/lib/Sema/SemaObjCProperty.cpp | 6 | ||||
| -rw-r--r-- | clang/test/SemaObjC/property-implement-readonly-with-custom-setter.m | 21 |
2 files changed, 26 insertions, 1 deletions
diff --git a/clang/lib/Sema/SemaObjCProperty.cpp b/clang/lib/Sema/SemaObjCProperty.cpp index 18f509caaa0..9c61d45158a 100644 --- a/clang/lib/Sema/SemaObjCProperty.cpp +++ b/clang/lib/Sema/SemaObjCProperty.cpp @@ -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/clang/test/SemaObjC/property-implement-readonly-with-custom-setter.m b/clang/test/SemaObjC/property-implement-readonly-with-custom-setter.m new file mode 100644 index 00000000000..7ac13807675 --- /dev/null +++ b/clang/test/SemaObjC/property-implement-readonly-with-custom-setter.m @@ -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 |

