gcc/libstdc++-v3/testsuite/25_algorithms
Jonathan Wakely 822a11a1e6 libstdc++: Do not use memmove for 1-element ranges [PR108846]
This avoids overwriting tail padding when algorithms like std::copy are
used to write a single value through a pointer to a base subobject.

The pointer arithmetic on a Base* is valid for N==1, but the copy/move
operation needs to be done using assignment, not a memmove or memcpy of
sizeof(Base) bytes.

Instead of putting a check for N==1 in all of copy, copy_n, move etc.
this adds it to the __copy_move and __copy_move_backward partial
specializations used for trivially copyable types. When N==1 those
partial specializations dispatch to new static member functions of the
partial specializations for non-trivial types, so that a copy/move
assignment is done appropriately for the _IsMove constant.

libstdc++-v3/ChangeLog:

	PR libstdc++/108846
	* include/bits/stl_algobase.h (__copy_move<false, false, RA>)
	Add __assign_one static member function.
	(__copy_move<true, false, RA>): Likewise.
	(__copy_move<IsMove, true, RA>): Do not use memmove for a single
	value.
	(__copy_move_backward<IsMove, true, RA>): Likewise.
	* testsuite/25_algorithms/copy/108846.cc: New test.
	* testsuite/25_algorithms/copy_backward/108846.cc: New test.
	* testsuite/25_algorithms/copy_n/108846.cc: New test.
	* testsuite/25_algorithms/move/108846.cc: New test.
	* testsuite/25_algorithms/move_backward/108846.cc: New test.
2023-02-28 09:49:11 +00:00
..
adjacent_find Update copyright years. 2023-01-16 11:52:17 +01:00
advance/istreambuf_iterators Update copyright years. 2023-01-16 11:52:17 +01:00
all_of Update copyright years. 2023-01-16 11:52:17 +01:00
any_of Update copyright years. 2023-01-16 11:52:17 +01:00
binary_search Update copyright years. 2023-01-16 11:52:17 +01:00
clamp Update copyright years. 2023-01-16 11:52:17 +01:00
contains libstdc++: Implement ranges::contains/contains_subrange from P2302R4 2023-02-03 10:52:13 -05:00
contains_subrange libstdc++: Implement ranges::contains/contains_subrange from P2302R4 2023-02-03 10:52:13 -05:00
copy libstdc++: Do not use memmove for 1-element ranges [PR108846] 2023-02-28 09:49:11 +00:00
copy_backward libstdc++: Do not use memmove for 1-element ranges [PR108846] 2023-02-28 09:49:11 +00:00
copy_if Update copyright years. 2023-01-16 11:52:17 +01:00
copy_n libstdc++: Do not use memmove for 1-element ranges [PR108846] 2023-02-28 09:49:11 +00:00
count Update copyright years. 2023-01-16 11:52:17 +01:00
count_if Update copyright years. 2023-01-16 11:52:17 +01:00
equal Update copyright years. 2023-01-16 11:52:17 +01:00
equal_range Update copyright years. 2023-01-16 11:52:17 +01:00
fill Update copyright years. 2023-01-16 11:52:17 +01:00
fill_n Update copyright years. 2023-01-16 11:52:17 +01:00
find Update copyright years. 2023-01-16 11:52:17 +01:00
find_end Update copyright years. 2023-01-16 11:52:17 +01:00
find_first_of Update copyright years. 2023-01-16 11:52:17 +01:00
find_if Update copyright years. 2023-01-16 11:52:17 +01:00
find_if_not Update copyright years. 2023-01-16 11:52:17 +01:00
find_last libstdc++: Implement ranges::find_last{,_if,_if_not} from P1223R5 2023-02-03 10:52:18 -05:00
find_last_if libstdc++: Implement ranges::find_last{,_if,_if_not} from P1223R5 2023-02-03 10:52:18 -05:00
find_last_if_not libstdc++: Implement ranges::find_last{,_if,_if_not} from P1223R5 2023-02-03 10:52:18 -05:00
for_each Update copyright years. 2023-01-16 11:52:17 +01:00
generate Update copyright years. 2023-01-16 11:52:17 +01:00
generate_n Update copyright years. 2023-01-16 11:52:17 +01:00
headers Update copyright years. 2023-01-16 11:52:17 +01:00
heap Update copyright years. 2023-01-16 11:52:17 +01:00
includes Update copyright years. 2023-01-16 11:52:17 +01:00
inplace_merge Update copyright years. 2023-01-16 11:52:17 +01:00
iota libstdc++: Implement ranges::iota from P2440R1 2023-02-03 10:52:15 -05:00
is_heap Update copyright years. 2023-01-16 11:52:17 +01:00
is_heap_until Update copyright years. 2023-01-16 11:52:17 +01:00
is_partitioned Update copyright years. 2023-01-16 11:52:17 +01:00
is_permutation Update copyright years. 2023-01-16 11:52:17 +01:00
is_sorted Update copyright years. 2023-01-16 11:52:17 +01:00
is_sorted_until Update copyright years. 2023-01-16 11:52:17 +01:00
iter_swap Update copyright years. 2023-01-16 11:52:17 +01:00
lexicographical_compare Update copyright years. 2023-01-16 11:52:17 +01:00
lexicographical_compare_three_way Update copyright years. 2023-01-16 11:52:17 +01:00
lower_bound Update copyright years. 2023-01-16 11:52:17 +01:00
make_heap Update copyright years. 2023-01-16 11:52:17 +01:00
max Update copyright years. 2023-01-16 11:52:17 +01:00
max_element Update copyright years. 2023-01-16 11:52:17 +01:00
merge Update copyright years. 2023-01-16 11:52:17 +01:00
min Update copyright years. 2023-01-16 11:52:17 +01:00
min_element Update copyright years. 2023-01-16 11:52:17 +01:00
minmax Update copyright years. 2023-01-16 11:52:17 +01:00
minmax_element Update copyright years. 2023-01-16 11:52:17 +01:00
mismatch Update copyright years. 2023-01-16 11:52:17 +01:00
move libstdc++: Do not use memmove for 1-element ranges [PR108846] 2023-02-28 09:49:11 +00:00
move_backward libstdc++: Do not use memmove for 1-element ranges [PR108846] 2023-02-28 09:49:11 +00:00
next_permutation Update copyright years. 2023-01-16 11:52:17 +01:00
none_of Update copyright years. 2023-01-16 11:52:17 +01:00
nth_element Update copyright years. 2023-01-16 11:52:17 +01:00
partial_sort Update copyright years. 2023-01-16 11:52:17 +01:00
partial_sort_copy Update copyright years. 2023-01-16 11:52:17 +01:00
partition Update copyright years. 2023-01-16 11:52:17 +01:00
partition_copy Update copyright years. 2023-01-16 11:52:17 +01:00
partition_point Update copyright years. 2023-01-16 11:52:17 +01:00
pop_heap Update copyright years. 2023-01-16 11:52:17 +01:00
prev_permutation Update copyright years. 2023-01-16 11:52:17 +01:00
pstl Update copyright years. 2023-01-16 11:52:17 +01:00
push_heap Update copyright years. 2023-01-16 11:52:17 +01:00
random_shuffle Update copyright years. 2023-01-16 11:52:17 +01:00
remove Update copyright years. 2023-01-16 11:52:17 +01:00
remove_copy Update copyright years. 2023-01-16 11:52:17 +01:00
remove_copy_if Update copyright years. 2023-01-16 11:52:17 +01:00
remove_if Update copyright years. 2023-01-16 11:52:17 +01:00
replace Update copyright years. 2023-01-16 11:52:17 +01:00
replace_copy Update copyright years. 2023-01-16 11:52:17 +01:00
replace_copy_if Update copyright years. 2023-01-16 11:52:17 +01:00
replace_if Update copyright years. 2023-01-16 11:52:17 +01:00
reverse Update copyright years. 2023-01-16 11:52:17 +01:00
reverse_copy Update copyright years. 2023-01-16 11:52:17 +01:00
rotate Update copyright years. 2023-01-16 11:52:17 +01:00
rotate_copy Update copyright years. 2023-01-16 11:52:17 +01:00
sample Update copyright years. 2023-01-16 11:52:17 +01:00
search Update copyright years. 2023-01-16 11:52:17 +01:00
search_n Update copyright years. 2023-01-16 11:52:17 +01:00
set_difference Update copyright years. 2023-01-16 11:52:17 +01:00
set_intersection Update copyright years. 2023-01-16 11:52:17 +01:00
set_symmetric_difference Update copyright years. 2023-01-16 11:52:17 +01:00
set_union Update copyright years. 2023-01-16 11:52:17 +01:00
shift_left Update copyright years. 2023-01-16 11:52:17 +01:00
shift_right Update copyright years. 2023-01-16 11:52:17 +01:00
shuffle Update copyright years. 2023-01-16 11:52:17 +01:00
sort Update copyright years. 2023-01-16 11:52:17 +01:00
sort_heap Update copyright years. 2023-01-16 11:52:17 +01:00
stable_partition Update copyright years. 2023-01-16 11:52:17 +01:00
stable_sort Update copyright years. 2023-01-16 11:52:17 +01:00
swap Update copyright years. 2023-01-16 11:52:17 +01:00
swap_ranges Update copyright years. 2023-01-16 11:52:17 +01:00
transform Update copyright years. 2023-01-16 11:52:17 +01:00
unique Update copyright years. 2023-01-16 11:52:17 +01:00
unique_copy Update copyright years. 2023-01-16 11:52:17 +01:00
upper_bound Update copyright years. 2023-01-16 11:52:17 +01:00
constexpr_macro.cc Update copyright years. 2023-01-16 11:52:17 +01:00
cpp_lib_constexpr.cc Update copyright years. 2023-01-16 11:52:17 +01:00