r307923 - NFC, Cleanup the code for -Wdeprecated-implementations
Alex Lorenz via cfe-commits
cfe-commits at lists.llvm.org
Thu Jul 13 09:35:59 PDT 2017
Author: arphaman
Date: Thu Jul 13 09:35:59 2017
New Revision: 307923
URL: http://llvm.org/viewvc/llvm-project?rev=307923&view=rev
Log:
NFC, Cleanup the code for -Wdeprecated-implementations
and void capitalization of the warning message
rdar://22867595
Modified:
cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
cfe/trunk/lib/Sema/SemaDeclObjC.cpp
cfe/trunk/test/SemaObjC/warn-deprecated-implementations.m
Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td?rev=307923&r1=307922&r2=307923&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Thu Jul 13 09:35:59 2017
@@ -4579,8 +4579,8 @@ def warn_deprecated_fwdclass_message : W
"%0 may be deprecated because the receiver type is unknown">,
InGroup<DeprecatedDeclarations>;
def warn_deprecated_def : Warning<
- "Implementing deprecated %select{method|class|category}0">,
- InGroup<DeprecatedImplementations>, DefaultIgnore;
+ "implementing deprecated %select{method|class|category}0">,
+ InGroup<DeprecatedImplementations>, DefaultIgnore;
def err_unavailable : Error<"%0 is unavailable">;
def err_property_method_unavailable :
Error<"property access is using %0 method which is unavailable">;
Modified: cfe/trunk/lib/Sema/SemaDeclObjC.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDeclObjC.cpp?rev=307923&r1=307922&r2=307923&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaDeclObjC.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDeclObjC.cpp Thu Jul 13 09:35:59 2017
@@ -248,19 +248,31 @@ bool Sema::CheckARCMethodDecl(ObjCMethod
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<ObjCCategoryDecl>(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<ObjCCategoryDecl>(ND)) {
+ if (!CD->getClassInterface()->isDeprecated())
+ return;
+ ND = CD->getClassInterface();
+ IsCategory = true;
+ } 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
@@ -385,9 +397,7 @@ void Sema::ActOnStartOfObjCMethodDef(Sco
// 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<NamedDecl>(IMD),
- MDecl->getLocation(), 0);
+ DiagnoseObjCImplementedDeprecations(*this, IMD, MDecl->getLocation());
}
if (MDecl->getMethodFamily() == OMF_init) {
@@ -1873,10 +1883,8 @@ Decl *Sema::ActOnStartCategoryImplementa
CatIDecl->setImplementation(CDecl);
// Warn on implementating category of deprecated class under
// -Wdeprecated-implementations flag.
- DiagnoseObjCImplementedDeprecations(
- *this,
- CatIDecl->isDeprecated() ? CatIDecl : dyn_cast<NamedDecl>(IDecl),
- CDecl->getLocation(), 2);
+ DiagnoseObjCImplementedDeprecations(*this, CatIDecl,
+ CDecl->getLocation());
}
}
@@ -1996,9 +2004,7 @@ Decl *Sema::ActOnStartClassImplementatio
PushOnScopeChains(IMPDecl, TUScope);
// Warn on implementating deprecated class under
// -Wdeprecated-implementations flag.
- DiagnoseObjCImplementedDeprecations(*this,
- dyn_cast<NamedDecl>(IDecl),
- IMPDecl->getLocation(), 1);
+ DiagnoseObjCImplementedDeprecations(*this, IDecl, IMPDecl->getLocation());
}
// If the superclass has the objc_runtime_visible attribute, we
Modified: cfe/trunk/test/SemaObjC/warn-deprecated-implementations.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaObjC/warn-deprecated-implementations.m?rev=307923&r1=307922&r2=307923&view=diff
==============================================================================
--- cfe/trunk/test/SemaObjC/warn-deprecated-implementations.m (original)
+++ cfe/trunk/test/SemaObjC/warn-deprecated-implementations.m Thu Jul 13 09:35:59 2017
@@ -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-
@interface CL // expected-note 2 {{class declared here}}
@end
- at implementation CL // expected-warning {{Implementing deprecated class}}
+ at implementation CL // expected-warning {{implementing deprecated class}}
@end
- at implementation CL (SomeCategory) // expected-warning {{Implementing deprecated category}}
+ at 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-
@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
- at implementation Test(DeprecatedCategory) // expected-warning {{Implementing deprecated category}}
+ at implementation Test(DeprecatedCategory) // expected-warning {{implementing deprecated category}}
@end
More information about the cfe-commits
mailing list