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

Andrew Pinski <pinskia at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
         Resolution|---                         |INVALID
             Status|UNCONFIRMED                 |RESOLVED

--- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
  D.198035 = f (); [return slot optimization]
  v.m_lhs = &D.198035;
  MEM[(struct CwiseNullaryOp *)&v + 8B] ={v} {CLOBBER(bob)};
  MEM[(struct scalar_constant_op *)&v + 12B] ={v} {CLOBBER(bob)};
  MEM[(struct scalar_constant_op *)&v + 12B].m_other = 0.0;
  D.198035 ={v} {CLOBBER(eos)};
  _6 = &MEM[(struct Matrix *)_4(D)].D.198029;
  _12 = v.m_lhs;




  auto v = Eigen::Product(f(), Eigen::Vector2f::Zero());

The bug is there is a temporary created for the return value of f but that is
destoried at the end of the full statement but the product does not happen
until afterwards in the use of v happens.

Rewriting the code like:
```
        auto t = f();
  auto v = Eigen::Product(t, Eigen::Vector2f::Zero());
```

Fixes the code.

Reply via email to