]> gcc.gnu.org Git - gcc.git/commit
libstdc++: Deprecate non-standard std::pair constructors [PR 99957]
authorJonathan Wakely <jwakely@redhat.com>
Wed, 28 Apr 2021 16:46:01 +0000 (17:46 +0100)
committerJonathan Wakely <jwakely@redhat.com>
Wed, 28 Apr 2021 16:56:50 +0000 (17:56 +0100)
commitd96db15967e78d7cecea3b1cf3169ceb924678ac
tree4d6dd96a448af957090569668408642b8a2ad7c5
parent668df9e769e7d89bcefa07f72b68dcae9a8f3970
libstdc++: Deprecate non-standard std::pair constructors [PR 99957]

This deprecates the non-standard std::pair constructors that support
construction from an rvalue and a literal zero used as a null pointer
constant. We can't just add the deprecated attribute to those
constructors, because they're currently used by correct code when they
are a better match than the constructors required by the standard e.g.

  int i = 0;
  const int j = 0;
  std::pair<int, int> p(i, j); // uses pair(U1&&, const int&)

This patch adjusts the parameter types and constraints of those
constructors so that they only get used for literal zeros, and the
pair(U1&&, U2&&) constructor gets used otherwise. Once they're only used
for initializations that should be ill-formed we can add the deprecated
attribute.

The deprecated attribute is used to suggest that the user code uses
nullptr, which avoids the problem of 0 deducing as int instead of a null
pointer constant.

libstdc++-v3/ChangeLog:

PR libstdc++/99957
* include/bits/stl_pair.h (_PCC::_MoveCopyPair, _PCC::_CopyMovePair):
Combine and replace with ...
(_PCC::_DeprConsPair): New SFINAE helper function.
(pair): Merge preprocessor blocks so that all C++03 members
are defined together at the end.
(pair::pair(const _T1&, _U2&&), pair::pair(_U1&&, const _T2&)):
Replace _T1 and _T2 parameters with __null_ptr_constant and
adjust constraints.
* testsuite/20_util/pair/40925.cc: Use nullptr instead of 0.
* testsuite/20_util/pair/cons/explicit_construct.cc: Likewise.
* testsuite/20_util/pair/cons/99957.cc: New test.
libstdc++-v3/include/bits/stl_pair.h
libstdc++-v3/testsuite/20_util/pair/40925.cc
libstdc++-v3/testsuite/20_util/pair/cons/99957.cc [new file with mode: 0644]
libstdc++-v3/testsuite/20_util/pair/cons/explicit_construct.cc
This page took 0.062516 seconds and 6 git commands to generate.