[libcxx-commits] [libcxx] [libc++] Implement P1901R2: owner_hash and owner_equal for shared_ptr/weak_ptr (PR #210551)

Hristo Hristov via libcxx-commits libcxx-commits at lists.llvm.org
Wed Jul 22 22:47:47 PDT 2026


================
@@ -555,6 +556,22 @@ class _LIBCPP_SHARED_PTR_TRIVIAL_ABI shared_ptr {
 
   _LIBCPP_HIDE_FROM_ABI bool __owner_equivalent(const shared_ptr& __p) const { return __cntrl_ == __p.__cntrl_; }
 
+#if _LIBCPP_STD_VER >= 26
+  [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI size_t owner_hash() const _NOEXCEPT {
----------------
Zingam wrote:

Same as the above comment. Generally, when possible avoid using the macros in newer code if there are non-macro alternatives (see bellow).

Every part of a function signatures needs to be tested. `[[nodiscard]]`, return type, `const`-ness, `noexcept`-ness, etc.
The `[[nodiscard]]` test cases live in files in the `tests/libcxx` directory as they are libc++ specific.

`[[__nodiscard__]]` is a Clang extension used in pre C++17 code.

https://github.com/llvm/llvm-project/pull/210551


More information about the libcxx-commits mailing list