]> granicus.if.org Git - clang/commitdiff
With -Wselector, don't warn about unimplemented optional method
authorFariborz Jahanian <fjahanian@apple.com>
Wed, 13 Jul 2011 19:05:43 +0000 (19:05 +0000)
committerFariborz Jahanian <fjahanian@apple.com>
Wed, 13 Jul 2011 19:05:43 +0000 (19:05 +0000)
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

lib/Sema/SemaExprObjC.cpp
test/SemaObjC/selector-3.m

index 3df6d3f96e431f1bfbf1fc8cca2eb155f5f19f32..02a4682cc840cd18b503435646af0208174b4f1d 100644 (file)
@@ -178,11 +178,14 @@ ExprResult Sema::ParseObjCSelectorExpression(Selector Sel,
                                           SourceRange(LParenLoc, RParenLoc));
   if (!Method)
     Diag(SelLoc, diag::warn_undeclared_selector) << Sel;
-
-  llvm::DenseMap<Selector, SourceLocation>::iterator Pos
-    = ReferencedSelectors.find(Sel);
-  if (Pos == ReferencedSelectors.end())
-    ReferencedSelectors.insert(std::make_pair(Sel, SelLoc));
+  
+  if (!Method ||
+      Method->getImplementationControl() != ObjCMethodDecl::Optional) {
+    llvm::DenseMap<Selector, SourceLocation>::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.
index 69a74f830ce527fed921ad1a90e1be343137dc5f..b248a5d036ab3ed58e68c589163af3f30fb975c6 100644 (file)
@@ -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<MSPauseManagerDelegate> _delegate;
+}
+@end
+
+
+@implementation MSPauseManager
+- (id) Meth {
+  if ([_delegate respondsToSelector:@selector(pauseManagerDidPause:)])
+    return 0;
+  return 0;
+}
+@end
+