[libcxx-commits] [libcxx] [libc++] cv-qualified types in atomic and atomic_ref (P3323R1) (PR #121414)
Louis Dionne via libcxx-commits
libcxx-commits at lists.llvm.org
Fri Jan 31 12:34:41 PST 2025
================
@@ -251,17 +284,24 @@ struct atomic_ref : 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 __base::value_type operator=(__base::value_type __desired) const noexcept
+ requires(!is_const_v<_Tp>)
+ {
+ return __base::operator=(__desired);
+ }
atomic_ref& operator=(const atomic_ref&) = delete;
};
template <class _Tp>
- requires(std::integral<_Tp> && !std::same_as<bool, _Tp>)
+ requires(integral<_Tp> && !same_as<bool, __remove_cv_t<_Tp>>)
struct atomic_ref<_Tp> : public __atomic_ref_base<_Tp> {
using __base _LIBCPP_NODEBUG = __atomic_ref_base<_Tp>;
+ static_assert(__base::is_always_lock_free || !is_volatile_v<_Tp>);
+
using difference_type = __base::value_type;
+ using value_type = __base::value_type;
----------------
ldionne wrote:
I would get rid of this one and the one for `floating_point` since this is already provided in `__atomic_ref_impl`. This makes it clearer that we're only providing the typedefs that we actually need to fulfill the public API, which in this case is `difference_type`.
If you have trouble referring to `value_type` (I think you might need something like `typename atomic_ref::value_type` which is annoying), you could always do
```
using typename __base::value_type;
```
IIRC that's legal and that makes it clear that we're only bringing the name that already exists into the current scope instead of introducing a new name.
https://github.com/llvm/llvm-project/pull/121414
More information about the libcxx-commits
mailing list