public inbox for libstdc++-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc r13-5661] libstdc++: Use emplace in std::variant::operator=(T&&) as per LWG 3585
@ 2023-02-02 16:47 Jonathan Wakely
0 siblings, 0 replies; only message in thread
From: Jonathan Wakely @ 2023-02-02 16:47 UTC (permalink / raw)
To: gcc-cvs, libstdc++-cvs
https://gcc.gnu.org/g:1395415fdc2d60e5346dbcf476749daf42d5b724
commit r13-5661-g1395415fdc2d60e5346dbcf476749daf42d5b724
Author: Jonathan Wakely <jwakely@redhat.com>
Date: Wed Feb 1 20:54:22 2023 +0000
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.
Diff:
---
libstdc++-v3/include/std/variant | 4 +++-
libstdc++-v3/testsuite/20_util/variant/lwg3585.cc | 16 ++++++++++++++++
2 files changed, 19 insertions(+), 1 deletion(-)
diff --git a/libstdc++-v3/include/std/variant b/libstdc++-v3/include/std/variant
index 35781495e31..5155124522f 100644
--- a/libstdc++-v3/include/std/variant
+++ b/libstdc++-v3/include/std/variant
@@ -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;
}
diff --git a/libstdc++-v3/testsuite/20_util/variant/lwg3585.cc b/libstdc++-v3/testsuite/20_util/variant/lwg3585.cc
new file mode 100644
index 00000000000..0cbfc0db7f5
--- /dev/null
+++ b/libstdc++-v3/testsuite/20_util/variant/lwg3585.cc
@@ -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";
+}
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2023-02-02 16:47 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-02-02 16:47 [gcc r13-5661] libstdc++: Use emplace in std::variant::operator=(T&&) as per LWG 3585 Jonathan Wakely
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).