<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">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:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div lang="EN-US" link="#0563C1" vlink="#954F72"><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)</p></div></blockquote><div><br></div><div>If you're not providing a declaration of a real 'cos' function, you do not have a conforming C standard library. See C11 7.1.4/1:</div><div><br></div><div>"Any function declared in a header may be additionally implemented as a function-like macro defined in the header, so if a library function is declared explicitly when its header is included, one of the techniques shown below can be used to ensure the declaration is not affected by such a macro. Any macro definition of a function can be suppressed locally by enclosing the name of the function in parentheses, because the name is then not followed by the left parenthesis that indicates expansion of a macro function name. For the same syntactic reason, it is permitted to take the address of a library function even if it is also defined as a macro. [Footnote: This means that an implementation shall provide an actual function for each library function, even if it also provides a macro for that function.]"</div><div><br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div lang="EN-US" link="#0563C1" vlink="#954F72"><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></blockquote><div><br></div><div>We should just fix this with</div><div><br></div><div>#undef cos</div><div><br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div lang="EN-US" link="#0563C1" vlink="#954F72"><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.<u></u><u></u></p><p class="MsoNormal"><u></u> <u></u></p><p class="MsoNormal"><span style="font-size:10pt;font-family:'Courier New'">Employee of Qualcomm Innovation Center, Inc.<u></u><u></u></span></p><p class="MsoNormal"><span style="font-size:10pt;font-family:'Courier New'">Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, a Linux Foundation Collaborative Project<u></u><u></u></span></p><p class="MsoNormal"><u></u> <u></u></p></div><br>_______________________________________________<br>
cfe-dev mailing list<br>
<a href="mailto:cfe-dev@lists.llvm.org">cfe-dev@lists.llvm.org</a><br>
<a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev" rel="noreferrer" target="_blank">http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev</a><br>
<br></blockquote></div><br></div></div>