From patchwork Sun Sep 15 15:23:34 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonathan Wakely X-Patchwork-Id: 1985878 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=HiAbTAL8; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=8.43.85.97; helo=server2.sourceware.org; envelope-from=gcc-patches-bounces~incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=patchwork.ozlabs.org) Received: from server2.sourceware.org (server2.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4X6BgP2PZ9z1y1T for ; Mon, 16 Sep 2024 01:25:02 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id D7345385C6C3 for ; Sun, 15 Sep 2024 15:25:00 +0000 (GMT) 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.129.124]) by sourceware.org (Postfix) with ESMTP id D51E33858D20 for ; Sun, 15 Sep 2024 15:24:37 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org D51E33858D20 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org D51E33858D20 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1726413879; cv=none; b=fM3xALn2Cj4PyaEEYndmMEMAkM+BP0dDCbSEID9841pLQacDkCZjylB6JkywhfOswPCnsdfx9tc1y4Iy7N5X/+xTQ0rls/jDk8uIoj1PAkKVWDuN+C6lKXqZ3ILHxKu6REZ3gXvoet3BxMzIoKMWm+vlM8aWBxP+W8gPOObdbAU= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1726413879; c=relaxed/simple; bh=3iXrVGuiTwf8NxC6UszBvYjpM8E8/w8hr0W92TMD6C4=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=n1aY0iByF1TzLYZDGVhL2os1n5L6YiFC6fKVyz98nU4AC9lcbMmBEyj9YMXnMUSsz6czoI6pvAxXVTSNb2uJ1FfhRsxgGJ+APrsS2PTkvBIzSTPrzbvFnLZfdAD2K66YXZBFsnPwcNgyrYoomMA72nRyWFE/uYvBG16vHloyrzs= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1726413877; 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=BAzlS58aS4HNIGvTgTtd7b2F97M/GF6uMVo89XzNmho=; b=HiAbTAL8UBVh2hA1qLdoq/1oRmzfGta8AkhwDVaR8KDJ0+wbBmDJbCaZ2l661GurJz48Sn o9ho6ZBYJcwxlzeRrihLud+ueATagpU4t1tHT//+8deaBB+bcP+pBnq6b2KWZO2WOEgj16 ZVJ4IBrY0pfZCSwfsSgr18AxQr6xztk= Received: from mx-prod-mc-05.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-473-yUcoLUwWPfOG5R-_KahDkw-1; Sun, 15 Sep 2024 11:24:36 -0400 X-MC-Unique: yUcoLUwWPfOG5R-_KahDkw-1 Received: from mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.4]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 392191956080; Sun, 15 Sep 2024 15:24:35 +0000 (UTC) Received: from localhost (unknown [10.45.224.43]) by mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 5953430001AB; Sun, 15 Sep 2024 15:24:33 +0000 (UTC) From: Jonathan Wakely To: libstdc++@gcc.gnu.org, gcc-patches@gcc.gnu.org Subject: [PATCH] libstdc++: Avoid forming T* in unique_ptr(auto_ptr&&) constraints [PR116529] Date: Sun, 15 Sep 2024 16:23:34 +0100 Message-ID: <20240915152430.28787-1-jwakely@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.4 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, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_NONE, TXREP, URI_HEX 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.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces~incoming=patchwork.ozlabs.org@gcc.gnu.org Tested x86_64-linux. -- >8 -- PR 116529 shows that std::unique_ptr is currently unusable because the constructor taking std::auto_ptr (which is a non-standard extension since C++17) tries to form the invalid type X&* during overload resolution. We can use the `pointer` type in the constructor constraints, instead of trying to form an invalid type. The std::auto_ptr constructor can never actually match for the case where element_type is a reference, so we just need it to produce a substitution failure instead of being ill-formed. LWG 4144 might make std::unique_ptr ill-formed, which would invalidate this new test. We would have to remove this test in that case. Using `pointer` in the constructor from std::auto_ptr would not be needed to support the std::unique_ptr case, but would not cause any harm either. libstdc++-v3/ChangeLog: PR libstdc++/116529 * include/bits/unique_ptr.h (unique_ptr(auto_ptr&&)): Use pointer instead of T*. * testsuite/20_util/unique_ptr/creation/116529.cc: New test. --- libstdc++-v3/include/bits/unique_ptr.h | 5 +-- .../20_util/unique_ptr/creation/116529.cc | 35 +++++++++++++++++++ 2 files changed, 38 insertions(+), 2 deletions(-) create mode 100644 libstdc++-v3/testsuite/20_util/unique_ptr/creation/116529.cc diff --git a/libstdc++-v3/include/bits/unique_ptr.h b/libstdc++-v3/include/bits/unique_ptr.h index 0f600db32f9..edcff78bff9 100644 --- a/libstdc++-v3/include/bits/unique_ptr.h +++ b/libstdc++-v3/include/bits/unique_ptr.h @@ -379,8 +379,9 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION #pragma GCC diagnostic push #pragma GCC diagnostic ignored "-Wdeprecated-declarations" /// Converting constructor from @c auto_ptr - template, is_same<_Dp, default_delete<_Tp>>>> + template, + is_same<_Dp, default_delete<_Tp>>>> unique_ptr(auto_ptr<_Up>&& __u) noexcept; #pragma GCC diagnostic pop #endif diff --git a/libstdc++-v3/testsuite/20_util/unique_ptr/creation/116529.cc b/libstdc++-v3/testsuite/20_util/unique_ptr/creation/116529.cc new file mode 100644 index 00000000000..323fc7cb27c --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/unique_ptr/creation/116529.cc @@ -0,0 +1,35 @@ +// { dg-do run { target c++11 } } + +// Bug libstdc++/116529 - Construction of unique_ptr with reference type +// is rejected because of auto_ptr constructor + +#include +#include + +int count = 0; + +struct X +{ + ~X() { ++count; } +}; + +struct deleter : std::default_delete +{ + using pointer = X*; +}; + +void +test01() +{ + { + std::unique_ptr up(new X); + // { dg-bogus "forming pointer to reference" "" { target *-*-* } 0 } + VERIFY( count == 0 ); + } + VERIFY( count == 1 ); +} + +int main() +{ + test01(); +}