[Objective-C Sema]. Issue availability/deprecated warning when

there is a uinque method found when message is sent to receiver 
of 'id' type. // rdar://18848183

llvm-svn: 221562
This commit is contained in:
Fariborz Jahanian 2014-11-07 23:51:15 +00:00
parent 02862bc83a
commit 05e77f8349
3 changed files with 25 additions and 6 deletions

View File

@ -2448,10 +2448,14 @@ ExprResult Sema::BuildInstanceMessage(Expr *Receiver,
Method = LookupFactoryMethodInGlobalPool(Sel,
SourceRange(LBracLoc,RBracLoc),
receiverIsId);
if (Method)
if (Method) {
if (ObjCMethodDecl *BestMethod =
SelectBestMethod(Sel, ArgsIn, Method->isInstanceMethod()))
Method = BestMethod;
SmallVector<ObjCMethodDecl*, 4> Methods;
if (!CollectMultipleMethodsInGlobalPool(Sel, Methods, Method->isInstanceMethod()))
DiagnoseUseOfDecl(Method, SelLoc);
}
} else if (ReceiverType->isObjCClassType() ||
ReceiverType->isObjCQualifiedClassType()) {
// Handle messages to Class.

View File

@ -14,9 +14,9 @@ typedef int BOOL;
typedef unsigned NSUInteger;
@protocol NSObject
- (id)retain NS_AUTOMATED_REFCOUNT_UNAVAILABLE;
- (id)retain NS_AUTOMATED_REFCOUNT_UNAVAILABLE; // expected-note {{'retain' has been explicitly marked unavailable here}}
- (NSUInteger)retainCount NS_AUTOMATED_REFCOUNT_UNAVAILABLE;
- (oneway void)release NS_AUTOMATED_REFCOUNT_UNAVAILABLE;
- (oneway void)release NS_AUTOMATED_REFCOUNT_UNAVAILABLE; // expected-note 4 {{'release' has been explicitly marked unavailable here}}
- (id)autorelease NS_AUTOMATED_REFCOUNT_UNAVAILABLE;
@end
@ -74,16 +74,20 @@ id global_foo;
void test1(A *a, BOOL b, struct UnsafeS *unsafeS) {
[[a delegate] release]; // expected-error {{it is not safe to remove 'retain' message on the result of a 'delegate' message; the object that was passed to 'setDelegate:' may not be properly retained}} \
// expected-error {{'release' is unavailable: not available in automatic reference counting mode}} \
// expected-error {{ARC forbids explicit message send}}
[a.delegate release]; // expected-error {{it is not safe to remove 'retain' message on the result of a 'delegate' message; the object that was passed to 'setDelegate:' may not be properly retained}} \
// expected-error {{'release' is unavailable: not available in automatic reference counting mode}} \
// expected-error {{ARC forbids explicit message send}}
[unsafeS->unsafeObj retain]; // expected-error {{it is not safe to remove 'retain' message on an __unsafe_unretained type}} \
// expected-error {{ARC forbids explicit message send}} \
// expected-error {{'retain' is unavailable}}
id foo = [unsafeS->unsafeObj retain]; // no warning.
[global_foo retain]; // expected-error {{it is not safe to remove 'retain' message on a global variable}} \
// expected-error {{'retain' is unavailable: not available in automatic reference counting mode}} \
// expected-error {{ARC forbids explicit message send}}
[global_foo release]; // expected-error {{it is not safe to remove 'release' message on a global variable}} \
// expected-error {{'release' is unavailable: not available in automatic reference counting mode}} \
// expected-error {{ARC forbids explicit message send}}
[a dealloc];
[a retain];
@ -304,7 +308,8 @@ void rdar9491791(int p) {
// rdar://9504750
void rdar9504750(id p) {
RELEASE_MACRO(p); // expected-error {{ARC forbids explicit message send of 'release'}}
RELEASE_MACRO(p); // expected-error {{ARC forbids explicit message send of 'release'}} \
// expected-error {{'release' is unavailable: not available in automatic reference counting mode}}
}
// rdar://8939557

View File

@ -5,7 +5,7 @@
int X __attribute__((deprecated)); // expected-note 2 {{'X' has been explicitly marked deprecated here}}
}
+ (void)F __attribute__((deprecated)); // expected-note 2 {{'F' has been explicitly marked deprecated here}}
- (void)f __attribute__((deprecated)); // expected-note 4 {{'f' has been explicitly marked deprecated here}}
- (void)f __attribute__((deprecated)); // expected-note 5 {{'f' has been explicitly marked deprecated here}}
@end
@implementation A
@ -54,7 +54,7 @@ void t1(A *a)
void t2(id a)
{
[a f];
[a f]; // expected-warning {{'f' is deprecated}}
}
void t3(A<P>* a)
@ -228,3 +228,13 @@ expected-note {{property declared here}}
@end
// rdar://18848183
@interface NSString
- (const char *)cString __attribute__((availability(macosx,introduced=10.0 ,deprecated=10.4,message="" ))); // expected-note {{'cString' has been explicitly marked deprecated here}}
@end
id PID = 0;
const char * func() {
return [PID cString]; // expected-warning {{'cString' is deprecated: first deprecated in OS X 10.4}}
}