From 740991bdf8bb2638ff111ae2084791c52c1cee00 Mon Sep 17 00:00:00 2001 From: Fariborz Jahanian Date: Thu, 4 Apr 2013 18:45:52 +0000 Subject: [PATCH] Objective-C: Issue deprecated warning when using a deprecated typedef to subclass or invoke a class method. // rdar://13569424 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@178775 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Sema/SemaDeclObjC.cpp | 8 +++++++- lib/Sema/SemaExprObjC.cpp | 6 ++++-- test/SemaObjC/attr-deprecated.m | 19 +++++++++++++++++++ 3 files changed, 30 insertions(+), 3 deletions(-) diff --git a/lib/Sema/SemaDeclObjC.cpp b/lib/Sema/SemaDeclObjC.cpp index 96a432a108..5c26d7ff8e 100644 --- a/lib/Sema/SemaDeclObjC.cpp +++ b/lib/Sema/SemaDeclObjC.cpp @@ -521,8 +521,14 @@ ActOnStartClassInterface(SourceLocation AtInterfaceLoc, dyn_cast_or_null(PrevDecl)) { QualType T = TDecl->getUnderlyingType(); if (T->isObjCObjectType()) { - if (NamedDecl *IDecl = T->getAs()->getInterface()) + if (NamedDecl *IDecl = T->getAs()->getInterface()) { SuperClassDecl = dyn_cast(IDecl); + // This handles the following case: + // @interface NewI @end + // typedef NewI DeprI __attribute__((deprecated("blah"))) + // @interface SI : DeprI /* warn here */ @end + (void)DiagnoseUseOfDecl(const_cast(TDecl), SuperLoc); + } } } diff --git a/lib/Sema/SemaExprObjC.cpp b/lib/Sema/SemaExprObjC.cpp index 51a190651e..e7b5ec9b01 100644 --- a/lib/Sema/SemaExprObjC.cpp +++ b/lib/Sema/SemaExprObjC.cpp @@ -1786,9 +1786,11 @@ Sema::ObjCMessageKind Sema::getObjCMessageKind(Scope *S, QualType T; if (ObjCInterfaceDecl *Class = dyn_cast(ND)) T = Context.getObjCInterfaceType(Class); - else if (TypeDecl *Type = dyn_cast(ND)) + else if (TypeDecl *Type = dyn_cast(ND)) { T = Context.getTypeDeclType(Type); - else + DiagnoseUseOfDecl(Type, NameLoc); + } + else return ObjCInstanceMessage; // We have a class message, and T is the type we're diff --git a/test/SemaObjC/attr-deprecated.m b/test/SemaObjC/attr-deprecated.m index c0aa9fc070..aa4b479e00 100644 --- a/test/SemaObjC/attr-deprecated.m +++ b/test/SemaObjC/attr-deprecated.m @@ -1,4 +1,5 @@ // RUN: %clang_cc1 -fsyntax-only -verify -Wno-objc-root-class %s +// RUN: %clang_cc1 -x objective-c++ -fsyntax-only -verify -Wno-objc-root-class %s @interface A { int X __attribute__((deprecated)); // expected-note 2 {{declared here}} @@ -135,3 +136,21 @@ typedef struct { @property footype c; // expected-warning {{'footype' is deprecated}} @property footype d __attribute((deprecated)); @end + +// rdar://13569424 +@interface NewI ++(void)cmeth; +@end + +typedef NewI DeprI __attribute__((deprecated("blah"))); // expected-note 4 {{'DeprI' declared here}} + +@interface SI : DeprI // expected-warning {{'DeprI' is deprecated: blah}} +-(DeprI*)meth; // expected-warning {{'DeprI' is deprecated: blah}} +@end + +@implementation SI +-(DeprI*)meth { // expected-warning {{'DeprI' is deprecated: blah}} + [DeprI cmeth]; // expected-warning {{'DeprI' is deprecated: blah}} + return 0; +} +@end -- 2.40.0