[Bug tree-optimization/110536] [12/13/14 regression] Bogus -Wstringop-overflow warning in std::transform
redi at gcc dot gnu.org
gcc-bugzilla@gcc.gnu.org
Fri Mar 28 23:50:41 GMT 2025
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110536
Jonathan Wakely <redi at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Ever confirmed|0 |1
Last reconfirmed| |2025-03-28
Status|UNCONFIRMED |NEW
--- Comment #2 from Jonathan Wakely <redi at gcc dot gnu.org> ---
(In reply to Eric Niebler from comment #0)
> Compile the following with -O3 -std=c++17 -Wall
>
> <<<<<<BEGIN
>
> #include <algorithm>
> #include <cstdint>
> #include <vector>
>
> template <typename TypeParam, typename T>
> std::vector<TypeParam>
> make_type_param_vector(std::initializer_list<T> const& init_list) {
> // std::vector<T> input{init_list}; //uncomment to remove warning
> std::vector<TypeParam> vec(init_list.size());
GCC is unable to tell that vec.size() == init_list.size() after this
constructor and so it's worried that vec.begin() might not point to anything.
Adding this makes the warnings go away:
std::vector<TypeParam> vec(init_list.size());
if (vec.size() != init_list.size())
__builtin_unreachable();
> std::transform(std::cbegin(init_list), std::cend(init_list),
> std::begin(vec), [](auto const& e) {
I tried adding if (size() != __l.size()) __builtin_unreachable() as the last
line of the vector(initializer_list<T>) constructor but it didn't help.
More information about the Gcc-bugs
mailing list