[PUSHED] gdb: Use std::abs instead of abs on LONGEST types

Pedro Alves palves@redhat.com
Thu Feb 27 19:26:00 GMT 2020


On 2/27/20 7:09 PM, Christian Biesinger via gdb-patches wrote:
> On Thu, Feb 27, 2020 at 1:07 PM Pedro Alves <palves@redhat.com> wrote:
>>
>> On 2/27/20 4:46 PM, Andrew Burgess wrote:
>>> Use std::abs so that we get the C++ overloaded version that matches
>>> the argument type instead of the C abs function which is only for int
>>> arguments.
>>
>> Note that stdlib.h/stdmath.h are supposed to provide the overloads in
>> the global namespace as well; the standard requires it.  Older
>> GCCs got that wrong (e.g. 4.8), but more modern GCCs get it right.
>>
>> Just a FYI, the patch is fine.
> 
> Hm... I saw a build error from this on arm-netbsd with clang 9, I
> wonder what happened there. Anyway, the patch does fix it.
> 

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

Odd, clang 5, which is what I have handy, gets it right:

$ cat abs.cc 
#include <stdlib.h>
#include <stdio.h>

void
foo (long i)
{
  printf ("long\n");
}

void
foo (int i)
{
  printf ("int\n");
}

int
main ()
{
  foo (abs ((long)1));
  foo (abs ((int)1));
}

$ clang++ abs.cc -o abs && ./abs
long
int

I wonder whether you were seeing a gnulib override issue, but I
can't find an abs override in our import.

Thanks,
Pedro Alves



More information about the Gdb-patches mailing list