<html><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><br><div><div>On Feb 10, 2009, at 2:33 PM, Ken Ferry wrote:</div><br class="Apple-interchange-newline"><blockquote type="cite"><div class="gmail_quote">On Tue, Feb 10, 2009 at 1:44 PM, Chris Lattner <span dir="ltr"><<a href="mailto:clattner@apple.com">clattner@apple.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
<div class="Ih2E3d"><br>
On Feb 9, 2009, at 8:33 AM, Douglas Gregor wrote:<br>
>><br>
><br>
> It would take a bit of work to support such a pragma in Clang,<br>
> because we currently have quite a few places where we make a lot of<br>
> assumptions about language-specific data structures based on the<br>
> current language we're parsing (e.g., we assume that all class types<br>
> are handled by CXXRecordDecl in C++ mode). However, it seems<br>
> reasonable that we would work toward making Clang #pragma c++'able.<br>
><br>
> In the shorter term, I think some kind of __overload__ attribute<br>
> would be relatively easy to implement. Most of the pain would be in<br>
> making sure that the C++ implicit-conversion rules handle all of the<br>
> funky C99 types :)<br>
<br>
</div>I spoke with Doug more about this offline, and I agree.  We should add<br>
an __attribute__((overloadable)) or something like that.  Doug<br>
volunteered to tackle this when he gets to a good intermediate point<br>
on his template work.  I filed PR 3542 to track this.<br>
<br>
Thanks Doug!  When this is done, I'll do the horrible header hacking<br>
stuff to hook it up for tgmath.h to use.<br>
<font color="#888888"><br>
-Chris<br>
</font><div><div></div><div class="Wj3C7c"></div></div></blockquote><div><br></div><div>I'm curious if this would be useful for a case I've hit as a user of compilers.</div><div><br></div><div>In Cocoa and CoreFoundation, there are a bunch of types that different as far as the compiler is concerned, but the user knows that they are the same.  NSString* and CFStringRef are interchangeable, for example.  </div></div></blockquote><div><br></div><div>Interesting.</div><br><blockquote type="cite"><div class="gmail_quote"><div>I'd love to be able to inform the compiler that certain types are compatible, but short of that, I have an NSToCF macro that does sort of a type-safe cast.  If passed an argument of type of NSString*, for example, the result is type CFStringRef.  It looks like this:</div>
<div><br></div><div><span class="Apple-style-span" style="font-family: Helvetica; font-size: 12px; "><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 10px/normal Monaco; color: rgb(117, 73, 45); ">
#define NSToCF(nsObject) ( \</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 10px/normal Monaco; color: rgb(117, 73, 45); ">__builtin_choose_expr (__builtin_types_compatible_p (typeof (nsObject), NSArray*), (CFArrayRef)(nsObject), \</div>
<div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 10px/normal Monaco; color: rgb(117, 73, 45); ">__builtin_choose_expr (__builtin_types_compatible_p (typeof (nsObject), NSAttributedString*), (CFAttributedStringRef)(nsObject), \</div>
<div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 10px/normal Monaco; color: rgb(117, 73, 45); ">__builtin_choose_expr (__builtin_types_compatible_p (typeof (nsObject), NSCalendar*), (CFCalendarRef)(nsObject), \</div>
<div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 10px/normal Monaco; color: rgb(117, 73, 45); ">__builtin_choose_expr (__builtin_types_compatible_p (typeof (nsObject), NSCharacterSet*), (CFCharacterSetRef)(nsObject), \</div>
<div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 10px/normal Monaco; color: rgb(117, 73, 45); ">__builtin_choose_expr (__builtin_types_compatible_p (typeof (nsObject), NSData*), (CFDataRef)(nsObject), \</div>
<div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 10px/normal Monaco; color: rgb(117, 73, 45); ">__builtin_choose_expr (__builtin_types_compatible_p (typeof (nsObject), NSDate*), (CFDateRef)(nsObject), \</div>
<div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 10px/normal Monaco; color: rgb(117, 73, 45); ">__builtin_choose_expr (__builtin_types_compatible_p (typeof (nsObject), NSDictionary*), (CFDictionaryRef)(nsObject), \</div>
<div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 10px/normal Monaco; color: rgb(117, 73, 45); ">__builtin_choose_expr (__builtin_types_compatible_p (typeof (nsObject), NSError*), (CFErrorRef)(nsObject), \</div>
<div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 10px/normal Monaco; color: rgb(117, 73, 45); ">__builtin_choose_expr (__builtin_types_compatible_p (typeof (nsObject), NSLocale*), (CFLocaleRef)(nsObject), \</div>
<div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 10px/normal Monaco; color: rgb(117, 73, 45); ">__builtin_choose_expr (__builtin_types_compatible_p (typeof (nsObject), NSMutableArray*), (CFMutableArrayRef)(nsObject), \</div>
<div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 10px/normal Monaco; color: rgb(117, 73, 45); ">__builtin_choose_expr (__builtin_types_compatible_p (typeof (nsObject), NSMutableAttributedString*), (CFMutableAttributedStringRef)(nsObject), \</div>
<div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 10px/normal Monaco; color: rgb(117, 73, 45); ">__builtin_choose_expr (__builtin_types_compatible_p (typeof (nsObject), NSMutableCharacterSet*), (CFMutableCharacterSetRef)(nsObject), \</div>
<div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 10px/normal Monaco; color: rgb(117, 73, 45); ">__builtin_choose_expr (__builtin_types_compatible_p (typeof (nsObject), NSMutableData*), (CFMutableDataRef)(nsObject), \</div>
<div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 10px/normal Monaco; color: rgb(117, 73, 45); ">__builtin_choose_expr (__builtin_types_compatible_p (typeof (nsObject), NSMutableDictionary*), (CFMutableDictionaryRef)(nsObject), \</div>
<div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 10px/normal Monaco; color: rgb(117, 73, 45); ">__builtin_choose_expr (__builtin_types_compatible_p (typeof (nsObject), NSMutableSet*), (CFMutableSetRef)(nsObject), \</div>
<div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 10px/normal Monaco; color: rgb(117, 73, 45); ">__builtin_choose_expr (__builtin_types_compatible_p (typeof (nsObject), NSMutableString*), (CFMutableStringRef)(nsObject), \</div>
<div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 10px/normal Monaco; color: rgb(117, 73, 45); ">__builtin_choose_expr (__builtin_types_compatible_p (typeof (nsObject), NSNumber*), (CFNumberRef)(nsObject), \</div>
<div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 10px/normal Monaco; color: rgb(117, 73, 45); ">__builtin_choose_expr (__builtin_types_compatible_p (typeof (nsObject), NSInputStream*), (CFReadStreamRef)(nsObject), \</div>
<div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 10px/normal Monaco; color: rgb(117, 73, 45); ">__builtin_choose_expr (__builtin_types_compatible_p (typeof (nsObject), NSTimer*), (CFRunLoopTimerRef)(nsObject), \</div>
<div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 10px/normal Monaco; color: rgb(117, 73, 45); ">__builtin_choose_expr (__builtin_types_compatible_p (typeof (nsObject), NSSet*), (CFSetRef)(nsObject), \</div>
<div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 10px/normal Monaco; color: rgb(117, 73, 45); ">__builtin_choose_expr (__builtin_types_compatible_p (typeof (nsObject), NSString*), (CFStringRef)(nsObject), \</div>
<div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 10px/normal Monaco; color: rgb(117, 73, 45); ">__builtin_choose_expr (__builtin_types_compatible_p (typeof (nsObject), NSTimeZone*), (CFTimeZoneRef)(nsObject), \</div>
<div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 10px/normal Monaco; color: rgb(117, 73, 45); ">__builtin_choose_expr (__builtin_types_compatible_p (typeof (nsObject), NSURL*), (CFURLRef)(nsObject), \</div>
<div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 10px/normal Monaco; color: rgb(117, 73, 45); ">__builtin_choose_expr (__builtin_types_compatible_p (typeof (nsObject), NSOutputStream*), (CFWriteStreamRef)(nsObject), \</div>
<div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 10px/normal Monaco; color: rgb(20, 135, 11); "><span style="color: rgb(50, 0, 214); ">1.0</span>/*error on type not found*/<span style="color: rgb(117, 73, 45); "> )))))))))))))))))))))))))</span></div>
<div><font class="Apple-style-span" color="#75492D" face="Monaco" size="2"><span class="Apple-style-span" style="font-size: 10px;"><br></span></font></div><div><font class="Apple-style-span" face="arial" size="3"><span class="Apple-style-span" style="font-size: 13px;">Would the changes you're talking about make this less disgusting?</span></font></div></span></div></div></blockquote><br></div><div><br></div><div>I believe so. The idea would be to create a bunch of overloaded functions like so:</div><div><br></div><div>  inline CFArrayRef NSToCF(NSArray *nsObject) __attribute__((always_inline, overloaded)) { return (CFArrayRef)nsObject; }</div><div><div>  inline CFAttributedStringRef NSToCF(NSAttributedString *nsObject) __attribute__((always_inline, overloaded)) { return (CFAttributedStringRef)nsObject; }</div><div><div>  inline CFCalendarRef NSToCF(NSCalendar *nsObject) __attribute__((always_inline, overloaded)) { return (CFCalendarRef)nsObject; }</div><div><div>  inline CFDataRef NSToCF(NSData *nsObject) __attribute__((always_inline, overloaded)) { return (CFDataRef)nsObject; }</div><div>  // and so on</div><div><br></div><div>It's better than counting parentheses :)</div><div><br></div></div></div></div><div><span class="Apple-tab-span" style="white-space:pre">   </span>- Doug<br></div><br></body></html>