<div dir="ltr"><div dir="ltr"><br></div><br><div class="gmail_quote gmail_quote_container"><div dir="ltr" class="gmail_attr">On Mon, May 18, 2026 at 10:14 AM Jonathan Wakely <<a href="mailto:jwakely.gcc@gmail.com">jwakely.gcc@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="auto"><div><br><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Mon, 18 May 2026, 09:02 Tomasz Kamiński, <<a href="mailto:tkaminsk@redhat.com" target="_blank">tkaminsk@redhat.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">This is specified as const in the standard, and required to be const-callable<br>
per layout mapping requirement. This made calls to is_exhaustive on mdspan<br>
with such layout ill-formed.<br>
<br>
libstdc++-v3/ChangeLog:<br>
<br>
        * include/std/mdspan (layout_left_padded::is_exhaustive)<br>
        (layout_righ_padded::is_exhaustive): Mark as const.<br>
        * testsuite/23_containers/mdspan/layouts/mapping.cc: Test noexcept and<br>
        const-invocability for is_exhaustive, is_strided, and is_unique.<br>
        * testsuite/23_containers/mdspan/layouts/padded.cc: Test is_exhaustive on<br>
        const mapping..<br>
        * testsuite/23_containers/mdspan/layouts/stride.cc: Likewise.<br>
        * testsuite/23_containers/mdspan/mdspan.cc: Checks const-invocability<br>
        for is_exhaustive, is_strided, is_unique.<br>
---<br>
This patch fixes both padded layouts mappings. Expands test to check<br>
const-invocability for all layouts.<br>
<br>
Testing on x86_64-linux. *mdspan* test already passed.<br>
OK for trunk. I would like to backport that to 16 (mdspan::is_exhaustive calls<br>
are ill-formed), any objections?<br></blockquote></div></div><div dir="auto"><br></div><div dir="auto">OK for trunk and 16</div></div></blockquote><div>Backported to 16. </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="auto"><div dir="auto"><br></div><div dir="auto"><br></div><div dir="auto"><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
<br>
 libstdc++-v3/include/std/mdspan                          | 4 ++--<br>
 .../testsuite/23_containers/mdspan/layouts/mapping.cc    | 8 ++++++++<br>
 .../testsuite/23_containers/mdspan/layouts/padded.cc     | 9 +++++----<br>
 .../testsuite/23_containers/mdspan/layouts/stride.cc     | 2 +-<br>
 libstdc++-v3/testsuite/23_containers/mdspan/mdspan.cc    | 6 +++---<br>
 5 files changed, 19 insertions(+), 10 deletions(-)<br>
<br>
diff --git a/libstdc++-v3/include/std/mdspan b/libstdc++-v3/include/std/mdspan<br>
index 5938bf09a94..adc1c0c6421 100644<br>
--- a/libstdc++-v3/include/std/mdspan<br>
+++ b/libstdc++-v3/include/std/mdspan<br>
@@ -2621,7 +2621,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION<br>
        { return _PaddedStorage::_M_is_always_exhaustive(); }<br>
<br>
        constexpr bool<br>
-       is_exhaustive() noexcept<br>
+       is_exhaustive() const noexcept<br>
        { return _M_storage._M_is_exhaustive(); }<br>
<br>
        static constexpr bool<br>
@@ -2794,7 +2794,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION<br>
        { return _PaddedStorage::_M_is_always_exhaustive(); }<br>
<br>
        constexpr bool<br>
-       is_exhaustive() noexcept<br>
+       is_exhaustive() const noexcept<br>
        { return _M_storage._M_is_exhaustive(); }<br>
<br>
        static constexpr bool<br>
diff --git a/libstdc++-v3/testsuite/23_containers/mdspan/layouts/mapping.cc b/libstdc++-v3/testsuite/23_containers/mdspan/layouts/mapping.cc<br>
index 17cfac54113..28aa69eca77 100644<br>
--- a/libstdc++-v3/testsuite/23_containers/mdspan/layouts/mapping.cc<br>
+++ b/libstdc++-v3/testsuite/23_containers/mdspan/layouts/mapping.cc<br>
@@ -44,6 +44,14 @@ template<typename Layout, typename Extents><br>
     static_assert(M::is_always_strided() && M::is_strided());<br>
     if constexpr (has_static_is_exhaustive<M>)<br>
       static_assert(M::is_always_exhaustive() && M::is_exhaustive());<br>
+<br>
+    static_assert(noexcept(M::is_always_unique()));<br>
+    static_assert(noexcept(M::is_always_strided()));<br>
+    static_assert(noexcept(M::is_always_exhaustive()));<br>
+    static_assert(noexcept(std::declval<const M>().is_unique()));<br>
+    static_assert(noexcept(std::declval<const M>().is_strided()));<br>
+    static_assert(noexcept(std::declval<const M>().is_exhaustive()));<br>
+<br>
     return true;<br>
   }<br>
<br>
diff --git a/libstdc++-v3/testsuite/23_containers/mdspan/layouts/padded.cc b/libstdc++-v3/testsuite/23_containers/mdspan/layouts/padded.cc<br>
index 1b6e063d12d..30e52c10d1c 100644<br>
--- a/libstdc++-v3/testsuite/23_containers/mdspan/layouts/padded.cc<br>
+++ b/libstdc++-v3/testsuite/23_containers/mdspan/layouts/padded.cc<br>
@@ -509,7 +509,7 @@ template<template<size_t> typename Layout><br>
   {<br>
     auto exts = std::extents<int>{};<br>
<br>
-    auto check = [](auto m)<br>
+    auto check = [](const auto m)<br>
     {<br>
       static_assert(m.is_always_exhaustive());<br>
       VERIFY(m.is_exhaustive());<br>
@@ -529,9 +529,10 @@ constexpr void<br>
     {<br>
       auto check = [](auto exts)<br>
       {<br>
-       auto m = typename PaddedLayout::mapping(exts);<br>
+       const auto m = typename PaddedLayout::mapping(exts);<br>
        static_assert(m.is_always_exhaustive());<br>
-       VERIFY(m.is_exhaustive());<br>
+        VERIFY(m.is_exhaustive());<br>
+       VERIFY(std::as_const(m).is_exhaustive());<br>
       };<br>
<br>
       check(std::extents(4));<br>
@@ -554,7 +555,7 @@ template<template<size_t> typename Layout><br>
     auto ctrue = std::cw<true>;<br>
     auto cfalse= std::cw<false>;<br>
<br>
-    auto check = [](auto m, auto static_expected, auto runtime_expected)<br>
+    auto check = [](const auto m, auto static_expected, auto runtime_expected)<br>
     {<br>
       static_assert(m.is_always_exhaustive() == static_expected);<br>
       VERIFY(m.is_exhaustive() == runtime_expected);<br>
diff --git a/libstdc++-v3/testsuite/23_containers/mdspan/layouts/stride.cc b/libstdc++-v3/testsuite/23_containers/mdspan/layouts/stride.cc<br>
index 8d2fad2936f..94deea33e1c 100644<br>
--- a/libstdc++-v3/testsuite/23_containers/mdspan/layouts/stride.cc<br>
+++ b/libstdc++-v3/testsuite/23_containers/mdspan/layouts/stride.cc<br>
@@ -278,7 +278,7 @@ template<typename Extents, typename Strides><br>
   constexpr void<br>
   test_is_exhaustive(Extents extents, Strides strides, bool expected)<br>
   {<br>
-    std::layout_stride::mapping<Extents> m(extents, strides);<br>
+    const std::layout_stride::mapping<Extents> m(extents, strides);<br>
     VERIFY(m.is_exhaustive() == expected);<br>
<br>
     bool always_exhaustive = extents.rank() == 0 || m.required_span_size() == 0;<br>
diff --git a/libstdc++-v3/testsuite/23_containers/mdspan/mdspan.cc b/libstdc++-v3/testsuite/23_containers/mdspan/mdspan.cc<br>
index 62ff7201cce..a2e244df3c5 100644<br>
--- a/libstdc++-v3/testsuite/23_containers/mdspan/mdspan.cc<br>
+++ b/libstdc++-v3/testsuite/23_containers/mdspan/mdspan.cc<br>
@@ -720,9 +720,9 @@ template<typename Layout, bool Expected><br>
     static_assert(noexcept(MDSpan::is_always_exhaustive()) == Expected);<br>
     static_assert(noexcept(MDSpan::is_always_strided()) == Expected);<br>
<br>
-    static_assert(noexcept(std::declval<MDSpan>().is_unique()) == Expected);<br>
-    static_assert(noexcept(std::declval<MDSpan>().is_exhaustive()) == Expected);<br>
-    static_assert(noexcept(std::declval<MDSpan>().is_strided()) == Expected);<br>
+    static_assert(noexcept(std::declval<const MDSpan>().is_unique()) == Expected);<br>
+    static_assert(noexcept(std::declval<const MDSpan>().is_exhaustive()) == Expected);<br>
+    static_assert(noexcept(std::declval<const MDSpan>().is_strided()) == Expected);<br>
   }<br>
<br>
 int<br>
-- <br>
2.54.0<br>
<br>
</blockquote></div></div></div>
</blockquote></div></div>