https://gcc.gnu.org/bugzilla/show_bug.cgi?id=116332

Frank Heckenbach <f.heckenb...@fh-soft.de> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |f.heckenb...@fh-soft.de

--- Comment #3 from Frank Heckenbach <f.heckenb...@fh-soft.de> ---
It's not only std::regex. This strange code gives a bogus warning, too, but
only under very peculiar circumstances (e.g. c must have ", 0", d must not, a
must be there, as well as the loop etc.).

(I hope that's the same problem, or should I file a separate bug report?)

% cat test.cpp
#include <vector>

void f (int m = 0)
{
  std::vector <int> a (m), b;
  do
    {
      b.push_back (0);
      std::vector <int> c (m, 0);
      std::vector <int> d (m);
    }
  while (m);
}

int main ()
{
  f ();
}
% g++-14 -O2 -Walloc-zero test.cpp
In file included from
/usr/include/x86_64-linux-gnu/c++/14/bits/c++allocator.h:33,
                 from /usr/include/c++/14/bits/allocator.h:46,
                 from /usr/include/c++/14/vector:63,
                 from test.cpp:1:
In member function ‘_Tp* std::__new_allocator<_Tp>::allocate(size_type, const
void*) [with _Tp = int]’,
    inlined from ‘static _Tp* std::allocator_traits<std::allocator<_Tp1>
>::allocate(allocator_type&, size_type) [with _Tp = int]’ at
/usr/include/c++/14/bits/alloc_traits.h:515:28,
    inlined from ‘std::_Vector_base<_Tp, _Alloc>::pointer
std::_Vector_base<_Tp, _Alloc>::_M_allocate(std::size_t) [with _Tp = int;
_Alloc = std::allocator<int>]’ at /usr/include/c++/14/bits/stl_vector.h:380:33,
    inlined from ‘void std::_Vector_base<_Tp,
_Alloc>::_M_create_storage(std::size_t) [with _Tp = int; _Alloc =
std::allocator<int>]’ at /usr/include/c++/14/bits/stl_vector.h:398:44,
    inlined from ‘std::_Vector_base<_Tp, _Alloc>::_Vector_base(std::size_t,
const allocator_type&) [with _Tp = int; _Alloc = std::allocator<int>]’ at
/usr/include/c++/14/bits/stl_vector.h:334:26,
    inlined from ‘std::vector<_Tp, _Alloc>::vector(size_type, const
allocator_type&) [with _Tp = int; _Alloc = std::allocator<int>]’ at
/usr/include/c++/14/bits/stl_vector.h:557:47,
    inlined from ‘void f(int)’ at test.cpp:10:29:
/usr/include/c++/14/bits/new_allocator.h:151:55: warning: argument 1 value is
zero [-Walloc-zero]
  151 |         return static_cast<_Tp*>(_GLIBCXX_OPERATOR_NEW(__n *
sizeof(_Tp)));
      |                                                       ^
In file included from /usr/include/c++/14/bits/new_allocator.h:34:
/usr/include/c++/14/new: In function ‘void f(int)’:
/usr/include/c++/14/new:131:26: note: in a call to allocation function ‘void*
operator new(std::size_t)’ declared here
  131 | _GLIBCXX_NODISCARD void* operator new(std::size_t) _GLIBCXX_THROW
(std::bad_alloc)
      |                          ^~~~~~~~

Reply via email to