[libcxx-commits] [libcxx] [libc++] cv-qualified types in atomic and atomic_ref (P3323R1) (PR #121414)
A. Jiang via libcxx-commits
libcxx-commits at lists.llvm.org
Tue Jan 7 20:00:36 PST 2025
================
@@ -317,56 +414,112 @@ struct atomic_ref<_Tp> : public __atomic_ref_base<_Tp> {
_LIBCPP_HIDE_FROM_ABI atomic_ref(const atomic_ref&) noexcept = default;
- _LIBCPP_HIDE_FROM_ABI _Tp operator=(_Tp __desired) const noexcept { return __base::operator=(__desired); }
+ _LIBCPP_HIDE_FROM_ABI value_type operator=(value_type __desired) const noexcept
+ requires(!is_const_v<_Tp>)
+ {
+ return __base::operator=(__desired);
+ }
atomic_ref& operator=(const atomic_ref&) = delete;
- _LIBCPP_HIDE_FROM_ABI _Tp fetch_add(_Tp __arg, memory_order __order = memory_order_seq_cst) const noexcept {
- _Tp __old = this->load(memory_order_relaxed);
- _Tp __new = __old + __arg;
+ _LIBCPP_HIDE_FROM_ABI value_type
+ fetch_add(value_type __arg, memory_order __order = memory_order_seq_cst) const noexcept
+ requires(!is_const_v<_Tp>)
+ {
+ value_type __old = this->load(memory_order_relaxed);
+ value_type __new = __old + __arg;
while (!this->compare_exchange_weak(__old, __new, __order, memory_order_relaxed)) {
__new = __old + __arg;
}
return __old;
}
- _LIBCPP_HIDE_FROM_ABI _Tp fetch_sub(_Tp __arg, memory_order __order = memory_order_seq_cst) const noexcept {
- _Tp __old = this->load(memory_order_relaxed);
- _Tp __new = __old - __arg;
+ _LIBCPP_HIDE_FROM_ABI value_type
+ fetch_sub(value_type __arg, memory_order __order = memory_order_seq_cst) const noexcept
+ requires(!is_const_v<_Tp>)
+ {
+ value_type __old = this->load(memory_order_relaxed);
+ value_type __new = __old - __arg;
while (!this->compare_exchange_weak(__old, __new, __order, memory_order_relaxed)) {
__new = __old - __arg;
}
return __old;
}
- _LIBCPP_HIDE_FROM_ABI _Tp operator+=(_Tp __arg) const noexcept { return fetch_add(__arg) + __arg; }
- _LIBCPP_HIDE_FROM_ABI _Tp operator-=(_Tp __arg) const noexcept { return fetch_sub(__arg) - __arg; }
+ _LIBCPP_HIDE_FROM_ABI value_type operator+=(value_type __arg) const noexcept
+ requires(!is_const_v<_Tp>)
+ {
+ return fetch_add(__arg) + __arg;
+ }
+ _LIBCPP_HIDE_FROM_ABI value_type operator-=(value_type __arg) const noexcept
+ requires(!is_const_v<_Tp>)
+ {
+ return fetch_sub(__arg) - __arg;
+ }
};
template <class _Tp>
-struct atomic_ref<_Tp*> : public __atomic_ref_base<_Tp*> {
- using __base = __atomic_ref_base<_Tp*>;
+ requires(std::is_pointer_v<_Tp>)
----------------
frederick-vs-ja wrote:
Per [[atomics.ref.pointer]/1](https://eel.is/c++draft/atomics.ref.pointer#1), only pointer-to-object types are specially handled.
```suggestion
requires(is_pointer_v<_Tp> && is_object_v<remove_pointer_t<_Tp>>)
```
Also, `<__type_traits/is_object.h>` should be included, and `std/atomics/atomics.ref/member_types.compile.pass.cpp` needs to be modified.
BTW, we don't need to add `std::` for non-function things unless there's conflict.
https://github.com/llvm/llvm-project/pull/121414
More information about the libcxx-commits
mailing list