libstdc++: Fix return type of ranges::ssize for 128-bit integer [PR 100824]

Signed-off-by: Jonathan Wakely <jwakely@redhat.com>

libstdc++-v3/ChangeLog:

	PR libstdc++/100824
	* include/bits/ranges_base.h (_SSize): Return signed type.
	* testsuite/std/ranges/access/ssize.cc: Check with __int128.

(cherry picked from commit 96963713f6a648a0ed890450e02ebdd8ff583b14)
This commit is contained in:
Jonathan Wakely 2021-06-05 11:42:01 +01:00
parent 1112f1226a
commit 2ba1680d3e
2 changed files with 16 additions and 1 deletions

View File

@ -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<unsigned __int128>(__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);

View File

@ -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<decltype(std::ranges::ssize(r)), __int128> );
VERIFY( std::ranges::ssize(r) == 4 );
#endif
}
int
main()
{
@ -93,4 +107,5 @@ main()
test04();
test05();
test06();
test07();
}