<div dir="ltr">forgot to cc the list on my reply.<div><br></div><div>-- Marshall</div><div><br><div class="gmail_quote">---------- Forwarded message ----------<br>From: <b class="gmail_sendername">Marshall Clow</b> <span dir="ltr"><<a href="mailto:mclow.lists@gmail.com">mclow.lists@gmail.com</a>></span><br>Date: Wed, Sep 30, 2015 at 11:58 AM<br>Subject: Re: [cfe-dev] [libc++] Should we guard against macro definitions<br>To: Ben Craig <<a href="mailto:ben.craig@codeaurora.org">ben.craig@codeaurora.org</a>><br><div dir="ltr"><br><div class="gmail_extra"><br><div class="gmail_quote"><span class="">On Tue, Sep 22, 2015 at 9:44 AM, Ben Craig via cfe-dev <span dir="ltr"><<a href="mailto:cfe-dev@lists.llvm.org" target="_blank">cfe-dev@lists.llvm.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div lang="EN-US" link="#0563C1" vlink="#954F72"><div><p class="MsoNormal">I have a C library, and I want to build libc++ and libc++abi against it. This C library’s implementation of many of the math.h functions involves code similar to…<u></u><u></u></p><p class="MsoNormal">#define cos(Val) RealCosImpl(Val)<u></u><u></u></p><p class="MsoNormal"><u></u> <u></u></p><p class="MsoNormal">This interacts poorly with libcxx’s cmath header, as the float and long double overload declarations hit this #define.<u></u><u></u></p><p class="MsoNormal"><u></u> <u></u></p><p class="MsoNormal">If I make a patch that guards the bulk of cmath from this kind of macro, do people feel that this would be useful, or would it get rejected on the grounds that it is unnecessary noise to support an odd C library? This fix would generally take the form of putting the function name in parenthesis to suppress function macro expansion. So code that looks like this… <u></u><u></u></p><p class="MsoNormal">float cos(float val)<u></u><u></u></p><p class="MsoNormal">… would turn into this…<u></u><u></u></p><p class="MsoNormal">float (cos)(float val)</p></div></div></blockquote><div><br></div></span><div>That's not good enough, because we have to "hoist" the function into namespace std.</div><span class=""><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div lang="EN-US" link="#0563C1" vlink="#954F72"><div><p class="MsoNormal"><u></u><u></u></p><p class="MsoNormal"><u></u> <u></u></p><p class="MsoNormal">One could argue that this would be a reasonable thing to do across libcxx, but I think it is more important to do so for cmath, as many of those functions must have macro version in the C tgmath.h header (but not the C++ one). It probably wouldn’t hurt to throw some parenthesis at std::min and std::max in <algorithm> as well, considering the unfortunate history with those and the <windows.h> min and max macros.</p></div></div></blockquote><div><br></div></span><div>libc++'s <cmath> header does this for some of the calls there (look at 'fpclassify', for example).</div><div><br></div><div>Doing the same for cos (and others) shouldn't be too hard.</div><div>Can you provide a list of the functions that your library defines as macros?</div><span class="HOEnZb"><font color="#888888"><div><br></div><div>-- Marshall</div><div><br></div></font></span></div></div></div>
</div><br></div></div>