[Bug libstdc++/89816] [9 Regression] std::variant move construction regressed since GCC 8.3

antoshkka at gmail dot com gcc-bugzilla@gcc.gnu.org
Mon Mar 25 15:34:00 GMT 2019


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

--- Comment #6 from Antony Polukhin <antoshkka at gmail dot com> ---
The fix seems pretty trivial: in function `__variant_construct` get the address
of the sorage before entering the `__do_visit` and make it switch only by the
`__rhs`.

Pseudo-code:

  template<typename... _Types, typename _Tp, typename _Up>
    void __variant_construct(_Tp&& __lhs, _Up&& __rhs)
    {
      __lhs._M_index = __rhs._M_index;
      void* storage = std::addressof(__lhs._M_u);
      __do_visit([storage](auto&& __rhs_mem)
                 -> __detail::__variant::__variant_cookie
        {
          using _Type = remove_reference_t<decltype(__rhs_mem)>;
          ::new (storage)
              _Type(std::forward<decltype(__rhs_mem)>(__rhs_mem));
          return {};
        }, __variant_cast<_Types...>(std::forward<decltype(__rhs)>(__rhs)));
  }


More information about the Gcc-bugs mailing list