r204093 - Objective-C. No need to issue deprecated warning if deprecated method

Fariborz Jahanian fjahanian at apple.com
Mon Mar 17 17:10:37 PDT 2014


Author: fjahanian
Date: Mon Mar 17 19:10:37 2014
New Revision: 204093

URL: http://llvm.org/viewvc/llvm-project?rev=204093&view=rev
Log:
Objective-C. No need to issue deprecated warning if deprecated method 
in class extension is being implemented in primary class implementation
(no overriding is involved).
// rdar://16249335

Modified:
    cfe/trunk/lib/Sema/SemaDeclObjC.cpp
    cfe/trunk/test/SemaObjC/warn-deprecated-implementations.m

Modified: cfe/trunk/lib/Sema/SemaDeclObjC.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDeclObjC.cpp?rev=204093&r1=204092&r2=204093&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaDeclObjC.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDeclObjC.cpp Mon Mar 17 19:10:37 2014
@@ -372,6 +372,7 @@ void Sema::ActOnStartOfObjCMethodDef(Sco
       IC->lookupMethod(MDecl->getSelector(), MDecl->isInstanceMethod());
     
     if (IMD) {
+      ObjCCategoryDecl *CD = 0;
       ObjCImplDecl *ImplDeclOfMethodDef = 
         dyn_cast<ObjCImplDecl>(MDecl->getDeclContext());
       ObjCContainerDecl *ContDeclOfMethodDecl = 
@@ -379,11 +380,20 @@ void Sema::ActOnStartOfObjCMethodDef(Sco
       ObjCImplDecl *ImplDeclOfMethodDecl = 0;
       if (ObjCInterfaceDecl *OID = dyn_cast<ObjCInterfaceDecl>(ContDeclOfMethodDecl))
         ImplDeclOfMethodDecl = OID->getImplementation();
-      else if (ObjCCategoryDecl *CD = dyn_cast<ObjCCategoryDecl>(ContDeclOfMethodDecl))
+      else if ((CD = dyn_cast<ObjCCategoryDecl>(ContDeclOfMethodDecl))) {
         ImplDeclOfMethodDecl = CD->getImplementation();
+      }
+      bool warn;
+      // No need to issue deprecated warning if deprecated method in class
+      // extension is being implemented in primary class implementation
+      // (no overriding is involved).
+      if (ImplDeclOfMethodDef && CD && CD->IsClassExtension())
+        warn = false;
+      else
       // No need to issue deprecated warning if deprecated mehod in class/category
       // is being implemented in its own implementation (no overriding is involved).
-      if (!ImplDeclOfMethodDecl || ImplDeclOfMethodDecl != ImplDeclOfMethodDef)
+        warn = (!ImplDeclOfMethodDecl || ImplDeclOfMethodDecl != ImplDeclOfMethodDef);
+      if (warn)
         DiagnoseObjCImplementedDeprecations(*this, 
                                           dyn_cast<NamedDecl>(IMD), 
                                           MDecl->getLocation(), 0);

Modified: cfe/trunk/test/SemaObjC/warn-deprecated-implementations.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaObjC/warn-deprecated-implementations.m?rev=204093&r1=204092&r2=204093&view=diff
==============================================================================
--- cfe/trunk/test/SemaObjC/warn-deprecated-implementations.m (original)
+++ cfe/trunk/test/SemaObjC/warn-deprecated-implementations.m Mon Mar 17 19:10:37 2014
@@ -11,13 +11,13 @@
 @end
 
 @interface A()
-- (void) E __attribute__((deprecated)); // expected-note {{method 'E' declared here}}
+- (void) E __attribute__((deprecated));
 @end
 
 @implementation A
 + (void)F { }	// No warning, implementing its own deprecated method
 - (void) D {} //  expected-warning {{Implementing deprecated method}}
-- (void) E {} //  expected-warning {{Implementing deprecated method}}
+- (void) E {} // No warning, implementing deprecated method in its class extension.
 @end
 
 @interface A(CAT)
@@ -53,3 +53,15 @@ __attribute__((deprecated))
 - (void) B {} // expected-warning {{Implementing deprecated method}}
 @end
 
+ at interface Test
+ at end
+
+ at interface Test()
+- (id)initSpecialInPrivateHeader __attribute__((deprecated));
+ at end
+
+ at implementation Test
+- (id)initSpecialInPrivateHeader {
+  return (void *)0;
+}
+ at end





More information about the cfe-commits mailing list