diff --git a/stl/inc/memory b/stl/inc/memory index 17aa1aee70a..e52aa0b932f 100644 --- a/stl/inc/memory +++ b/stl/inc/memory @@ -78,7 +78,7 @@ namespace ranges { _STL_INTERNAL_STATIC_ASSERT(_No_throw_sentinel_for<_OSe, _Out>); _STL_INTERNAL_STATIC_ASSERT(constructible_from, iter_reference_t<_It>>); - if constexpr (is_same_v<_Se, _It> && _Ptr_copy_cat<_It, _Out>::_Really_trivial) { + if constexpr (is_same_v<_Se, _It> && is_same_v<_OSe, _Out> && _Ptr_copy_cat<_It, _Out>::_Really_trivial) { return _Copy_memcpy_common(_IFirst, _ILast, _OFirst, _OLast); } else { _Uninitialized_backout _Backout{_STD move(_OFirst)}; diff --git a/stl/inc/xmemory b/stl/inc/xmemory index 95b331f12f0..ca3bb9bc9bf 100644 --- a/stl/inc/xmemory +++ b/stl/inc/xmemory @@ -1582,7 +1582,7 @@ namespace ranges { uninitialized_move_result<_It, _Out> _Uninitialized_move_unchecked( _It _IFirst, const _Se _ILast, _Out _OFirst, const _OSe _OLast) { // clang-format on - if constexpr (is_same_v<_Se, _It> && _Ptr_move_cat<_It, _Out>::_Really_trivial) { + if constexpr (is_same_v<_Se, _It> && is_same_v<_OSe, _Out> && _Ptr_move_cat<_It, _Out>::_Really_trivial) { return _Copy_memcpy_common(_IFirst, _ILast, _OFirst, _OLast); } else { _Uninitialized_backout _Backout{_STD move(_OFirst)}; diff --git a/tests/std/tests/P0896R4_ranges_alg_uninitialized_copy/test.cpp b/tests/std/tests/P0896R4_ranges_alg_uninitialized_copy/test.cpp index 38c0d687d54..0199745aa45 100644 --- a/tests/std/tests/P0896R4_ranges_alg_uninitialized_copy/test.cpp +++ b/tests/std/tests/P0896R4_ranges_alg_uninitialized_copy/test.cpp @@ -203,7 +203,7 @@ struct memcpy_test { static constexpr int expected_input_long[] = {13, 55, 12345, 42}; static void call() { - { // Validate only range overload + { // Validate matching ranges int input[] = {13, 55, 12345}; int output[] = {-1, -1, -1}; @@ -235,6 +235,30 @@ struct memcpy_test { assert(ranges::equal(input, expected_input_long)); assert(ranges::equal(output, expected_output)); } + + { // Validate non-common input range + int input[] = {13, 55, 12345}; + int output[] = {-1, -1, -1}; + + const auto result = + ranges::uninitialized_copy(begin(input), unreachable_sentinel, begin(output), end(output)); + assert(result.in == end(input)); + assert(result.out == end(output)); + assert(ranges::equal(input, expected_input)); + assert(ranges::equal(output, expected_output)); + } + + { // Validate non-common output range + int input[] = {13, 55, 12345}; + int output[] = {-1, -1, -1}; + + const auto result = + ranges::uninitialized_copy(begin(input), end(input), begin(output), unreachable_sentinel); + assert(result.in == end(input)); + assert(result.out == end(output)); + assert(ranges::equal(input, expected_input)); + assert(ranges::equal(output, expected_output)); + } } }; diff --git a/tests/std/tests/P0896R4_ranges_alg_uninitialized_move/test.cpp b/tests/std/tests/P0896R4_ranges_alg_uninitialized_move/test.cpp index 865dcffcccf..45adaeecf7e 100644 --- a/tests/std/tests/P0896R4_ranges_alg_uninitialized_move/test.cpp +++ b/tests/std/tests/P0896R4_ranges_alg_uninitialized_move/test.cpp @@ -204,11 +204,13 @@ struct memcpy_test { static constexpr int expected_input_long[] = {13, 55, 12345, 42}; static void call() { - { // Validate range + { // Validate matching ranges int input[] = {13, 55, 12345}; int output[] = {-1, -1, -1}; - ranges::uninitialized_move(input, output); + const auto result = ranges::uninitialized_move(input, output); + assert(result.in == end(input)); + assert(result.out == end(output)); assert(ranges::equal(input, expected_input)); assert(ranges::equal(output, expected_output)); } @@ -234,6 +236,30 @@ struct memcpy_test { assert(ranges::equal(input, expected_input_long)); assert(ranges::equal(output, expected_output)); } + + { // Validate non-common input range + int input[] = {13, 55, 12345}; + int output[] = {-1, -1, -1}; + + const auto result = + ranges::uninitialized_move(begin(input), unreachable_sentinel, begin(output), end(output)); + assert(result.in == end(input)); + assert(result.out == end(output)); + assert(ranges::equal(input, expected_input)); + assert(ranges::equal(output, expected_output)); + } + + { // Validate non-common output range + int input[] = {13, 55, 12345}; + int output[] = {-1, -1, -1}; + + const auto result = + ranges::uninitialized_move(begin(input), end(input), begin(output), unreachable_sentinel); + assert(result.in == end(input)); + assert(result.out == end(output)); + assert(ranges::equal(input, expected_input)); + assert(ranges::equal(output, expected_output)); + } } };