https://gcc.gnu.org/bugzilla/show_bug.cgi?id=118879
Jonathan Wakely <redi at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Ever confirmed|0 |1
Status|UNCONFIRMED |NEW
Last reconfirmed| |2025-02-14
--- Comment #1 from Jonathan Wakely <redi at gcc dot gnu.org> ---
The libstdc++ std::in_range does:
template<typename _Res, typename _Tp>
constexpr bool
in_range(_Tp __t) noexcept
{
static_assert(__is_standard_integer<_Res>::value);
static_assert(__is_standard_integer<_Tp>::value);
using __gnu_cxx::__int_traits;
if constexpr (is_signed_v<_Tp> == is_signed_v<_Res>)
return __int_traits<_Res>::__min <= __t
&& __t <= __int_traits<_Res>::__max;
else if constexpr (is_signed_v<_Tp>)
return __t >= 0
&& make_unsigned_t<_Tp>(__t) <= __int_traits<_Res>::__max;
else
return __t <= make_unsigned_t<_Res>(__int_traits<_Res>::__max);
}
In C++17 the result of int(v) was impl-defined, but since C++20 it's
well-defined, and std::in_range was only added in C++20. So we could change the
first branch to just return __t == _Ret(__t).