diff --git a/libstdc++-v3/include/bits/ranges_base.h b/libstdc++-v3/include/bits/ranges_base.h index e3c3962bcd9..728d3ad2b25 100644 --- a/libstdc++-v3/include/bits/ranges_base.h +++ b/libstdc++-v3/include/bits/ranges_base.h @@ -447,7 +447,7 @@ namespace ranges #if defined __STRICT_ANSI__ && defined __SIZEOF_INT128__ // For strict-ansi modes integral<__int128> is false else if constexpr (__detail::__is_int128<__size_type>) - return static_cast(__size); + return static_cast<__int128>(__size); #endif else // Must be one of __max_diff_type or __max_size_type. return __detail::__max_diff_type(__size); diff --git a/libstdc++-v3/testsuite/std/ranges/access/ssize.cc b/libstdc++-v3/testsuite/std/ranges/access/ssize.cc index f53f462580c..fdbf245d036 100644 --- a/libstdc++-v3/testsuite/std/ranges/access/ssize.cc +++ b/libstdc++-v3/testsuite/std/ranges/access/ssize.cc @@ -85,6 +85,20 @@ test06() VERIFY( s == 4 ); } +void +test07() +{ +#ifdef __SIZEOF_INT128__ + struct R + { + unsigned __int128 size() const { return 4; } + }; + R r; + static_assert( std::same_as ); + VERIFY( std::ranges::ssize(r) == 4 ); +#endif +} + int main() { @@ -93,4 +107,5 @@ main() test04(); test05(); test06(); + test07(); }