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
This commit is contained in:
Tim Shen 2016-09-22 08:45:55 +00:00 committed by Tim Shen
parent a8de3002f1
commit c42bc5d73b
3 changed files with 13 additions and 2 deletions

View File

@ -1,3 +1,9 @@
2016-09-22 Tim Shen <timshen@google.com>
* 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 <timshen@google.com>
PR libstdc++/77641

View File

@ -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));

View File

@ -169,6 +169,12 @@ void copy_assign()
variant<DefaultNoexcept> a;
static_assert(!noexcept(a = a), "");
}
{
float f1 = 1.0f, f2 = 2.0f;
std::variant<float&> v1(f1);
v1 = f2;
}
}
void move_assign()