From patchwork Thu Apr 22 15:07:53 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonathan Wakely X-Patchwork-Id: 1469246 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: 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@gcc.gnu.org; receiver=) Authentication-Results: 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=Q7nsuJ2+; 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 RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4FR16p2Bptz9sSC for ; Fri, 23 Apr 2021 01:09:38 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 671AD3A13CF2; Thu, 22 Apr 2021 15:09:24 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 671AD3A13CF2 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1619104164; bh=Hghz8ncY2fgbNoMDgKjRfp6V2SSbtZIcMmpqDtEwU4g=; h=Date:To:Subject:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=Q7nsuJ2+DYyyTgJMEQSuh2NkhCmQ6PkvDT+ekMRVY23YDbovcaKyAZtRUc3G8k1Ao cj0lGc6VE4gVH/EsOgKNXFESV+32doZbIEf2Zu2GtqOtkSNenBU2xQVc40Y6PjqTK6 4HdT9qGlmPSekEO2L/kRZH3YAHPPQGoTRkKkFJ2o= 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 [216.205.24.124]) by sourceware.org (Postfix) with ESMTP id 2B82639D5C31 for ; Thu, 22 Apr 2021 15:09:21 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 2B82639D5C31 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-479-OF6qm0IeM_q3NwGaJsjoBA-1; Thu, 22 Apr 2021 11:09:18 -0400 X-MC-Unique: OF6qm0IeM_q3NwGaJsjoBA-1 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id D618B107AD93; Thu, 22 Apr 2021 15:07:54 +0000 (UTC) Received: from localhost (unknown [10.33.36.164]) by smtp.corp.redhat.com (Postfix) with ESMTP id 81F1919C45; Thu, 22 Apr 2021 15:07:54 +0000 (UTC) Date: Thu, 22 Apr 2021 16:07:53 +0100 To: libstdc++@gcc.gnu.org, gcc-patches@gcc.gnu.org Subject: [committed] libstdc++: Reject std::make_shared [PR 99006] Message-ID: MIME-Version: 1.0 X-Clacks-Overhead: GNU Terry Pratchett X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Disposition: inline X-Spam-Status: No, score=-14.0 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_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) 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@gcc.gnu.org Sender: "Gcc-patches" Prior to C++20 it should be ill-formed to use std::make_shared with an array type (and we don't support the C++20 feature to make it valid yet anyway). libstdc++-v3/ChangeLog: PR libstdc++/99006 * include/bits/shared_ptr.h (allocate_shared): Assert that _Tp is not an array type. * include/bits/shared_ptr_base.h (__allocate_shared): Likewise. * testsuite/20_util/shared_ptr/creation/99006.cc: New test. Tested powerpc64le-linux. Committed to trunk. commit 55650236cd97d81f42f9fdb4f6bcb12babafe51f Author: Jonathan Wakely Date: Thu Apr 22 15:46:51 2021 libstdc++: Reject std::make_shared [PR 99006] Prior to C++20 it should be ill-formed to use std::make_shared with an array type (and we don't support the C++20 feature to make it valid yet anyway). libstdc++-v3/ChangeLog: PR libstdc++/99006 * include/bits/shared_ptr.h (allocate_shared): Assert that _Tp is not an array type. * include/bits/shared_ptr_base.h (__allocate_shared): Likewise. * testsuite/20_util/shared_ptr/creation/99006.cc: New test. diff --git a/libstdc++-v3/include/bits/shared_ptr.h b/libstdc++-v3/include/bits/shared_ptr.h index ac4aa20b794..d5386ad535f 100644 --- a/libstdc++-v3/include/bits/shared_ptr.h +++ b/libstdc++-v3/include/bits/shared_ptr.h @@ -857,6 +857,8 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION inline shared_ptr<_Tp> allocate_shared(const _Alloc& __a, _Args&&... __args) { + static_assert(!is_array<_Tp>::value, "make_shared not supported"); + return shared_ptr<_Tp>(_Sp_alloc_shared_tag<_Alloc>{__a}, std::forward<_Args>(__args)...); } diff --git a/libstdc++-v3/include/bits/shared_ptr_base.h b/libstdc++-v3/include/bits/shared_ptr_base.h index 8766b61fd81..71099afbf7a 100644 --- a/libstdc++-v3/include/bits/shared_ptr_base.h +++ b/libstdc++-v3/include/bits/shared_ptr_base.h @@ -1831,6 +1831,8 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION inline __shared_ptr<_Tp, _Lp> __allocate_shared(const _Alloc& __a, _Args&&... __args) { + static_assert(!is_array<_Tp>::value, "make_shared not supported"); + return __shared_ptr<_Tp, _Lp>(_Sp_alloc_shared_tag<_Alloc>{__a}, std::forward<_Args>(__args)...); } diff --git a/libstdc++-v3/testsuite/20_util/shared_ptr/creation/99006.cc b/libstdc++-v3/testsuite/20_util/shared_ptr/creation/99006.cc new file mode 100644 index 00000000000..d5f7a5da5e9 --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/shared_ptr/creation/99006.cc @@ -0,0 +1,9 @@ +// FIXME: This should use { target { ! c++20 } } +// { dg-do compile } + +#include + +auto p = std::make_shared(2); // { dg-error "here" } +auto q = std::make_shared(1, 2); // { dg-error "here" } + +// { dg-prune-output "static assertion failed" }