From c9b7c209bb7b6dfb85dc33fd8ce5ab5bdd53663c Mon Sep 17 00:00:00 2001 From: Fariborz Jahanian Date: Fri, 4 Feb 2011 23:19:27 +0000 Subject: -Wselector should warn on implemented selectors only when selector metadata is generated, which is triggered by at least on class implementation. This is to match gcc's behavior. // rdar://8851684. llvm-svn: 124909 --- clang/include/clang/AST/ASTContext.h | 5 ++++ clang/lib/Sema/SemaDeclObjC.cpp | 6 ++++- clang/test/SemaObjC/selector-1.m | 44 ++++++++++++++++-------------------- clang/test/SemaObjC/selector-2.m | 14 ++++++++++++ 4 files changed, 43 insertions(+), 26 deletions(-) create mode 100644 clang/test/SemaObjC/selector-2.m (limited to 'clang') diff --git a/clang/include/clang/AST/ASTContext.h b/clang/include/clang/AST/ASTContext.h index 5587bf72724..6d3a9f06199 100644 --- a/clang/include/clang/AST/ASTContext.h +++ b/clang/include/clang/AST/ASTContext.h @@ -1381,6 +1381,11 @@ public: /// \brief Get the implementation of ObjCCategoryDecl, or NULL if none exists. ObjCCategoryImplDecl *getObjCImplementation(ObjCCategoryDecl *D); + /// \brief returns true if there is at lease one @implementation in TU. + bool AnyObjCImplementation() { + return !ObjCImpls.empty(); + } + /// \brief Set the implementation of ObjCInterfaceDecl. void setObjCImplementation(ObjCInterfaceDecl *IFaceD, ObjCImplementationDecl *ImplD); diff --git a/clang/lib/Sema/SemaDeclObjC.cpp b/clang/lib/Sema/SemaDeclObjC.cpp index 338a5333c89..a2f6b516bee 100644 --- a/clang/lib/Sema/SemaDeclObjC.cpp +++ b/clang/lib/Sema/SemaDeclObjC.cpp @@ -1994,7 +1994,11 @@ void ObjCImplementationDecl::setIvarInitializers(ASTContext &C, } void Sema::DiagnoseUseOfUnimplementedSelectors() { - if (ReferencedSelectors.empty()) + // Warning will be issued only when selector table is + // generated (which means there is at lease one implementation + // in the TU). This is to match gcc's behavior. + if (ReferencedSelectors.empty() || + !Context.AnyObjCImplementation()) return; for (llvm::DenseMap::iterator S = ReferencedSelectors.begin(), diff --git a/clang/test/SemaObjC/selector-1.m b/clang/test/SemaObjC/selector-1.m index 9a7375b8d28..69a74f830ce 100644 --- a/clang/test/SemaObjC/selector-1.m +++ b/clang/test/SemaObjC/selector-1.m @@ -1,35 +1,29 @@ -// RUN: %clang_cc1 -verify %s +// RUN: %clang_cc1 -fsyntax-only -Wselector -verify %s +// rdar://8851684 -@interface Lancelot @end -@implementation Lancelot +@interface Foo +- (void) foo; +- (void) bar; +@end -- (void):(int)x {} -- (void)xx:(int)x :(int)y { } +@implementation Foo +- (void) bar +{ +} +- (void) foo +{ + SEL a,b,c; + a = @selector(b1ar); // expected-warning {{unimplemented selector 'b1ar'}} + b = @selector(bar); +} @end @interface I -- (id) compare: (char) arg1; +- length; @end -@interface J -- (id) compare: (id) arg1; -@end - -SEL foo() +SEL func() { - return @selector(compare:); // Non warning on multiple selector found. -} - -int main() { - SEL s = @selector(retain); - SEL s1 = @selector(meth1:); - SEL s2 = @selector(retainArgument::); - SEL s3 = @selector(retainArgument:::::); - SEL s4 = @selector(retainArgument:with:); - SEL s5 = @selector(meth1:with:with:); - SEL s6 = @selector(getEnum:enum:bool:); - SEL s7 = @selector(char:float:double:unsigned:short:long:); - - SEL s9 = @selector(:enum:bool:); + return @selector(length); // expected-warning {{unimplemented selector 'length'}} } diff --git a/clang/test/SemaObjC/selector-2.m b/clang/test/SemaObjC/selector-2.m new file mode 100644 index 00000000000..fb75369a9a1 --- /dev/null +++ b/clang/test/SemaObjC/selector-2.m @@ -0,0 +1,14 @@ +// RUN: %clang_cc1 -fsyntax-only -Wselector -verify %s +// rdar://8851684 +@interface I +- length; +@end + +static inline SEL IsEmpty() { + return @selector(length); +} + +int main (int argc, const char * argv[]) { + return 0; +} + -- cgit v1.2.3