aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJonathan Wakely <jwakely@redhat.com>2025-03-24 21:21:02 +0000
committerJonathan Wakely <redi@gcc.gnu.org>2025-03-25 17:38:39 +0000
commit2848b8dabcaca05563b92528206345f8f845daff (patch)
tree55f4d65cb494823c80c3068970d3a6ac5a6e2dc5
parentd4f7d18b3ed83a8265be913bb230f6efa395e527 (diff)
downloadgcc-2848b8dabcaca05563b92528206345f8f845daff.zip
gcc-2848b8dabcaca05563b92528206345f8f845daff.tar.gz
gcc-2848b8dabcaca05563b92528206345f8f845daff.tar.bz2
libstdc++: Adjust how __gnu_debug::vector detects invalidation
The new C++23 member functions assign_range, insert_range and append_range were checking whether the begin() iterator changed after calling the base class member. That works, but is technically undefined when the original iterator has been invalidated by a change in capacity. We can just check the capacity directly, because reallocation only occurs if a change in capacity is required. N.B. we can't use data() either because std::vector<bool> doesn't have it. libstdc++-v3/ChangeLog: * include/debug/vector (vector::assign_range): Use change in capacity to detect reallocation. (vector::insert_range, vector::append_range): Likewise. Remove unused variables. Reviewed-by: Tomasz KamiƄski <tkaminsk@redhat.com>
-rw-r--r--libstdc++-v3/include/debug/vector14
1 files changed, 6 insertions, 8 deletions
diff --git a/libstdc++-v3/include/debug/vector b/libstdc++-v3/include/debug/vector
index 022ebe8..b49766c 100644
--- a/libstdc++-v3/include/debug/vector
+++ b/libstdc++-v3/include/debug/vector
@@ -876,12 +876,12 @@ namespace __debug
constexpr void
assign_range(_Rg&& __rg)
{
- auto __old_begin = _Base::begin();
+ auto __old_capacity = _Base::capacity();
auto __old_size = _Base::size();
_Base::assign_range(__rg);
if (!std::__is_constant_evaluated())
{
- if (_Base::begin() != __old_begin)
+ if (_Base::capacity() != __old_capacity)
this->_M_invalidate_all();
else if (_Base::size() < __old_size)
this->_M_invalidate_after_nth(_Base::size());
@@ -893,12 +893,11 @@ namespace __debug
constexpr iterator
insert_range(const_iterator __pos, _Rg&& __rg)
{
- auto __old_begin = _Base::begin();
- auto __old_size = _Base::size();
+ auto __old_capacity = _Base::capacity();
auto __res = _Base::insert_range(__pos.base(), __rg);
if (!std::__is_constant_evaluated())
{
- if (_Base::begin() != __old_begin)
+ if (_Base::capacity() != __old_capacity)
this->_M_invalidate_all();
this->_M_update_guaranteed_capacity();
}
@@ -909,12 +908,11 @@ namespace __debug
constexpr void
append_range(_Rg&& __rg)
{
- auto __old_begin = _Base::begin();
- auto __old_size = _Base::size();
+ auto __old_capacity = _Base::capacity();
_Base::append_range(__rg);
if (!std::__is_constant_evaluated())
{
- if (_Base::begin() != __old_begin)
+ if (_Base::capacity() != __old_capacity)
this->_M_invalidate_all();
this->_M_update_guaranteed_capacity();
}