[libc++] Deprecates and removes shared_ptr::unqiue. (#76576)

The status table incorrectly marks P0521R0 as nothing to do. This is not
correct the function should be deprecated.
During our latest monthly meeting we argreed to remove the
_LIBCPP_ENABLE_CXXyy_REMOVED_FEATURES macros, therefore the new macro is
not
added to that global list.

Implements
- P0521R0 Proposed Resolution for CA 14 (shared_ptr use_count/unique)

Implements parts of
- P0619R4 Reviewing Deprecated Facilities of C++17 for C++20

---------

Co-authored-by: Nikolas Klauser <nikolasklauser@berlin.de>
This commit is contained in:
Mark de Wever 2023-12-30 14:05:22 +01:00 committed by GitHub
parent bd3d358ec6
commit 81cedac8f6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 63 additions and 5 deletions

View File

@ -57,6 +57,7 @@ Implemented Papers
- P2871R3 - Remove Deprecated Unicode Conversion Facets from C++26
- P2870R3 - Remove basic_string::reserve()
- P2909R4 - Fix formatting of code units as integers (Dude, wheres my ``char``?)
- P0521R0 - Proposed Resolution for CA 14 (shared_ptr use_count/unique)
Improvements and New Features
@ -83,6 +84,9 @@ Improvements and New Features
- The ``_LIBCPP_ENABLE_CXX26_REMOVED_STRING_RESERVE`` macro has been added to make
the function ``std::basic_string<...>::reserve()`` available.
- The ``_LIBCPP_ENABLE_CXX20_REMOVED_SHARED_PTR_UNIQUE`` macro has been added to make
the function ``std::shared_ptr<...>::unique()`` available.
Deprecations and Removals
-------------------------

View File

@ -87,7 +87,7 @@
"`P0513R0 <https://wg21.link/P0513R0>`__","LWG","Poisoning the Hash","Issaquah","|Complete|","5.0"
"`P0516R0 <https://wg21.link/P0516R0>`__","LWG","Clarify That shared_future's Copy Operations have Wide Contracts","Issaquah","|Complete|","4.0"
"`P0517R0 <https://wg21.link/P0517R0>`__","LWG","Make future_error Constructible","Issaquah","|Complete|","4.0"
"`P0521R0 <https://wg21.link/P0521R0>`__","LWG","Proposed Resolution for CA 14 (shared_ptr use_count/unique)","Issaquah","|Nothing To Do|","n/a"
"`P0521R0 <https://wg21.link/P0521R0>`__","LWG","Proposed Resolution for CA 14 (shared_ptr use_count/unique)","Issaquah","|Complete|","18.0"
"","","","","",""
"`P0156R2 <https://wg21.link/P0156R2>`__","LWG","Variadic Lock guard(rev 5)","Kona","|Complete|","5.0"
"`P0270R3 <https://wg21.link/P0270R3>`__","CWG","Removing C dependencies from signal handler wording","Kona","",""

1 Paper # Group Paper Name Meeting Status First released version
87 `P0513R0 <https://wg21.link/P0513R0>`__ LWG Poisoning the Hash Issaquah |Complete| 5.0
88 `P0516R0 <https://wg21.link/P0516R0>`__ LWG Clarify That shared_future's Copy Operations have Wide Contracts Issaquah |Complete| 4.0
89 `P0517R0 <https://wg21.link/P0517R0>`__ LWG Make future_error Constructible Issaquah |Complete| 4.0
90 `P0521R0 <https://wg21.link/P0521R0>`__ LWG Proposed Resolution for CA 14 (shared_ptr use_count/unique) Issaquah |Nothing To Do| |Complete| n/a 18.0
91
92 `P0156R2 <https://wg21.link/P0156R2>`__ LWG Variadic Lock guard(rev 5) Kona |Complete| 5.0
93 `P0270R3 <https://wg21.link/P0270R3>`__ CWG Removing C dependencies from signal handler wording Kona

View File

@ -44,7 +44,7 @@ Paper Status
.. [#note-P0645] P0645: The paper is implemented but still marked as an incomplete feature
(the feature-test macro is not set).
.. [#note-P0966] P0966: It was previously erroneously marked as complete in version 8.0. See `bug 45368 <https://llvm.org/PR45368>`__.
.. [#note-P0619] P0619: Only sections D.8, D.9, D.10 and D.13 are implemented. Sections D.4, D.7, D.11, D.12, and D.14 remain undone.
.. [#note-P0619] P0619: Only sections D.8, D.9, D.10 and D.13 are implemented. Sections D.4, D.7, D.11, and D.12 remain undone.
.. [#note-P0883.1] P0883: shared_ptr and floating-point changes weren't applied as they themselves aren't implemented yet.
.. [#note-P0883.2] P0883: ``ATOMIC_FLAG_INIT`` was marked deprecated in version 14.0, but was undeprecated with the implementation of LWG3659 in version 15.0.
.. [#note-P2231] P2231: Optional is complete. The changes to variant haven't been implemented yet.

View File

@ -296,6 +296,10 @@ C++17 Specific Configuration Macros
C++20 Specific Configuration Macros
-----------------------------------
**_LIBCPP_ENABLE_CXX20_REMOVED_SHARED_PTR_UNIQUE**
This macro is used to re-enable the function
``std::shared_ptr<...>::unique()``.
**_LIBCPP_ENABLE_CXX20_REMOVED_FEATURES**:
This macro is used to re-enable all the features removed in C++20. The effect
is equivalent to manually defining each macro listed below.

View File

@ -723,7 +723,9 @@ public:
_LIBCPP_HIDE_FROM_ABI long use_count() const _NOEXCEPT { return __cntrl_ ? __cntrl_->use_count() : 0; }
_LIBCPP_HIDE_FROM_ABI bool unique() const _NOEXCEPT { return use_count() == 1; }
#if _LIBCPP_STD_VER < 20 || defined(_LIBCPP_ENABLE_CXX20_REMOVED_SHARED_PTR_UNIQUE)
_LIBCPP_DEPRECATED_IN_CXX17 _LIBCPP_HIDE_FROM_ABI bool unique() const _NOEXCEPT { return use_count() == 1; }
#endif
_LIBCPP_HIDE_FROM_ABI explicit operator bool() const _NOEXCEPT { return get() != nullptr; }

View File

@ -629,7 +629,7 @@ public:
T& operator*() const noexcept;
T* operator->() const noexcept;
long use_count() const noexcept;
bool unique() const noexcept;
bool unique() const noexcept; // deprected in C++17, removed in C++20
explicit operator bool() const noexcept;
template<class U> bool owner_before(shared_ptr<U> const& b) const noexcept;
template<class U> bool owner_before(weak_ptr<U> const& b) const noexcept;

View File

@ -0,0 +1,24 @@
//===----------------------------------------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
// UNSUPPORTED: c++03, c++11, c++14
// ADDITIONAL_COMPILE_FLAGS: -D_LIBCPP_ENABLE_CXX20_REMOVED_SHARED_PTR_UNIQUE
// <memory>
// shared_ptr
// bool unique() const; // deprecated in C++17, removed in C++20
#include <memory>
void f() {
const std::shared_ptr<int> p;
p.unique(); // expected-warning {{'unique' is deprecated}}
}

View File

@ -10,7 +10,9 @@
// shared_ptr
// bool unique() const;
// bool unique() const; // deprecated in C++17, removed in C++20
// ADDITIONAL_COMPILE_FLAGS: -D_LIBCPP_DISABLE_DEPRECATION_WARNINGS -D_LIBCPP_ENABLE_CXX20_REMOVED_SHARED_PTR_UNIQUE
#include <memory>
#include <cassert>

View File

@ -0,0 +1,22 @@
//===----------------------------------------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
// UNSUPPORTED: c++03, c++11, c++14, c++17
// <memory>
// shared_ptr
// bool unique() const; // deprecated in C++17, removed in C++20
#include <memory>
void f() {
const std::shared_ptr<int> p;
p.unique(); // expected-error {{no member named 'unique' in 'std::shared_ptr<int>}}
}