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

* [Bug libstdc++/114354] std::shared_ptr constructor constraints are checked too late
  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 ` 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
  2 siblings, 0 replies; 4+ messages in thread
From: redi at gcc dot gnu.org @ 2024-03-15 15:37 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=114354

Jonathan Wakely <redi at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |ASSIGNED
     Ever confirmed|0                           |1
           Assignee|unassigned at gcc dot gnu.org      |redi at gcc dot gnu.org
   Last reconfirmed|                            |2024-03-15

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

* [Bug libstdc++/114354] std::shared_ptr constructor constraints are checked too late
  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
  2 siblings, 0 replies; 4+ messages in thread
From: de34 at live dot cn @ 2024-03-16  7:33 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=114354

Jiang An <de34 at live dot cn> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |de34 at live dot cn

--- Comment #1 from Jiang An <de34 at live dot cn> ---
The constraints were transformed from preconditions by LWG2874
(https://cplusplus.github.io/LWG/issue2874). So perhaps the actually issue is
not having implemented LWG2874, and I think the constraints need to be
implemented for C++17.

The wording change in LWG2874 seems to be on the top of P0414R2 + P0497R0. I'm
not sure what the "backported form of LWG2874" exactly is. Perhaps it's simply
"This constructor shall not participate in overload resolution unless the
expression delete p is well-formed and Y* is convertible to T*." (not
considering whether T or Y is an array type)?

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

* [Bug libstdc++/114354] std::shared_ptr constructor constraints are checked too late
  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
  2 siblings, 0 replies; 4+ messages in thread
From: redi at gcc dot gnu.org @ 2024-03-16 10:07 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=114354

--- Comment #2 from Jonathan Wakely <redi at gcc dot gnu.org> ---
Ah yes, thanks. It looks like I converted them to constraints for array support
with g:a2e0054e1d169984ec64d64145b71a88a9628537 but only for the pointer
conversions, I missed the delete expression.

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