From patchwork Thu Feb 2 16:48:02 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonathan Wakely X-Patchwork-Id: 1736545 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.a=rsa-sha256 header.s=default header.b=PqP5FryG; dkim-atps=neutral Received: from sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4P74VQ5JMBz1yhq for ; Fri, 3 Feb 2023 03:48:28 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 5D36D38582AB for ; Thu, 2 Feb 2023 16:48:26 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 5D36D38582AB DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1675356506; bh=uZQ0dUK8khvY9rhvfo8mKW5bD2gZUvrozF5m/NuLVuY=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=PqP5FryG9nETijEP6Y4JAkPe8kmAXTsmTtFOdUbiMfoq7/6ctvIKnoBtvlZgYyn+K bPo1zrvDl9lWjjZ9GLwk8V0wDClKdYRbQrC6PPzgFcbpwSwdkwIfb/pb85hmIikps0 Db0uXlUcPk4+VwBAZUf5jyN3gyTzaGtyl5oTADVU= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by sourceware.org (Postfix) with ESMTPS id 24A71385843D for ; Thu, 2 Feb 2023 16:48:05 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 24A71385843D Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-454-alr3WiZsP_KLN7F8RONegw-1; Thu, 02 Feb 2023 11:48:03 -0500 X-MC-Unique: alr3WiZsP_KLN7F8RONegw-1 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 461281C189B0; Thu, 2 Feb 2023 16:48:03 +0000 (UTC) Received: from localhost (unknown [10.33.36.186]) by smtp.corp.redhat.com (Postfix) with ESMTP id 0F7AF112132C; Thu, 2 Feb 2023 16:48:02 +0000 (UTC) To: libstdc++@gcc.gnu.org, gcc-patches@gcc.gnu.org Subject: [committed] libstdc++: Use emplace in std::variant::operator=(T&&) as per LWG 3585 Date: Thu, 2 Feb 2023 16:48:02 +0000 Message-Id: <20230202164802.2634934-1-jwakely@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.3 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-11.9 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_NUMSUBJECT, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_NONE, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Jonathan Wakely via Gcc-patches From: Jonathan Wakely Reply-To: Jonathan Wakely Errors-To: gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org Sender: "Gcc-patches" Tested powerpc64le-linux. Pushed to trunk. -- >8 -- This was approved at the October 2021 plenary. libstdc++-v3/ChangeLog: * include/std/variant (variant::operator=): Implement resolution of LWG 3585. * testsuite/20_util/variant/lwg3585.cc: New test. --- libstdc++-v3/include/std/variant | 4 +++- .../testsuite/20_util/variant/lwg3585.cc | 16 ++++++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) create mode 100644 libstdc++-v3/testsuite/20_util/variant/lwg3585.cc diff --git a/libstdc++-v3/include/std/variant b/libstdc++-v3/include/std/variant index 35781495e31..5155124522f 100644 --- a/libstdc++-v3/include/std/variant +++ b/libstdc++-v3/include/std/variant @@ -1481,7 +1481,9 @@ namespace __variant || !is_nothrow_move_constructible_v<_Tj>) this->emplace<__index>(std::forward<_Tp>(__rhs)); else - operator=(variant(std::forward<_Tp>(__rhs))); + // _GLIBCXX_RESOLVE_LIB_DEFECTS + // 3585. converting assignment with immovable alternative + this->emplace<__index>(_Tj(std::forward<_Tp>(__rhs))); } return *this; } diff --git a/libstdc++-v3/testsuite/20_util/variant/lwg3585.cc b/libstdc++-v3/testsuite/20_util/variant/lwg3585.cc new file mode 100644 index 00000000000..0cbfc0db7f5 --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/variant/lwg3585.cc @@ -0,0 +1,16 @@ +// { dg-do compile { target c++17 } } + +// LWG 3585. Variant converting assignment with immovable alternative + +#include +#include + +struct A { + A() = default; + A(A&&) = delete; +}; + +int main() { + std::variant v; + v = "hello"; +}