[libcxx-commits] [libcxx] [libcxx] Implementation of P1831R1 (PR #101439)

Mark de Wever via libcxx-commits libcxx-commits at lists.llvm.org
Sun Aug 4 03:34:42 PDT 2024


================
@@ -27,6 +27,19 @@
 
 _LIBCPP_BEGIN_NAMESPACE_STD
 
+#if _LIBCPP_STD_VER >= 20
+#  define _LIBCPP_DEPRECATED_NOT_ALWAYS_LOCK_FREE                                                                      \
+    [[deprecated("volatile atomic operations are deprecated when std::atomic<T>::is_always_lock_free is false")]]
+#else
+#  define _LIBCPP_DEPRECATED_NOT_ALWAYS_LOCK_FREE
+#endif
+
+template <class _Tp, bool always_lock_free>
+constexpr bool __deprecated_if_not_awlays_lock_free = true;
+
+template <class _Tp>
+_LIBCPP_DEPRECATED_NOT_ALWAYS_LOCK_FREE constexpr bool __deprecated_if_not_awlays_lock_free<_Tp, false> = true;
+
----------------
mordante wrote:

I'm not too fond of this entire code, the `static_assert` feels very misleading. It is only used to generate a diagnostic. How about something along the lines of:
```
#if _LIBCPP_STD_VER >= 20
inline constexpr bool __deprecated_if_not_awlays_lock_free = true;

template <class _Tp>
[[deprecated("volatile atomic operations are deprecated when std::atomic<T>::is_always_lock_free is false")]] 
inline constexpr bool __deprecated_if_not_awlays_lock_free<_Tp, false> = true;

#  define _LIBCPP_DEPRECATED_NOT_ALWAYS_LOCK_FREE(_Tp, __is_always_lock_free) \
       static_assert(__deprecated_if_not_awlays_lock_free<_Tp, __is_always_lock_free>)
#else 
  define _LIBCPP_DEPRECATED_NOT_ALWAYS_LOCK_FREE(_Tp, __is_always_lock_free) \
    do { } while(1)
#endif
```
Then change the code to
```
 _LIBCPP_HIDE_FROM_ABI void store(_Tp __d, memory_order __m = memory_order_seq_cst) volatile _NOEXCEPT
      _LIBCPP_CHECK_STORE_MEMORY_ORDER(__m) {
   _LIBCPP_DEPRECATED_NOT_ALWAYS_LOCK_FREE(_Tp, is_always_lock_free)
    std::__cxx_atomic_store(std::addressof(__a_), __d, __m);
  }
```
It also needs a comment describing why.

https://github.com/llvm/llvm-project/pull/101439


More information about the libcxx-commits mailing list