2980. Cannot compare_exchange empty pointers

Section: 23.11.2.6 [util.smartptr.shared.atomic] Status: WP Submitter: Alisdair Meredith Opened: 2017-06-15 Last modified: 2017-11-13

Priority: Not Prioritized

View all other issues in [util.smartptr.shared.atomic].

View all issues with WP status.

Discussion:

[util.smartptr.shared.atomic] p35 states that two shared pointers are equivalent if they store the same pointer value, and share ownership. As empty shared pointers never share ownership, it is not possible to replace an empty shared pointer using the atomic compare_exchange API.

Note that through aliasing, empty shared pointers may still point to different objects, and any resolution must allow for that case too.

[ 2017-06-26 Moved to Tentatively Ready after 5 positive votes on c++std-lib. ]

Proposed resolution:

This wording is relative to N4659.

  1. Edit 23.11.2.6 [util.smartptr.shared.atomic] as indicated:

    template<class T>
      bool atomic_compare_exchange_weak_explicit(
        shared_ptr<T>* p, shared_ptr<T>* v, shared_ptr<T> w,
        memory_order success, memory_order failure);
    template<class T>
      bool atomic_compare_exchange_strong_explicit(
        shared_ptr<T>* p, shared_ptr<T>* v, shared_ptr<T> w,
        memory_order success, memory_order failure);
    

    […]

    -35- Remarks: Two shared_ptr objects are equivalent if they store the same pointer value and share ownership, or if they store the same pointer value and both are empty. The weak form may fail spuriously. See 32.6.1.