[libcxx-commits] [libcxx] 7f2bd53 - [libc++] Fix acceptance of convertible-to-{float, double, long double} in std::isfinite() (#98841)
via libcxx-commits
libcxx-commits at lists.llvm.org
Thu Jul 18 06:01:12 PDT 2024
Author: Robin Caloudis
Date: 2024-07-18T09:01:09-04:00
New Revision: 7f2bd53b142ec147da9f8bd98775be1d14457ba1
URL: https://github.com/llvm/llvm-project/commit/7f2bd53b142ec147da9f8bd98775be1d14457ba1
DIFF: https://github.com/llvm/llvm-project/commit/7f2bd53b142ec147da9f8bd98775be1d14457ba1.diff
LOG: [libc++] Fix acceptance of convertible-to-{float,double,long double} in std::isfinite() (#98841)
Closes https://github.com/llvm/llvm-project/issues/98816.
Added:
Modified:
libcxx/include/__math/traits.h
libcxx/test/std/numerics/c.math/isfinite.pass.cpp
Removed:
################################################################################
diff --git a/libcxx/include/__math/traits.h b/libcxx/include/__math/traits.h
index a448266797557..27ec52ecef022 100644
--- a/libcxx/include/__math/traits.h
+++ b/libcxx/include/__math/traits.h
@@ -55,6 +55,18 @@ _LIBCPP_NODISCARD _LIBCPP_CONSTEXPR_SINCE_CXX23 _LIBCPP_HIDE_FROM_ABI bool isfin
return true;
}
+_LIBCPP_NODISCARD inline _LIBCPP_CONSTEXPR_SINCE_CXX23 _LIBCPP_HIDE_FROM_ABI bool isfinite(float __x) _NOEXCEPT {
+ return __builtin_isfinite(__x);
+}
+
+_LIBCPP_NODISCARD inline _LIBCPP_CONSTEXPR_SINCE_CXX23 _LIBCPP_HIDE_FROM_ABI bool isfinite(double __x) _NOEXCEPT {
+ return __builtin_isfinite(__x);
+}
+
+_LIBCPP_NODISCARD inline _LIBCPP_CONSTEXPR_SINCE_CXX23 _LIBCPP_HIDE_FROM_ABI bool isfinite(long double __x) _NOEXCEPT {
+ return __builtin_isfinite(__x);
+}
+
// isinf
template <class _A1, __enable_if_t<is_arithmetic<_A1>::value && numeric_limits<_A1>::has_infinity, int> = 0>
diff --git a/libcxx/test/std/numerics/c.math/isfinite.pass.cpp b/libcxx/test/std/numerics/c.math/isfinite.pass.cpp
index 6bbc3aaac6d13..3d5be61634334 100644
--- a/libcxx/test/std/numerics/c.math/isfinite.pass.cpp
+++ b/libcxx/test/std/numerics/c.math/isfinite.pass.cpp
@@ -62,9 +62,21 @@ struct TestInt {
}
};
+template <typename T>
+struct ConvertibleTo {
+ operator T() const { return T(); }
+};
+
int main(int, char**) {
types::for_each(types::floating_point_types(), TestFloat());
types::for_each(types::integral_types(), TestInt());
+ // Make sure we can call `std::isfinite` with convertible types
+ {
+ assert(std::isfinite(ConvertibleTo<float>()));
+ assert(std::isfinite(ConvertibleTo<double>()));
+ assert(std::isfinite(ConvertibleTo<long double>()));
+ }
+
return 0;
}
More information about the libcxx-commits
mailing list