diff --git a/clang/lib/Sema/SemaExprObjC.cpp b/clang/lib/Sema/SemaExprObjC.cpp index 3df6d3f96e43..02a4682cc840 100644 --- a/clang/lib/Sema/SemaExprObjC.cpp +++ b/clang/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/clang/test/SemaObjC/selector-3.m b/clang/test/SemaObjC/selector-3.m index 69a74f830ce5..b248a5d036ab 100644 --- a/clang/test/SemaObjC/selector-3.m +++ b/clang/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 +