https://gcc.gnu.org/bugzilla/show_bug.cgi?id=89855

--- Comment #2 from Jonathan Wakely <redi at gcc dot gnu.org> ---
The same problem exists for ::div in <cstdlib>, and for ::abs in both <cmath>
and <cstdlib>. Calling ::abs(INT_MAX + 1LL) or abs(INT_MAX + 1LL) will overflow
and so is undefined.

Clang warns about this and suggests using std::abs instead:

abs.cc:5:10: warning: absolute value function 'abs' given an argument of type
'long' but has parameter of type 'int' which may cause truncation of value
[-Wabsolute-value]
  return ::abs(long(argc) << 32);
         ^
abs.cc:5:10: note: use function 'std::abs' instead
  return ::abs(long(argc) << 32);
         ^~~~~
         std::abs

It doesn't warn for the log(f) example above though.

(In reply to Andrew Pinski from comment #1)
> I there is a related defect report against the c++ standard about this exact
> issue.

I don't think there is.

Only regarding abs, which used to be defined differently in two different
headers. That was changed by:
https://cplusplus.github.io/LWG/issue2294
and
https://cplusplus.github.io/LWG/issue2192

(And it had previously been touched on by
https://cplusplus.github.io/LWG/issue323 which was closed as NAD).

I don't recall an issue about the more general problem of functions other than
abs.

Reply via email to