On Sat, 28 Mar 2026, 13:50 Tomasz Kamiński, <[email protected]> wrote:

> This implements with P3936R1 Safer atomic_ref::address with
> the bump to __cpp_lib_atomic_ref feture test macro.
>
> libstdc++-v3/ChangeLog:
>
>         * include/bits/atomic_base.h
> (__atomic_ref_base::_Address_return_t):
>         Define.
>         (__atomic_ref_base::address): Change return type to
> _Address_return_t.
>         * include/bits/version.def (atomic_ref): Bump to 202503.
>

The new value should be 202603.

OK with that change.


        * include/bits/version.h: Regenerate.
>         * testsuite/29_atomics/atomic_ref/address.cc: Update check for
>         return type.
> ---
> Tested *atomic_ref* on x86_64-linux.
> OK for trunk when full testsuite passes?
>
>  libstdc++-v3/include/bits/atomic_base.h              | 10 ++++++++--
>  libstdc++-v3/include/bits/version.def                |  2 +-
>  libstdc++-v3/include/bits/version.h                  |  4 ++--
>  .../testsuite/29_atomics/atomic_ref/address.cc       | 12 ++++++------
>  4 files changed, 17 insertions(+), 11 deletions(-)
>
> diff --git a/libstdc++-v3/include/bits/atomic_base.h
> b/libstdc++-v3/include/bits/atomic_base.h
> index 6c5b83a0818..62970108ea6 100644
> --- a/libstdc++-v3/include/bits/atomic_base.h
> +++ b/libstdc++-v3/include/bits/atomic_base.h
> @@ -1649,6 +1649,8 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
>      {
>      private:
>        using _Vt = remove_cv_t<_Tp>;
> +      using _Address_return_t = __conditional_t<is_volatile_v<_Tp>,
> +                                               const volatile void*,
> const void*>;
>
>        static consteval bool
>        _S_is_always_lock_free()
> @@ -1714,7 +1716,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
>  #endif // __glibcxx_atomic_wait
>
>  #if __glibcxx_atomic_ref >= 202411L
> -      _GLIBCXX_ALWAYS_INLINE constexpr const _Tp*
> +      _GLIBCXX_ALWAYS_INLINE constexpr const _Address_return_t
>        address() const noexcept
>        { return _M_ptr; }
>  #endif // __glibcxx_atomic_ref >= 202411L
> @@ -1727,6 +1729,10 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
>      struct __atomic_ref_base
>        : __atomic_ref_base<const _Tp>
>      {
> +      using _Address_return_t = __conditional_t<is_volatile_v<_Tp>,
> +                                               volatile void*, void*>;
> +
> +    public:
>        using value_type = typename __atomic_ref_base<const
> _Tp>::value_type;
>
>        explicit
> @@ -1807,7 +1813,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
>  #endif // __glibcxx_atomic_wait
>
>  #if __glibcxx_atomic_ref >= 202411L
> -      _GLIBCXX_ALWAYS_INLINE constexpr _Tp*
> +      _GLIBCXX_ALWAYS_INLINE constexpr _Address_return_t
>        address() const noexcept
>        { return this->_M_ptr; }
>  #endif // __glibcxx_atomic_ref >= 202411L
> diff --git a/libstdc++-v3/include/bits/version.def
> b/libstdc++-v3/include/bits/version.def
> index dd77524b5a9..5aaf1550829 100644
> --- a/libstdc++-v3/include/bits/version.def
> +++ b/libstdc++-v3/include/bits/version.def
> @@ -817,7 +817,7 @@ ftms = {
>  ftms = {
>    name = atomic_ref;
>    values = {
> -    v = 202411;
> +    v = 202503;
>      cxxmin = 26;
>    };
>    values = {
> diff --git a/libstdc++-v3/include/bits/version.h
> b/libstdc++-v3/include/bits/version.h
> index bef61baeba8..ed1f0028691 100644
> --- a/libstdc++-v3/include/bits/version.h
> +++ b/libstdc++-v3/include/bits/version.h
> @@ -910,9 +910,9 @@
>
>  #if !defined(__cpp_lib_atomic_ref)
>  # if (__cplusplus >  202302L)
> -#  define __glibcxx_atomic_ref 202411L
> +#  define __glibcxx_atomic_ref 202503L
>  #  if defined(__glibcxx_want_all) || defined(__glibcxx_want_atomic_ref)
> -#   define __cpp_lib_atomic_ref 202411L
> +#   define __cpp_lib_atomic_ref 202503L
>  #  endif
>  # elif (__cplusplus >= 202002L)
>  #  define __glibcxx_atomic_ref 201806L
> diff --git a/libstdc++-v3/testsuite/29_atomics/atomic_ref/address.cc
> b/libstdc++-v3/testsuite/29_atomics/atomic_ref/address.cc
> index e2eda506efa..d4bb500185e 100644
> --- a/libstdc++-v3/testsuite/29_atomics/atomic_ref/address.cc
> +++ b/libstdc++-v3/testsuite/29_atomics/atomic_ref/address.cc
> @@ -8,26 +8,26 @@
>
>  #include <testsuite_hooks.h>
>
> -template <typename T>
> +template <typename T, typename CVV>
>  void testAtomicRefAddress()
>  {
>    T x(T(42));
>    const std::atomic_ref<T> a(x);
>
>    static_assert( noexcept(a.address()) );
> -  static_assert( std::is_same_v<decltype(a.address()), T*> );
> +  static_assert( std::is_same_v<decltype(a.address()), CVV*> );
>    VERIFY( std::addressof(x) == a.address() );
>  }
>
>  template <typename T>
>  void testAtomicRefAddressForCV()
>  {
> -  testAtomicRefAddress<T>();
> -  testAtomicRefAddress<const T>();
> +  testAtomicRefAddress<T, void>();
> +  testAtomicRefAddress<const T, const void>();
>    if constexpr (std::atomic_ref<T>::is_always_lock_free)
>    {
> -    testAtomicRefAddress<volatile T>();
> -    testAtomicRefAddress<const volatile T>();
> +    testAtomicRefAddress<volatile T, volatile void>();
> +    testAtomicRefAddress<const volatile T, const volatile void>();
>    }
>  }
>
> --
> 2.53.0
>
>

Reply via email to