Skip to content
Snippets Groups Projects
Commit e9abcb4c authored by Alex Lorenz's avatar Alex Lorenz
Browse files

NFC, Cleanup the code for -Wdeprecated-implementations

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
parent 5ad4badf
No related branches found
No related tags found
No related merge requests found
...@@ -4579,8 +4579,8 @@ def warn_deprecated_fwdclass_message : Warning< ...@@ -4579,8 +4579,8 @@ def warn_deprecated_fwdclass_message : Warning<
"%0 may be deprecated because the receiver type is unknown">, "%0 may be deprecated because the receiver type is unknown">,
InGroup<DeprecatedDeclarations>; InGroup<DeprecatedDeclarations>;
def warn_deprecated_def : Warning< def warn_deprecated_def : Warning<
"Implementing deprecated %select{method|class|category}0">, "implementing deprecated %select{method|class|category}0">,
InGroup<DeprecatedImplementations>, DefaultIgnore; InGroup<DeprecatedImplementations>, DefaultIgnore;
def err_unavailable : Error<"%0 is unavailable">; def err_unavailable : Error<"%0 is unavailable">;
def err_property_method_unavailable : def err_property_method_unavailable :
Error<"property access is using %0 method which is unavailable">; Error<"property access is using %0 method which is unavailable">;
......
...@@ -248,19 +248,31 @@ bool Sema::CheckARCMethodDecl(ObjCMethodDecl *method) { ...@@ -248,19 +248,31 @@ bool Sema::CheckARCMethodDecl(ObjCMethodDecl *method) {
return false; return false;
} }
static void DiagnoseObjCImplementedDeprecations(Sema &S, static void DiagnoseObjCImplementedDeprecations(Sema &S, const NamedDecl *ND,
NamedDecl *ND, SourceLocation ImplLoc) {
SourceLocation ImplLoc, if (!ND)
int select) { return;
if (ND && ND->isDeprecated()) { bool IsCategory = false;
S.Diag(ImplLoc, diag::warn_deprecated_def) << select; if (!ND->isDeprecated()) {
if (select == 0) if (const auto *CD = dyn_cast<ObjCCategoryDecl>(ND)) {
S.Diag(ND->getLocation(), diag::note_method_declared_at) if (!CD->getClassInterface()->isDeprecated())
<< ND->getDeclName(); return;
else ND = CD->getClassInterface();
S.Diag(ND->getLocation(), diag::note_previous_decl) IsCategory = true;
<< (isa<ObjCCategoryDecl>(ND) ? "category" : "class"); } 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 /// AddAnyMethodToGlobalPool - Add any method, instance or factory to global
...@@ -385,9 +397,7 @@ void Sema::ActOnStartOfObjCMethodDef(Scope *FnBodyScope, Decl *D) { ...@@ -385,9 +397,7 @@ void Sema::ActOnStartOfObjCMethodDef(Scope *FnBodyScope, Decl *D) {
// No need to issue deprecated warning if deprecated mehod in class/category // No need to issue deprecated warning if deprecated mehod in class/category
// is being implemented in its own implementation (no overriding is involved). // is being implemented in its own implementation (no overriding is involved).
if (!ImplDeclOfMethodDecl || ImplDeclOfMethodDecl != ImplDeclOfMethodDef) if (!ImplDeclOfMethodDecl || ImplDeclOfMethodDecl != ImplDeclOfMethodDef)
DiagnoseObjCImplementedDeprecations(*this, DiagnoseObjCImplementedDeprecations(*this, IMD, MDecl->getLocation());
dyn_cast<NamedDecl>(IMD),
MDecl->getLocation(), 0);
} }
if (MDecl->getMethodFamily() == OMF_init) { if (MDecl->getMethodFamily() == OMF_init) {
...@@ -1873,10 +1883,8 @@ Decl *Sema::ActOnStartCategoryImplementation( ...@@ -1873,10 +1883,8 @@ Decl *Sema::ActOnStartCategoryImplementation(
CatIDecl->setImplementation(CDecl); CatIDecl->setImplementation(CDecl);
// Warn on implementating category of deprecated class under // Warn on implementating category of deprecated class under
// -Wdeprecated-implementations flag. // -Wdeprecated-implementations flag.
DiagnoseObjCImplementedDeprecations( DiagnoseObjCImplementedDeprecations(*this, CatIDecl,
*this, CDecl->getLocation());
CatIDecl->isDeprecated() ? CatIDecl : dyn_cast<NamedDecl>(IDecl),
CDecl->getLocation(), 2);
} }
} }
...@@ -1996,9 +2004,7 @@ Decl *Sema::ActOnStartClassImplementation( ...@@ -1996,9 +2004,7 @@ Decl *Sema::ActOnStartClassImplementation(
PushOnScopeChains(IMPDecl, TUScope); PushOnScopeChains(IMPDecl, TUScope);
// Warn on implementating deprecated class under // Warn on implementating deprecated class under
// -Wdeprecated-implementations flag. // -Wdeprecated-implementations flag.
DiagnoseObjCImplementedDeprecations(*this, DiagnoseObjCImplementedDeprecations(*this, IDecl, IMPDecl->getLocation());
dyn_cast<NamedDecl>(IDecl),
IMPDecl->getLocation(), 1);
} }
// If the superclass has the objc_runtime_visible attribute, we // If the superclass has the objc_runtime_visible attribute, we
......
...@@ -16,7 +16,7 @@ ...@@ -16,7 +16,7 @@
@implementation A @implementation A
+ (void)F { } // No warning, implementing its own deprecated method + (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. - (void) E {} // No warning, implementing deprecated method in its class extension.
@end @end
...@@ -32,10 +32,10 @@ __attribute__((deprecated)) // expected-note {{'CL' has been explicitly marked d ...@@ -32,10 +32,10 @@ __attribute__((deprecated)) // expected-note {{'CL' has been explicitly marked d
@interface CL // expected-note 2 {{class declared here}} @interface CL // expected-note 2 {{class declared here}}
@end @end
@implementation CL // expected-warning {{Implementing deprecated class}} @implementation CL // expected-warning {{implementing deprecated class}}
@end @end
@implementation CL (SomeCategory) // expected-warning {{Implementing deprecated category}} @implementation CL (SomeCategory) // expected-warning {{implementing deprecated category}}
@end @end
@interface CL_SUB : CL // expected-warning {{'CL' is deprecated}} @interface CL_SUB : CL // expected-warning {{'CL' is deprecated}}
...@@ -49,7 +49,7 @@ __attribute__((deprecated)) // expected-note {{'CL' has been explicitly marked d ...@@ -49,7 +49,7 @@ __attribute__((deprecated)) // expected-note {{'CL' has been explicitly marked d
@end @end
@implementation SUB @implementation SUB
- (void) B {} // expected-warning {{Implementing deprecated method}} - (void) B {} // expected-warning {{implementing deprecated method}}
@end @end
@interface Test @interface Test
...@@ -69,5 +69,5 @@ __attribute__((deprecated)) ...@@ -69,5 +69,5 @@ __attribute__((deprecated))
@interface Test(DeprecatedCategory) // expected-note {{category declared here}} @interface Test(DeprecatedCategory) // expected-note {{category declared here}}
@end @end
@implementation Test(DeprecatedCategory) // expected-warning {{Implementing deprecated category}} @implementation Test(DeprecatedCategory) // expected-warning {{implementing deprecated category}}
@end @end
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment