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

--- Comment #2 from Jonathan Wakely <redi at gcc dot gnu.org> ---
The aggregate copy is intended, because std::optional<T> must have a trivial
copy constructor if T has a trivial copy constructor.

There should be no uninitialized value, because the std::optional<T>'s storage
member has a  default constructor that inits the first member of the union (an
empty struct):

      struct _Empty_byte { };

      template<typename _Up, bool = is_trivially_destructible_v<_Up>>
        union _Storage
        {
          constexpr _Storage() noexcept : _M_empty() { }

          // ...

          _Empty_byte _M_empty;
          _Up _M_value;
        };

The compiler seems to be eliding the _M_empty() initialization, because
_M_empty has no value bits, it's all padding.

Reply via email to