This is the mail archive of the
libstdc++@gcc.gnu.org
mailing list for the libstdc++ project.
Re: [Patch] Fix variant::operator= on references
- From: Jonathan Wakely <jwakely at redhat dot com>
- To: Tim Shen <timshen at google dot com>
- Cc: libstdc++ <libstdc++ at gcc dot gnu dot org>, gcc-patches <gcc-patches at gcc dot gnu dot org>, Ville Voutilainen <ville dot voutilainen at gmail dot com>
- Date: Thu, 22 Sep 2016 09:39:52 +0100
- Subject: Re: [Patch] Fix variant::operator= on references
- Authentication-results: sourceware.org; auth=none
- References: <CAG4ZjNn3pK3LhyPSRxVT1gzmmbBuCcjnqOtsP3ZOiXJM=eFcew@mail.gmail.com>
On 22/09/16 00:43 -0700, Tim Shen wrote:
Hi, this patch fixes the following compilation failure:
#include <variant>
int main()
{
float f1 = 1.0f, f2 = 2.0f;
std::variant<float&> v1(f1);
v1 = f2; // #1
}
The bug is caused by a misuse of __storage. I also examined other
__storage usage, they all seem appropriate.
@@ -1147,8 +1147,7 @@ namespace __variant
{
constexpr auto __index = __accepted_index<_Tp&&>;
if (index() == __index)
- *static_cast<__storage<__to_type<__index>>*>(this->_M_storage())
- = forward<_Tp>(__rhs);
+ std::get<__index>(*this) = forward<_Tp>(__rhs);
Please qualify std::forward here.
OK for trunk with that change, thanks for the quick fix.