On Wed, 22 Apr 2026 at 08:35, Tomasz Kamiński <[email protected]> wrote:
>
> 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.
> ---
> Testing on x86_64-linux locally. All *mdspan* test passed in C++23,C++26
> mode and with modules. OK for trunk when all test passes?
OK, thanks
>
> libstdc++-v3/include/std/mdspan | 4 +++-
> .../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 f30c5e83d16..fae4ce0baa2 100644
> --- a/libstdc++-v3/include/std/mdspan
> +++ b/libstdc++-v3/include/std/mdspan
> @@ -3267,8 +3267,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 270b3f18daa..62ff7201cce 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();
> --
> 2.53.0
>