[llvm-bugs] [Bug 34566] New: libc++ appears to be missing overloads for some cmath functions (isfinite, etc.)
via llvm-bugs
llvm-bugs at lists.llvm.org
Mon Sep 11 18:26:50 PDT 2017
https://bugs.llvm.org/show_bug.cgi?id=34566
Bug ID: 34566
Summary: libc++ appears to be missing overloads for some cmath
functions (isfinite, etc.)
Product: libc++
Version: 5.0
Hardware: PC
OS: Linux
Status: NEW
Severity: enhancement
Priority: P
Component: All Bugs
Assignee: richard-llvm at metafoo.co.uk
Reporter: dlj at google.com
CC: llvm-bugs at lists.llvm.org, mclow.lists at gmail.com
In libc++, SFINAE is used to select different implementations of isfinite
(apparently, mostly for integral types). The C++ standard stipulates additional
overloads in [c.math], with an additional codicil for conversions of types
other than long double, double, and float.
In C++11:
"Moreover, there shall be additional overloads sufficient to ensure:
...
3. Otherwise, all arguments corresponding to double parameters are effectively
cast to float." (26.8p11)
In C++14:
"Moreover, there shall be additional overloads sufficient to ensure:
...
3. Otherwise, all arithmetic arguments corresponding to double parameters have
type float." (still 26.8p11)
It's not clear exactly what "arithmetic" means in the C++14 context, but libc++
uses the std::is_arithmetic type trait as part of the SFINAE overload selection
for std::isfinite. This might be in line with C++14 requirements, assuming that
satisfaction of std::is_arithmetic is the correct interpretation for the term
"arithmetic argument."
The upshot is that types which appear to be valid arguments to std::isfinite
under C++11 rules (through an implicit conversion operator) do not work in
libc++.
Example:
=====
#include <cmath>
struct MyFloat {
operator float() const { return 0.f; }
};
void checkfinite(void) {
MyFloat mf;
std::isfinite(0.0f); // OK
std::isfinite(0.0); // OK
std::isfinite(mf); // fails
}
=====
https://godbolt.org/g/xX4rMb
The fix for the SFINAE code could simply be additionally allow a check for
whether the argument is convertible to 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/20170912/06405528/attachment.html>
More information about the llvm-bugs
mailing list