public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug libstdc++/114354] New: std::shared_ptr constructor constraints are checked too late
@ 2024-03-15 15:36 redi at gcc dot gnu.org
  2024-03-15 15:37 ` [Bug libstdc++/114354] " redi at gcc dot gnu.org
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: redi at gcc dot gnu.org @ 2024-03-15 15:36 UTC (permalink / raw)
  To: gcc-bugs

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.

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2024-03-16 10:07 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-03-15 15:36 [Bug libstdc++/114354] New: std::shared_ptr constructor constraints are checked too late redi at gcc dot gnu.org
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

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).