public inbox for libstdc++@gcc.gnu.org
 help / color / mirror / Atom feed
* [committed] libstdc++: Fix constraint on std::optional assignment [PR 100982]
@ 2021-06-09 11:45 Jonathan Wakely
  0 siblings, 0 replies; only message in thread
From: Jonathan Wakely @ 2021-06-09 11:45 UTC (permalink / raw)
  To: libstdc++, gcc-patches

[-- Attachment #1: Type: text/plain, Size: 272 bytes --]

libstdc++-v3/ChangeLog:

	PR libstdc++/100982
	* include/std/optional (optional::operator=(const optional<U>&)):
	Fix value category used in is_assignable check.
	* testsuite/20_util/optional/assignment/100982.cc: New test.

Tested powerpc64le-linux. Committed to trunk.


[-- Attachment #2: patch.txt --]
[-- Type: text/plain, Size: 1627 bytes --]

commit b3fce1bd45f72cc9e55fb7431762e92e30fefcf1
Author: Jonathan Wakely <jwakely@redhat.com>
Date:   Wed Jun 9 11:03:15 2021

    libstdc++: Fix constraint on std::optional assignment [PR 100982]
    
    libstdc++-v3/ChangeLog:
    
            PR libstdc++/100982
            * include/std/optional (optional::operator=(const optional<U>&)):
            Fix value category used in is_assignable check.
            * testsuite/20_util/optional/assignment/100982.cc: New test.

diff --git a/libstdc++-v3/include/std/optional b/libstdc++-v3/include/std/optional
index 415f8c49ef4..0a67ce24bbd 100644
--- a/libstdc++-v3/include/std/optional
+++ b/libstdc++-v3/include/std/optional
@@ -815,7 +815,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
       template<typename _Up>
 	enable_if_t<__and_v<__not_<is_same<_Tp, _Up>>,
 			    is_constructible<_Tp, const _Up&>,
-			    is_assignable<_Tp&, _Up>,
+			    is_assignable<_Tp&, const _Up&>,
 			    __not_<__converts_from_optional<_Tp, _Up>>,
 			    __not_<__assigns_from_optional<_Tp, _Up>>>,
 		    optional&>
diff --git a/libstdc++-v3/testsuite/20_util/optional/assignment/100982.cc b/libstdc++-v3/testsuite/20_util/optional/assignment/100982.cc
new file mode 100644
index 00000000000..ae565250d68
--- /dev/null
+++ b/libstdc++-v3/testsuite/20_util/optional/assignment/100982.cc
@@ -0,0 +1,17 @@
+// { dg-do compile { target c++17 } }
+
+#include <optional>
+
+struct U {};
+
+struct T {
+  explicit T(const U&);
+  T& operator=(const U&);
+  T& operator=(U&&) = delete;
+};
+
+int main() {
+  std::optional<U> opt1;
+  std::optional<T> opt2;
+  opt2 = opt1; // PR libstdc++/100982
+}

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

only message in thread, other threads:[~2021-06-09 11:45 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-06-09 11:45 [committed] libstdc++: Fix constraint on std::optional assignment [PR 100982] 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).