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
This commit is contained in:
Jean-Daniel Dupas 2013-07-19 20:25:56 +00:00
parent d4b5a0f53f
commit 06028a5454
2 changed files with 5 additions and 4 deletions

View File

@ -2080,9 +2080,7 @@ bool Expr::isUnusedResultAWarning(const Expr *&WarnE, SourceLocation &Loc,
if (Ctx.getLangOpts().ObjCAutoRefCount && if (Ctx.getLangOpts().ObjCAutoRefCount &&
ME->isInstanceMessage() && ME->isInstanceMessage() &&
!ME->getType()->isVoidType() && !ME->getType()->isVoidType() &&
ME->getSelector().getIdentifierInfoForSlot(0) && ME->getMethodFamily() == OMF_init) {
ME->getSelector().getIdentifierInfoForSlot(0)
->getName().startswith("init")) {
WarnE = this; WarnE = this;
Loc = getExprLoc(); Loc = getExprLoc();
R1 = ME->getSourceRange(); R1 = ME->getSourceRange();

View File

@ -84,14 +84,17 @@ void test1(A *a) {
// rdar://8861761 // rdar://8861761
@interface B @interface B
-(id)alloc; + (id)alloc;
- (id)initWithInt: (int) i; - (id)initWithInt: (int) i;
- (id)myInit __attribute__((objc_method_family(init)));
@end @end
void rdar8861761() { void rdar8861761() {
B *o1 = [[B alloc] initWithInt:0]; B *o1 = [[B alloc] initWithInt:0];
B *o2 = [B alloc]; B *o2 = [B alloc];
[o2 initWithInt:0]; // expected-warning {{expression result unused}} [o2 initWithInt:0]; // expected-warning {{expression result unused}}
B *o3 = [[B alloc] myInit];
[[B alloc] myInit]; // expected-warning {{expression result unused}}
} }
// rdar://8925835 // rdar://8925835