diff --git a/stl/inc/mdspan b/stl/inc/mdspan index 72b6e73895..0335d83971 100644 --- a/stl/inc/mdspan +++ b/stl/inc/mdspan @@ -572,7 +572,8 @@ public: && conjunction_v..., is_nothrow_constructible...> _NODISCARD constexpr index_type operator()(_IndexTypes... _Indices) const noexcept { - return _Index_impl(make_index_sequence{}, static_cast(_Indices)...); + return _Index_impl( + make_index_sequence{}, static_cast(_STD move(_Indices))...); } _NODISCARD static constexpr bool is_always_unique() noexcept { @@ -727,7 +728,8 @@ public: && conjunction_v..., is_nothrow_constructible...> _NODISCARD constexpr index_type operator()(_IndexTypes... _Indices) const noexcept { - return _Index_impl(make_index_sequence{}, static_cast(_Indices)...); + return _Index_impl( + make_index_sequence{}, static_cast(_STD move(_Indices))...); } _NODISCARD static constexpr bool is_always_unique() noexcept { @@ -975,7 +977,8 @@ public: && conjunction_v..., is_nothrow_constructible...> _NODISCARD constexpr index_type operator()(_IndexTypes... _Indices) const noexcept { - return _Index_impl(make_index_sequence{}, static_cast(_Indices)...); + return _Index_impl( + make_index_sequence{}, static_cast(_STD move(_Indices))...); } _NODISCARD static constexpr bool is_always_unique() noexcept { diff --git a/tests/std/tests/P0009R18_mdspan_layout_left/test.cpp b/tests/std/tests/P0009R18_mdspan_layout_left/test.cpp index d241bd74ff..aa8158b888 100644 --- a/tests/std/tests/P0009R18_mdspan_layout_left/test.cpp +++ b/tests/std/tests/P0009R18_mdspan_layout_left/test.cpp @@ -340,6 +340,23 @@ constexpr void check_call_operator() { assert(m3(1, 2) == 11); assert(m3(4, 5) == 29); } + + { // LWG-4314: Missing move in mdspan layout mapping::operator() + struct LwgIndex { + constexpr operator int() & noexcept { + return 0; + } + + constexpr operator int() && noexcept { + return 1; + } + }; + + layout_left::mapping> m; + LwgIndex idx; + assert(m(idx) == 1); + assert(m(LwgIndex{}) == 1); + } } constexpr void check_stride_function() { diff --git a/tests/std/tests/P0009R18_mdspan_layout_right/test.cpp b/tests/std/tests/P0009R18_mdspan_layout_right/test.cpp index 32c74462d4..c7e30243bd 100644 --- a/tests/std/tests/P0009R18_mdspan_layout_right/test.cpp +++ b/tests/std/tests/P0009R18_mdspan_layout_right/test.cpp @@ -341,6 +341,23 @@ constexpr void check_call_operator() { assert(m3(2, 2) == 12); assert(m3(3, 4) == 19); } + + { // LWG-4314: Missing move in mdspan layout mapping::operator() + struct LwgIndex { + constexpr operator int() & noexcept { + return 1; + } + + constexpr operator int() && noexcept { + return 0; + } + }; + + layout_right::mapping> m; + LwgIndex idx; + assert(m(idx) == 0); + assert(m(LwgIndex{}) == 0); + } } constexpr void check_stride_function() { diff --git a/tests/std/tests/P0009R18_mdspan_layout_stride/test.cpp b/tests/std/tests/P0009R18_mdspan_layout_stride/test.cpp index d2d931ab16..2814081a69 100644 --- a/tests/std/tests/P0009R18_mdspan_layout_stride/test.cpp +++ b/tests/std/tests/P0009R18_mdspan_layout_stride/test.cpp @@ -548,6 +548,23 @@ constexpr void check_call_operator() { assert(m4(1, 1, 1) == 19); assert(m4(1, 2, 4) == 29); } + + { // LWG-4314: Missing move in mdspan layout mapping::operator() + struct LwgIndex { + constexpr operator int() & noexcept { + return 0; + } + + constexpr operator int() && noexcept { + return 1; + } + }; + + layout_stride::mapping> m({}, array{2}); + LwgIndex idx; + assert(m(idx) == 2); + assert(m(LwgIndex{}) == 2); + } } constexpr void check_stride_function() {