[PATCH] D33661: [Sema][ObjC] Don't emit availability diagnostics for categories extending unavailable interfaces

Erik Pilkington via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Mon May 29 17:39:14 PDT 2017


erik.pilkington created this revision.

Previously, @implementations of categories that extended unavailable/deprecated/partial @interfaces triggered availability diagnostics. There was no way to turn this off, as we check the use of the unavailable decl outside of the context of the @implementation, so attaching an attribute to the category @interface doesn't do anything. Moreover, this diagnostic can't actually catch any bugs even if it worked correctly, there is no way to use stuff declared in a category without referencing the extended @interface (AFAIK, I'm not fluent in Objective-C), which will trigger the diagnostic.

rdar://32427296

Thanks for taking a look,
Erik


https://reviews.llvm.org/D33661

Files:
  lib/Sema/SemaDeclObjC.cpp
  test/SemaObjC/attr-deprecated.m
  test/SemaObjC/class-unavail-warning.m
  test/SemaObjC/warn-deprecated-implementations.m


Index: test/SemaObjC/warn-deprecated-implementations.m
===================================================================
--- test/SemaObjC/warn-deprecated-implementations.m
+++ test/SemaObjC/warn-deprecated-implementations.m
@@ -28,15 +28,14 @@
 - (void) G {} 	// No warning, implementing its own deprecated method
 @end
 
-__attribute__((deprecated)) // expected-note 2 {{'CL' has been explicitly marked deprecated here}}
+__attribute__((deprecated)) // expected-note {{'CL' has been explicitly marked deprecated here}}
 @interface CL // expected-note 2 {{class declared here}} 
 @end
 
 @implementation CL // expected-warning {{Implementing deprecated class}}
 @end
 
- at implementation CL ( SomeCategory ) // expected-warning {{'CL' is deprecated}} \
-                                    // expected-warning {{Implementing deprecated category}}
+ at implementation CL (SomeCategory) // expected-warning {{Implementing deprecated category}}
 @end
 
 @interface CL_SUB : CL // expected-warning {{'CL' is deprecated}}
Index: test/SemaObjC/class-unavail-warning.m
===================================================================
--- test/SemaObjC/class-unavail-warning.m
+++ test/SemaObjC/class-unavail-warning.m
@@ -2,7 +2,7 @@
 // rdar://9092208
 
 __attribute__((unavailable("not available")))
- at interface MyClass { // expected-note 8 {{'MyClass' has been explicitly marked unavailable here}}
+ at interface MyClass { // expected-note 7 {{'MyClass' has been explicitly marked unavailable here}}
 @public
     void *_test;
     MyClass *ivar; // no error.
@@ -28,7 +28,7 @@
 @interface MyClass (Cat2) // no error.
 @end
 
- at implementation MyClass (Cat2) // expected-error {{unavailable}}
+ at implementation MyClass (Cat2) // no error.
 @end
 
 int main() {
Index: test/SemaObjC/attr-deprecated.m
===================================================================
--- test/SemaObjC/attr-deprecated.m
+++ test/SemaObjC/attr-deprecated.m
@@ -83,7 +83,7 @@
 }
 
 
-__attribute ((deprecated)) // expected-note 2 {{'DEPRECATED' has been explicitly marked deprecated here}}
+__attribute ((deprecated)) // expected-note {{'DEPRECATED' has been explicitly marked deprecated here}}
 @interface DEPRECATED { 
   @public int ivar; 
   DEPRECATED *ivar2; // no warning.
@@ -98,9 +98,17 @@
 @end
 
 @interface DEPRECATED (Category2) // no warning.
+- (id)meth;
 @end
 
- at implementation DEPRECATED (Category2) // expected-warning {{'DEPRECATED' is deprecated}}
+__attribute__((deprecated))
+void depr_function();
+
+ at implementation DEPRECATED (Category2) // no warning
+- (id)meth {
+  depr_function(); // no warning.
+  return 0;
+}
 @end
 
 @interface NS : DEPRECATED  // expected-warning {{'DEPRECATED' is deprecated}}
Index: lib/Sema/SemaDeclObjC.cpp
===================================================================
--- lib/Sema/SemaDeclObjC.cpp
+++ lib/Sema/SemaDeclObjC.cpp
@@ -1851,10 +1851,6 @@
   // FIXME: PushOnScopeChains?
   CurContext->addDecl(CDecl);
 
-  // If the interface is deprecated/unavailable, warn/error about it.
-  if (IDecl)
-    DiagnoseUseOfDecl(IDecl, ClassLoc);
-
   // If the interface has the objc_runtime_visible attribute, we
   // cannot implement a category for it.
   if (IDecl && IDecl->hasAttr<ObjCRuntimeVisibleAttr>()) {


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D33661.100645.patch
Type: text/x-patch
Size: 3249 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20170530/005c9567/attachment.bin>


More information about the cfe-commits mailing list