public inbox for gcc-bugs@sourceware.org help / color / mirror / Atom feed
From: "redi at gcc dot gnu.org" <gcc-bugzilla@gcc.gnu.org> To: gcc-bugs@gcc.gnu.org Subject: [Bug libstdc++/114354] New: std::shared_ptr constructor constraints are checked too late Date: Fri, 15 Mar 2024 15:36:47 +0000 [thread overview] Message-ID: <bug-114354-4@http.gcc.gnu.org/bugzilla/> (raw) https://gcc.gnu.org/bugzilla/show_bug.cgi?id=114354 Bug ID: 114354 Summary: std::shared_ptr constructor constraints are checked too late Product: gcc Version: 14.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: libstdc++ Assignee: unassigned at gcc dot gnu.org Reporter: redi at gcc dot gnu.org Blocks: 88322 Target Milestone: --- The standard says: template<class Y> explicit shared_ptr(Y* p); Constraints: When T is an array type, the expression delete[] p is well-formed and either T is U[N] and Y(*)[N] is convertible to T*, or T is U[] and Y(*)[] is convertible to T*. When T is not an array type, the expression delete p is well-formed and Y* is convertible to T*. We do not constrain that constructor with checks for the delete expressions being well-formed, so this gives the wrong answer: #include <memory> struct A { private: ~A(); }; static_assert( ! std::is_constructible_v<std::shared_ptr<A>, A*> ); Similarly for the constructors taking a deleter: template<class Y, class D> shared_ptr(Y* p, D d); template<class Y, class D, class A> shared_ptr(Y* p, D d, A a); template<class D> shared_ptr(nullptr_t p, D d); template<class D, class A> shared_ptr(nullptr_t p, D d, A a); Constraints: is_move_constructible_v<D> is true, and d(p) is a well-formed expression. [...] We check that with a static assert in the constructor body, which is too late, so this fails: struct D { }; static_assert( ! std::is_constructible_v<std::shared_ptr<A>, A*, D> ); Prior to C++20 the requirements were just preconditions, so not required to be SFINAE-able. So we must fix this for C++20, and could do so for C++11 as QoI. Referenced Bugs: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=88322 [Bug 88322] Implement C++20 library features.
next reply other threads:[~2024-03-15 15:36 UTC|newest] Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top 2024-03-15 15:36 redi at gcc dot gnu.org [this message] 2024-03-15 15:37 ` [Bug libstdc++/114354] " redi at gcc dot gnu.org 2024-03-16 7:33 ` de34 at live dot cn 2024-03-16 10:07 ` redi at gcc dot gnu.org
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=bug-114354-4@http.gcc.gnu.org/bugzilla/ \ --to=gcc-bugzilla@gcc.gnu.org \ --cc=gcc-bugs@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).