public inbox for libstdc++@gcc.gnu.org
 help / color / mirror / Atom feed
* [RFC] Deprecate non-standard constructors in std::pair
@ 2021-04-07 12:30 Jonathan Wakely
  2021-04-07 12:41 ` Ville Voutilainen
  0 siblings, 1 reply; 14+ messages in thread
From: Jonathan Wakely @ 2021-04-07 12:30 UTC (permalink / raw)
  To: libstdc++

This variation on the example in https://wg21.link/lwg811 is supposed
to be ill-formed:

   pair<char*, unique_ptr<int>> p(0, std::make_unique<int>(0));

This cannot use the pair(U1&&, U2&&) constructor because it deduces
int for U1, which isn't convertible to char*.  But it also cannot use
the pair(const first_type&, const second_type&) constructor, because
second_type is move-only.

It works in libstdc++ because extra non-standard constructors were
added by https://gcc.gnu.org/PR40925 when implementing LWG 811:

   template<typename U1, /* constraints */>
   explicit(/*...*/)
   pair(U1&&, const second_type&);

   template<typename U2, /* constraints */>
   explicit(/*...*/)
   pair(const first_type&, U2&&);

I think we should deprecate these extra constructors.

Unless I'm mistaken, those non-standard constructors have two uses:

- Support literal 0 as a constructor argument for a pointer type.
   Such code should use nullptr instead. It exists to solve the problem
   of 0 not deducing as a pointer type.

- Support {} as a constructor argument for a move-only type. I don't
   think this was an intentional design choice (we don't test for it)
   but it does work. Adopting https://wg21.link/p1951 for C++23 will
   make that work anyway.

I propose that we deprecate the constructors for C++11/14/17/20 in
stage 1, and do not support them at all in C++23 mode once P1951 is
supported. I have a patch which I'll send in stage 1 (it also uses
C++20 concepts to simplify std::pair and fix PR 97930).

After a period of deprecation we could remove them, and support P1951
for -std=gnu++11/14/17/20 too so that {} continues to work.



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

end of thread, other threads:[~2021-04-28 17:19 UTC | newest]

Thread overview: 14+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-04-07 12:30 [RFC] Deprecate non-standard constructors in std::pair Jonathan Wakely
2021-04-07 12:41 ` Ville Voutilainen
2021-04-07 12:46   ` Jonathan Wakely
2021-04-07 16:59     ` Jonathan Wakely
2021-04-07 17:18       ` Jonathan Wakely
2021-04-28 16:57         ` Jonathan Wakely
2021-04-28 17:19           ` Jonathan Wakely
2021-04-07 18:00       ` Jonathan Wakely
2021-04-07 18:17         ` Jonathan Wakely
2021-04-07 18:25           ` Ville Voutilainen
2021-04-07 18:26             ` Ville Voutilainen
2021-04-28 16:57       ` Jonathan Wakely
2021-04-28 17:00         ` Jonathan Wakely
2021-04-28 17:11           ` Jonathan Wakely

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