From: Daniel Dunbar Date: Tue, 26 Aug 2008 07:16:44 +0000 (+0000) Subject: Add ObjCPropertyDecl::isReadOnly. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=394d33f1f602f7681032a659dff5bb09061ee510;p=clang Add ObjCPropertyDecl::isReadOnly. Respect isReadOnly when generating synthesized method decls. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@55364 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/include/clang/AST/DeclObjC.h b/include/clang/AST/DeclObjC.h index 84abdfd802..d985ce3962 100644 --- a/include/clang/AST/DeclObjC.h +++ b/include/clang/AST/DeclObjC.h @@ -1205,6 +1205,10 @@ public: void setPropertyAttributes(PropertyAttributeKind PRVal) { PropertyAttributes |= PRVal; } + + bool isReadOnly() const { + return (PropertyAttributes & OBJC_PR_readonly); + } Selector getGetterName() const { return GetterName; } void setGetterName(Selector Sel) { GetterName = Sel; } diff --git a/lib/AST/DeclObjC.cpp b/lib/AST/DeclObjC.cpp index 2e03802436..e74e21dbbc 100644 --- a/lib/AST/DeclObjC.cpp +++ b/lib/AST/DeclObjC.cpp @@ -433,6 +433,10 @@ void ObjCInterfaceDecl::addPropertyMethods( } property->setGetterMethodDecl(GetterDecl); + // Skip setter if property is read-only. + if (property->isReadOnly()) + return; + // Find the default setter and if one not found, add one. ObjCMethodDecl *SetterDecl = getInstanceMethod(property->getSetterName()); if (!SetterDecl) { diff --git a/test/SemaObjC/property-5.m b/test/SemaObjC/property-5.m index c467e634dc..70ef315b22 100644 --- a/test/SemaObjC/property-5.m +++ b/test/SemaObjC/property-5.m @@ -29,3 +29,6 @@ @property(readonly) ConstData *p_base; // expected-warning {{property type 'ConstData *' does not match property type inherited from 'Data'}} @end +void foo(Base *b, id x) { + [ b setRef: x ]; // expected-warning {{method '-setRef:' not found}} +}