public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [committed] libstdc++: Use emplace in std::variant::operator=(T&&) as per LWG 3585
@ 2023-02-02 16:48 Jonathan Wakely
  0 siblings, 0 replies; only message in thread
From: Jonathan Wakely @ 2023-02-02 16:48 UTC (permalink / raw)
  To: libstdc++, gcc-patches

Tested powerpc64le-linux. Pushed to trunk.

-- >8 --

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.
---
 libstdc++-v3/include/std/variant                 |  4 +++-
 .../testsuite/20_util/variant/lwg3585.cc         | 16 ++++++++++++++++
 2 files changed, 19 insertions(+), 1 deletion(-)
 create mode 100644 libstdc++-v3/testsuite/20_util/variant/lwg3585.cc

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";
+}
-- 
2.39.1


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2023-02-02 16:48 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:48 [committed] 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).