diff options
author | Fariborz Jahanian <fjahanian@apple.com> | 2013-02-10 00:16:04 +0000 |
---|---|---|
committer | Fariborz Jahanian <fjahanian@apple.com> | 2013-02-10 00:16:04 +0000 |
commit | b7b25659355d736a4f19099d96acc54d672340a5 (patch) | |
tree | bfa14acd93afaf0cb4f88b540462fa4b577e82b0 | |
parent | 7728057cf03f8e5791e46eefc6e146214d0a1c24 (diff) |
objective-C: Fixes a bogus warning due to not setting
the "nonatomic" attribute in property redeclaration
in class extension. Also, improved on diagnostics in
this area while at it. // rdar://13156292
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@174821 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r-- | include/clang/Basic/DiagnosticSemaKinds.td | 2 | ||||
-rw-r--r-- | lib/Sema/SemaObjCProperty.cpp | 16 | ||||
-rw-r--r-- | test/SemaObjC/property-3.m | 21 | ||||
-rw-r--r-- | test/SemaObjC/property-4.m | 2 | ||||
-rw-r--r-- | test/SemaObjC/property-category-3.m | 2 |
5 files changed, 36 insertions, 7 deletions
diff --git a/include/clang/Basic/DiagnosticSemaKinds.td b/include/clang/Basic/DiagnosticSemaKinds.td index 615b598e77..b2f28d561b 100644 --- a/include/clang/Basic/DiagnosticSemaKinds.td +++ b/include/clang/Basic/DiagnosticSemaKinds.td @@ -482,7 +482,7 @@ def warn_readonly_property : Warning< "'readwrite' of property inherited from %1">; def warn_property_attribute : Warning< - "property %0 '%1' attribute does not match the property inherited from %2">; + "'%1' attribute on property %0 does not match the property inherited from %2">; def warn_property_types_are_incompatible : Warning< "property type %0 is incompatible with type %1 inherited from %2">; def err_undef_interface : Error<"cannot find interface declaration for %0">; diff --git a/lib/Sema/SemaObjCProperty.cpp b/lib/Sema/SemaObjCProperty.cpp index 298bad8efb..1fe88a26ab 100644 --- a/lib/Sema/SemaObjCProperty.cpp +++ b/lib/Sema/SemaObjCProperty.cpp @@ -368,6 +368,10 @@ Sema::HandlePropertyInClassExtension(Scope *S, PDecl->setPropertyAttributes(ObjCPropertyDecl::OBJC_PR_readonly); if (Attributes & ObjCDeclSpec::DQ_PR_readwrite) PDecl->setPropertyAttributes(ObjCPropertyDecl::OBJC_PR_readwrite); + if (Attributes & ObjCDeclSpec::DQ_PR_nonatomic) + PDecl->setPropertyAttributes(ObjCPropertyDecl::OBJC_PR_nonatomic); + if (Attributes & ObjCDeclSpec::DQ_PR_atomic) + PDecl->setPropertyAttributes(ObjCPropertyDecl::OBJC_PR_atomic); // Set setter/getter selector name. Needed later. PDecl->setGetterName(GetterSel); PDecl->setSetterName(SetterSel); @@ -1292,15 +1296,21 @@ Sema::DiagnosePropertyMismatch(ObjCPropertyDecl *Property, } if ((CAttr & ObjCPropertyDecl::OBJC_PR_nonatomic) - != (SAttr & ObjCPropertyDecl::OBJC_PR_nonatomic)) + != (SAttr & ObjCPropertyDecl::OBJC_PR_nonatomic)) { Diag(Property->getLocation(), diag::warn_property_attribute) << Property->getDeclName() << "atomic" << inheritedName; - if (Property->getSetterName() != SuperProperty->getSetterName()) + Diag(SuperProperty->getLocation(), diag::note_property_declare); + } + if (Property->getSetterName() != SuperProperty->getSetterName()) { Diag(Property->getLocation(), diag::warn_property_attribute) << Property->getDeclName() << "setter" << inheritedName; - if (Property->getGetterName() != SuperProperty->getGetterName()) + Diag(SuperProperty->getLocation(), diag::note_property_declare); + } + if (Property->getGetterName() != SuperProperty->getGetterName()) { Diag(Property->getLocation(), diag::warn_property_attribute) << Property->getDeclName() << "getter" << inheritedName; + Diag(SuperProperty->getLocation(), diag::note_property_declare); + } QualType LHSType = Context.getCanonicalType(SuperProperty->getType()); diff --git a/test/SemaObjC/property-3.m b/test/SemaObjC/property-3.m index 439dc28be9..3f82bcc3b7 100644 --- a/test/SemaObjC/property-3.m +++ b/test/SemaObjC/property-3.m @@ -9,6 +9,25 @@ @end @interface NOW : I -@property (readonly) id d1; // expected-warning {{attribute 'readonly' of property 'd1' restricts attribute 'readwrite' of property inherited from 'I'}} expected-warning {{property 'd1' 'copy' attribute does not match the property inherited from 'I'}} +@property (readonly) id d1; // expected-warning {{attribute 'readonly' of property 'd1' restricts attribute 'readwrite' of property inherited from 'I'}} expected-warning {{'copy' attribute on property 'd1' does not match the property inherited from 'I'}} @property (readwrite, copy) I* d2; @end + +// rdar://13156292 +typedef signed char BOOL; + +@protocol EKProtocolCalendar +@property (nonatomic, readonly) BOOL allowReminders; +@property (atomic, readonly) BOOL allowNonatomicProperty; // expected-note {{property declared here}} +@end + +@protocol EKProtocolMutableCalendar <EKProtocolCalendar> +@end + +@interface EKCalendar +@end + +@interface EKCalendar () <EKProtocolMutableCalendar> +@property (nonatomic, assign) BOOL allowReminders; +@property (nonatomic, assign) BOOL allowNonatomicProperty; // expected-warning {{'atomic' attribute on property 'allowNonatomicProperty' does not match the property inherited from 'EKProtocolCalendar'}} +@end diff --git a/test/SemaObjC/property-4.m b/test/SemaObjC/property-4.m index 2168048800..49f0958fb2 100644 --- a/test/SemaObjC/property-4.m +++ b/test/SemaObjC/property-4.m @@ -24,6 +24,6 @@ int newO; int oldO; } -@property (retain) id MayCauseError; // expected-warning {{property 'MayCauseError' 'copy' attribute does not match the property inherited from 'ProtocolObject'}} +@property (retain) id MayCauseError; // expected-warning {{'copy' attribute on property 'MayCauseError' does not match the property inherited from 'ProtocolObject'}} @end diff --git a/test/SemaObjC/property-category-3.m b/test/SemaObjC/property-category-3.m index 47e93a33d2..9be97ae5c8 100644 --- a/test/SemaObjC/property-category-3.m +++ b/test/SemaObjC/property-category-3.m @@ -16,7 +16,7 @@ @end @interface I (Cat2) <P1> -@property (retain) id ID; // expected-warning {{property 'ID' 'copy' attribute does not match the property inherited from 'P1'}} +@property (retain) id ID; // expected-warning {{'copy' attribute on property 'ID' does not match the property inherited from 'P1'}} @end |