This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Strange C++ function pointer test


On 31 December 2015 at 13:09, Dominik Vogt <vogt@linux.vnet.ibm.com> wrote:
> On Thu, Dec 31, 2015 at 12:42:56PM +0000, Jonathan Wakely wrote:
>> On 31 December 2015 at 11:54, Dominik Vogt wrote:
>> > Is there a requirement for a certain minimum Glibc version for
>> > this to work?
>>
>> It doesn't work with any glibc, because it doesn't declare the C++ overloads.
>
> All right, so, the situation is:
>
>  * The test includes just stdlib.h and math.h.
>  * The test expects the float variant of abs to be available.
>  * It tests the C++ compiler on C code, so it *does not* use any
>    C++ specific code (namespace or C++ headers).

That sentence is meaningless. If you use a C++ compiler then you're
compiling C++ code.

>  * The C++-11 standard does *not* require that any overloaded
>    variants of abs() are available when inclding math.h, right?

Wrong. As specified in [c.math], <cmath> declares these in namespace std:

float abs(float);
double abs(double);
long double abs(long double);

and <math.h> declares the same overloads in the global namespace.

>
> ==>
>
> The assumption that the test should compile without error is
> bogus?

No, the test is valid.

> The test seems to assume that including math.h with the
> C++ compiler is the same as including cmath.

No it doesn't. If the test included <cmath> then it would have to use
std::abs. Because it includes <math.h> it uses ::abs.

>> Libstdc++ has an include/c_compatibility/math.h header that would
>> include <cmath> (which declares the C++ overloads) and then pull them
>> into the global namespace, but that isn't used on GNU/Linux, and would
>> create other problems.
>>
>> This is already in Bugzilla: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=60401
>
> Yet this bug report wants stdlib.h (or math.h) included from C++
> to add the non-int signatures to the abs() function?

Yes.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]