mirror of
git://gcc.gnu.org/git/gcc.git
synced 2025-03-24 13:01:13 +08:00
libstdc++: Define atomic lock-free type aliases for C++20 [PR98034]
libstdc++-v3/ChangeLog: PR libstdc++/98034 * include/std/atomic (__cpp_lib_atomic_lock_free_type_aliases): Define macro. (atomic_signed_lock_free, atomic_unsigned_lock_free): Define aliases. * include/std/version (__cpp_lib_atomic_lock_free_type_aliases): Define macro. * testsuite/29_atomics/atomic/lock_free_aliases.cc: New test.
This commit is contained in:
parent
2327d93314
commit
320ac807da
libstdc++-v3
@ -1727,6 +1727,23 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
|
||||
using __atomic_ref<_Tp>::operator=;
|
||||
};
|
||||
|
||||
#define __cpp_lib_atomic_lock_free_type_aliases 201907L
|
||||
#ifdef _GLIBCXX_HAVE_PLATFORM_WAIT
|
||||
using atomic_signed_lock_free
|
||||
= atomic<make_signed_t<__detail::__platform_wait_t>>;
|
||||
using atomic_unsigned_lock_free
|
||||
= atomic<make_unsigned_t<__detail::__platform_wait_t>>;
|
||||
#elif ATOMIC_INT_LOCK_FREE || !(ATOMIC_LONG_LOCK_FREE || ATOMIC_CHAR_LOCK_FREE)
|
||||
using atomic_signed_lock_free = atomic<signed int>;
|
||||
using atomic_unsigned_lock_free = atomic<unsigned int>;
|
||||
#elif ATOMIC_LONG_LOCK_FREE
|
||||
using atomic_signed_lock_free = atomic<signed long>;
|
||||
using atomic_unsigned_lock_free = atomic<unsigned long>;
|
||||
#elif ATOMIC_CHAR_LOCK_FREE
|
||||
using atomic_signed_lock_free = atomic<signed char>;
|
||||
using atomic_unsigned_lock_free = atomic<unsigned char>;
|
||||
#endif
|
||||
|
||||
#endif // C++2a
|
||||
|
||||
/// @} group atomics
|
||||
|
@ -187,6 +187,7 @@
|
||||
#define __cpp_lib_assume_aligned 201811L
|
||||
#define __cpp_lib_atomic_flag_test 201907L
|
||||
#define __cpp_lib_atomic_float 201711L
|
||||
#define __cpp_lib_atomic_lock_free_type_aliases 201907L
|
||||
#define __cpp_lib_atomic_ref 201806L
|
||||
#define __cpp_lib_atomic_value_initialization 201911L
|
||||
#define __cpp_lib_bind_front 201907L
|
||||
|
@ -0,0 +1,34 @@
|
||||
// { dg-options "-std=gnu++20" }
|
||||
// { dg-do compile { target c++20 } }
|
||||
|
||||
#include <atomic>
|
||||
|
||||
#ifndef __cpp_lib_atomic_lock_free_type_aliases
|
||||
# error "Feature test macro for lock-free type aliases is missing in <atomic>"
|
||||
#elif __cpp_lib_atomic_lock_free_type_aliases != 201907L
|
||||
# error "Feature test macro for lock-free type aliases has wrong value in <atomic>"
|
||||
#endif
|
||||
|
||||
template<typename T>
|
||||
constexpr bool is_atomic_specialization = false;
|
||||
template<typename T>
|
||||
constexpr bool is_atomic_specialization<std::atomic<T>> = true;
|
||||
|
||||
// The type aliases atomic_signed_lock_free and atomic_unsigned_lock_free
|
||||
// name specializations of atomic
|
||||
static_assert( is_atomic_specialization<std::atomic_signed_lock_free> );
|
||||
static_assert( is_atomic_specialization<std::atomic_unsigned_lock_free> );
|
||||
|
||||
#include <type_traits>
|
||||
|
||||
// ... whose template arguments are integral types,
|
||||
static_assert( std::is_integral_v<std::atomic_signed_lock_free::value_type> );
|
||||
static_assert( std::is_integral_v<std::atomic_unsigned_lock_free::value_type> );
|
||||
|
||||
// ... respectively signed and unsigned,
|
||||
static_assert( std::is_signed_v<std::atomic_signed_lock_free::value_type> );
|
||||
static_assert( std::is_unsigned_v<std::atomic_unsigned_lock_free::value_type> );
|
||||
|
||||
// and whose is_always_lock_free property is true.
|
||||
static_assert( std::atomic_signed_lock_free::is_always_lock_free );
|
||||
static_assert( std::atomic_unsigned_lock_free::is_always_lock_free );
|
Loading…
x
Reference in New Issue
Block a user