Commit 41501d1a by Tim Shen Committed by Tim Shen

re PR libstdc++/77641 (std::variant copy-initialization fails for type with…

re PR libstdc++/77641 (std::variant copy-initialization fails for type with non-trivial constexpr ctor)

	PR libstdc++/77641
	* include/std/variant (_Variant_storage::_Variant_storage):
	Change _Variant_storage's union to be default constructible.
	* testsuite/20_util/variant/compile.cc: New test.

From-SVN: r240340
parent 77d7987a
2016-09-22 Tim Shen <timshen@google.com>
PR libstdc++/77641
* include/std/variant (_Variant_storage::_Variant_storage):
Change _Variant_storage's union to be default constructible.
* testsuite/20_util/variant/compile.cc: New test.
2016-09-21 Ville Voutilainen <ville.voutilainen@gmail.com>
PR libstdc++/77288
......
......@@ -296,15 +296,9 @@ namespace __variant
{
constexpr _Variant_storage() = default;
template<typename... _Args>
constexpr _Variant_storage(in_place_index_t<0>, _Args&&... __args)
: _M_first(in_place<0>, forward<_Args>(__args)...)
{ }
template<size_t _Np, typename... _Args,
typename = enable_if_t<0 < _Np && _Np < sizeof...(_Rest) + 1>>
template<size_t _Np, typename... _Args>
constexpr _Variant_storage(in_place_index_t<_Np>, _Args&&... __args)
: _M_rest(in_place<_Np - 1>, forward<_Args>(__args)...)
: _M_union(in_place<_Np>, forward<_Args>(__args)...)
{ }
~_Variant_storage() = default;
......@@ -313,14 +307,27 @@ namespace __variant
_M_storage() const
{
return const_cast<void*>(
static_cast<const void*>(std::addressof(_M_first._M_storage)));
static_cast<const void*>(std::addressof(_M_union._M_first._M_storage)));
}
union
union _Union
{
constexpr _Union() {};
template<typename... _Args>
constexpr _Union(in_place_index_t<0>, _Args&&... __args)
: _M_first(in_place<0>, forward<_Args>(__args)...)
{ }
template<size_t _Np, typename... _Args,
typename = enable_if_t<0 < _Np && _Np < sizeof...(_Rest) + 1>>
constexpr _Union(in_place_index_t<_Np>, _Args&&... __args)
: _M_rest(in_place<_Np - 1>, forward<_Args>(__args)...)
{ }
_Uninitialized<__storage<_First>> _M_first;
_Variant_storage<_Rest...> _M_rest;
};
} _M_union;
};
template<typename _Derived, bool __is_trivially_destructible>
......
......@@ -403,3 +403,12 @@ void test_void()
v = 3;
v = "asdf";
}
void test_pr77641()
{
struct X {
constexpr X() { }
};
constexpr std::variant<X> v1 = X{};
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment