Skip to content

Commit

Permalink
[libc++] Fix acceptance of convertible-to-{float,double,long double} …
Browse files Browse the repository at this point in the history
…in std::isfinite() (#98841)

Summary: Closes #98816.

Test Plan: 

Reviewers: 

Subscribers: 

Tasks: 

Tags: 


Differential Revision: https://phabricator.intern.facebook.com/D60250840
  • Loading branch information
robincaloudis authored and yuxuanchen1997 committed Jul 25, 2024
1 parent 23754b1 commit 93dd234
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
12 changes: 12 additions & 0 deletions libcxx/include/__math/traits.h
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down
12 changes: 12 additions & 0 deletions libcxx/test/std/numerics/c.math/isfinite.pass.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

0 comments on commit 93dd234

Please sign in to comment.