From e9abcb4c08cd75b29a7c58138de1ecc2fcea996a Mon Sep 17 00:00:00 2001 From: Alex Lorenz Date: Thu, 13 Jul 2017 16:35:59 +0000 Subject: [PATCH] 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 --- include/clang/Basic/DiagnosticSemaKinds.td | 4 +- lib/Sema/SemaDeclObjC.cpp | 50 +++++++++++-------- .../warn-deprecated-implementations.m | 10 ++-- 3 files changed, 35 insertions(+), 29 deletions(-) diff --git a/include/clang/Basic/DiagnosticSemaKinds.td b/include/clang/Basic/DiagnosticSemaKinds.td index 709a96a6c9..671c3e92f4 100644 --- a/include/clang/Basic/DiagnosticSemaKinds.td +++ b/include/clang/Basic/DiagnosticSemaKinds.td @@ -4579,8 +4579,8 @@ def warn_deprecated_fwdclass_message : Warning< "%0 may be deprecated because the receiver type is unknown">, InGroup; def warn_deprecated_def : Warning< - "Implementing deprecated %select{method|class|category}0">, - InGroup, DefaultIgnore; + "implementing deprecated %select{method|class|category}0">, + InGroup, DefaultIgnore; def err_unavailable : Error<"%0 is unavailable">; def err_property_method_unavailable : Error<"property access is using %0 method which is unavailable">; diff --git a/lib/Sema/SemaDeclObjC.cpp b/lib/Sema/SemaDeclObjC.cpp index 778b8062f6..2cf0ca94ac 100644 --- a/lib/Sema/SemaDeclObjC.cpp +++ b/lib/Sema/SemaDeclObjC.cpp @@ -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(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(ND)) { + if (!CD->getClassInterface()->isDeprecated()) + return; + ND = CD->getClassInterface(); + IsCategory = true; + } else + return; } + S.Diag(ImplLoc, diag::warn_deprecated_def) + << (isa(ND) + ? /*Method*/ 0 + : isa(ND) || IsCategory ? /*Category*/ 2 + : /*Class*/ 1); + if (isa(ND)) + S.Diag(ND->getLocation(), diag::note_method_declared_at) + << ND->getDeclName(); + else + S.Diag(ND->getLocation(), diag::note_previous_decl) + << (isa(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(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(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(IDecl), - IMPDecl->getLocation(), 1); + DiagnoseObjCImplementedDeprecations(*this, IDecl, IMPDecl->getLocation()); } // If the superclass has the objc_runtime_visible attribute, we diff --git a/test/SemaObjC/warn-deprecated-implementations.m b/test/SemaObjC/warn-deprecated-implementations.m index df2557b9cd..ed2156d9ab 100644 --- a/test/SemaObjC/warn-deprecated-implementations.m +++ b/test/SemaObjC/warn-deprecated-implementations.m @@ -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 -- 2.40.0