From: Tim Shen Date: Thu, 22 Sep 2016 08:45:55 +0000 (+0000) Subject: variant (variant::operator=): Fix assignment on references. X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=c42bc5d73bcfa5c631a4da35830a710a11d507b7;p=gcc.git variant (variant::operator=): Fix assignment on references. * libstdc++-v3/include/std/variant (variant::operator=): Fix assignment on references. * libstdc++-v3/testsuite/20_util/variant/compile.cc: Add test. From-SVN: r240343 --- diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog index 0de2044de14..ff984c37f0e 100644 --- a/libstdc++-v3/ChangeLog +++ b/libstdc++-v3/ChangeLog @@ -1,3 +1,9 @@ +2016-09-22 Tim Shen + + * libstdc++-v3/include/std/variant (variant::operator=): Fix assignment + on references. + * libstdc++-v3/testsuite/20_util/variant/compile.cc: Add test. + 2016-09-22 Tim Shen PR libstdc++/77641 diff --git a/libstdc++-v3/include/std/variant b/libstdc++-v3/include/std/variant index 013884bb23e..1ad33fc5da0 100644 --- a/libstdc++-v3/include/std/variant +++ b/libstdc++-v3/include/std/variant @@ -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) = std::forward<_Tp>(__rhs); else this->emplace<__index>(forward<_Tp>(__rhs)); __glibcxx_assert(holds_alternative<__accepted_type<_Tp&&>>(*this)); diff --git a/libstdc++-v3/testsuite/20_util/variant/compile.cc b/libstdc++-v3/testsuite/20_util/variant/compile.cc index 99f980a72db..a0a8d70ce87 100644 --- a/libstdc++-v3/testsuite/20_util/variant/compile.cc +++ b/libstdc++-v3/testsuite/20_util/variant/compile.cc @@ -169,6 +169,12 @@ void copy_assign() variant a; static_assert(!noexcept(a = a), ""); } + + { + float f1 = 1.0f, f2 = 2.0f; + std::variant v1(f1); + v1 = f2; + } } void move_assign()