Skip to content

<atomic>: atomic_ref<void*> and atomic<void*> lack difference_type #4688

@StephanTLavavej

Description

@StephanTLavavej

While updating our libcxx test suite, I found that https://github.com/llvm/llvm-project/blob/af6812085cc7a7251a3095acbc96343ce660f135/libcxx/test/std/atomics/atomics.ref/member_types.pass.cpp is failing with:

error: no type named 'difference_type' in 'std::atomic_ref<void *>'

AFAICT, this happens because atomic_ref:

STL/stl/inc/atomic

Lines 2323 to 2324 in 63354c3

_EXPORT_STD template <class _Ty>
struct atomic_ref : _Choose_atomic_base_t<_Ty, _Ty&> { // atomic reference

and atomic:

STL/stl/inc/atomic

Lines 2143 to 2144 in 63354c3

_EXPORT_STD template <class _Ty>
struct atomic : _Choose_atomic_base_t<_Ty> { // atomic value

check for is_pointer_v<_TVal> && is_object_v<remove_pointer_t<_TVal>>:

STL/stl/inc/atomic

Lines 2128 to 2141 in 63354c3

template <class _TVal, class _Ty = _TVal>
using _Choose_atomic_base2_t =
typename _Select<is_integral_v<_TVal> && !is_same_v<bool, _TVal>>::template _Apply<_Atomic_integral_facade<_Ty>,
typename _Select<is_pointer_v<_TVal> && is_object_v<remove_pointer_t<_TVal>>>::template _Apply<
_Atomic_pointer<_Ty>, _Atomic_storage<_Ty>>>;
#if _HAS_CXX20
template <class _TVal, class _Ty = _TVal>
using _Choose_atomic_base_t =
_Select<is_floating_point_v<_TVal>>::template _Apply<_Atomic_floating<_Ty>, _Choose_atomic_base2_t<_TVal, _Ty>>;
#else // ^^^ _HAS_CXX20 / !_HAS_CXX20 vvv
template <class _TVal, class _Ty = _TVal>
using _Choose_atomic_base_t = _Choose_atomic_base2_t<_TVal, _Ty>;
#endif // ^^^ !_HAS_CXX20 ^^^

Yet WG21-N4981 [atomics.ref.pointer] depicts:

template<class T> struct atomic_ref<T*> {
private:
  T** ptr; // exposition only

public:
  using value_type = T*;
  using difference_type = ptrdiff_t;

and [atomics.types.pointer] depicts:

template<class T> struct atomic<T*> {
  using value_type = T*;
  using difference_type = ptrdiff_t;

without making any special cases for void*.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingfixedSomething works now, yay!

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions