summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--clang/include/clang/Basic/DiagnosticGroups.td2
-rw-r--r--clang/include/clang/Basic/DiagnosticSemaKinds.td3
-rw-r--r--clang/lib/Sema/SemaDeclObjC.cpp41
-rw-r--r--clang/test/SemaObjC/warn-deprecated-implementations.m45
4 files changed, 90 insertions, 1 deletions
diff --git a/clang/include/clang/Basic/DiagnosticGroups.td b/clang/include/clang/Basic/DiagnosticGroups.td
index b2ab86b0528..e257c482ba4 100644
--- a/clang/include/clang/Basic/DiagnosticGroups.td
+++ b/clang/include/clang/Basic/DiagnosticGroups.td
@@ -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">;
diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index 4e42fefdf11..272ca6892ab 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -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<
diff --git a/clang/lib/Sema/SemaDeclObjC.cpp b/clang/lib/Sema/SemaDeclObjC.cpp
index a3d93ab85e7..3aeb50b032d 100644
--- a/clang/lib/Sema/SemaDeclObjC.cpp
+++ b/clang/lib/Sema/SemaDeclObjC.cpp
@@ -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/clang/test/SemaObjC/warn-deprecated-implementations.m b/clang/test/SemaObjC/warn-deprecated-implementations.m
new file mode 100644
index 00000000000..7bcd10cc3e0
--- /dev/null
+++ b/clang/test/SemaObjC/warn-deprecated-implementations.m
@@ -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
+
OpenPOWER on IntegriCloud