From: Fariborz Jahanian Date: Fri, 9 May 2014 19:51:39 +0000 (+0000) Subject: Objective-C. Reduce false positive warnings with -Wselector by issuing warning X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=53331ec34a9298dce6c86d3c464f939f956a1bb3;p=clang 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 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@208443 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Sema/SemaExprObjC.cpp b/lib/Sema/SemaExprObjC.cpp index 037175e601..d388a4b82e 100644 --- a/lib/Sema/SemaExprObjC.cpp +++ b/lib/Sema/SemaExprObjC.cpp @@ -1049,8 +1049,9 @@ ExprResult Sema::ParseObjCSelectorExpression(Selector Sel, } else DiagnoseMismatchedSelectors(*this, AtLoc, Method); - if (!Method || - Method->getImplementationControl() != ObjCMethodDecl::Optional) { + if (Method && + Method->getImplementationControl() != ObjCMethodDecl::Optional && + !getSourceManager().isInSystemHeader(Method->getLocation())) { llvm::DenseMap::iterator Pos = ReferencedSelectors.find(Sel); if (Pos == ReferencedSelectors.end()) diff --git a/test/PCH/Inputs/chain-selectors2.h b/test/PCH/Inputs/chain-selectors2.h index d54244de61..741da9288a 100644 --- a/test/PCH/Inputs/chain-selectors2.h +++ b/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/test/SemaObjC/selector-3.m b/test/SemaObjC/selector-3.m index c934dbcd8d..dfd216a16f 100644 --- a/test/SemaObjC/selector-3.m +++ b/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 @@ extern SEL MySelector(SEL s); @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/test/SemaObjC/selector-4.m b/test/SemaObjC/selector-4.m new file mode 100644 index 0000000000..59a8233f6b --- /dev/null +++ b/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