Bug 63789

Summary: g++ -m32 on solaris has trouble finding abs with int64_t
Product: gcc Reporter: Richard PALO <richard>
Component: targetAssignee: Not yet assigned to anyone <unassigned>
Status: WAITING ---    
Severity: normal CC: marc.glisse
Priority: P3    
Version: 4.8.1   
Target Milestone: ---   
Host: Target:
Build: Known to work:
Known to fail: Last reconfirmed: 2016-08-30 00:00:00
Attachments: tabs.ii

Description Richard PALO 2014-11-09 10:40:13 UTC
with the following simplified test program (tabs.cc):
==================>8===============
#include <stdint.h>
#include <stdlib.h>

int64_t tabs(int64_t foo)
{
	return	abs(foo);
}
=================>8================

building with g++ -m32 -c tabs.cc gives the following error:
>tabs.cc: In function ‘int64_t tabs(int64_t)’:
>tabs.cc:6:16: error: call of overloaded ‘abs(int64_t&)’ is ambiguous
>  return abs(foo);
>                ^
>tabs.cc:6:16: note: candidates are:
>In file included from /usr/include/stdlib.h:37:0,
>                 from tabs.cc:2:
>/usr/include/iso/stdlib_iso.h:165:16: note: long int std::abs(long int)
>  inline long   abs(long _l) { return labs(_l); }
>                ^
>/usr/include/iso/stdlib_iso.h:119:12: note: int std::abs(int)
> extern int abs(int);
>            ^

there is no error specifying -m64.

Also, copying tabs.cc to tabs.c and building with gcc gives no error either
('gcc -m32 -c tabs.c' or to be pedantic with -std=c99 added).

I should mention that this seems to work okay with gcc4.4.4, but reproducible with the compilers accessible, namely gcc47..gcc49.

The test program seems to work fine on NetBSD and FreeBSD.

This platform is SunOS 5.11 (illumos).
Comment 1 Richard PALO 2014-11-09 10:45:28 UTC
I should mention that rendering the test program pure c++ by replacing the first two lines with:
>#include <cstdlib>
>#include <cmath>
allows the snippet build with both -m32 and -m64.
It should be able to build as is, though.
Comment 2 Marc Glisse 2014-11-09 11:55:02 UTC
long long (or int64_t) is not part of C++03, so solaris headers don't provide the overload. We complete the set of overloads in c* headers, but there is a well known bug that we don't provide wrappers for the *.h headers. It would be interesting to see how Oracle is updating the solaris headers for C++11.
Comment 3 Richard PALO 2014-11-11 09:34:30 UTC
Apparently with gcc 4.8.2 on Or*acle Solaris 11.2 the error manifests itself as well. Perhaps there is something [in the works] for s12?
Comment 4 Marc Glisse 2016-08-29 13:09:05 UTC
I would expect that this is fixed (or at least the behavior changed) in recent versions of gcc, that ship a C++ stdlib.h wrapper. Can someone confirm?
Comment 5 Richard PALO 2016-08-29 13:24:34 UTC
Created attachment 39510 [details]
tabs.ii

No, I still see the issue with both v5 and 4.9.4
attached is tabs.ii using -save-temps
Comment 6 Marc Glisse 2016-08-29 13:46:25 UTC
Sorry, by recent I meant at least 6.1, I should have been more specific.
Comment 7 Jonathan Wakely 2016-08-30 10:07:11 UTC
Yes, this should be fixed in GCC 6, and if it isn't we now have the tools to fix it.