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
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();
// 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