This is the mail archive of the
mailing list for the GCC project.
Re: Strange C++ function pointer test
- From: Jonathan Wakely <jwakely dot gcc at gmail dot com>
- To: Dominik Vogt <vogt at linux dot vnet dot ibm dot com>, "gcc at gcc dot gnu dot org" <gcc at gcc dot gnu dot org>
- Date: Thu, 31 Dec 2015 12:28:12 +0000
- Subject: Re: Strange C++ function pointer test
- Authentication-results: sourceware.org; auth=none
- References: <20151231094918 dot GA12885 at linux dot vnet dot ibm dot com> <alpine dot DEB dot 2 dot 20 dot 1512311055290 dot 17945 at laptop-mg dot saclay dot inria dot fr> <CAH6eHdTASETHDhGYdC60iOw1PgmtUOhwVT_iJ4Fi4ZCYCzomyg at mail dot gmail dot com> <20151231113458 dot GA19211 at linux dot vnet dot ibm dot com>
On 31 December 2015 at 11:34, Dominik Vogt wrote:
> On Thu, Dec 31, 2015 at 10:11:55AM +0000, Jonathan Wakely wrote:
>> <cmath> is required to declare std::abs and it's unspecified whether
>> it also declares it as ::abs.
>> <math.h> is required to declare ::abs and it's unspecified whether it
>> also declares it as std::abs.
> (*abs should be in <cstdlib> or <stdlib.h>).
For the integer overloads, yes, but in C++ the floating point
overloads are in <cmath> and <math.h>. I did double-check the standard
before posting, even though I know what I'm talking about quite well
Again, please see [c.math].
> I see. abs and ::abs are the same in this case, and std::abs
> refers to the "double" variant, so that does not compile either.
No, it refers to an overload set, which includes the float overload.
> The minimal failing program is
> -- abs.C --
> #include <stdlib.h>
> static float (*p1_)(float) = abs;
> -- abs.C --
> G++-6.0.0, Glibc-2.20 on S390x, compiled with
> $ g++ -std=c++11 abs.C
> The test program from the xvs suite includes stdlib.h and math.h,
> but not cstdlib, cmath (or ctgmath). It's not clear to me which
> headers g++ includes automatically, but this seems to be correct
> behaviour, or is it not? Does it depend on the Glibc version?
G++ doesn't include any headers automatically, but again, you need
<cmath> or <math.h> for the floating point overloads.