public inbox for libstdc++@gcc.gnu.org
 help / color / mirror / Atom feed
From: Jonathan Wakely <jwakely@redhat.com>
To: libstdc++@gcc.gnu.org, gcc-patches@gcc.gnu.org
Subject: [committed 3/3] libstdc++: Fix constraints on std::expected<void, E> constructor [PR105153]
Date: Fri,  8 Apr 2022 18:38:06 +0100	[thread overview]
Message-ID: <20220408173806.336422-3-jwakely@redhat.com> (raw)
In-Reply-To: <20220408173806.336422-1-jwakely@redhat.com>

Tested x86_64-linux, pushed to trunk.

-- >8 --

libstdc++-v3/ChangeLog:

	PR libstdc++/105153
	* include/std/expected
	(expected<void,E>::expected(expected<U,G>&&)): Fix constraints.
	* testsuite/20_util/expected/cons.cc: Check constructor.
---
 libstdc++-v3/include/std/expected              |  4 ++--
 .../testsuite/20_util/expected/cons.cc         | 18 ++++++++++++++++++
 2 files changed, 20 insertions(+), 2 deletions(-)

diff --git a/libstdc++-v3/include/std/expected b/libstdc++-v3/include/std/expected
index 1864e866ed0..3446d6dbaed 100644
--- a/libstdc++-v3/include/std/expected
+++ b/libstdc++-v3/include/std/expected
@@ -966,8 +966,8 @@ namespace __expected
 	}
 
       template<typename _Up, typename _Gr>
-	requires is_void_v<_Tp>
-	      && is_constructible_v<_Er, const _Gr&>
+	requires is_void_v<_Up>
+	      && is_constructible_v<_Er, _Gr>
 	      && (!__cons_from_expected<_Up, _Gr>)
 	constexpr explicit(!is_convertible_v<_Gr, _Er>)
 	expected(expected<_Up, _Gr>&& __x)
diff --git a/libstdc++-v3/testsuite/20_util/expected/cons.cc b/libstdc++-v3/testsuite/20_util/expected/cons.cc
index 1fe5b7bf4d1..6946858198c 100644
--- a/libstdc++-v3/testsuite/20_util/expected/cons.cc
+++ b/libstdc++-v3/testsuite/20_util/expected/cons.cc
@@ -162,6 +162,22 @@ test_copy()
   return true;
 }
 
+constexpr bool
+test_pr105153()
+{
+  struct E {
+    E(int&&) = delete;
+    E(const int&);
+  };
+
+  std::expected<void, E> e(std::expected<void, int>{});
+
+  static_assert( ! std::is_constructible_v<std::expected<void, int>,
+					   std::expected<int, int>> );
+
+  return true;
+}
+
 int main()
 {
   test_default();
@@ -172,4 +188,6 @@ int main()
   static_assert( test_err() );
   test_copy();
   static_assert( test_copy() );
+  test_pr105153();
+  static_assert( test_pr105153() );
 }
-- 
2.34.1


      parent reply	other threads:[~2022-04-08 17:38 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-04-08 17:38 [committed 1/3] libstdc++: Fix std::bad_expected_access constructor [PR105146] Jonathan Wakely
2022-04-08 17:38 ` [committed 2/3] libstdc++: Fix std::expected<void, E>::swap(expected&) [PR105154] Jonathan Wakely
2022-04-08 17:38 ` Jonathan Wakely [this message]

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=20220408173806.336422-3-jwakely@redhat.com \
    --to=jwakely@redhat.com \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=libstdc++@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).