<html><head><meta http-equiv="Content-Type" content="text/html charset=windows-1252"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;"><br><div><div>On Aug 28, 2013, at 1:49 PM, Fariborz Jahanian <<a href="mailto:fjahanian@apple.com">fjahanian@apple.com</a>> wrote:</div><br class="Apple-interchange-newline"><blockquote type="cite">Author: fjahanian<br>Date: Wed Aug 28 15:49:58 2013<br>New Revision: 189514<br><br>URL: <a href="http://llvm.org/viewvc/llvm-project?rev=189514&view=rev">http://llvm.org/viewvc/llvm-project?rev=189514&view=rev</a><br>Log:<br>For methods where clang automatically infers instancetype from the selector <br>(e.g., all -init* methods), no need to suggest "instancetype" because it <br>is redundant.<br><br>Modified:<br>    cfe/trunk/lib/ARCMigrate/ObjCMT.cpp<br>    cfe/trunk/test/ARCMT/objcmt-arc-cf-annotations.m.result<br>    cfe/trunk/test/ARCMT/objcmt-instancetype-2.m.result<br>    cfe/trunk/test/ARCMT/objcmt-instancetype.m.result<br><br>Modified: cfe/trunk/lib/ARCMigrate/ObjCMT.cpp<br>URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/ARCMigrate/ObjCMT.cpp?rev=189514&r1=189513&r2=189514&view=diff">http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/ARCMigrate/ObjCMT.cpp?rev=189514&r1=189513&r2=189514&view=diff</a><br>==============================================================================<br>--- cfe/trunk/lib/ARCMigrate/ObjCMT.cpp (original)<br>+++ cfe/trunk/lib/ARCMigrate/ObjCMT.cpp Wed Aug 28 15:49:58 2013<br>@@ -668,15 +668,13 @@ void ObjCMigrateASTConsumer::migrateMeth<br>     case OIT_None:<br>       migrateFactoryMethod(Ctx, CDecl, OM);<br>       return;<br>+    // For methods where Clang automatically infers instancetype from the selector <br>+    // (e.g., all -init* methods), we should not suggest "instancetype" because it <br>+    // is redundant,<br>     case OIT_Array:<br>-      ClassName = "NSArray";<br>-      break;<br>     case OIT_Dictionary:<br>-      ClassName = "NSDictionary";<br>-      break;<br>     case OIT_MemManage:<br>-      ClassName = "NSObject";<br>-      break;<br>+      return;<br>     case OIT_Singleton:<br>       migrateFactoryMethod(Ctx, CDecl, OM, OIT_Singleton);<br>       return;<br></blockquote><div><br></div><div>This is just checking a few special cases. What we want is to avoid adding ‘instancetype’ when the method already has a related result type, which you can check directly with ObjCMethodDecl::hasRelatedResultType().</div><div><br></div><div>For example, migrateFactoryMethod() should replace the “== Ctx.getObjCInstanceType()” check with a call to hasRelatedResultType().</div><div><br></div><div><div style="margin: 0px; font-size: 11px; font-family: Menlo; color: rgb(49, 89, 93);"><span style="color: #000000">  </span><span style="color: #bb2ca2">if</span><span style="color: #000000"> (OM-></span>isInstanceMethod<span style="color: #000000">() ||</span></div><div style="margin: 0px; font-size: 11px; font-family: Menlo; color: rgb(49, 89, 93);"><span style="color: #000000">      OM-></span>getResultType<span style="color: #000000">() == Ctx.</span>getObjCInstanceType<span style="color: #000000">() ||</span></div><div style="margin: 0px; font-size: 11px; font-family: Menlo; color: rgb(49, 89, 93);"><span style="color: #000000">      !OM-></span>getResultType<span style="color: #000000">()-></span>isObjCIdType<span style="color: #000000">())</span></div><div style="margin: 0px; font-size: 11px; font-family: Menlo; color: rgb(187, 44, 162);"><span style="color: #000000">    </span>return<span style="color: #000000">;</span></div></div><div><br></div><div>And migrateMethodInstanceType() should bail out early if it sees that the method already has a related result type.</div><div><br></div><div><span class="Apple-tab-span" style="white-space:pre">      </span>- Doug</div><br><blockquote type="cite">Modified: cfe/trunk/test/ARCMT/objcmt-arc-cf-annotations.m.result<br>URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/test/ARCMT/objcmt-arc-cf-annotations.m.result?rev=189514&r1=189513&r2=189514&view=diff">http://llvm.org/viewvc/llvm-project/cfe/trunk/test/ARCMT/objcmt-arc-cf-annotations.m.result?rev=189514&r1=189513&r2=189514&view=diff</a><br>==============================================================================<br>--- cfe/trunk/test/ARCMT/objcmt-arc-cf-annotations.m.result (original)<br>+++ cfe/trunk/test/ARCMT/objcmt-arc-cf-annotations.m.result Wed Aug 28 15:49:58 2013<br>@@ -154,8 +154,8 @@ typedef struct _NSZone NSZone;<br> @protocol NSCoding  - (void)encodeWithCoder:(NSCoder *)aCoder;<br> @end<br> @interface NSObject <NSObject> {}<br>-+ (instancetype)allocWithZone:(NSZone *)zone;<br>-+ (instancetype)alloc;<br>++ (id)allocWithZone:(NSZone *)zone;<br>++ (id)alloc;<br> + (id)new;<br> - (void)dealloc;<br> @end<br>@@ -174,19 +174,19 @@ NSFastEnumerationState;<br> @end<br> @interface NSNumber : NSValue<br> - (char)charValue;<br>-- (instancetype)initWithInt:(int)value;<br>+- (id)initWithInt:(int)value;<br> + (NSNumber *)numberWithInt:(int)value;<br> @end<br> @class NSString;<br> @interface NSArray : NSObject <NSCopying, NSMutableCopying, NSCoding, NSFastEnumeration><br> - (NSUInteger)count;<br>-- (instancetype)initWithObjects:(const id [])objects count:(NSUInteger)cnt;<br>-+ (instancetype)arrayWithObject:(id)anObject;<br>-+ (instancetype)arrayWithObjects:(const id [])objects count:(NSUInteger)cnt;<br>-+ (instancetype)arrayWithObjects:(id)firstObj, ... __attribute__((sentinel(0,1)));<br>-- (instancetype)initWithObjects:(id)firstObj, ... __attribute__((sentinel(0,1)));<br>-- (instancetype)initWithArray:(NSArray *)array;<br>-@end  @interface NSArray (NSArrayCreation)  + (instancetype)array;<br>+- (id)initWithObjects:(const id [])objects count:(NSUInteger)cnt;<br>++ (id)arrayWithObject:(id)anObject;<br>++ (id)arrayWithObjects:(const id [])objects count:(NSUInteger)cnt;<br>++ (id)arrayWithObjects:(id)firstObj, ... __attribute__((sentinel(0,1)));<br>+- (id)initWithObjects:(id)firstObj, ... __attribute__((sentinel(0,1)));<br>+- (id)initWithArray:(NSArray *)array;<br>+@end  @interface NSArray (NSArrayCreation)  + (id)array;<br> @end       @interface NSAutoreleasePool : NSObject {<br> }<br> - (void)drain;<br>@@ -198,7 +198,7 @@ typedef double NSTimeInterval;<br> - (NSUInteger)length;<br> - (NSString *)stringByAppendingString:(NSString *)aString;<br> - ( const char *)UTF8String;<br>-- (instancetype)initWithUTF8String:(const char *)nullTerminatedCString;<br>+- (id)initWithUTF8String:(const char *)nullTerminatedCString;<br> + (instancetype)stringWithUTF8String:(const char *)nullTerminatedCString;<br> @end        @class NSString, NSURL, NSError;<br> @interface NSData : NSObject <NSCopying, NSMutableCopying, NSCoding>  - (NSUInteger)length;<br>@@ -207,12 +207,12 @@ typedef double NSTimeInterval;<br> @end   @class NSLocale, NSDate, NSCalendar, NSTimeZone, NSError, NSArray, NSMutableDictionary;<br> @interface NSDictionary : NSObject <NSCopying, NSMutableCopying, NSCoding, NSFastEnumeration><br> - (NSUInteger)count;<br>-+ (instancetype)dictionaryWithObjects:(NSArray *)objects forKeys:(NSArray *)keys;<br>-+ (instancetype)dictionaryWithObjects:(const id [])objects forKeys:(const id <NSCopying> [])keys count:(NSUInteger)cnt;<br>++ (id)dictionaryWithObjects:(NSArray *)objects forKeys:(NSArray *)keys;<br>++ (id)dictionaryWithObjects:(const id [])objects forKeys:(const id <NSCopying> [])keys count:(NSUInteger)cnt;<br> @end<br> @interface NSMutableDictionary : NSDictionary  - (void)removeObjectForKey:(id)aKey;<br> - (void)setObject:(id)anObject forKey:(id)aKey;<br>-@end  @interface NSMutableDictionary (NSMutableDictionaryCreation)  + (instancetype)dictionaryWithCapacity:(NSUInteger)numItems;<br>+@end  @interface NSMutableDictionary (NSMutableDictionaryCreation)  + (id)dictionaryWithCapacity:(NSUInteger)numItems;<br> @end  typedef double CGFloat;<br> struct CGSize {<br> };<br>@@ -254,7 +254,7 @@ extern DADiskRef DADiskCreateFromBSDName<br> extern DADiskRef DADiskCreateFromIOMedia( CFAllocatorRef allocator, DASessionRef session, io_service_t media ) CF_RETURNS_RETAINED;<br> extern CFDictionaryRef DADiskCopyDescription( DADiskRef disk ) CF_RETURNS_RETAINED;<br> extern DADiskRef DADiskCopyWholeDisk( DADiskRef disk ) CF_RETURNS_RETAINED;<br>-@interface NSTask : NSObject - (instancetype)init;<br>+@interface NSTask : NSObject - (id)init;<br> @end                    typedef struct CGColorSpace *CGColorSpaceRef;<br> typedef struct CGImage *CGImageRef;<br> typedef struct CGLayer *CGLayerRef;<br>@@ -350,7 +350,7 @@ CF_IMPLICIT_BRIDGING_DISABLED<br><br> @interface NSMutableArray : NSObject<br> - (void)addObject:(id)object;<br>-+ (instancetype)array;<br>++ (id)array;<br> @end<br><br> // This is how NSMakeCollectable is declared in the OS X 10.8 headers.<br>@@ -677,7 +677,7 @@ static void rdar_6659160(char *inkind, c<br> //  conventions with respect to 'return'ing ownership.<br> @interface PR3677: NSObject @end<br> @implementation PR3677<br>-+ (instancetype)allocWithZone:(NSZone *)inZone {<br>++ (id)allocWithZone:(NSZone *)inZone {<br>   return [super allocWithZone:inZone];  // no-warning<br> }<br> @end<br>@@ -846,16 +846,16 @@ CF_IMPLICIT_BRIDGING_DISABLED<br> @interface RDar6320065 : NSObject {<br>   NSString *_foo;<br> }<br>-- (instancetype)initReturningNewClass;<br>+- (id)initReturningNewClass;<br> - (id)_initReturningNewClassBad;<br>-- (instancetype)initReturningNewClassBad2;<br>+- (id)initReturningNewClassBad2;<br> @end<br><br> @interface RDar6320065Subclass : RDar6320065<br> @end<br><br> @implementation RDar6320065<br>-- (instancetype)initReturningNewClass {<br>+- (id)initReturningNewClass {<br>   [self release];<br>   self = [[RDar6320065Subclass alloc] init]; // no-warning<br>   return self;<br>@@ -865,7 +865,7 @@ CF_IMPLICIT_BRIDGING_DISABLED<br>   [[RDar6320065Subclass alloc] init]; // expected-warning {{leak}}<br>   return self;<br> }<br>-- (instancetype)initReturningNewClassBad2 {<br>+- (id)initReturningNewClassBad2 {<br>   [self release];<br>   self = [[RDar6320065Subclass alloc] init];<br>   return [self autorelease]; // expected-warning{{Object with a +0 retain count returned to caller where a +1 (owning) retain count is expected}}<br>@@ -1580,7 +1580,7 @@ void test_blocks_1_indirect_retain_via_c<br><br> @interface Rdar8015556 : NSObject {} @end<br> @implementation Rdar8015556<br>-- (instancetype)retain {<br>+- (id)retain {<br>   return [super retain];<br> }<br> @end<br>@@ -1796,11 +1796,11 @@ void rdar9658496() {<br><br> // Support annotations with method families.<br> @interface RDar10824732 : NSObject<br>-- (instancetype)initWithObj:(id CF_CONSUMED)obj;<br>+- (id)initWithObj:(id CF_CONSUMED)obj;<br> @end<br><br> @implementation RDar10824732<br>-- (instancetype)initWithObj:(id)obj {<br>+- (id)initWithObj:(id)obj {<br>   [obj release];<br>   return [super init];<br> }<br>@@ -2068,12 +2068,12 @@ void testCustomReturnsNotRetained() {<br> // Don't print variables which are out of the current scope.<br> //===----------------------------------------------------------------------===//<br> @interface MyObj12706177 : NSObject<br>--(instancetype)initX;<br>+-(id)initX;<br> +(void)test12706177;<br> @end<br> static int Cond;<br> @implementation MyObj12706177<br>--(instancetype)initX {<br>+-(id)initX {<br>   if (Cond)<br>     return 0;<br>   self = [super init];<br><br>Modified: cfe/trunk/test/ARCMT/objcmt-instancetype-2.m.result<br>URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/test/ARCMT/objcmt-instancetype-2.m.result?rev=189514&r1=189513&r2=189514&view=diff">http://llvm.org/viewvc/llvm-project/cfe/trunk/test/ARCMT/objcmt-instancetype-2.m.result?rev=189514&r1=189513&r2=189514&view=diff</a><br>==============================================================================<br>--- cfe/trunk/test/ARCMT/objcmt-instancetype-2.m.result (original)<br>+++ cfe/trunk/test/ARCMT/objcmt-instancetype-2.m.result Wed Aug 28 15:49:58 2013<br>@@ -51,7 +51,7 @@ typedef enum NSURLBookmarkResolutionOpti<br> @interface NSMutableDictionary @end<br><br> @interface NSMutableDictionary (NSSharedKeySetDictionary)<br>-+ (instancetype )dictionaryWithSharedKeySet:(id)keyset __attribute__((availability(macosx,introduced=10.8)));<br>++ (id )dictionaryWithSharedKeySet:(id)keyset __attribute__((availability(macosx,introduced=10.8)));<br> @end<br><br> @interface NSProtocolChecker<br><br>Modified: cfe/trunk/test/ARCMT/objcmt-instancetype.m.result<br>URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/test/ARCMT/objcmt-instancetype.m.result?rev=189514&r1=189513&r2=189514&view=diff">http://llvm.org/viewvc/llvm-project/cfe/trunk/test/ARCMT/objcmt-instancetype.m.result?rev=189514&r1=189513&r2=189514&view=diff</a><br>==============================================================================<br>--- cfe/trunk/test/ARCMT/objcmt-instancetype.m.result (original)<br>+++ cfe/trunk/test/ARCMT/objcmt-instancetype.m.result Wed Aug 28 15:49:58 2013<br>@@ -7,12 +7,12 @@ typedef signed char BOOL;<br> #define nil ((void*) 0)<br><br> @interface NSObject<br>-+ (instancetype)alloc;<br>++ (id)alloc;<br> @end<br><br> @interface NSString : NSObject<br> + (instancetype)stringWithString:(NSString *)string;<br>-- (instancetype)initWithString:(NSString *)aString;<br>+- (id)initWithString:(NSString *)aString;<br> @end<br><br> @interface NSArray : NSObject<br>@@ -21,15 +21,15 @@ typedef signed char BOOL;<br> @end<br><br> @interface NSArray (NSArrayCreation)<br>-+ (instancetype)array;<br>-+ (instancetype)arrayWithObject:(id)anObject;<br>-+ (instancetype)arrayWithObjects:(const id [])objects count:(unsigned long)cnt;<br>-+ (instancetype)arrayWithObjects:(id)firstObj, ...;<br>-+ (instancetype) arrayWithArray:(NSArray *)array;<br>-<br>-- (instancetype)initWithObjects:(const id [])objects count:(unsigned long)cnt;<br>-- (instancetype)initWithObjects:(id)firstObj, ...;<br>-- (instancetype)initWithArray:(NSArray *)array;<br>++ (id)array;<br>++ (id)arrayWithObject:(id)anObject;<br>++ (id)arrayWithObjects:(const id [])objects count:(unsigned long)cnt;<br>++ (id)arrayWithObjects:(id)firstObj, ...;<br>++ arrayWithArray:(NSArray *)array;<br>+<br>+- (id)initWithObjects:(const id [])objects count:(unsigned long)cnt;<br>+- (id)initWithObjects:(id)firstObj, ...;<br>+- (id)initWithArray:(NSArray *)array;<br><br> - (id)objectAtIndex:(unsigned long)index;<br> @end<br>@@ -44,17 +44,17 @@ typedef signed char BOOL;<br> @end<br><br> @interface NSDictionary (NSDictionaryCreation)<br>-+ (instancetype)dictionary;<br>-+ (instancetype)dictionaryWithObject:(id)object forKey:(id)key;<br>-+ (instancetype)dictionaryWithObjects:(const id [])objects forKeys:(const id [])keys count:(unsigned long)cnt;<br>-+ (instancetype) dictionaryWithObjectsAndKeys:(id)firstObject, ...;<br>-+ (instancetype)dictionaryWithDictionary:(NSDictionary *)dict;<br>-+ (instancetype)dictionaryWithObjects:(NSArray *)objects forKeys:(NSArray *)keys;<br>-<br>-- (instancetype)initWithObjects:(const id [])objects forKeys:(const id [])keys count:(unsigned long)cnt;<br>-- (instancetype)initWithObjectsAndKeys:(id)firstObject, ...;<br>-- (instancetype)initWithDictionary:(NSDictionary *)otherDictionary;<br>-- (instancetype)initWithObjects:(NSArray *)objects forKeys:(NSArray *)keys;<br>++ (id)dictionary;<br>++ (id)dictionaryWithObject:(id)object forKey:(id)key;<br>++ (id)dictionaryWithObjects:(const id [])objects forKeys:(const id [])keys count:(unsigned long)cnt;<br>++ dictionaryWithObjectsAndKeys:(id)firstObject, ...;<br>++ (id)dictionaryWithDictionary:(NSDictionary *)dict;<br>++ (id)dictionaryWithObjects:(NSArray *)objects forKeys:(NSArray *)keys;<br>+<br>+- (id)initWithObjects:(const id [])objects forKeys:(const id [])keys count:(unsigned long)cnt;<br>+- (id)initWithObjectsAndKeys:(id)firstObject, ...;<br>+- (id)initWithDictionary:(NSDictionary *)otherDictionary;<br>+- (id)initWithObjects:(NSArray *)objects forKeys:(NSArray *)keys;<br><br> - (id)objectForKey:(id)aKey;<br> @end<br><br><br>_______________________________________________<br>cfe-commits mailing list<br><a href="mailto:cfe-commits@cs.uiuc.edu">cfe-commits@cs.uiuc.edu</a><br>http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits<br></blockquote></div><br></body></html>