Actions
Bug #5290
openint64_t issues for abs() with c++ out of stdlib.h
Status:
New
Priority:
Normal
Assignee:
-
Category:
-
Start date:
2014-11-06
Due date:
% Done:
0%
Estimated time:
Difficulty:
Medium
Tags:
needs-triage
Gerrit CR:
Description
This is the original issue found is reproduced with the following program:
richard@omnis:/home/richard/src$ cat tabs.cc #include <stdlib.h> void tabs(int64_t foo) { int64_t bar = abs(foo); } richard@omnis:/home/richard/src$ /opt/gcc-4.8.1/bin/g++ -c tabs.cc tabs.cc: In function ‘void tabs(int64_t)’: tabs.cc:4:23: error: call of overloaded ‘abs(int64_t&)’ is ambiguous int64_t bar = abs(foo); ^ tabs.cc:4:23: note: candidates are: In file included from /usr/include/stdlib.h:37:0, from tabs.cc:1: /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); ^ richard@omnis:/home/richard/src$ /opt/gcc-4.8.1/bin/g++ -m64 -c tabs.cc
There is (on i386) a first issue of a problematic definition when uint64_t (here long long) is used.
Then, by simply copying the .cc to a .c and trying again with gcc
richard@omnis:/home/richard/src$ cp tabs.cc tabs.c richard@omnis:/home/richard/src$ /opt/gcc-4.8.1/bin/gcc -c tabs.c tabs.c:2:11: error: unknown type name ‘int64_t’ void tabs(int64_t foo) ^ richard@omnis:/home/richard/src$ richard@omnis:/home/richard/src$ /opt/gcc-4.8.1/bin/gcc -m64 -c tabs.c tabs.c:2:11: error: unknown type name ‘int64_t’ void tabs(int64_t foo) ^
Here the ball is completely dropped.
outputting via '-E -dD -o <file>' indicates what is determined by the compiler.
Clang gives informative output as well:
richard@omnis:/home/richard/src$ clang++ -m32 -c tabs.cc tabs.cc:4:16: error: call to 'abs' is ambiguous int64_t bar = abs(foo); ^~~ /usr/include/iso/stdlib_iso.h:119:12: note: candidate function extern int abs(int); ^ /usr/include/iso/stdlib_iso.h:165:16: note: candidate function inline long abs(long _l) { return labs(_l); } ^ 1 error generated. richard@omnis:/home/richard/src$ clang++ -m64 -c tabs.cc richard@omnis:/home/richard/src$ clang -m32 -c tabs.c tabs.c:4:16: warning: absolute value function 'abs' given an argument of type 'int64_t' (aka 'long long') but has parameter of type 'int' which may cause truncation of value [-Wabsolute-value] int64_t bar = abs(foo); ^ tabs.c:4:16: note: use function 'llabs' instead int64_t bar = abs(foo); ^~~ llabs 1 warning generated. richard@omnis:/home/richard/src$ clang -m64 -c tabs.c tabs.c:4:16: warning: absolute value function 'abs' given an argument of type 'int64_t' (aka 'long') but has parameter of type 'int' which may cause truncation of value [-Wabsolute-value] int64_t bar = abs(foo); ^ tabs.c:4:16: note: use function 'labs' instead int64_t bar = abs(foo); ^~~ labs 1 warning generated.
Files
Actions