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 2/3] libstdc++: Fix std::expected<void, E>::swap(expected&) [PR105154]
Date: Fri,  8 Apr 2022 18:38:05 +0100	[thread overview]
Message-ID: <20220408173806.336422-2-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++/105154
	* include/std/expected (expected<void, E>::swap): Set
	_M_has_value to false for objects that previously had a value.
	* testsuite/20_util/expected/swap.cc: Fix test to check void
	specialization.
---
 libstdc++-v3/include/std/expected               |  2 ++
 libstdc++-v3/testsuite/20_util/expected/swap.cc | 12 ++++++------
 2 files changed, 8 insertions(+), 6 deletions(-)

diff --git a/libstdc++-v3/include/std/expected b/libstdc++-v3/include/std/expected
index 7b01a17fb57..1864e866ed0 100644
--- a/libstdc++-v3/include/std/expected
+++ b/libstdc++-v3/include/std/expected
@@ -1104,6 +1104,7 @@ namespace __expected
 		std::construct_at(__builtin_addressof(_M_unex),
 				  std::move(__x._M_unex)); // might throw
 		std::destroy_at(__builtin_addressof(__x._M_unex));
+		_M_has_value = false;
 		__x._M_has_value = true;
 	      }
 	  }
@@ -1115,6 +1116,7 @@ namespace __expected
 				  std::move(_M_unex)); // might throw
 		std::destroy_at(__builtin_addressof(_M_unex));
 		_M_has_value = true;
+		__x._M_has_value = false;
 	      }
 	    else
 	      {
diff --git a/libstdc++-v3/testsuite/20_util/expected/swap.cc b/libstdc++-v3/testsuite/20_util/expected/swap.cc
index 1b3b8c5f4e8..745db65fc6c 100644
--- a/libstdc++-v3/testsuite/20_util/expected/swap.cc
+++ b/libstdc++-v3/testsuite/20_util/expected/swap.cc
@@ -27,19 +27,19 @@ test_swap()
   VERIFY( e3.error() == 4 );
   VERIFY( e4.error() == 3 );
 
-  std::expected<int, int> v1(1), v2(2);
-  std::expected<int, int> v3(std::unexpect, 3), v4(std::unexpect, 4);
+  std::expected<void, int> v1, v2;
+  std::expected<void, int> v3(std::unexpect, 3), v4(std::unexpect, 4);
 
   swap(v1, v2);
-  VERIFY( v1.value() == 2 );
-  VERIFY( v2.value() == 1 );
+  VERIFY( v1.has_value() );
+  VERIFY( v2.has_value() );
   swap(v1, v3);
   VERIFY( ! v1.has_value() );
   VERIFY( v1.error() == 3 );
-  VERIFY( v3.value() == 2 );
+  VERIFY( v3.has_value() );
   swap(v1, v3);
   VERIFY( ! v3.has_value() );
-  VERIFY( v1.value() == 2 );
+  VERIFY( v1.has_value() );
   VERIFY( v3.error() == 3 );
   swap(v3, v4);
   VERIFY( ! v3.has_value() );
-- 
2.34.1


  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 ` Jonathan Wakely [this message]
2022-04-08 17:38 ` [committed 3/3] libstdc++: Fix constraints on std::expected<void, E> constructor [PR105153] Jonathan Wakely

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-2-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).