]> git.ipfire.org Git - thirdparty/gcc.git/commit
libstdc++: Check prerequisites of layout_*::operator().
authorLuc Grosheintz <luc.grosheintz@gmail.com>
Fri, 4 Jul 2025 08:29:43 +0000 (10:29 +0200)
committerTomasz Kamiński <tkaminsk@redhat.com>
Tue, 8 Jul 2025 11:43:47 +0000 (13:43 +0200)
commit4d86e4cda01aa3ab60de164a8492a99bc9ca1f70
tree91ad7eed2d0bc0de5724403d2ea31a3f38d53b58
parent90f7df6194e3c687000fcf725e18532838881d2f
libstdc++: Check prerequisites of layout_*::operator().

Previously, the prerequisite that the arguments passed to operator() are
a multi-dimensional index (of extents()) was not checked.

Both mapping::operator() and mdspan::operator[] have the same
prerequisite. Since, mdspan must check the prerequisite for user-defined
layout mappings, the preference is to check in mdspan.

Because out-of-bounds accesses are very common it's nevertheless useful
to check the prerequisite in mapping::operator(). This is relevant for
cases where the layout mappings are used without mdspan. This commit
checks the prerequisites via _GLIBCXX_DEBUG_ASSERTs and adds the required
tests.

More discussion in the email chain starting at:

  https://gcc.gnu.org/pipermail/libstdc++/2025-July/062265.html

libstdc++-v3/ChangeLog:

* include/std/mdspan: Check prerequisites of
layout_*::operator() with _GLIBCXX_DEBUG_ASSERTs.
* testsuite/23_containers/mdspan/layouts/debug/out_of_bounds_neg.cc:
Add tests for prerequisites.

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/layouts/debug/out_of_bounds_neg.cc [new file with mode: 0644]