From: Jean-Daniel Dupas Date: Fri, 19 Jul 2013 20:25:56 +0000 (+0000) Subject: Fix another place where clang check objc selector name instead of checking the select... X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=4bdb602d1a70ea432aad909825eb4748a2aca768;p=clang 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 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@186718 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/AST/Expr.cpp b/lib/AST/Expr.cpp index 2e45962646..37f7d267d9 100644 --- a/lib/AST/Expr.cpp +++ b/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/test/SemaObjC/arc.m b/test/SemaObjC/arc.m index 2646adce94..76a97f3ab3 100644 --- a/test/SemaObjC/arc.m +++ b/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