Skip to content

Commit

Permalink
Update isfinite declaration to be constexpr for c++23 only
Browse files Browse the repository at this point in the history
  • Loading branch information
hchataing committed Dec 9, 2023
1 parent dee0dbf commit 2b23e4e
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 2 deletions.
6 changes: 6 additions & 0 deletions include/fmt/core.h
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,12 @@
# define FMT_CONSTEXPR20
#endif

#if (FMT_CPLUSPLUS >= 202302L)
# define FMT_CONSTEXPR23 constexpr
#else
# define FMT_CONSTEXPR23
#endif

// Check if constexpr std::char_traits<>::{compare,length} are supported.
#if defined(__GLIBCXX__)
# if FMT_CPLUSPLUS >= 201703L && defined(_GLIBCXX_RELEASE) && \
Expand Down
2 changes: 1 addition & 1 deletion include/fmt/format.h
Original file line number Diff line number Diff line change
Expand Up @@ -2750,7 +2750,7 @@ struct has_isfinite<T, enable_if_t<sizeof(std::isfinite(T())) != 0>>

template <typename T, FMT_ENABLE_IF(std::is_floating_point<T>::value&&
has_isfinite<T>::value)>
FMT_CONSTEXPR20 bool isfinite(T value) {
FMT_CONSTEXPR23 bool isfinite(T value) {
constexpr T inf = T(std::numeric_limits<double>::infinity());
if (is_constant_evaluated())
return !detail::isnan(value) && value < inf && value > -inf;
Expand Down
2 changes: 1 addition & 1 deletion test/format-test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ template <typename Float> void check_isfinite() {
EXPECT_TRUE(isfinite(Float(fmt::detail::max_value<double>())));
// Use double because std::numeric_limits is broken for __float128.
using limits = std::numeric_limits<double>;
FMT_CONSTEXPR20 auto result = isfinite(Float(limits::infinity()));
FMT_CONSTEXPR23 auto result = isfinite(Float(limits::infinity()));
EXPECT_FALSE(result);
EXPECT_FALSE(isfinite(Float(limits::infinity())));
EXPECT_FALSE(isfinite(Float(-limits::infinity())));
Expand Down

0 comments on commit 2b23e4e

Please sign in to comment.