r186718 - Fix another place where clang check objc selector name instead of checking the selector family

Jean-Daniel Dupas devlists at shadowlab.org
Fri Jul 19 13:25:56 PDT 2013


Author: jddupas
Date: Fri Jul 19 15:25:56 2013
New Revision: 186718

URL: http://llvm.org/viewvc/llvm-project?rev=186718&view=rev
Log:
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

Modified:
    cfe/trunk/lib/AST/Expr.cpp
    cfe/trunk/test/SemaObjC/arc.m

Modified: cfe/trunk/lib/AST/Expr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/Expr.cpp?rev=186718&r1=186717&r2=186718&view=diff
==============================================================================
--- cfe/trunk/lib/AST/Expr.cpp (original)
+++ cfe/trunk/lib/AST/Expr.cpp Fri Jul 19 15:25:56 2013
@@ -2080,9 +2080,7 @@ bool Expr::isUnusedResultAWarning(const
     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();

Modified: cfe/trunk/test/SemaObjC/arc.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaObjC/arc.m?rev=186718&r1=186717&r2=186718&view=diff
==============================================================================
--- cfe/trunk/test/SemaObjC/arc.m (original)
+++ cfe/trunk/test/SemaObjC/arc.m Fri Jul 19 15:25:56 2013
@@ -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





More information about the cfe-commits mailing list