]> git.ipfire.org Git - thirdparty/gcc.git/commit
libstdc++: Fix constraint for custom integer types in mdspan [PR121061]
authorLuc Grosheintz <luc.grosheintz@gmail.com>
Wed, 16 Jul 2025 13:45:44 +0000 (15:45 +0200)
committerTomasz Kamiński <tkaminsk@redhat.com>
Thu, 17 Jul 2025 14:08:58 +0000 (16:08 +0200)
commit1eee8430794f790b6d364603685e70d83d8d42f5
tree888068bf5403502b9780ca3b50143e395d8b83be
parentb38382e36410a9a649b904a2d0a0abcb90f9c418
libstdc++: Fix constraint for custom integer types in mdspan [PR121061]

PR121061 consists of two bugs for mdspan related code. This commit fixes
the first one. Namely, when passing custom IndexType as an array or
span, the conversion to int must be const. Prior to this commit the
constraint incorrectly also allowed non-const conversion. This commit
updates all related constraints to check

  __valid_index_type<const OtherIndexType&, index_type>

in those cases. Also adds a MutatingInt to int_like.h which only
supports non-const conversion to int and updates the tests.

PR libstdc++/121061

libstdc++-v3/ChangeLog:

* include/std/mdspan (extents::extents): Fix constraint to
prevent non-const conversion to index_type.
(layout_stride::mapping::mapping): Ditto.
(mdspan::mdspan): Ditto.
(mdspan::operator[]): Ditto.
* testsuite/23_containers/mdspan/extents/custom_integer.cc: Add
test for MutatingInt.
* testsuite/23_containers/mdspan/int_like.h (MutatingInt): Add.
* testsuite/23_containers/mdspan/layouts/mapping.cc: Add test for
MutatingInt.
* testsuite/23_containers/mdspan/layouts/stride.cc: Ditto.
* testsuite/23_containers/mdspan/mdspan.cc: Ditto.

Reviewed-by: Jonathan Wakely <jwakely@redhat.com>
Reviewed-by: Tomasz Kamiński <tkaminsk@redhat.com>
Signed-off-by: Luc Grosheintz <luc.grosheintz@gmail.com>
libstdc++-v3/include/std/mdspan
libstdc++-v3/testsuite/23_containers/mdspan/extents/custom_integer.cc
libstdc++-v3/testsuite/23_containers/mdspan/int_like.h
libstdc++-v3/testsuite/23_containers/mdspan/layouts/mapping.cc
libstdc++-v3/testsuite/23_containers/mdspan/layouts/stride.cc
libstdc++-v3/testsuite/23_containers/mdspan/mdspan.cc