]> granicus.if.org Git - clang/commitdiff
Warn if method for a deprecated method is implemented.
authorFariborz Jahanian <fjahanian@apple.com>
Tue, 15 Feb 2011 00:59:30 +0000 (00:59 +0000)
committerFariborz Jahanian <fjahanian@apple.com>
Tue, 15 Feb 2011 00:59:30 +0000 (00:59 +0000)
Warn if class for a deprecated class is implemented.
Warn if category for a deprecated class is implemented.
All under control of -Wdeprecated-implementations.
// rdar://8973810.

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

include/clang/Basic/DiagnosticGroups.td
include/clang/Basic/DiagnosticSemaKinds.td
lib/Sema/SemaDeclObjC.cpp
test/SemaObjC/warn-deprecated-implementations.m [new file with mode: 0644]

index b2ab86b0528283d396a0d5f8a1faeefa1060338d..e257c482ba44ed831be6ac87eb64c40e2630d0bc 100644 (file)
@@ -39,6 +39,8 @@ def DeprecatedWritableStr : DiagGroup<"deprecated-writable-strings">;
 def Deprecated : DiagGroup<"deprecated", [ DeprecatedDeclarations] >,
                  DiagCategory<"Deprecations">;
 
+def DeprecatedImplementations :DiagGroup<"deprecated-implementations">;
+
 def : DiagGroup<"disabled-optimization">;
 def : DiagGroup<"discard-qual">;
 def : DiagGroup<"div-by-zero">;
index 4e42fefdf1115bf478905b6aee26d02f54f8e830..272ca6892ab9d69e8e695c9e0553cd0f1528150c 100644 (file)
@@ -1969,6 +1969,9 @@ def warn_deprecated_message : Warning<"%0 is deprecated: %1">,
 def warn_deprecated_fwdclass_message : Warning<
     "%0 maybe deprecated because receiver type is unknown">,
     InGroup<DeprecatedDeclarations>;
+def warn_depercated_def : Warning<
+    "Implementing deprecated %select{method|class|category}0">,
+    InGroup<DeprecatedImplementations>, DefaultIgnore;
 def err_unavailable : Error<"%0 is unavailable">;
 def err_unavailable_message : Error<"%0 is unavailable: %1">;
 def warn_unavailable_fwdclass_message : Warning<
index a3d93ab85e7b9b15972ce27635f78167e262bc02..3aeb50b032d0dc8b9e7d62c8c57a155fcc50f6d6 100644 (file)
@@ -64,6 +64,21 @@ void Sema::ActOnStartOfObjCMethodDef(Scope *FnBodyScope, Decl *D) {
     if ((*PI)->getIdentifier())
       PushOnScopeChains(*PI, FnBodyScope);
   }
+  // Warn on implementating deprecated methods under 
+  // -Wdeprecated-implementations flag.
+  // FIXME. Refactor using common routine.
+  unsigned DIAG = diag::warn_depercated_def;
+  if (Diags.getDiagnosticLevel(DIAG, MDecl->getLocation())
+      != Diagnostic::Ignored)
+    if (ObjCInterfaceDecl *IC = MDecl->getClassInterface()) {
+      if (ObjCMethodDecl *IMD = 
+          IC->lookupMethod(MDecl->getSelector(), MDecl->isInstanceMethod()))
+        if (NamedDecl *ND = dyn_cast<NamedDecl>(IMD))
+          if (ND->getAttr<DeprecatedAttr>()) {
+            Diag(MDecl->getLocation(), DIAG) << 0;
+            Diag(IMD->getLocation(), diag::note_method_declared_at);
+          }
+    }
 }
 
 Decl *Sema::
@@ -537,8 +552,21 @@ Decl *Sema::ActOnStartCategoryImplementation(
         << CatName;
       Diag(CatIDecl->getImplementation()->getLocation(),
            diag::note_previous_definition);
-    } else
+    } else {
       CatIDecl->setImplementation(CDecl);
+      // Warn on implementating category of deprecated class under 
+      // -Wdeprecated-implementations flag.
+      // FIXME. Refactor using common routine.
+      unsigned DIAG = diag::warn_depercated_def;
+      if (Diags.getDiagnosticLevel(DIAG, CDecl->getLocation())
+          != Diagnostic::Ignored)
+        if (NamedDecl *ND = dyn_cast<NamedDecl>(IDecl))
+          if (ND->getAttr<DeprecatedAttr>()) {
+            Diag(CDecl->getLocation(), DIAG) << 2;
+            Diag(IDecl->getLocation(), diag::note_previous_decl) << "class";
+          }
+
+    }
   }
 
   CheckObjCDeclScope(CDecl);
@@ -647,6 +675,17 @@ Decl *Sema::ActOnStartClassImplementation(
   } else { // add it to the list.
     IDecl->setImplementation(IMPDecl);
     PushOnScopeChains(IMPDecl, TUScope);
+    // Warn on implementating deprecated class under 
+    // -Wdeprecated-implementations flag.
+    // FIXME. Refactor using common routine.
+    unsigned DIAG = diag::warn_depercated_def;
+    if (Diags.getDiagnosticLevel(DIAG, IMPDecl->getLocation())
+          != Diagnostic::Ignored)
+      if (NamedDecl *ND = dyn_cast<NamedDecl>(IDecl))
+        if (ND->getAttr<DeprecatedAttr>()) {
+          Diag(IMPDecl->getLocation(), DIAG) << 1;
+          Diag(IDecl->getLocation(), diag::note_previous_decl) << "class";
+       }
   }
   return IMPDecl;
 }
diff --git a/test/SemaObjC/warn-deprecated-implementations.m b/test/SemaObjC/warn-deprecated-implementations.m
new file mode 100644 (file)
index 0000000..7bcd10c
--- /dev/null
@@ -0,0 +1,45 @@
+// RUN: %clang_cc1 -fsyntax-only -Wdeprecated-implementations -verify %s
+// rdar://8973810
+
+@protocol P
+- (void) D __attribute__((deprecated)); // expected-note {{method declared here}}
+@end
+
+@interface A <P>
++ (void)F __attribute__((deprecated)); // expected-note {{method declared here}}
+@end
+
+@interface A()
+- (void) E __attribute__((deprecated)); // expected-note {{method declared here}}
+@end
+
+@implementation A
++ (void)F { } //  expected-warning {{Implementing deprecated method}}
+- (void) D {} //  expected-warning {{Implementing deprecated method}}
+- (void) E {} //  expected-warning {{Implementing deprecated method}}
+@end
+
+__attribute__((deprecated))
+@interface CL // expected-note 2 {{class declared here}}
+@end
+
+@implementation CL // expected-warning {{Implementing deprecated class}}
+@end
+
+@implementation CL ( SomeCategory ) // expected-warning {{Implementing deprecated category}}
+@end
+
+@interface CL_SUB : CL // expected-warning {{'CL' is deprecated}}
+@end
+
+@interface BASE
+- (void) B __attribute__((deprecated)); // expected-note {{method declared here}}
+@end
+
+@interface SUB : BASE
+@end
+
+@implementation SUB
+- (void) B {} // expected-warning {{Implementing deprecated method}}
+@end
+