Skip to content
This repository was archived by the owner on Nov 1, 2021. It is now read-only.

Commit e9abcb4

Browse files
committed
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
1 parent 5ad4bad commit e9abcb4

File tree

3 files changed

+35
-29
lines changed

3 files changed

+35
-29
lines changed

Diff for: include/clang/Basic/DiagnosticSemaKinds.td

+2-2
Original file line numberDiff line numberDiff line change
@@ -4579,8 +4579,8 @@ def warn_deprecated_fwdclass_message : Warning<
45794579
"%0 may be deprecated because the receiver type is unknown">,
45804580
InGroup<DeprecatedDeclarations>;
45814581
def warn_deprecated_def : Warning<
4582-
"Implementing deprecated %select{method|class|category}0">,
4583-
InGroup<DeprecatedImplementations>, DefaultIgnore;
4582+
"implementing deprecated %select{method|class|category}0">,
4583+
InGroup<DeprecatedImplementations>, DefaultIgnore;
45844584
def err_unavailable : Error<"%0 is unavailable">;
45854585
def err_property_method_unavailable :
45864586
Error<"property access is using %0 method which is unavailable">;

Diff for: lib/Sema/SemaDeclObjC.cpp

+28-22
Original file line numberDiff line numberDiff line change
@@ -248,19 +248,31 @@ bool Sema::CheckARCMethodDecl(ObjCMethodDecl *method) {
248248
return false;
249249
}
250250

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;
263264
}
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");
264276
}
265277

266278
/// AddAnyMethodToGlobalPool - Add any method, instance or factory to global
@@ -385,9 +397,7 @@ void Sema::ActOnStartOfObjCMethodDef(Scope *FnBodyScope, Decl *D) {
385397
// No need to issue deprecated warning if deprecated mehod in class/category
386398
// is being implemented in its own implementation (no overriding is involved).
387399
if (!ImplDeclOfMethodDecl || ImplDeclOfMethodDecl != ImplDeclOfMethodDef)
388-
DiagnoseObjCImplementedDeprecations(*this,
389-
dyn_cast<NamedDecl>(IMD),
390-
MDecl->getLocation(), 0);
400+
DiagnoseObjCImplementedDeprecations(*this, IMD, MDecl->getLocation());
391401
}
392402

393403
if (MDecl->getMethodFamily() == OMF_init) {
@@ -1873,10 +1883,8 @@ Decl *Sema::ActOnStartCategoryImplementation(
18731883
CatIDecl->setImplementation(CDecl);
18741884
// Warn on implementating category of deprecated class under
18751885
// -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());
18801888
}
18811889
}
18821890

@@ -1996,9 +2004,7 @@ Decl *Sema::ActOnStartClassImplementation(
19962004
PushOnScopeChains(IMPDecl, TUScope);
19972005
// Warn on implementating deprecated class under
19982006
// -Wdeprecated-implementations flag.
1999-
DiagnoseObjCImplementedDeprecations(*this,
2000-
dyn_cast<NamedDecl>(IDecl),
2001-
IMPDecl->getLocation(), 1);
2007+
DiagnoseObjCImplementedDeprecations(*this, IDecl, IMPDecl->getLocation());
20022008
}
20032009

20042010
// If the superclass has the objc_runtime_visible attribute, we

Diff for: test/SemaObjC/warn-deprecated-implementations.m

+5-5
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ - (void) E __attribute__((deprecated));
1616

1717
@implementation A
1818
+ (void)F { } // No warning, implementing its own deprecated method
19-
- (void) D {} // expected-warning {{Implementing deprecated method}}
19+
- (void) D {} // expected-warning {{implementing deprecated method}}
2020
- (void) E {} // No warning, implementing deprecated method in its class extension.
2121
@end
2222

@@ -32,10 +32,10 @@ - (void) G {} // No warning, implementing its own deprecated method
3232
@interface CL // expected-note 2 {{class declared here}}
3333
@end
3434

35-
@implementation CL // expected-warning {{Implementing deprecated class}}
35+
@implementation CL // expected-warning {{implementing deprecated class}}
3636
@end
3737

38-
@implementation CL (SomeCategory) // expected-warning {{Implementing deprecated category}}
38+
@implementation CL (SomeCategory) // expected-warning {{implementing deprecated category}}
3939
@end
4040

4141
@interface CL_SUB : CL // expected-warning {{'CL' is deprecated}}
@@ -49,7 +49,7 @@ @interface SUB : BASE
4949
@end
5050

5151
@implementation SUB
52-
- (void) B {} // expected-warning {{Implementing deprecated method}}
52+
- (void) B {} // expected-warning {{implementing deprecated method}}
5353
@end
5454

5555
@interface Test
@@ -69,5 +69,5 @@ - (id)initSpecialInPrivateHeader {
6969
@interface Test(DeprecatedCategory) // expected-note {{category declared here}}
7070
@end
7171

72-
@implementation Test(DeprecatedCategory) // expected-warning {{Implementing deprecated category}}
72+
@implementation Test(DeprecatedCategory) // expected-warning {{implementing deprecated category}}
7373
@end

0 commit comments

Comments
 (0)