[cfe-commits] r125545 - in /cfe/trunk: include/clang/Basic/DiagnosticGroups.td include/clang/Basic/DiagnosticSemaKinds.td lib/Sema/SemaDeclObjC.cpp test/SemaObjC/warn-deprecated-implementations.m

Fariborz Jahanian fjahanian at apple.com
Mon Feb 14 16:59:30 PST 2011


Author: fjahanian
Date: Mon Feb 14 18:59:30 2011
New Revision: 125545

URL: http://llvm.org/viewvc/llvm-project?rev=125545&view=rev
Log:
Warn if method for a deprecated method is implemented.
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.

Added:
    cfe/trunk/test/SemaObjC/warn-deprecated-implementations.m
Modified:
    cfe/trunk/include/clang/Basic/DiagnosticGroups.td
    cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
    cfe/trunk/lib/Sema/SemaDeclObjC.cpp

Modified: cfe/trunk/include/clang/Basic/DiagnosticGroups.td
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticGroups.td?rev=125545&r1=125544&r2=125545&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/DiagnosticGroups.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticGroups.td Mon Feb 14 18:59:30 2011
@@ -39,6 +39,8 @@
 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">;

Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td?rev=125545&r1=125544&r2=125545&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Mon Feb 14 18:59:30 2011
@@ -1969,6 +1969,9 @@
 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<

Modified: cfe/trunk/lib/Sema/SemaDeclObjC.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDeclObjC.cpp?rev=125545&r1=125544&r2=125545&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaDeclObjC.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDeclObjC.cpp Mon Feb 14 18:59:30 2011
@@ -64,6 +64,21 @@
     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 @@
         << 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 @@
   } 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;
 }

Added: cfe/trunk/test/SemaObjC/warn-deprecated-implementations.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaObjC/warn-deprecated-implementations.m?rev=125545&view=auto
==============================================================================
--- cfe/trunk/test/SemaObjC/warn-deprecated-implementations.m (added)
+++ cfe/trunk/test/SemaObjC/warn-deprecated-implementations.m Mon Feb 14 18:59:30 2011
@@ -0,0 +1,45 @@
+// RUN: %clang_cc1 -fsyntax-only -Wdeprecated-implementations -verify %s
+// rdar://8973810
+
+ at protocol P
+- (void) D __attribute__((deprecated)); // expected-note {{method declared here}}
+ at end
+
+ at interface A <P>
++ (void)F __attribute__((deprecated)); // expected-note {{method declared here}}
+ at end
+
+ at interface A()
+- (void) E __attribute__((deprecated)); // expected-note {{method declared here}}
+ at end
+
+ at implementation A
++ (void)F { } //  expected-warning {{Implementing deprecated method}}
+- (void) D {} //  expected-warning {{Implementing deprecated method}}
+- (void) E {} //  expected-warning {{Implementing deprecated method}}
+ at end
+
+__attribute__((deprecated))
+ at interface CL // expected-note 2 {{class declared here}}
+ at end
+
+ at implementation CL // expected-warning {{Implementing deprecated class}}
+ at end
+
+ at implementation CL ( SomeCategory ) // expected-warning {{Implementing deprecated category}}
+ at end
+
+ at interface CL_SUB : CL // expected-warning {{'CL' is deprecated}}
+ at end
+
+ at interface BASE
+- (void) B __attribute__((deprecated)); // expected-note {{method declared here}}
+ at end
+
+ at interface SUB : BASE
+ at end
+
+ at implementation SUB
+- (void) B {} // expected-warning {{Implementing deprecated method}}
+ at end
+





More information about the cfe-commits mailing list