Bug 63789 - g++ -m32 on solaris has trouble finding abs with int64_t
Summary: g++ -m32 on solaris has trouble finding abs with int64_t
Alias: None
Product: gcc
Classification: Unclassified
Component: target (show other bugs)
Version: 4.8.1
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
Depends on:
Reported: 2014-11-09 10:40 UTC by Richard PALO
Modified: 2016-08-30 10:07 UTC (History)
1 user (show)

See Also:
Known to work:
Known to fail:
Last reconfirmed: 2016-08-30 00:00:00

tabs.ii (6.14 KB, application/gzip)
2016-08-29 13:24 UTC, Richard PALO

Note You need to log in before you can comment on or make changes to this bug.
Description Richard PALO 2014-11-09 10:40:13 UTC
with the following simplified test program (tabs.cc):
#include <stdint.h>
#include <stdlib.h>

int64_t tabs(int64_t foo)
	return	abs(foo);

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]

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.