[libcxx-commits] [libcxx] [libc++] Implement P0493R5: Atomic minimum/maximum (PR #180333)
via libcxx-commits
libcxx-commits at lists.llvm.org
Sun Jun 21 01:39:01 PDT 2026
================
@@ -259,6 +261,77 @@ __cxx_atomic_fetch_xor(__cxx_atomic_base_impl<_Tp>* __a, _Tp __pattern, memory_o
std::addressof(__a->__a_value), __pattern, static_cast<__memory_order_underlying_t>(__order));
}
+// Clang's __c11_atomic_fetch_max/min builtins do not accept pointer
+// arguments, so dispatch to a CAS loop for pointer types.
+// TODO: Use the builtin for pointer types once Clang accepts them.
+template <class _Tp, __enable_if_t<!is_pointer<_Tp>::value, int> = 0>
----------------
huixie90 wrote:
It seems that the builtin has implemented the Sema check properly so I think we can write a simple concept to do the dispatch (I think it is reasonable to guard the language version at least to C++ 20 to use concept instead of enable_if. What do you think?
https://godbolt.org/z/8vbqhev3o
something like
``` cpp
if constexpr (has_c11_atomic_minmax<T>)
// use builtin
else
// use cas loop
```
https://github.com/llvm/llvm-project/pull/180333
More information about the libcxx-commits
mailing list