[PATCH 2/2] gdb: fix unittests/gmp-utils-selftests.c build on solaris

Pedro Alves pedro@palves.net
Fri Nov 20 16:31:47 GMT 2020


On 11/20/20 4:08 PM, Simon Marchi via Gdb-patches wrote:
> On 2020-11-20 10:31 a.m., Tom Tromey wrote:
>>>>>>> "Simon" == Simon Marchi via Gdb-patches <gdb-patches@sourceware.org> writes:
>>
>> Simon> The "pow" function overloads only exist for float-like types, and the
>> Simon> compiler doesn't know which one we want.  Change "2" for "2.0", which
>> Simon> makes the compiler choose one alternative (the double one, I believe).
>>
>> Simon> gdb/ChangeLog:
>>
>> Simon> 	* unittests/gmp-utils-selftests.c (gdb_mpz_read_all_from_small):
>> Simon> 	Pass 2.0 to pow.
>> Simon> 	(gdb_mpz_write_all_from_small): Likewise.
>>
>> This seems fine, though I wonder if it should use std::pow.
>> I guess I'm a little surprised that ordinary 'pow' has overloads.
> 
> It doesn't seem to matter whether I used the std:: prefix or not.  Since
> we include <math.h>, the entities provided by that file are necessarily
> put in the global namespace:
> 
>   https://en.cppreference.com/w/cpp/header#C_compatibility_headers
> 
> So just using 'pow' considers all std::pow overloads.
> 
> My only question is why with libstdc++, we don't have this problem (an
> overload is automatically chosen), but we do with Oracle's libCstd:
> 
>   https://www.oracle.com/solaris/technologies/cmp-stlport-libcstd.html

See this excellent blog post from Jonathan Wakely:

 https://developers.redhat.com/blog/2016/02/29/why-cstdlib-is-more-complicated-than-you-might-think/


More information about the Gdb-patches mailing list