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.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 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1675356484; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=uZQ0dUK8khvY9rhvfo8mKW5bD2gZUvrozF5m/NuLVuY=; b=i9biqcXfQKLz0cgCQxMLkid0vnhF+OLJooh8C6482gorKARexVWug+V9JbJVBPA+EFfhcA P05J9yyX4i7BTtqwAu6Qh3SJ5oWJ+D+Of66Ac3+YoBjmdtlINL2linBjQcOCE/xMcuYYGG q1W2buF4B2Y6GZE5V4B7HMn/WUHrQMo= 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) From: Jonathan Wakely 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 Content-Type: text/plain Content-Transfer-Encoding: 8bit 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 List-Id: 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"; +} -- 2.39.1