[PATCH] Fix another place where clang check objc selector name instead of checking the selector family
Jean-Daniel Dupas
devlists at shadowlab.org
Wed Jul 17 04:35:49 PDT 2013
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
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D1163.1.patch
Type: text/x-patch
Size: 1203 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20130717/747759c5/attachment.bin>
More information about the cfe-commits
mailing list