[PATCH] Warn on suspicious use of absolute value function

Reid Kleckner rnk at google.com
Thu Jan 16 09:40:55 PST 2014


On Mon, Jan 6, 2014 at 3:48 PM, James Dennett <jdennett at googlers.com> wrote:

> On Mon, Jan 6, 2014 at 12:30 PM, Marshall Clow <mclow.lists at gmail.com>
> wrote:
> >
> >   Two questions:
> >   * Is this meant to be just for ‘abs’, or will it be generalized for
> all the calls in <math.h>?
> >   * What about in C++ code, where there can be many functions named
> “abs” that take different arguments? What will this patch do in that case?
> >   [ Ok, they’re named std::abs, but people hoist them into the global
> namespace _all the time_ ]
>
> People including authors of <math.h> if they get it right; it should
> provide the same overload set as <cmath> (and similarly for <stdlib.b>
> and <cstdlib>).  (Appendix D of the C++ standard describes this
> behavior for the C compatibility headers.)
>
> However, some (most?) implementations of <math.h> and/or <stdlib.h> do
> get this wrong.  We shouldn't assume that they have the right
> overloads in the global namespace, but we also shouldn't assume that
> they don't.
>

This warning looks for extern "C" functions named abs (and labs, fabs,
etc), so I don't think it will fire if the right overload was declared
math.h and found by overload resolution.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20140116/ec602338/attachment.html>


More information about the cfe-commits mailing list