public inbox for libstdc++-cvs@sourceware.org help / color / mirror / Atom feed
From: Jonathan Wakely <redi@gcc.gnu.org> To: gcc-cvs@gcc.gnu.org, libstdc++-cvs@gcc.gnu.org Subject: [gcc r10-9936] libstdc++: Reject std::make_shared<T[]> [PR 99006] Date: Fri, 18 Jun 2021 12:56:23 +0000 (GMT) [thread overview] Message-ID: <20210618125623.B6D6C3860C32@sourceware.org> (raw) https://gcc.gnu.org/g:36d6e7fe997aa85dc64b13ce4bb3c2e51e13cd36 commit r10-9936-g36d6e7fe997aa85dc64b13ce4bb3c2e51e13cd36 Author: Jonathan Wakely <jwakely@redhat.com> Date: Thu Apr 22 15:46:51 2021 +0100 libstdc++: Reject std::make_shared<T[]> [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. (cherry picked from commit 55650236cd97d81f42f9fdb4f6bcb12babafe51f) Diff: --- libstdc++-v3/include/bits/shared_ptr.h | 2 ++ libstdc++-v3/include/bits/shared_ptr_base.h | 2 ++ libstdc++-v3/testsuite/20_util/shared_ptr/creation/99006.cc | 9 +++++++++ 3 files changed, 13 insertions(+) diff --git a/libstdc++-v3/include/bits/shared_ptr.h b/libstdc++-v3/include/bits/shared_ptr.h index 0baec4e0882..af7a696adb0 100644 --- a/libstdc++-v3/include/bits/shared_ptr.h +++ b/libstdc++-v3/include/bits/shared_ptr.h @@ -856,6 +856,8 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION inline shared_ptr<_Tp> allocate_shared(const _Alloc& __a, _Args&&... __args) { + static_assert(!is_array<_Tp>::value, "make_shared<T[]> 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 219007b2c07..792d8344664 100644 --- a/libstdc++-v3/include/bits/shared_ptr_base.h +++ b/libstdc++-v3/include/bits/shared_ptr_base.h @@ -1870,6 +1870,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<T[]> 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 <memory> + +auto p = std::make_shared<int[]>(2); // { dg-error "here" } +auto q = std::make_shared<int[2]>(1, 2); // { dg-error "here" } + +// { dg-prune-output "static assertion failed" }
reply other threads:[~2021-06-18 12:56 UTC|newest] Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=20210618125623.B6D6C3860C32@sourceware.org \ --to=redi@gcc.gnu.org \ --cc=gcc-cvs@gcc.gnu.org \ --cc=libstdc++-cvs@gcc.gnu.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).