]> granicus.if.org Git - clang/commitdiff
NFC, Cleanup the code for -Wdeprecated-implementations
authorAlex Lorenz <arphaman@gmail.com>
Thu, 13 Jul 2017 16:35:59 +0000 (16:35 +0000)
committerAlex Lorenz <arphaman@gmail.com>
Thu, 13 Jul 2017 16:35:59 +0000 (16:35 +0000)
and void capitalization of the warning message

rdar://22867595

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@307923 91177308-0d34-0410-b5e6-96231b3b80d8

include/clang/Basic/DiagnosticSemaKinds.td
lib/Sema/SemaDeclObjC.cpp
test/SemaObjC/warn-deprecated-implementations.m

index 709a96a6c957bcc09d12b329b0080af16b811fde..671c3e92f4518be1add0984ae1d8c959f0aa0f5e 100644 (file)
@@ -4579,8 +4579,8 @@ def warn_deprecated_fwdclass_message : Warning<
     "%0 may be deprecated because the receiver type is unknown">,
     InGroup<DeprecatedDeclarations>;
 def warn_deprecated_def : Warning<
-    "Implementing deprecated %select{method|class|category}0">,
-    InGroup<DeprecatedImplementations>, DefaultIgnore;
+  "implementing deprecated %select{method|class|category}0">,
+  InGroup<DeprecatedImplementations>, DefaultIgnore;
 def err_unavailable : Error<"%0 is unavailable">;
 def err_property_method_unavailable :
     Error<"property access is using %0 method which is unavailable">;
index 778b8062f68cb0c438ebfd5fde805f38b021e209..2cf0ca94ac25fd6475539df07870337a412d3453 100644 (file)
@@ -248,19 +248,31 @@ bool Sema::CheckARCMethodDecl(ObjCMethodDecl *method) {
   return false;
 }
 
-static void DiagnoseObjCImplementedDeprecations(Sema &S,
-                                                NamedDecl *ND,
-                                                SourceLocation ImplLoc,
-                                                int select) {
-  if (ND && ND->isDeprecated()) {
-    S.Diag(ImplLoc, diag::warn_deprecated_def) << select;
-    if (select == 0)
-      S.Diag(ND->getLocation(), diag::note_method_declared_at)
-        << ND->getDeclName();
-    else
-      S.Diag(ND->getLocation(), diag::note_previous_decl)
-          << (isa<ObjCCategoryDecl>(ND) ? "category" : "class");
+static void DiagnoseObjCImplementedDeprecations(Sema &S, const NamedDecl *ND,
+                                                SourceLocation ImplLoc) {
+  if (!ND)
+    return;
+  bool IsCategory = false;
+  if (!ND->isDeprecated()) {
+    if (const auto *CD = dyn_cast<ObjCCategoryDecl>(ND)) {
+      if (!CD->getClassInterface()->isDeprecated())
+        return;
+      ND = CD->getClassInterface();
+      IsCategory = true;
+    } else
+      return;
   }
+  S.Diag(ImplLoc, diag::warn_deprecated_def)
+      << (isa<ObjCMethodDecl>(ND)
+              ? /*Method*/ 0
+              : isa<ObjCCategoryDecl>(ND) || IsCategory ? /*Category*/ 2
+                                                        : /*Class*/ 1);
+  if (isa<ObjCMethodDecl>(ND))
+    S.Diag(ND->getLocation(), diag::note_method_declared_at)
+        << ND->getDeclName();
+  else
+    S.Diag(ND->getLocation(), diag::note_previous_decl)
+        << (isa<ObjCCategoryDecl>(ND) ? "category" : "class");
 }
 
 /// AddAnyMethodToGlobalPool - Add any method, instance or factory to global
@@ -385,9 +397,7 @@ void Sema::ActOnStartOfObjCMethodDef(Scope *FnBodyScope, Decl *D) {
       // 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)
-        DiagnoseObjCImplementedDeprecations(*this, 
-                                          dyn_cast<NamedDecl>(IMD), 
-                                          MDecl->getLocation(), 0);
+        DiagnoseObjCImplementedDeprecations(*this, IMD, MDecl->getLocation());
     }
 
     if (MDecl->getMethodFamily() == OMF_init) {
@@ -1873,10 +1883,8 @@ Decl *Sema::ActOnStartCategoryImplementation(
       CatIDecl->setImplementation(CDecl);
       // Warn on implementating category of deprecated class under 
       // -Wdeprecated-implementations flag.
-      DiagnoseObjCImplementedDeprecations(
-          *this,
-          CatIDecl->isDeprecated() ? CatIDecl : dyn_cast<NamedDecl>(IDecl),
-          CDecl->getLocation(), 2);
+      DiagnoseObjCImplementedDeprecations(*this, CatIDecl,
+                                          CDecl->getLocation());
     }
   }
 
@@ -1996,9 +2004,7 @@ Decl *Sema::ActOnStartClassImplementation(
     PushOnScopeChains(IMPDecl, TUScope);
     // Warn on implementating deprecated class under 
     // -Wdeprecated-implementations flag.
-    DiagnoseObjCImplementedDeprecations(*this, 
-                                        dyn_cast<NamedDecl>(IDecl), 
-                                        IMPDecl->getLocation(), 1);
+    DiagnoseObjCImplementedDeprecations(*this, IDecl, IMPDecl->getLocation());
   }
 
   // If the superclass has the objc_runtime_visible attribute, we
index df2557b9cd520e9984d23069495e7eaffcc49cca..ed2156d9abe68a5b95016705e2ae0a7aed396c8e 100644 (file)
@@ -16,7 +16,7 @@
 
 @implementation A
 + (void)F { }  // No warning, implementing its own deprecated method
-- (void) D {} //  expected-warning {{Implementing deprecated method}}
+- (void) D {} //  expected-warning {{implementing deprecated method}}
 - (void) E {} // No warning, implementing deprecated method in its class extension.
 @end
 
@@ -32,10 +32,10 @@ __attribute__((deprecated)) // expected-note {{'CL' has been explicitly marked d
 @interface CL // expected-note 2 {{class declared here}} 
 @end
 
-@implementation CL // expected-warning {{Implementing deprecated class}}
+@implementation CL // expected-warning {{implementing deprecated class}}
 @end
 
-@implementation CL (SomeCategory) // expected-warning {{Implementing deprecated category}}
+@implementation CL (SomeCategory) // expected-warning {{implementing deprecated category}}
 @end
 
 @interface CL_SUB : CL // expected-warning {{'CL' is deprecated}}
@@ -49,7 +49,7 @@ __attribute__((deprecated)) // expected-note {{'CL' has been explicitly marked d
 @end
 
 @implementation SUB
-- (void) B {} // expected-warning {{Implementing deprecated method}}
+- (void) B {} // expected-warning {{implementing deprecated method}}
 @end
 
 @interface Test
@@ -69,5 +69,5 @@ __attribute__((deprecated))
 @interface Test(DeprecatedCategory) // expected-note {{category declared here}}
 @end
 
-@implementation Test(DeprecatedCategory) // expected-warning {{Implementing deprecated category}}
+@implementation Test(DeprecatedCategory) // expected-warning {{implementing deprecated category}}
 @end