[LLVMbugs] [Bug 18218] incorrect implementation of isnan and similar functions

bugzilla-daemon at llvm.org bugzilla-daemon at llvm.org
Tue Apr 7 19:00:02 PDT 2015


https://llvm.org/bugs/show_bug.cgi?id=18218

Richard Smith <richard-llvm at metafoo.co.uk> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|RESOLVED                    |REOPENED
                 CC|                            |richard-llvm at metafoo.co.uk
         Resolution|INVALID                     |---

--- Comment #8 from Richard Smith <richard-llvm at metafoo.co.uk> ---
(In reply to comment #7)
>       The only valid types that can be passed to isnan (and others in
> <cmath>) are arithmetic types; i.e, the built-in integral and floating point
> types. No user-defined types.

That may have been the intent, but I don't see any way to read the standard's
wording that way. From the example in comment#0:

      std::isnan(A());

There are no arguments of arithmetic type, so none of the bullets in 26.8/11
apply. The overload set contains 'isnan(float)', 'isnan(double)', and
'isnan(long double)', and 'isnan(float)' should be selected.


To my reading, what paragraph 11 requires is overload sets like this:

template<typename T, typename U>
typename conditional<is_arithmetic<U>::value, T, U>::type
cast_if_arithmetic(U u) { return u; }

template<typename T>
struct is_double_or_integral :
    integral_constant<bool, is_arithmetic<T>::value &&
                            !is_same<T, float>::value &&
                            !is_same<T, long double>::value> {};

bool isgreater(float, float);
bool isgreater(double, double);
bool isgreater(long double, long double);

// bullet 1
template<typename T, typename U>
typename enable_if<is_same<T, long double>::value ||
                   is_same<U, long double>::value, bool>::type
isgreater(T t, U u) {
  return isgreater(cast_if_arithmetic<long double>(t),
                   cast_if_arithmetic<long double>(u));
}
// bullet 2
template<typename T, typename U>
typename enable_if<is_double_or_integral<T>::value ||
                   is_double_or_integral<U>::value, bool>::type
isgreater(T t, U u) {
  return isgreater(cast_if_arithmetic<double>(t),
                   cast_if_arithmetic<double>(u));
}
// bullet 3 requires no overloads: bullets 1 and 2 would have applied
// if there were an arithmetic argument of a type other than float

-- 
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20150408/d5d88d88/attachment.html>


More information about the llvm-bugs mailing list