From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by sourceware.org (Postfix) with ESMTPS id B5F5A3858D3C for ; Fri, 8 Apr 2022 17:38:09 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org B5F5A3858D3C Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-451-0xZ2C_yFOlalNaQAimtPEA-1; Fri, 08 Apr 2022 13:38:08 -0400 X-MC-Unique: 0xZ2C_yFOlalNaQAimtPEA-1 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id D527385A5A8; Fri, 8 Apr 2022 17:38:07 +0000 (UTC) Received: from localhost (unknown [10.33.36.25]) by smtp.corp.redhat.com (Postfix) with ESMTP id A0DDB2166BA3; Fri, 8 Apr 2022 17:38:07 +0000 (UTC) From: Jonathan Wakely To: libstdc++@gcc.gnu.org, gcc-patches@gcc.gnu.org Subject: [committed 2/3] libstdc++: Fix std::expected::swap(expected&) [PR105154] Date: Fri, 8 Apr 2022 18:38:05 +0100 Message-Id: <20220408173806.336422-2-jwakely@redhat.com> In-Reply-To: <20220408173806.336422-1-jwakely@redhat.com> References: <20220408173806.336422-1-jwakely@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.78 on 10.11.54.6 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset="US-ASCII"; x-default=true X-Spam-Status: No, score=-12.1 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H4, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_NONE, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on server2.sourceware.org X-BeenThere: libstdc++@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libstdc++ mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 08 Apr 2022 17:38:10 -0000 Tested x86_64-linux, pushed to trunk. -- >8 -- libstdc++-v3/ChangeLog: PR libstdc++/105154 * include/std/expected (expected::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 v1(1), v2(2); - std::expected v3(std::unexpect, 3), v4(std::unexpect, 4); + std::expected v1, v2; + std::expected 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