From: Fariborz Jahanian Date: Wed, 13 Jul 2011 19:05:43 +0000 (+0000) Subject: With -Wselector, don't warn about unimplemented optional method X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=4c91d89453c4a540d9ad697ceae89c8ef6049a6b;p=clang With -Wselector, don't warn about unimplemented optional method used in @selector expression because, well, their implementation is optional. // rdar://9545564 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@135057 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Sema/SemaExprObjC.cpp b/lib/Sema/SemaExprObjC.cpp index 3df6d3f96e..02a4682cc8 100644 --- a/lib/Sema/SemaExprObjC.cpp +++ b/lib/Sema/SemaExprObjC.cpp @@ -178,11 +178,14 @@ ExprResult Sema::ParseObjCSelectorExpression(Selector Sel, SourceRange(LParenLoc, RParenLoc)); if (!Method) Diag(SelLoc, diag::warn_undeclared_selector) << Sel; - - llvm::DenseMap::iterator Pos - = ReferencedSelectors.find(Sel); - if (Pos == ReferencedSelectors.end()) - ReferencedSelectors.insert(std::make_pair(Sel, SelLoc)); + + if (!Method || + Method->getImplementationControl() != ObjCMethodDecl::Optional) { + llvm::DenseMap::iterator Pos + = ReferencedSelectors.find(Sel); + if (Pos == ReferencedSelectors.end()) + ReferencedSelectors.insert(std::make_pair(Sel, SelLoc)); + } // In ARC, forbid the user from using @selector for // retain/release/autorelease/dealloc/retainCount. diff --git a/test/SemaObjC/selector-3.m b/test/SemaObjC/selector-3.m index 69a74f830c..b248a5d036 100644 --- a/test/SemaObjC/selector-3.m +++ b/test/SemaObjC/selector-3.m @@ -27,3 +27,28 @@ SEL func() { return @selector(length); // expected-warning {{unimplemented selector 'length'}} } + +// rdar://9545564 +@class MSPauseManager; + +@protocol MSPauseManagerDelegate +@optional +- (void)pauseManagerDidPause:(MSPauseManager *)manager; +- (int)respondsToSelector:(SEL)aSelector; +@end + +@interface MSPauseManager +{ + id _delegate; +} +@end + + +@implementation MSPauseManager +- (id) Meth { + if ([_delegate respondsToSelector:@selector(pauseManagerDidPause:)]) + return 0; + return 0; +} +@end +