@@ -248,19 +248,31 @@ bool Sema::CheckARCMethodDecl(ObjCMethodDecl *method) {
248
248
return false ;
249
249
}
250
250
251
- static void DiagnoseObjCImplementedDeprecations (Sema &S,
252
- NamedDecl *ND,
253
- SourceLocation ImplLoc,
254
- int select) {
255
- if (ND && ND->isDeprecated ()) {
256
- S.Diag (ImplLoc, diag::warn_deprecated_def) << select ;
257
- if (select == 0 )
258
- S.Diag (ND->getLocation (), diag::note_method_declared_at)
259
- << ND->getDeclName ();
260
- else
261
- S.Diag (ND->getLocation (), diag::note_previous_decl)
262
- << (isa<ObjCCategoryDecl>(ND) ? " category" : " class" );
251
+ static void DiagnoseObjCImplementedDeprecations (Sema &S, const NamedDecl *ND,
252
+ SourceLocation ImplLoc) {
253
+ if (!ND)
254
+ return ;
255
+ bool IsCategory = false ;
256
+ if (!ND->isDeprecated ()) {
257
+ if (const auto *CD = dyn_cast<ObjCCategoryDecl>(ND)) {
258
+ if (!CD->getClassInterface ()->isDeprecated ())
259
+ return ;
260
+ ND = CD->getClassInterface ();
261
+ IsCategory = true ;
262
+ } else
263
+ return ;
263
264
}
265
+ S.Diag (ImplLoc, diag::warn_deprecated_def)
266
+ << (isa<ObjCMethodDecl>(ND)
267
+ ? /* Method*/ 0
268
+ : isa<ObjCCategoryDecl>(ND) || IsCategory ? /* Category*/ 2
269
+ : /* Class*/ 1 );
270
+ if (isa<ObjCMethodDecl>(ND))
271
+ S.Diag (ND->getLocation (), diag::note_method_declared_at)
272
+ << ND->getDeclName ();
273
+ else
274
+ S.Diag (ND->getLocation (), diag::note_previous_decl)
275
+ << (isa<ObjCCategoryDecl>(ND) ? " category" : " class" );
264
276
}
265
277
266
278
// / AddAnyMethodToGlobalPool - Add any method, instance or factory to global
@@ -385,9 +397,7 @@ void Sema::ActOnStartOfObjCMethodDef(Scope *FnBodyScope, Decl *D) {
385
397
// No need to issue deprecated warning if deprecated mehod in class/category
386
398
// is being implemented in its own implementation (no overriding is involved).
387
399
if (!ImplDeclOfMethodDecl || ImplDeclOfMethodDecl != ImplDeclOfMethodDef)
388
- DiagnoseObjCImplementedDeprecations (*this ,
389
- dyn_cast<NamedDecl>(IMD),
390
- MDecl->getLocation (), 0 );
400
+ DiagnoseObjCImplementedDeprecations (*this , IMD, MDecl->getLocation ());
391
401
}
392
402
393
403
if (MDecl->getMethodFamily () == OMF_init) {
@@ -1873,10 +1883,8 @@ Decl *Sema::ActOnStartCategoryImplementation(
1873
1883
CatIDecl->setImplementation (CDecl);
1874
1884
// Warn on implementating category of deprecated class under
1875
1885
// -Wdeprecated-implementations flag.
1876
- DiagnoseObjCImplementedDeprecations (
1877
- *this ,
1878
- CatIDecl->isDeprecated () ? CatIDecl : dyn_cast<NamedDecl>(IDecl),
1879
- CDecl->getLocation (), 2 );
1886
+ DiagnoseObjCImplementedDeprecations (*this , CatIDecl,
1887
+ CDecl->getLocation ());
1880
1888
}
1881
1889
}
1882
1890
@@ -1996,9 +2004,7 @@ Decl *Sema::ActOnStartClassImplementation(
1996
2004
PushOnScopeChains (IMPDecl, TUScope);
1997
2005
// Warn on implementating deprecated class under
1998
2006
// -Wdeprecated-implementations flag.
1999
- DiagnoseObjCImplementedDeprecations (*this ,
2000
- dyn_cast<NamedDecl>(IDecl),
2001
- IMPDecl->getLocation (), 1 );
2007
+ DiagnoseObjCImplementedDeprecations (*this , IDecl, IMPDecl->getLocation ());
2002
2008
}
2003
2009
2004
2010
// If the superclass has the objc_runtime_visible attribute, we
0 commit comments