[gcc r16-8799] libstdc++: Accept data_handle_type by value in mdspan deduction guide.

Tomasz Kaminski tkaminsk@gcc.gnu.org
Wed Apr 22 09:56:36 GMT 2026


https://gcc.gnu.org/g:20d0b35cc75aa20731d6b48c90a8490cf9427539

commit r16-8799-g20d0b35cc75aa20731d6b48c90a8490cf9427539
Author: Tomasz Kamiński <tkaminsk@redhat.com>
Date:   Wed Apr 22 09:23:37 2026 +0200

    libstdc++: Accept data_handle_type by value in mdspan deduction guide.
    
    This makes the deduction guide accepting data_handle_type, mapping
    and accessor consistent with corresponding constructor.
    Resolves LWG4511.
    
    libstdc++-v3/ChangeLog:
    
            * include/std/mdspan (mdspan): Remove reference from
            _AccessorType::data_handle_type parameteter of deduction
            guide.
            * testsuite/23_containers/mdspan/mdspan.cc: New test.
    
    Reviewed-by: Jonathan Wakely <jwakely@redhat.com>
    Signed-off-by: Tomasz Kamiński <tkaminsk@redhat.com>

Diff:
---
 libstdc++-v3/include/std/mdspan                       |  4 +++-
 libstdc++-v3/testsuite/23_containers/mdspan/mdspan.cc | 19 +++++++++++++++++++
 2 files changed, 22 insertions(+), 1 deletion(-)

diff --git a/libstdc++-v3/include/std/mdspan b/libstdc++-v3/include/std/mdspan
index 14d8edc8ad17..a3ab64633ac3 100644
--- a/libstdc++-v3/include/std/mdspan
+++ b/libstdc++-v3/include/std/mdspan
@@ -3269,8 +3269,10 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
     -> mdspan<_ElementType, typename _MappingType::extents_type,
 	      typename _MappingType::layout_type>;
 
+  // _GLIBCXX_RESOLVE_LIB_DEFECTS
+  // 4511. Inconsistency between the deduction guide of std::mdspan taking...
   template<typename _MappingType, typename _AccessorType>
-    mdspan(const typename _AccessorType::data_handle_type&, const _MappingType&,
+    mdspan(typename _AccessorType::data_handle_type, const _MappingType&,
 	   const _AccessorType&)
     -> mdspan<typename _AccessorType::element_type,
 	      typename _MappingType::extents_type,
diff --git a/libstdc++-v3/testsuite/23_containers/mdspan/mdspan.cc b/libstdc++-v3/testsuite/23_containers/mdspan/mdspan.cc
index 270b3f18daad..62ff7201cce9 100644
--- a/libstdc++-v3/testsuite/23_containers/mdspan/mdspan.cc
+++ b/libstdc++-v3/testsuite/23_containers/mdspan/mdspan.cc
@@ -404,6 +404,24 @@ template<typename CustomInt, bool ValidForPacks, bool ValidForArrays>
     return true;
   }
 
+void
+test_from_volatile_ptr_and_accessor()
+{
+  constexpr size_t n = 3*5*7;
+  std::array<double, n> storage{};
+  double* volatile vptr = storage.data();
+  using Extents = std::extents<int, 3, 5, 7>;
+
+  auto exts = Extents{};
+  auto m = std::layout_left::mapping(exts);
+  auto a = std::default_accessor<double>{};
+  auto md = std::mdspan(vptr, m, a);
+
+  assert_deduced_typedefs<double, Extents, std::layout_left>(md);
+  VERIFY(md.data_handle() == storage.data());
+  VERIFY(md.mapping() == m);
+}
+
 template<typename T, bool NothrowConstructible = true,
 	 bool NothrowAssignable = true>
   class OpaqueAccessor
@@ -757,6 +775,7 @@ main()
   test_from_int_like<RValueInt, true, false>();
   test_from_int_like<ConstLValueInt, false, true>();
 
+  test_from_volatile_ptr_and_accessor();
   test_from_opaque_accessor();
   test_from_base_class_accessor();
   test_from_mapping_like();


More information about the Libstdc++-cvs mailing list