This page is a snapshot from the LWG issues list, see the Library Active Issues List for more information and the meaning of C++14 status.

2172. Does atomic_compare_exchange_* accept v == nullptr arguments?

Section: 99 [depr.util.smartptr.shared.atomic] Status: C++14 Submitter: Howard Hinnant Opened: 2012-07-28 Last modified: 2017-11-29

Priority: Not Prioritized

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

View all issues with C++14 status.

Discussion:

Looking at [util.smartptr.shared.atomic]/p31

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

-31- Requires: p shall not be null.

What about v? Can it be null? And if so, what happens?

This looks closely related to C++11 issue LWG 1030(i), where we gave every signature in this section a:

Requires: p shall not be null.

It looks like a simple oversight to me that we did not add for the atomic_compare_exchange_*:

Requires: p shall not be null and v shall not be null.

[2012-10 Portland: Move to Ready]

This is clearly the right thing to do, and Lawrence concurs.

[2013-04-20 Bristol]

Proposed resolution:

This wording is relative to N3376.

Change [util.smartptr.shared.atomic] as indicated:

template<class T>
  bool atomic_compare_exchange_weak(
    shared_ptr<T>* p, shared_ptr<T>* v, shared_ptr<T> w);

-27- Requires: p shall not be null and v shall not be null.

[…]

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

-31- Requires: p shall not be null and v shall not be null.

[…]