[Bug tree-optimization/80635] [8/9/10 regression] std::optional and bogus -Wmaybe-uninitialized warning

jason at gcc dot gnu.org gcc-bugzilla@gcc.gnu.org
Mon Jan 6 18:27:00 GMT 2020


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

--- Comment #38 from Jason Merrill <jason at gcc dot gnu.org> ---
(In reply to Jason Merrill from comment #37)
>(because the warning is correct for the over-reduced optional):

This is better:

template<typename T>
struct optional
{
  optional () : m_dummy (), live (false) {}
  void emplace () { new (&m_item) T (); live = true; }
  ~optional () { if (live) m_item.~T (); }

  union
  {
    int m_dummy;
    T m_item;
  };
  bool live;
};


More information about the Gcc-bugs mailing list