From: Fariborz Jahanian Date: Fri, 7 Nov 2014 23:51:15 +0000 (+0000) Subject: [Objective-C Sema]. Issue availability/deprecated warning when X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=90d23dda98b4136aaf8ef26a65f4f988829ddabd;p=clang [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 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@221562 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Sema/SemaExprObjC.cpp b/lib/Sema/SemaExprObjC.cpp index ae9942b1c3..0730cf6e7b 100644 --- a/lib/Sema/SemaExprObjC.cpp +++ b/lib/Sema/SemaExprObjC.cpp @@ -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 Methods; + if (!CollectMultipleMethodsInGlobalPool(Sel, Methods, Method->isInstanceMethod())) + DiagnoseUseOfDecl(Method, SelLoc); + } } else if (ReceiverType->isObjCClassType() || ReceiverType->isObjCQualifiedClassType()) { // Handle messages to Class. diff --git a/test/ARCMT/checking.m b/test/ARCMT/checking.m index d8ccf16752..76c4443076 100644 --- a/test/ARCMT/checking.m +++ b/test/ARCMT/checking.m @@ -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 diff --git a/test/SemaObjC/attr-deprecated.m b/test/SemaObjC/attr-deprecated.m index 4eb56ee7d7..20d8c1066e 100644 --- a/test/SemaObjC/attr-deprecated.m +++ b/test/SemaObjC/attr-deprecated.m @@ -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

* 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}} +} +