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

--- Comment #7 from Jan Hubicka <hubicka at gcc dot gnu.org> ---
Thanks for explanation.  I think it is quite common pattern that new object is
construted and worked on and later returned, so I think we ought to handle this
correctly.

Another example just came up in
https://gcc.gnu.org/pipermail/gcc-patches/2023-November/637878.html

We should gnerate same code for the following two functions:

#include <vector>

auto
f()
{
  std::vector<int> x;
  x.reserve(10);
  for (int i = 0; i < 10; ++i)
    x.push_back(0);
  return x;
}

auto
g()
{ return std::vector<int>(10, 0); }


but we don't since we lose track of values stored in x after every call to new.

Reply via email to