libstdc++: Use emplace in std::variant::operator=(T&&) as per LWG 3585
This was approved at the October 2021 plenary. libstdc++-v3/ChangeLog: * include/std/variant (variant::operator=): Implement resolution of LWG 3585. * testsuite/20_util/variant/lwg3585.cc: New test.
This commit is contained in:
parent
f25dd779d4
commit
1395415fdc
2 changed files with 19 additions and 1 deletions
|
@ -1481,7 +1481,9 @@ namespace __variant
|
|||
|| !is_nothrow_move_constructible_v<_Tj>)
|
||||
this->emplace<__index>(std::forward<_Tp>(__rhs));
|
||||
else
|
||||
operator=(variant(std::forward<_Tp>(__rhs)));
|
||||
// _GLIBCXX_RESOLVE_LIB_DEFECTS
|
||||
// 3585. converting assignment with immovable alternative
|
||||
this->emplace<__index>(_Tj(std::forward<_Tp>(__rhs)));
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
|
16
libstdc++-v3/testsuite/20_util/variant/lwg3585.cc
Normal file
16
libstdc++-v3/testsuite/20_util/variant/lwg3585.cc
Normal file
|
@ -0,0 +1,16 @@
|
|||
// { dg-do compile { target c++17 } }
|
||||
|
||||
// LWG 3585. Variant converting assignment with immovable alternative
|
||||
|
||||
#include <variant>
|
||||
#include <string>
|
||||
|
||||
struct A {
|
||||
A() = default;
|
||||
A(A&&) = delete;
|
||||
};
|
||||
|
||||
int main() {
|
||||
std::variant<A, std::string> v;
|
||||
v = "hello";
|
||||
}
|
Loading…
Add table
Reference in a new issue