Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update isfinite declaration to be constexpr for c++23 only #3746

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion include/fmt/format.h
Original file line number Diff line number Diff line change
Expand Up @@ -2752,7 +2752,7 @@ template <typename T, FMT_ENABLE_IF(std::is_floating_point<T>::value&&
has_isfinite<T>::value)>
FMT_CONSTEXPR20 bool isfinite(T value) {
constexpr T inf = T(std::numeric_limits<double>::infinity());
if (is_constant_evaluated())
if (is_constant_evaluated(true))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One drawback is that it switches to a slightly worse implementation on older systems: https://www.godbolt.org/z/WWzjEsrxj. But I guess we can optimize it later.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't see an alternative other than testing FMT_CONSTEXPR20 in the body to replace is_constant_evaluated :(

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can use __builtin_is_constant_evaluated instead of std::is_constant_evaluated.

Copy link
Contributor

@phprus phprus Dec 13, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Or we can improve

fmt/include/fmt/core.h

Lines 108 to 110 in 89860eb

#if ((FMT_CPLUSPLUS >= 202002L) && \
(!defined(_GLIBCXX_RELEASE) || _GLIBCXX_RELEASE > 9)) || \
(FMT_CPLUSPLUS >= 201709L && FMT_GCC_VERSION >= 1002)

condition by adding a stdlib version check.

@hchataing, which version of libc++ (_LIBCPP_VERSION) or libstdc++ (_GLIBCXX_RELEASE) you are using?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@hchataing check PR #3754 please

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Neither macro is defined by the compiler... but maybe I am checking wrong (clang++ -std=c++20 -E -dM foo.cc)

return !detail::isnan(value) && value < inf && value > -inf;
return std::isfinite(value);
}
Expand Down