From 320ac807da125e6dc952b3d4abf02daeead88d44 Mon Sep 17 00:00:00 2001 From: Jonathan Wakely Date: Mon, 12 Dec 2022 12:49:40 +0000 Subject: [PATCH] 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. --- libstdc++-v3/include/std/atomic | 17 ++++++++++ libstdc++-v3/include/std/version | 1 + .../29_atomics/atomic/lock_free_aliases.cc | 34 +++++++++++++++++++ 3 files changed, 52 insertions(+) create mode 100644 libstdc++-v3/testsuite/29_atomics/atomic/lock_free_aliases.cc diff --git a/libstdc++-v3/include/std/atomic b/libstdc++-v3/include/std/atomic index 356f1458f446..857f92700495 100644 --- a/libstdc++-v3/include/std/atomic +++ b/libstdc++-v3/include/std/atomic @@ -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>; + using atomic_unsigned_lock_free + = atomic>; +#elif ATOMIC_INT_LOCK_FREE || !(ATOMIC_LONG_LOCK_FREE || ATOMIC_CHAR_LOCK_FREE) + using atomic_signed_lock_free = atomic; + using atomic_unsigned_lock_free = atomic; +#elif ATOMIC_LONG_LOCK_FREE + using atomic_signed_lock_free = atomic; + using atomic_unsigned_lock_free = atomic; +#elif ATOMIC_CHAR_LOCK_FREE + using atomic_signed_lock_free = atomic; + using atomic_unsigned_lock_free = atomic; +#endif + #endif // C++2a /// @} group atomics diff --git a/libstdc++-v3/include/std/version b/libstdc++-v3/include/std/version index 3c7c440bd808..61718ebad740 100644 --- a/libstdc++-v3/include/std/version +++ b/libstdc++-v3/include/std/version @@ -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 diff --git a/libstdc++-v3/testsuite/29_atomics/atomic/lock_free_aliases.cc b/libstdc++-v3/testsuite/29_atomics/atomic/lock_free_aliases.cc new file mode 100644 index 000000000000..02c4ccc3aa30 --- /dev/null +++ b/libstdc++-v3/testsuite/29_atomics/atomic/lock_free_aliases.cc @@ -0,0 +1,34 @@ +// { dg-options "-std=gnu++20" } +// { dg-do compile { target c++20 } } + +#include + +#ifndef __cpp_lib_atomic_lock_free_type_aliases +# error "Feature test macro for lock-free type aliases is missing in " +#elif __cpp_lib_atomic_lock_free_type_aliases != 201907L +# error "Feature test macro for lock-free type aliases has wrong value in " +#endif + +template +constexpr bool is_atomic_specialization = false; +template +constexpr bool is_atomic_specialization> = true; + +// The type aliases atomic_signed_lock_free and atomic_unsigned_lock_free +// name specializations of atomic +static_assert( is_atomic_specialization ); +static_assert( is_atomic_specialization ); + +#include + +// ... whose template arguments are integral types, +static_assert( std::is_integral_v ); +static_assert( std::is_integral_v ); + +// ... respectively signed and unsigned, +static_assert( std::is_signed_v ); +static_assert( std::is_unsigned_v ); + +// 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 );