Objective-C. Reduce false positive warnings with -Wselector by issuing warning
only when named selector is declared in TU and it is not declared in a system
header. rdar://16600230
llvm-svn: 208443
diff --git a/clang/lib/Sema/SemaExprObjC.cpp b/clang/lib/Sema/SemaExprObjC.cpp
index 037175e..d388a4b 100644
--- a/clang/lib/Sema/SemaExprObjC.cpp
+++ b/clang/lib/Sema/SemaExprObjC.cpp
@@ -1049,8 +1049,9 @@
} else
DiagnoseMismatchedSelectors(*this, AtLoc, Method);
- if (!Method ||
- Method->getImplementationControl() != ObjCMethodDecl::Optional) {
+ if (Method &&
+ Method->getImplementationControl() != ObjCMethodDecl::Optional &&
+ !getSourceManager().isInSystemHeader(Method->getLocation())) {
llvm::DenseMap<Selector, SourceLocation>::iterator Pos
= ReferencedSelectors.find(Sel);
if (Pos == ReferencedSelectors.end())
diff --git a/clang/test/PCH/Inputs/chain-selectors2.h b/clang/test/PCH/Inputs/chain-selectors2.h
index d54244d..741da92 100644
--- a/clang/test/PCH/Inputs/chain-selectors2.h
+++ b/clang/test/PCH/Inputs/chain-selectors2.h
@@ -1,6 +1,8 @@
@interface Y
-(void)f;
-(void)f2;
+ -(void)x;
+ -(void)y;
-(void)e;
@end
diff --git a/clang/test/SemaObjC/selector-3.m b/clang/test/SemaObjC/selector-3.m
index c934dbc..dfd216a 100644
--- a/clang/test/SemaObjC/selector-3.m
+++ b/clang/test/SemaObjC/selector-3.m
@@ -14,7 +14,7 @@
- (void) foo
{
SEL a,b,c;
- a = @selector(b1ar); // expected-warning {{no method with selector 'b1ar' is implemented in this translation unit}}
+ a = @selector(b1ar);
b = @selector(bar);
}
@end
@@ -69,7 +69,7 @@
@implementation INTF
- (void) Meth {
- if( [cnx respondsToSelector:MySelector(@selector( _setQueue: ))] ) // expected-warning {{no method with selector '_setQueue:' is implemented in this translation unit}}
+ if( [cnx respondsToSelector:MySelector(@selector( _setQueue: ))] )
{
}
diff --git a/clang/test/SemaObjC/selector-4.m b/clang/test/SemaObjC/selector-4.m
new file mode 100644
index 0000000..59a8233
--- /dev/null
+++ b/clang/test/SemaObjC/selector-4.m
@@ -0,0 +1,28 @@
+// RUN: %clang_cc1 -Wselector -x objective-c %s -include %s -verify
+// expected-no-diagnostics
+// rdar://16600230
+
+#ifndef INCLUDED
+#define INCLUDED
+
+#pragma clang system_header
+
+@interface NSObject @end
+@interface NSString @end
+
+@interface NSString (NSStringExtensionMethods)
+- (void)compare:(NSString *)string;
+@end
+
+@interface MyObject : NSObject
+@end
+
+#else
+int main() {
+ (void)@selector(compare:);
+}
+
+@implementation MyObject
+
+@end
+#endif