From 48a98c7a8467a9570d2fc7f2aab7f5273a3e218e Mon Sep 17 00:00:00 2001 From: Fariborz Jahanian Date: Tue, 1 Nov 2011 23:02:16 +0000 Subject: [PATCH] objc: warn if a readonly property has a setter attribute too. // rdar://10357768 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@143518 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/clang/Basic/DiagnosticGroups.td | 1 + include/clang/Basic/DiagnosticSemaKinds.td | 3 +++ lib/Sema/SemaObjCProperty.cpp | 5 +++++ test/SemaObjC/property-10.m | 9 +++++++++ 4 files changed, 18 insertions(+) diff --git a/include/clang/Basic/DiagnosticGroups.td b/include/clang/Basic/DiagnosticGroups.td index 343ffdab1a..33a66a467d 100644 --- a/include/clang/Basic/DiagnosticGroups.td +++ b/include/clang/Basic/DiagnosticGroups.td @@ -110,6 +110,7 @@ def OverlengthStrings : DiagGroup<"overlength-strings">; def OverloadedVirtual : DiagGroup<"overloaded-virtual">; def ObjCMissingSuperCalls : DiagGroup<"objc-missing-super-calls">; def ObjCRetainBlockProperty : DiagGroup<"objc-noncopy-retain-block-property">; +def ObjCReadonlyPropertyHasSetter : DiagGroup<"objc-readonly-with-setter-property">; def ObjCContinuationPropertyType :DiagGroup<"objc-continuation-property-type">; def Packed : DiagGroup<"packed">; def Padded : DiagGroup<"padded">; diff --git a/include/clang/Basic/DiagnosticSemaKinds.td b/include/clang/Basic/DiagnosticSemaKinds.td index 9041a768a7..7bfd7fb32c 100644 --- a/include/clang/Basic/DiagnosticSemaKinds.td +++ b/include/clang/Basic/DiagnosticSemaKinds.td @@ -502,6 +502,9 @@ def warn_objc_property_copy_missing_on_block : Warning< def warn_objc_property_retain_of_block : Warning< "retain'ed block property does not copy the block " "- use copy attribute instead">, InGroup; +def warn_objc_readonly_property_has_setter : Warning< + "setter cannot be specified for a readonly property">, + InGroup; def warn_atomic_property_rule : Warning< "writable atomic property %0 cannot pair a synthesized %select{getter|setter}1 " "with a user defined %select{getter|setter}2">, diff --git a/lib/Sema/SemaObjCProperty.cpp b/lib/Sema/SemaObjCProperty.cpp index 617dbefada..ae054bc629 100644 --- a/lib/Sema/SemaObjCProperty.cpp +++ b/lib/Sema/SemaObjCProperty.cpp @@ -1798,4 +1798,9 @@ void Sema::CheckObjCPropertyAttributes(Decl *PDecl, !(Attributes & ObjCDeclSpec::DQ_PR_strong) && PropertyTy->isBlockPointerType()) Diag(Loc, diag::warn_objc_property_retain_of_block); + + if ((Attributes & ObjCDeclSpec::DQ_PR_readonly) && + (Attributes & ObjCDeclSpec::DQ_PR_setter)) + Diag(Loc, diag::warn_objc_readonly_property_has_setter); + } diff --git a/test/SemaObjC/property-10.m b/test/SemaObjC/property-10.m index e89d68e9d0..51eb39c9e7 100644 --- a/test/SemaObjC/property-10.m +++ b/test/SemaObjC/property-10.m @@ -37,3 +37,12 @@ @property(nonatomic,copy) int (*PROP1)(); // expected-error {{property with 'copy' attribute must be of object type}} @property(nonatomic,weak) int (*PROP2)(); // expected-error {{property with 'weak' attribute must be of object type}} @end + +// rdar://10357768 +@interface rdar10357768 +{ + int n1; +} +@property (readonly, setter=crushN1:) int n1; // expected-warning {{setter cannot be specified for a readonly property}} +@end + -- 2.40.0