objc: issue deprecated/unavailable diagnostic when

methods with these attributes are sent to receivers
of 'id' type too. // rdar://10459930

llvm-svn: 145999
This commit is contained in:
Fariborz Jahanian 2011-12-07 00:30:00 +00:00
parent 61e6d987bf
commit 6bdeb14d5d
5 changed files with 34 additions and 9 deletions

View File

@ -2276,6 +2276,9 @@ public:
bool CanUseDecl(NamedDecl *D); bool CanUseDecl(NamedDecl *D);
bool DiagnoseUseOfDecl(NamedDecl *D, SourceLocation Loc, bool DiagnoseUseOfDecl(NamedDecl *D, SourceLocation Loc,
const ObjCInterfaceDecl *UnknownObjCClass=0); const ObjCInterfaceDecl *UnknownObjCClass=0);
AvailabilityResult DiagnoseAvailabilityOfDecl(NamedDecl *D,
SourceLocation Loc,
const ObjCInterfaceDecl *UnknownObjCClass);
std::string getDeletedOrUnavailableSuffix(const FunctionDecl *FD); std::string getDeletedOrUnavailableSuffix(const FunctionDecl *FD);
bool DiagnosePropertyAccessorMismatch(ObjCPropertyDecl *PD, bool DiagnosePropertyAccessorMismatch(ObjCPropertyDecl *PD,
ObjCMethodDecl *Getter, ObjCMethodDecl *Getter,

View File

@ -62,7 +62,8 @@ bool Sema::CanUseDecl(NamedDecl *D) {
return true; return true;
} }
static AvailabilityResult DiagnoseAvailabilityOfDecl(Sema &S, AvailabilityResult
Sema::DiagnoseAvailabilityOfDecl(
NamedDecl *D, SourceLocation Loc, NamedDecl *D, SourceLocation Loc,
const ObjCInterfaceDecl *UnknownObjCClass) { const ObjCInterfaceDecl *UnknownObjCClass) {
// See if this declaration is unavailable or deprecated. // See if this declaration is unavailable or deprecated.
@ -81,22 +82,22 @@ static AvailabilityResult DiagnoseAvailabilityOfDecl(Sema &S,
break; break;
case AR_Deprecated: case AR_Deprecated:
S.EmitDeprecationWarning(D, Message, Loc, UnknownObjCClass); EmitDeprecationWarning(D, Message, Loc, UnknownObjCClass);
break; break;
case AR_Unavailable: case AR_Unavailable:
if (S.getCurContextAvailability() != AR_Unavailable) { if (getCurContextAvailability() != AR_Unavailable) {
if (Message.empty()) { if (Message.empty()) {
if (!UnknownObjCClass) if (!UnknownObjCClass)
S.Diag(Loc, diag::err_unavailable) << D->getDeclName(); Diag(Loc, diag::err_unavailable) << D->getDeclName();
else else
S.Diag(Loc, diag::warn_unavailable_fwdclass_message) Diag(Loc, diag::warn_unavailable_fwdclass_message)
<< D->getDeclName(); << D->getDeclName();
} }
else else
S.Diag(Loc, diag::err_unavailable_message) Diag(Loc, diag::err_unavailable_message)
<< D->getDeclName() << Message; << D->getDeclName() << Message;
S.Diag(D->getLocation(), diag::note_unavailable_here) Diag(D->getLocation(), diag::note_unavailable_here)
<< isa<FunctionDecl>(D) << false; << isa<FunctionDecl>(D) << false;
} }
break; break;
@ -151,7 +152,7 @@ bool Sema::DiagnoseUseOfDecl(NamedDecl *D, SourceLocation Loc,
return true; return true;
} }
} }
DiagnoseAvailabilityOfDecl(*this, D, Loc, UnknownObjCClass); DiagnoseAvailabilityOfDecl(D, Loc, UnknownObjCClass);
// Warn if this is used but marked unused. // Warn if this is used but marked unused.
if (D->hasAttr<UnusedAttr>()) if (D->hasAttr<UnusedAttr>())

View File

@ -1254,6 +1254,9 @@ ExprResult Sema::BuildInstanceMessage(Expr *Receiver,
Method = LookupFactoryMethodInGlobalPool(Sel, Method = LookupFactoryMethodInGlobalPool(Sel,
SourceRange(LBracLoc, RBracLoc), SourceRange(LBracLoc, RBracLoc),
receiverIsId); receiverIsId);
if (Method)
DiagnoseAvailabilityOfDecl(Method, Loc, 0);
} else if (ReceiverType->isObjCClassType() || } else if (ReceiverType->isObjCClassType() ||
ReceiverType->isObjCQualifiedClassType()) { ReceiverType->isObjCQualifiedClassType()) {
// Handle messages to Class. // Handle messages to Class.

View File

@ -1,4 +1,5 @@
// RUN: %clang_cc1 -arcmt-check -verify -triple x86_64-apple-darwin10 %s // RUN: %clang_cc1 -arcmt-check -verify -triple x86_64-apple-darwin10 %s
// XFAIL: *
#include "Common.h" #include "Common.h"

View File

@ -53,7 +53,7 @@ void t1(A *a)
void t2(id a) void t2(id a)
{ {
[a f]; [a f]; // expected-warning {{'f' is deprecated}}
} }
void t3(A<P>* a) void t3(A<P>* a)
@ -121,3 +121,20 @@ void test(Test2 *foo) {
__attribute__((deprecated)) __attribute__((deprecated))
@interface A(Blah) // expected-error{{attributes may not be specified on a category}} @interface A(Blah) // expected-error{{attributes may not be specified on a category}}
@end @end
// rdar://10459930
@class NSString;
@interface NSDocumentController
{
id iv;
}
- (void)fileExtensionsFromType:(NSString *)typeName __attribute__((deprecated));
@end
@implementation NSDocumentController
- (void) Meth {
[iv fileExtensionsFromType:@"public.text"]; // expected-warning {{'fileExtensionsFromType:' is deprecated}}
}
- (void)fileExtensionsFromType:(NSString *)typeName {}
@end