diff options
author | Ville Voutilainen <ville.voutilainen@gmail.com> | 2019-03-26 14:07:26 +0200 |
---|---|---|
committer | Ville Voutilainen <ville@gcc.gnu.org> | 2019-03-26 14:07:26 +0200 |
commit | 8be4d02ba9f6e6e309dee3d2fa599d806a0d1ef6 (patch) | |
tree | d2e051624b926ab4e08cb70597ba754f8f6ca337 | |
parent | f30d4934a90a6121674d882d391dc09d8fce190c (diff) | |
download | gcc-8be4d02ba9f6e6e309dee3d2fa599d806a0d1ef6.zip gcc-8be4d02ba9f6e6e309dee3d2fa599d806a0d1ef6.tar.gz gcc-8be4d02ba9f6e6e309dee3d2fa599d806a0d1ef6.tar.bz2 |
re PR libstdc++/89816 (std::variant move construction regressed since GCC 8.3)
PR libstdc++/89816
Fix based on a suggestion by Antony Polukhin.
* include/std/variant (__variant_construct): Capture a pointer
to the storage and visit just one variant.
From-SVN: r269940
-rw-r--r-- | libstdc++-v3/ChangeLog | 7 | ||||
-rw-r--r-- | libstdc++-v3/include/std/variant | 10 |
2 files changed, 12 insertions, 5 deletions
diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog index 061ec7f..91d8dbc 100644 --- a/libstdc++-v3/ChangeLog +++ b/libstdc++-v3/ChangeLog @@ -1,3 +1,10 @@ +2019-03-26 Ville Voutilainen <ville.voutilainen@gmail.com> + + PR libstdc++/89816 + Fix based on a suggestion by Antony Polukhin. + * include/std/variant (__variant_construct): Capture a pointer + to the storage and visit just one variant. + 2019-03-22 Jonathan Wakely <jwakely@redhat.com> * doc/xml/manual/backwards_compatibility.xml: Remove link to diff --git a/libstdc++-v3/include/std/variant b/libstdc++-v3/include/std/variant index a5b8fa8..0984e13 100644 --- a/libstdc++-v3/include/std/variant +++ b/libstdc++-v3/include/std/variant @@ -426,18 +426,18 @@ namespace __variant void __variant_construct(_Tp&& __lhs, _Up&& __rhs) { __lhs._M_index = __rhs._M_index; - __do_visit([](auto&& __this_mem, auto&& __rhs_mem) mutable + void* __storage = std::addressof(__lhs._M_u); + __do_visit([__storage](auto&& __rhs_mem) mutable -> __detail::__variant::__variant_cookie { - using _Type = remove_reference_t<decltype(__this_mem)>; + using _Type = remove_reference_t<decltype(__rhs_mem)>; if constexpr (is_same_v<__remove_cvref_t<decltype(__rhs_mem)>, remove_cv_t<_Type>> && !is_same_v<_Type, __variant_cookie>) - ::new ((void*)std::addressof(__this_mem)) + ::new (__storage) _Type(std::forward<decltype(__rhs_mem)>(__rhs_mem)); return {}; - }, __variant_cast<_Types...>(__lhs), - __variant_cast<_Types...>(std::forward<decltype(__rhs)>(__rhs))); + }, __variant_cast<_Types...>(std::forward<decltype(__rhs)>(__rhs))); } // The following are (Copy|Move) (ctor|assign) layers for forwarding |