The only way i can think to improve that is to make it so WEAK_ALIAS macro comes first, and make WEAK_DEF comes second and static_assert if WEAK_ALIAS has not been called (by using sizeof on the forward decl perhaps).  This way you will get a compiler error if you don't do both. <br><br>I don't even know if this would work (and i also don't think it should hold up this change regardless since it's only a minor improvement).<br><br>That said, I'm fine with any approach that works, so I'll leave it up kuba@ and aizatsky@ to decide which they like better <br><div class="gmail_quote"><div dir="ltr">On Wed, Jan 18, 2017 at 5:28 PM Marcos Pividori <<a href="mailto:mpividori@google.com">mpividori@google.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr" class="gmail_msg">Hi,<br class="gmail_msg">Yes, what @zturner proposes works. @<span style="font-size:12.8px" class="gmail_msg">kubabrecka </span>Would that make your editor work fine?<br class="gmail_msg">I would prefer to use only one macro as I defined it before, because if we use 2 macros, we always need to remember to include both.<br class="gmail_msg">But just let me know what you prefer and I will do that.<br class="gmail_msg">Thanks,<br class="gmail_msg">Marcos</div><div class="gmail_extra gmail_msg"><br class="gmail_msg"><div class="gmail_quote gmail_msg">On Wed, Jan 18, 2017 at 4:43 PM, Zachary Turner via Phabricator <span dir="ltr" class="gmail_msg"><<a href="mailto:reviews@reviews.llvm.org" class="gmail_msg" target="_blank">reviews@reviews.llvm.org</a>></span> wrote:<br class="gmail_msg"><blockquote class="gmail_quote gmail_msg" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">zturner added a comment.<br class="gmail_msg">
<span class="gmail_msg"><br class="gmail_msg">
In <a href="https://reviews.llvm.org/D28596#649978" rel="noreferrer" class="gmail_msg" target="_blank">https://reviews.llvm.org/D28596#649978</a>, @mpividori wrote:<br class="gmail_msg">
<br class="gmail_msg">
> > 2. Having a macro only around the function name, i.e.: `WEAK_ATTRIBUTE void WEAK_NAME(OnPrint)(const char *str) { code }`.<br class="gmail_msg">
><br class="gmail_msg">
> I can't do that because not only I need to change the name, I also need to add a linker pragma `WIN_WEAK_ALIAS(OnPrint, OnPrint__def)` and declare `OnPrint`.<br class="gmail_msg">
>  I mean, for non-windows `OnPrint` definition will be:<br class="gmail_msg">
><br class="gmail_msg">
>   void OnPrint(const char *str) {<br class="gmail_msg">
>     // Default implementation<br class="gmail_msg">
>   }<br class="gmail_msg">
><br class="gmail_msg">
><br class="gmail_msg">
> And for Windows, it will be:<br class="gmail_msg">
><br class="gmail_msg">
>   void OnPrint__def(const char *str) {<br class="gmail_msg">
>     // Default implementation<br class="gmail_msg">
>   }<br class="gmail_msg">
>   void OnPrint(const char *str);<br class="gmail_msg">
>   WIN_WEAK_ALIAS(OnPrint, OnPrint__def)<br class="gmail_msg">
><br class="gmail_msg">
><br class="gmail_msg">
> Thanks.<br class="gmail_msg">
<br class="gmail_msg">
<br class="gmail_msg">
</span>What if instead of getting it all into one line, we settle for this:<br class="gmail_msg">
<br class="gmail_msg">
  void WEAK_FN_DEF(OnPrint)(const char *str) {<br class="gmail_msg">
  }<br class="gmail_msg">
  WEAK_FN_ALIAS(OnPrint)<br class="gmail_msg">
<br class="gmail_msg">
The macro `WEAK_FN_ALIAS` could look like this:<br class="gmail_msg">
<br class="gmail_msg">
  #define WEAK_FN_ALIAS(Fn) \<br class="gmail_msg">
    decltype(Fn##__def) Fn; \<br class="gmail_msg">
    WIN_WEAK_ALIAS(Fn, Fn##__def)<br class="gmail_msg">
<br class="gmail_msg">
On non-Windows platforms, it would just do nothing.  Apparently the crazy decltype magic works and should give you a definition named `OnPrint__def` and a forward declaration named `OnPrint`.<br class="gmail_msg">
<br class="gmail_msg">
<br class="gmail_msg">
<a href="https://reviews.llvm.org/D28596" rel="noreferrer" class="gmail_msg" target="_blank">https://reviews.llvm.org/D28596</a><br class="gmail_msg">
<br class="gmail_msg">
<br class="gmail_msg">
<br class="gmail_msg">
</blockquote></div><br class="gmail_msg"></div>
</blockquote></div>