From 06028a54545a43eb7d16aae4ab7bcb8635b68434 Mon Sep 17 00:00:00 2001 From: Jean-Daniel Dupas Date: Fri, 19 Jul 2013 20:25:56 +0000 Subject: [PATCH] Fix another place where clang check objc selector name instead of checking the selector family Summary: In ARC mode, clang emits a warning if the result of an 'init' method is unused but miss cases where the method does not follows the Cocoa naming convention but is properly declared as an init family method. CC: cfe-commits, eli.friedman Differential Revision: http://llvm-reviews.chandlerc.com/D1163 llvm-svn: 186718 --- clang/lib/AST/Expr.cpp | 4 +--- clang/test/SemaObjC/arc.m | 5 ++++- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/clang/lib/AST/Expr.cpp b/clang/lib/AST/Expr.cpp index 2e459626468c..37f7d267d97c 100644 --- a/clang/lib/AST/Expr.cpp +++ b/clang/lib/AST/Expr.cpp @@ -2080,9 +2080,7 @@ bool Expr::isUnusedResultAWarning(const Expr *&WarnE, SourceLocation &Loc, if (Ctx.getLangOpts().ObjCAutoRefCount && ME->isInstanceMessage() && !ME->getType()->isVoidType() && - ME->getSelector().getIdentifierInfoForSlot(0) && - ME->getSelector().getIdentifierInfoForSlot(0) - ->getName().startswith("init")) { + ME->getMethodFamily() == OMF_init) { WarnE = this; Loc = getExprLoc(); R1 = ME->getSourceRange(); diff --git a/clang/test/SemaObjC/arc.m b/clang/test/SemaObjC/arc.m index 2646adce94f9..76a97f3ab3b6 100644 --- a/clang/test/SemaObjC/arc.m +++ b/clang/test/SemaObjC/arc.m @@ -84,14 +84,17 @@ void test1(A *a) { // rdar://8861761 @interface B --(id)alloc; ++ (id)alloc; - (id)initWithInt: (int) i; +- (id)myInit __attribute__((objc_method_family(init))); @end void rdar8861761() { B *o1 = [[B alloc] initWithInt:0]; B *o2 = [B alloc]; [o2 initWithInt:0]; // expected-warning {{expression result unused}} + B *o3 = [[B alloc] myInit]; + [[B alloc] myInit]; // expected-warning {{expression result unused}} } // rdar://8925835