[libcxx-commits] [libcxx] [libc++] constexpr atomic and atomic_ref (PR #98765)

Nikolas Klauser via libcxx-commits libcxx-commits at lists.llvm.org
Sun Jul 14 00:44:11 PDT 2024


================
@@ -105,23 +108,37 @@ struct __atomic_base // false
       volatile _NOEXCEPT {
     std::__atomic_wait(*this, __v, __m);
   }
-  _LIBCPP_AVAILABILITY_SYNC _LIBCPP_HIDE_FROM_ABI void
+  _LIBCPP_AVAILABILITY_SYNC _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 void
   wait(_Tp __v, memory_order __m = memory_order_seq_cst) const _NOEXCEPT {
-    std::__atomic_wait(*this, __v, __m);
+    if (__libcpp_is_constant_evaluated()) {
+      if (this->load(__m) != __v) {
+        __builtin_trap();
+      }
+    } else {
+      std::__atomic_wait(*this, __v, __m);
+    }
   }
   _LIBCPP_AVAILABILITY_SYNC _LIBCPP_HIDE_FROM_ABI void notify_one() volatile _NOEXCEPT {
     std::__atomic_notify_one(*this);
   }
-  _LIBCPP_AVAILABILITY_SYNC _LIBCPP_HIDE_FROM_ABI void notify_one() _NOEXCEPT { std::__atomic_notify_one(*this); }
+  _LIBCPP_AVAILABILITY_SYNC _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 void notify_one() _NOEXCEPT {
+    if !consteval {
----------------
philnik777 wrote:

I think this also has to use `__libcpp_is_constant_evaluated()`?

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


More information about the libcxx-commits mailing list