<html><head><meta http-equiv="Content-Type" content="text/html charset=windows-1252"><meta http-equiv="Content-Type" content="text/html charset=windows-1252"><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 2:09 PM, Douglas Gregor <<a href="mailto:dgregor@apple.com">dgregor@apple.com</a>> wrote:</div><br class="Apple-interchange-newline"><blockquote type="cite"><meta http-equiv="Content-Type" content="text/html charset=windows-1252"><div 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="">  </span><span style="color: #bb2ca2">if</span><span style=""> (OM-></span>isInstanceMethod<span style="">() ||</span></div><div style="margin: 0px; font-size: 11px; font-family: Menlo; color: rgb(49, 89, 93);"><span style="">      OM-></span>getResultType<span style="">() == Ctx.</span>getObjCInstanceType<span style="">() ||</span></div><div style="margin: 0px; font-size: 11px; font-family: Menlo; color: rgb(49, 89, 93);"><span style="">      !OM-></span>getResultType<span style="">()-></span>isObjCIdType<span style="">())</span></div><div style="margin: 0px; font-size: 11px; font-family: Menlo; color: rgb(187, 44, 162);"><span style="">    </span>return<span style="">;</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></div></blockquote><div><br></div>Early bail out is good. Thanks for pointing me to this API. In r189520.</div><div><br></div><div>- Fariborz</div><div><br></div><br></body></html>