]> git.ipfire.org Git - thirdparty/gcc.git/commit
libstdc++: Avoid bogus overflow warnings in std::vector<bool> [PR110807]
authorJonathan Wakely <jwakely@redhat.com>
Wed, 26 Jul 2023 13:09:24 +0000 (14:09 +0100)
committerJonathan Wakely <jwakely@redhat.com>
Wed, 26 Jul 2023 16:02:46 +0000 (17:02 +0100)
commit7931a1de9ec87b996d51d3d60786f5c81f63919f
treed7f6894dad6e32f22f03dbb82d4abe6b595f98c2
parentc01b344e814001e07fd304ce98d013d811e90192
libstdc++: Avoid bogus overflow warnings in std::vector<bool> [PR110807]

GCC thinks the allocation can alter the object being copied if it's
globally reachable, so doesn't realize that [x.begin(), x.end()) after
the allocation is the same as x.size() before it.

This causes a testsuite failure when testing with -D_GLIBCXX_DEBUG:
FAIL: 23_containers/vector/bool/swap.cc (test for excess errors)
A fix is to move the calls to x.begin() and x.end() to before the
allocation.

A similar problem exists in vector<bool>::_M_insert_range where *this is
globally reachable, as reported in PR libstdc++/110807. That can also be
fixed by moving calls to begin() and end() before the allocation.

libstdc++-v3/ChangeLog:

PR libstdc++/110807
* include/bits/stl_bvector.h (vector(const vector&)): Access
iterators before allocating.
* include/bits/vector.tcc (vector<bool>::_M_insert_range):
Likewise.
* testsuite/23_containers/vector/bool/110807.cc: New test.
libstdc++-v3/include/bits/stl_bvector.h
libstdc++-v3/include/bits/vector.tcc
libstdc++-v3/testsuite/23_containers/vector/bool/110807.cc [new file with mode: 0644]