]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
libstdc++: Make is_exhaustive const for layout_(left/right)_padded
authorTomasz Kamiński <tkaminsk@redhat.com>
Mon, 18 May 2026 07:45:46 +0000 (09:45 +0200)
committerTomasz Kamiński <tkaminsk@redhat.com>
Mon, 18 May 2026 08:41:41 +0000 (10:41 +0200)
This is specified as const in the standard, and required to be const-callable
per layout mapping requirement. This made calls to is_exhaustive on mdspan
with such layout ill-formed.

libstdc++-v3/ChangeLog:

* include/std/mdspan (layout_left_padded::is_exhaustive)
(layout_righ_padded::is_exhaustive): Mark as const.
* testsuite/23_containers/mdspan/layouts/mapping.cc: Test noexcept and
const-invocability for is_exhaustive, is_strided, and is_unique.
* testsuite/23_containers/mdspan/layouts/padded.cc: Test is_exhaustive on
const mapping..
* testsuite/23_containers/mdspan/layouts/stride.cc: Likewise.
* testsuite/23_containers/mdspan/mdspan.cc: Checks const-invocability
for is_exhaustive, is_strided, is_unique.

Reviewed-by: Jonathan Wakely <jwakely@redhat.com>
Signed-off-by: Tomasz Kamiński <tkaminsk@redhat.com>
libstdc++-v3/include/std/mdspan
libstdc++-v3/testsuite/23_containers/mdspan/layouts/mapping.cc
libstdc++-v3/testsuite/23_containers/mdspan/layouts/padded.cc
libstdc++-v3/testsuite/23_containers/mdspan/layouts/stride.cc
libstdc++-v3/testsuite/23_containers/mdspan/mdspan.cc

index 5938bf09a9407c6f795f3790e5d2f8219dfb41c8..adc1c0c64219a050f926f75d8c2c8f01ee55b548 100644 (file)
@@ -2621,7 +2621,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
        { return _PaddedStorage::_M_is_always_exhaustive(); }
 
        constexpr bool
-       is_exhaustive() noexcept
+       is_exhaustive() const noexcept
        { return _M_storage._M_is_exhaustive(); }
 
        static constexpr bool
@@ -2794,7 +2794,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
        { return _PaddedStorage::_M_is_always_exhaustive(); }
 
        constexpr bool
-       is_exhaustive() noexcept
+       is_exhaustive() const noexcept
        { return _M_storage._M_is_exhaustive(); }
 
        static constexpr bool
index 17cfac54113bd8cca5144790a11db8fed0a34761..28aa69eca779a43b280ed8de250eedd6b6dba3f6 100644 (file)
@@ -44,6 +44,14 @@ template<typename Layout, typename Extents>
     static_assert(M::is_always_strided() && M::is_strided());
     if constexpr (has_static_is_exhaustive<M>)
       static_assert(M::is_always_exhaustive() && M::is_exhaustive());
+
+    static_assert(noexcept(M::is_always_unique()));
+    static_assert(noexcept(M::is_always_strided()));
+    static_assert(noexcept(M::is_always_exhaustive()));
+    static_assert(noexcept(std::declval<const M>().is_unique()));
+    static_assert(noexcept(std::declval<const M>().is_strided()));
+    static_assert(noexcept(std::declval<const M>().is_exhaustive()));
+
     return true;
   }
 
index 1b6e063d12de92e5de723d2c59590a62c49d6e84..18821795355fb75008a576077102568be476124b 100644 (file)
@@ -509,7 +509,7 @@ template<template<size_t> typename Layout>
   {
     auto exts = std::extents<int>{};
 
-    auto check = [](auto m)
+    auto check = [](const auto m)
     {
       static_assert(m.is_always_exhaustive());
       VERIFY(m.is_exhaustive());
@@ -529,7 +529,7 @@ constexpr void
     {
       auto check = [](auto exts)
       {
-       auto m = typename PaddedLayout::mapping(exts);
+       const auto m = typename PaddedLayout::mapping(exts);
        static_assert(m.is_always_exhaustive());
        VERIFY(m.is_exhaustive());
       };
@@ -554,7 +554,7 @@ template<template<size_t> typename Layout>
     auto ctrue = std::cw<true>;
     auto cfalse= std::cw<false>;
 
-    auto check = [](auto m, auto static_expected, auto runtime_expected)
+    auto check = [](const auto m, auto static_expected, auto runtime_expected)
     {
       static_assert(m.is_always_exhaustive() == static_expected);
       VERIFY(m.is_exhaustive() == runtime_expected);
index 8d2fad2936f67278b26ccb3eecf000e6e1611d6d..94deea33e1cfceb755861e399d518f4976fe470e 100644 (file)
@@ -278,7 +278,7 @@ template<typename Extents, typename Strides>
   constexpr void
   test_is_exhaustive(Extents extents, Strides strides, bool expected)
   {
-    std::layout_stride::mapping<Extents> m(extents, strides);
+    const std::layout_stride::mapping<Extents> m(extents, strides);
     VERIFY(m.is_exhaustive() == expected);
 
     bool always_exhaustive = extents.rank() == 0 || m.required_span_size() == 0;
index 62ff7201cce919e0a0fa63d9a1dc1ed4aacb695c..a2e244df3c566ce60193113b887fdc5d501d2567 100644 (file)
@@ -720,9 +720,9 @@ template<typename Layout, bool Expected>
     static_assert(noexcept(MDSpan::is_always_exhaustive()) == Expected);
     static_assert(noexcept(MDSpan::is_always_strided()) == Expected);
 
-    static_assert(noexcept(std::declval<MDSpan>().is_unique()) == Expected);
-    static_assert(noexcept(std::declval<MDSpan>().is_exhaustive()) == Expected);
-    static_assert(noexcept(std::declval<MDSpan>().is_strided()) == Expected);
+    static_assert(noexcept(std::declval<const MDSpan>().is_unique()) == Expected);
+    static_assert(noexcept(std::declval<const MDSpan>().is_exhaustive()) == Expected);
+    static_assert(noexcept(std::declval<const MDSpan>().is_strided()) == Expected);
   }
 
 int