Jean-Daniel added you to the CC list for the revision "Improve 
idiomatic-parentheses test by checking selector family instead of just checking 
selector name.".

-Wparentheses try to be smart and filter out some common idiom like "if (self = 
[super init])".

This idiom should test that the invocation is an 'init' method. Actually it 
does that by checking the selector name, but doing this it failed to detect 
case where the name does not follow the Cocoa convention, but the method is 
declared with an objc_method_family(init) attribute.

This patch fix this issue by properly testing the method family instead of 
relying on the "init" convention.

http://llvm-reviews.chandlerc.com/D1162

Files:
  lib/Sema/SemaExpr.cpp
  test/SemaObjC/idiomatic-parentheses.m

Index: lib/Sema/SemaExpr.cpp
===================================================================
--- lib/Sema/SemaExpr.cpp
+++ lib/Sema/SemaExpr.cpp
@@ -11968,7 +11968,7 @@
       Selector Sel = ME->getSelector();
 
       // self = [<foo> init...]
-      if (isSelfExpr(Op->getLHS()) && Sel.getNameForSlot(0).startswith("init"))
+      if (isSelfExpr(Op->getLHS()) && ME->getMethodFamily() == OMF_init)
         diagnostic = diag::warn_condition_is_idiomatic_assignment;
 
       // <foo> = [<bar> nextObject]
Index: test/SemaObjC/idiomatic-parentheses.m
===================================================================
--- test/SemaObjC/idiomatic-parentheses.m
+++ test/SemaObjC/idiomatic-parentheses.m
@@ -9,6 +9,7 @@
 }
 - (id) init;
 - (id) initWithInt: (int) i;
+- (id) myInit __attribute__((objc_method_family(init)));
 - (void) iterate: (id) coll;
 - (id) nextObject;
 @property unsigned uid;
@@ -34,6 +35,12 @@
   return self;
 }
 
+- (id) myInit {
+  if (self = [self myInit]) {
+  }
+  return self;
+}
+
 - (void) iterate: (id) coll {
   id cur;
   while (cur = [coll nextObject]) {
Index: lib/Sema/SemaExpr.cpp
===================================================================
--- lib/Sema/SemaExpr.cpp
+++ lib/Sema/SemaExpr.cpp
@@ -11968,7 +11968,7 @@
       Selector Sel = ME->getSelector();
 
       // self = [<foo> init...]
-      if (isSelfExpr(Op->getLHS()) && Sel.getNameForSlot(0).startswith("init"))
+      if (isSelfExpr(Op->getLHS()) && ME->getMethodFamily() == OMF_init)
         diagnostic = diag::warn_condition_is_idiomatic_assignment;
 
       // <foo> = [<bar> nextObject]
Index: test/SemaObjC/idiomatic-parentheses.m
===================================================================
--- test/SemaObjC/idiomatic-parentheses.m
+++ test/SemaObjC/idiomatic-parentheses.m
@@ -9,6 +9,7 @@
 }
 - (id) init;
 - (id) initWithInt: (int) i;
+- (id) myInit __attribute__((objc_method_family(init)));
 - (void) iterate: (id) coll;
 - (id) nextObject;
 @property unsigned uid;
@@ -34,6 +35,12 @@
   return self;
 }
 
+- (id) myInit {
+  if (self = [self myInit]) {
+  }
+  return self;
+}
+
 - (void) iterate: (id) coll {
   id cur;
   while (cur = [coll nextObject]) {
_______________________________________________
cfe-commits mailing list
[email protected]
http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits

Reply via email to