https://gcc.gnu.org/bugzilla/show_bug.cgi?id=77641
Bug ID: 77641 Summary: std::variant copy-initialization fails for non-trivial literal type Product: gcc Version: 7.0 Status: UNCONFIRMED Keywords: rejects-valid Severity: normal Priority: P3 Component: libstdc++ Assignee: unassigned at gcc dot gnu.org Reporter: redi at gcc dot gnu.org CC: timshen at gcc dot gnu.org Target Milestone: --- #include <variant> struct X { constexpr X() { } }; int main() { std::variant<X> v1 = X{}; } In file included from v.cc:1:0: /home/jwakely/gcc/7/include/c++/7.0.0/variant: In instantiation of ‘std::__detail::__variant::_Variant_base<_Types>::_Variant_base(std::__detail::__variant::_Variant_base<_Types>&&) [with _Types = {X}]’: /home/jwakely/gcc/7/include/c++/7.0.0/variant:995:7: required from here /home/jwakely/gcc/7/include/c++/7.0.0/variant:369:44: error: use of deleted function ‘std::__detail::__variant::_Variant_storage<_First, _Rest ...>::_Variant_storage() [with _First = X; _Rest = {}]’ : _Storage(), _M_index(__rhs._M_index) ^ /home/jwakely/gcc/7/include/c++/7.0.0/variant:297:17: note: ‘std::__detail::__variant::_Variant_storage<_First, _Rest ...>::_Variant_storage() [with _First = X; _Rest = {}]’ is implicitly deleted because the default definition would be ill-formed: constexpr _Variant_storage() = default; ^~~~~~~~~~~~~~~~ /home/jwakely/gcc/7/include/c++/7.0.0/variant:321:36: error: union member ‘std::__detail::__variant::_Variant_storage<X>::<unnamed union>::_M_first’ with non-trivial ‘constexpr std::__detail::__variant::_Uninitialized<_Type, true>::_Uninitialized() [with _Type = X]’ _Uninitialized<__storage<_First>> _M_first; ^~~~~~~~ /home/jwakely/gcc/7/include/c++/7.0.0/variant: In instantiation of ‘constexpr void std::__detail::__variant::__erased_ctor(void*, void*) [with _Lhs = X&; _Rhs = X&&]’: /home/jwakely/gcc/7/include/c++/7.0.0/variant:373:30: required from ‘std::__detail::__variant::_Variant_base<_Types>::_Variant_base(std::__detail::__variant::_Variant_base<_Types>&&) [with _Types = {X}]’ /home/jwakely/gcc/7/include/c++/7.0.0/variant:995:7: required from here /home/jwakely/gcc/7/include/c++/7.0.0/variant:239:58: error: use of ‘decltype(auto) std::__detail::__variant::__get_alternative(void*) [with _Qualified_storage = X&&]’ before deduction of ‘auto’ { ::new (__lhs) decay_t<_Lhs>(__get_alternative<_Rhs>(__rhs)); } ~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~