diff options
author | Jonathan Wakely <jwakely@redhat.com> | 2025-03-06 10:53:38 +0000 |
---|---|---|
committer | Jonathan Wakely <redi@gcc.gnu.org> | 2025-03-08 10:39:56 +0000 |
commit | d456728667ddace4cf34ac7a5e63cb67de4c6257 (patch) | |
tree | c3d2828445eb8dd93dbb98363f5d31de823ede2e /gcc | |
parent | f0ff7539626e25341c1b450b537e69f86e0bd1f6 (diff) | |
download | gcc-d456728667ddace4cf34ac7a5e63cb67de4c6257.zip gcc-d456728667ddace4cf34ac7a5e63cb67de4c6257.tar.gz gcc-d456728667ddace4cf34ac7a5e63cb67de4c6257.tar.bz2 |
libstdc++: Simplify __memcpyable_iterators concept
My P3349R1 paper clarifies that we should be able to lower contiguous
iterators to pointers, without worrying about side effects of individual
increment or dereference operations.
We do need to advance the iterators, and we need to use std::to_address
on the result of advancing them. This ensures that iterators with error
detection get a chance to diagnose bugs. If we don't use std::to_address
on the advanced iterator, it would be possible for a memcpy on the
pointers to overflow a buffer. By performing the += or -= operations and
also using std::to_address, we give the iterator a chance to abort,
throw, or call a violation handler before the buffer overflow happens.
The new tests only check the std::copy* algorithms, because std::move
and std::move_backward use the same implementation details.
libstdc++-v3/ChangeLog:
* include/bits/stl_algobase.h (__nothrow_contiguous_iterator):
Remove.
(__memcpyable_iterators): Simplify.
(__copy_move_a2, __copy_n_a, __copy_move_backward_a2): Call
std::to_address on the iterators after advancing them.
* testsuite/25_algorithms/copy/contiguous.cc: New test.
* testsuite/25_algorithms/copy_backward/contiguous.cc: New test.
* testsuite/25_algorithms/copy_n/contiguous.cc: New test.
Reviewed-by: Tomasz KamiĆski <tkaminsk@redhat.com>
Diffstat (limited to 'gcc')
0 files changed, 0 insertions, 0 deletions