]> git.ipfire.org Git - thirdparty/gcc.git/commit
libstdc++: Fix -Wstringop-overread warning in std::vector<bool> [PR114758]
authorJonathan Wakely <jwakely@redhat.com>
Fri, 28 Mar 2025 15:41:41 +0000 (15:41 +0000)
committerJonathan Wakely <redi@gcc.gnu.org>
Mon, 31 Mar 2025 21:54:08 +0000 (22:54 +0100)
commit1f6c19f307c8de9830130a0ba071c24e3835beb3
tree233dcc42a959fc29954869c8dacd83f316750ddc
parent97cbe3cd5f36470884e940bda4469dc9b5b93cfd
libstdc++: Fix -Wstringop-overread warning in std::vector<bool> [PR114758]

As in r13-4393-gcca06f0d6d76b0 and a few other commits, we can avoid
bogus warnings in std::vector<bool> by hoisting some loads to before the
allocation that calls operator new. This means that the compiler has
enough info to remove the dead branches that trigger bogus warnings.

On trunk this is only needed with -fno-assume-sane-operators-new-delete
but it will help on the branches where that option doesn't exist.

libstdc++-v3/ChangeLog:

PR libstdc++/114758
* include/bits/vector.tcc (vector<bool, A>::_M_fill_insert):
Hoist loads of begin() and end() before allocation.
* testsuite/23_containers/vector/bool/capacity/114758.cc: New
test.

Reviewed-by: Tomasz KamiƄski <tkaminsk@redhat.com>
libstdc++-v3/include/bits/vector.tcc
libstdc++-v3/testsuite/23_containers/vector/bool/capacity/114758.cc [new file with mode: 0644]