From: Luc Grosheintz Date: Wed, 14 May 2025 19:13:52 +0000 (+0200) Subject: libstdc++: Fix class mandate for extents. X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=0babc6f29f7c29215674b3ee58d5dd17ce7b3849;p=thirdparty%2Fgcc.git libstdc++: Fix class mandate for extents. The standard states that the IndexType must be a signed or unsigned integer. This mandate was implemented using `std::is_integral_v`. Which also includes (among others) char and bool, which neither signed nor unsigned integers. libstdc++-v3/ChangeLog: * include/std/mdspan: Implement the mandate for extents as signed or unsigned integer and not any interal type. Remove leading underscores from names in static_assert message. * testsuite/23_containers/mdspan/extents/class_mandates_neg.cc: Check that extents and extents are invalid. Adjust dg-prune-output pattern. * testsuite/23_containers/mdspan/extents/misc.cc: Update tests to avoid `char` and `bool` as IndexType. Reviewed-by: Tomasz KamiƄski Reviewed-by: Jonathan Wakely --- diff --git a/libstdc++-v3/include/std/mdspan b/libstdc++-v3/include/std/mdspan index aee96dda7cd..47cfa405e44 100644 --- a/libstdc++-v3/include/std/mdspan +++ b/libstdc++-v3/include/std/mdspan @@ -163,10 +163,11 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION template class extents { - static_assert(is_integral_v<_IndexType>, "_IndexType must be integral."); + static_assert(__is_standard_integer<_IndexType>::value, + "IndexType must be a signed or unsigned integer type"); static_assert( (__mdspan::__valid_static_extent<_Extents, _IndexType> && ...), - "Extents must either be dynamic or representable as _IndexType"); + "Extents must either be dynamic or representable as IndexType"); public: using index_type = _IndexType; diff --git a/libstdc++-v3/testsuite/23_containers/mdspan/extents/class_mandates_neg.cc b/libstdc++-v3/testsuite/23_containers/mdspan/extents/class_mandates_neg.cc index b654e3920a8..f9c1c019666 100644 --- a/libstdc++-v3/testsuite/23_containers/mdspan/extents/class_mandates_neg.cc +++ b/libstdc++-v3/testsuite/23_containers/mdspan/extents/class_mandates_neg.cc @@ -1,8 +1,12 @@ // { dg-do compile { target c++23 } } #include -std::extents e1; // { dg-error "from here" } -std::extents e2; // { dg-error "from here" } -// { dg-prune-output "dynamic or representable as _IndexType" } -// { dg-prune-output "must be integral" } +#include + +std::extents e1; // { dg-error "from here" } +std::extents e2; // { dg-error "from here" } +std::extents e3; // { dg-error "from here" } +std::extents e4; // { dg-error "from here" } +// { dg-prune-output "dynamic or representable as IndexType" } +// { dg-prune-output "signed or unsigned integer" } // { dg-prune-output "invalid use of incomplete type" } diff --git a/libstdc++-v3/testsuite/23_containers/mdspan/extents/misc.cc b/libstdc++-v3/testsuite/23_containers/mdspan/extents/misc.cc index 16204aaaa75..e71fdc54230 100644 --- a/libstdc++-v3/testsuite/23_containers/mdspan/extents/misc.cc +++ b/libstdc++-v3/testsuite/23_containers/mdspan/extents/misc.cc @@ -1,6 +1,7 @@ // { dg-do run { target c++23 } } #include +#include #include constexpr size_t dyn = std::dynamic_extent; @@ -20,7 +21,6 @@ static_assert(std::is_same_v::rank_type, size_t>); static_assert(std::is_unsigned_v::size_type>); static_assert(std::is_unsigned_v::size_type>); -static_assert(std::is_same_v::index_type, char>); static_assert(std::is_same_v::index_type, int>); static_assert(std::is_same_v::index_type, unsigned int>); @@ -49,7 +49,7 @@ static_assert(check_rank_return_types()); // Check that the static extents don't take up space. static_assert(sizeof(std::extents) == sizeof(int)); -static_assert(sizeof(std::extents) == sizeof(char)); +static_assert(sizeof(std::extents) == sizeof(short)); template class Container @@ -58,7 +58,7 @@ class Container [[no_unique_address]] std::extents b0; }; -static_assert(sizeof(Container>) == sizeof(int)); +static_assert(sizeof(Container>) == sizeof(int)); static_assert(sizeof(Container>) == sizeof(int)); // operator= @@ -103,7 +103,7 @@ test_deduction_all() test_deduction<0>(); test_deduction<1>(1); test_deduction<2>(1.0, 2.0f); - test_deduction<3>(int(1), char(2), size_t(3)); + test_deduction<3>(int(1), short(2), size_t(3)); return true; }