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.
http://llvm-reviews.chandlerc.com/D1163 Files: lib/AST/Expr.cpp test/SemaObjC/arc.m Index: lib/AST/Expr.cpp =================================================================== --- lib/AST/Expr.cpp +++ lib/AST/Expr.cpp @@ -2080,9 +2080,7 @@ 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(); Index: test/SemaObjC/arc.m =================================================================== --- test/SemaObjC/arc.m +++ test/SemaObjC/arc.m @@ -84,14 +84,17 @@ // 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
Index: lib/AST/Expr.cpp =================================================================== --- lib/AST/Expr.cpp +++ lib/AST/Expr.cpp @@ -2080,9 +2080,7 @@ 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(); Index: test/SemaObjC/arc.m =================================================================== --- test/SemaObjC/arc.m +++ test/SemaObjC/arc.m @@ -84,14 +84,17 @@ // 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
_______________________________________________ cfe-commits mailing list cfe-commits@cs.uiuc.edu http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits