Title
atomic<T*> inheritance from atomic_address breaks type safety
Status
resolved
Section
[atomics.types.generic]
Submitter
BSI

Created on 2010-08-25.00:00:00 last changed 171 months ago

Messages

Date: 2010-11-13.02:14:14

Proposed resolution:

Add the following overloads to [atomics.types.generic], the synopsis around the specialization atomic<T*>, as indicated:

namespace std {
  [..]
  template <class T> struct atomic<T*> : atomic_address {
    [..]
  };

  template<typename T>
  void atomic_store(atomic<T*>&,T*);
  template<typename T>
  void atomic_store(atomic<T*>&,void*) = delete;
  template<typename T>
  void atomic_store_explicit(atomic<T*>&,T*,memory_order);
  template<typename T>
  void atomic_store_explicit(atomic<T*>&,void*,memory_order) = delete;
  template<typename T>
  T* atomic_exchange(atomic<T*>&,T*);
  template<typename T>
  T* atomic_exchange(atomic<T*>&,void*) = delete;
  template<typename T>
  T* atomic_exchange_explicit(atomic<T*>&,T*,memory_order);
  template<typename T>
  T* atomic_exchange_explicit(atomic<T*>&,void*,memory_order) = delete;
  template<typename T>
  T* atomic_compare_exchange_weak(atomic<T*>&,T**,T*);
  template<typename T>
  T* atomic_compare_exchange_weak(atomic<T*>&,void**,void*) = delete;
  template<typename T>
  T* atomic_compare_exchange_weak_explicit(atomic<T*>&,T**,T*,memory_order);
  template<typename T>
  T* atomic_compare_exchange_weak_explicit(atomic<T*>&,void**,void*,memory_order) = delete;
  template<typename T>
  T* atomic_compare_exchange_strong(atomic<T*>&,T**,T*);
  template<typename T>
  T* atomic_compare_exchange_strong(atomic<T*>&,void**,void*) = delete;
  template<typename T>
  T* atomic_compare_exchange_strong_explicit(atomic<T*>&,T**,T*,memory_order);
  template<typename T>
  T* atomic_compare_exchange_strong_explicit(atomic<T*>&,void**,void*,memory_order) = delete;

}
Date: 2010-11-13.02:14:14

[ Resolved in Batavia by accepting n3193. ]

Date: 2010-10-27.00:00:00

[ 2010-10-27 Daniel adds: ]

Resolving this issue will also solve 1467

Accepting n3164 would solve this issue by removing atomic_address.

Date: 2010-10-27.21:43:25

Addresses GB-133

The free functions that operate on atomic_address can be used to store a pointer to an unrelated type in an atomic<T*> without a cast. e.g.

int i;
atomic<int*> ai(&i);
string s;
atomic_store(&ai,&s);

Overload the atomic_store, atomic_exchange and atomic_compare_exchange_[weak/strong] operations for atomic<T*> to allow storing only pointers to T.

History
Date User Action Args
2010-11-18 12:46:23adminsetstatus: nad editorial -> resolved
2010-11-13 02:14:14adminsetmessages: + msg5350
2010-11-13 02:14:14adminsetstatus: open -> nad editorial
2010-10-27 21:43:25adminsetmessages: + msg5174
2010-10-21 19:47:27adminsetmessages: + msg4867
2010-08-25 00:00:00admincreate