Several algorithms check the is_trivially_copyable trait to decide whether to dispatch to memmove or memcmp as an optimization. Since r271435 (CWG DR 2094) the trait is true for volatile-qualified scalars, but we can't use memmove or memcmp when the type is volatile. We need to also check for volatile types. This is complicated by the fact that in C++20 (but not earlier standards) iterator_traits<volatile T*>::value_type is T, so we can't just check whether the value_type is volatile. The solution in this patch is to introduce new traits __memcpyable and __memcmpable which combine into a single trait the checks for pointers, the value types being the same, and the type being trivially copyable but not volatile-qualified. PR libstdc++/94013 * include/bits/cpp_type_traits.h (__memcpyable, __memcmpable): New traits to control when to use memmove and memcmp optimizations. (__is_nonvolatile_trivially_copyable): New helper trait. * include/bits/ranges_algo.h (__lexicographical_compare_fn): Do not use memcmp optimization with volatile data. * include/bits/ranges_algobase.h (__equal_fn): Use __memcmpable. (__copy_or_move, __copy_or_move_backward): Use __memcpyable. * include/bits/stl_algobase.h (__copy_move_a2): Use __memcpyable. (__copy_move_backward_a2): Likewise. (__equal_aux1): Use __memcmpable. (__lexicographical_compare_aux): Do not use memcmp optimization with volatile data. * testsuite/25_algorithms/copy/94013.cc: New test. * testsuite/25_algorithms/copy_backward/94013.cc: New test. * testsuite/25_algorithms/equal/94013.cc: New test. * testsuite/25_algorithms/fill/94013.cc: New test. * testsuite/25_algorithms/lexicographical_compare/94013.cc: New test. * testsuite/25_algorithms/move/94013.cc: New test. * testsuite/25_algorithms/move_backward/94013.cc: New test.
| Name |
Last commit
|
Last update |
|---|---|---|
| .. | ||
| adjacent_find | Loading commit data... | |
| advance/istreambuf_iterators | Loading commit data... | |
| all_of | Loading commit data... | |
| any_of | Loading commit data... | |
| binary_search | Loading commit data... | |
| clamp | Loading commit data... | |
| copy | Loading commit data... | |
| copy_backward | Loading commit data... | |
| copy_if | Loading commit data... | |
| copy_n | Loading commit data... | |
| count | Loading commit data... | |
| count_if | Loading commit data... | |
| equal | Loading commit data... | |
| equal_range | Loading commit data... | |
| fill | Loading commit data... | |
| fill_n | Loading commit data... | |
| find | Loading commit data... | |
| find_end | Loading commit data... | |
| find_first_of | Loading commit data... | |
| find_if | Loading commit data... | |
| find_if_not | Loading commit data... | |
| for_each | Loading commit data... | |
| generate | Loading commit data... | |
| generate_n | Loading commit data... | |
| headers | Loading commit data... | |
| heap | Loading commit data... | |
| includes | Loading commit data... | |
| inplace_merge | Loading commit data... | |
| is_heap | Loading commit data... | |
| is_heap_until | Loading commit data... | |
| is_partitioned | Loading commit data... | |
| is_permutation | Loading commit data... | |
| is_sorted | Loading commit data... | |
| is_sorted_until | Loading commit data... | |
| iter_swap | Loading commit data... | |
| lexicographical_compare | Loading commit data... | |
| lexicographical_compare_three_way | Loading commit data... | |
| lower_bound | Loading commit data... | |
| make_heap | Loading commit data... | |
| max | Loading commit data... | |
| max_element | Loading commit data... | |
| merge | Loading commit data... | |
| min | Loading commit data... | |
| min_element | Loading commit data... | |
| minmax | Loading commit data... | |
| minmax_element | Loading commit data... | |
| mismatch | Loading commit data... | |
| move | Loading commit data... | |
| move_backward | Loading commit data... | |
| next_permutation | Loading commit data... | |
| none_of | Loading commit data... | |
| nth_element | Loading commit data... | |
| partial_sort | Loading commit data... | |
| partial_sort_copy | Loading commit data... | |
| partition | Loading commit data... | |
| partition_copy | Loading commit data... | |
| partition_point | Loading commit data... | |
| pop_heap | Loading commit data... | |
| prev_permutation | Loading commit data... | |
| pstl | Loading commit data... | |
| push_heap | Loading commit data... | |
| random_shuffle | Loading commit data... | |
| remove | Loading commit data... | |
| remove_copy | Loading commit data... | |
| remove_copy_if | Loading commit data... | |
| remove_if | Loading commit data... | |
| replace | Loading commit data... | |
| replace_copy | Loading commit data... | |
| replace_copy_if | Loading commit data... | |
| replace_if | Loading commit data... | |
| reverse | Loading commit data... | |
| reverse_copy | Loading commit data... | |
| rotate | Loading commit data... | |
| rotate_copy | Loading commit data... | |
| sample | Loading commit data... | |
| search | Loading commit data... | |
| search_n | Loading commit data... | |
| set_difference | Loading commit data... | |
| set_intersection | Loading commit data... | |
| set_symmetric_difference | Loading commit data... | |
| set_union | Loading commit data... | |
| shift_left | Loading commit data... | |
| shift_right | Loading commit data... | |
| shuffle | Loading commit data... | |
| sort | Loading commit data... | |
| sort_heap | Loading commit data... | |
| stable_partition | Loading commit data... | |
| stable_sort | Loading commit data... | |
| swap | Loading commit data... | |
| swap_ranges | Loading commit data... | |
| transform | Loading commit data... | |
| unique | Loading commit data... | |
| unique_copy | Loading commit data... | |
| upper_bound | Loading commit data... | |
| constexpr_macro.cc | Loading commit data... | |
| cpp_lib_constexpr.cc | Loading commit data... |