This is the mail archive of the
mailing list for the GCC project.
Re: Strange C++ function pointer test
- From: Dominik Vogt <vogt at linux dot vnet dot ibm dot com>
- To: "gcc at gcc dot gnu dot org" <gcc at gcc dot gnu dot org>
- Date: Thu, 31 Dec 2015 12:34:58 +0100
- 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>
- Reply-to: vogt at linux dot vnet dot ibm dot com
On Thu, Dec 31, 2015 at 10:11:55AM +0000, Jonathan Wakely wrote:
> On 31 December 2015 at 09:57, Marc Glisse wrote:
> > On Thu, 31 Dec 2015, Dominik Vogt wrote:
> >> This snippet ist from the Plumhall 2014 xvs test suite:
> >> #if CXX03 || CXX11 || CXX14
> >> static float (*p1_)(float) = abs;
> >> ...
> >> checkthat(__LINE__, p1_ != 0);
> >> #endif
> >> (With the testsuite specific macros doing the obvious). abs() is
> >> declared as:
> >> int abs(int j)
> >> Am I missing some odd C++ feature or is that part of the test just
> >> plain wrong? I don't know where to look in the C++ standard; is
> Try searching the library clauses (17 to 30) for "abs". You'll find
> the answer in 26.8 [c.math].
> >> this supposed to compile (with or without a warning?) or generate
> >> an error or is it just undefined?
> >> error: invalid conversion from âint (*)(int) throw ()â to âfloat
> >> (*)(float)â [-fpermissive]
> >> (Of course even with -fpermissive this won't work because (at
> >> least on my platform) ints are passed in different registers than
> >> floats.)
> > There are other overloads of 'abs' declared in math.h / cmath (only in
> > namespace std in the second case, and there are bugs (or standard issues)
> > about having them in the global namespace for the first one).
> That's not quite accurate, C++11 was altered slightly to reflect reality.
> <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>).
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.
The minimal failing program is
-- abs.C --
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?
Dominik ^_^ ^_^