]> 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>
Wed, 2 Apr 2025 08:55:46 +0000 (09:55 +0100)
commitf0c4ffcd86e50e7758f2408926bc880d3b810895
tree404409024e47ac70d889e0ab9121d0bd0374683a
parent4366711d2d66ea9a2d4fe9dd112795ef0c6f785c
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>
(cherry picked from commit 1f6c19f307c8de9830130a0ba071c24e3835beb3)
libstdc++-v3/include/bits/vector.tcc
libstdc++-v3/testsuite/23_containers/vector/bool/capacity/114758.cc [new file with mode: 0644]