public inbox for libstdc++-cvs@sourceware.org
help / color / mirror / Atom feed
From: Jonathan Wakely <redi@gcc.gnu.org>
To: gcc-cvs@gcc.gnu.org, libstdc++-cvs@gcc.gnu.org
Subject: [gcc r10-9915] libstdc++: Fix constraint on std::optional assignment [PR 100982]
Date: Mon, 14 Jun 2021 18:52:09 +0000 (GMT)	[thread overview]
Message-ID: <20210614185209.80A23395BC24@sourceware.org> (raw)

https://gcc.gnu.org/g:37864c5e6aa6befc17051f162c02d4f593a57e57

commit r10-9915-g37864c5e6aa6befc17051f162c02d4f593a57e57
Author: Jonathan Wakely <jwakely@redhat.com>
Date:   Wed Jun 9 11:03:15 2021 +0100

    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.
    
    (cherry picked from commit b3fce1bd45f72cc9e55fb7431762e92e30fefcf1)

Diff:
---
 libstdc++-v3/include/std/optional                       |  2 +-
 .../testsuite/20_util/optional/assignment/100982.cc     | 17 +++++++++++++++++
 2 files changed, 18 insertions(+), 1 deletion(-)

diff --git a/libstdc++-v3/include/std/optional b/libstdc++-v3/include/std/optional
index d473b5369be..e3fbe625f25 100644
--- a/libstdc++-v3/include/std/optional
+++ b/libstdc++-v3/include/std/optional
@@ -798,7 +798,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
+}


                 reply	other threads:[~2021-06-14 18:52 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210614185209.80A23395BC24@sourceware.org \
    --to=redi@gcc.gnu.org \
    --cc=gcc-cvs@gcc.gnu.org \
    --cc=libstdc++-cvs@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).