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.
Showing
- libstdc++-v3/include/bits/stl_bvector.h 2 additions, 1 deletionlibstdc++-v3/include/bits/stl_bvector.h
- libstdc++-v3/include/bits/vector.tcc 3 additions, 2 deletionslibstdc++-v3/include/bits/vector.tcc
- libstdc++-v3/testsuite/23_containers/vector/bool/110807.cc 14 additions, 0 deletionslibstdc++-v3/testsuite/23_containers/vector/bool/110807.cc
Loading
Please register or sign in to comment