From: Alex Lorenz Date: Thu, 30 Mar 2017 13:33:51 +0000 (+0000) Subject: [Sema][ObjC] Avoid the "type of property does not match type of accessor" X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=225e636cbcb8567d8052d9b3049855d00679a727;p=clang [Sema][ObjC] Avoid the "type of property does not match type of accessor" 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 --- diff --git a/lib/Sema/SemaObjCProperty.cpp b/lib/Sema/SemaObjCProperty.cpp index b950615210..6c57164548 100644 --- a/lib/Sema/SemaObjCProperty.cpp +++ b/lib/Sema/SemaObjCProperty.cpp @@ -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( diff --git a/test/SemaObjC/property-typecheck-1.m b/test/SemaObjC/property-typecheck-1.m index 5fb05c8bd3..85e8d4624b 100644 --- a/test/SemaObjC/property-typecheck-1.m +++ b/test/SemaObjC/property-typecheck-1.m @@ -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 {