This patch adds the address function to __atomic_ref_base.
libstdc++-v3/ChangeLog:
* include/bits/atomic_base.h: Implement address().
* include/bits/version.def: Bump version number.
* include/bits/version.h: Regenerate.
* testsuite/29_atomics/atomic_ref/address.cc: New test.
}
#endif // __glibcxx_atomic_wait
+#if __glibcxx_atomic_ref >= 202411L
+ _GLIBCXX_ALWAYS_INLINE constexpr const _Tp*
+ address() const noexcept
+ { return _M_ptr; }
+#endif // __glibcxx_atomic_ref >= 202411L
+
protected:
_Tp* _M_ptr;
};
__atomic_impl::notify_all(this->_M_ptr);
}
#endif // __glibcxx_atomic_wait
+
+#if __glibcxx_atomic_ref >= 202411L
+ _GLIBCXX_ALWAYS_INLINE constexpr _Tp*
+ address() const noexcept
+ { return this->_M_ptr; }
+#endif // __glibcxx_atomic_ref >= 202411L
};
template<typename _Tp,
ftms = {
name = atomic_ref;
+ values = {
+ v = 202411;
+ cxxmin = 26;
+ };
values = {
v = 201806;
cxxmin = 20;
#undef __glibcxx_want_atomic_lock_free_type_aliases
#if !defined(__cpp_lib_atomic_ref)
-# if (__cplusplus >= 202002L)
+# if (__cplusplus > 202302L)
+# define __glibcxx_atomic_ref 202411L
+# if defined(__glibcxx_want_all) || defined(__glibcxx_want_atomic_ref)
+# define __cpp_lib_atomic_ref 202411L
+# endif
+# elif (__cplusplus >= 202002L)
# define __glibcxx_atomic_ref 201806L
# if defined(__glibcxx_want_all) || defined(__glibcxx_want_atomic_ref)
# define __cpp_lib_atomic_ref 201806L
--- /dev/null
+// { dg-do run { target c++26 } }
+// { dg-require-atomic-cmpxchg-word "" }
+// { dg-add-options libatomic }
+
+#include <atomic>
+#include <memory>
+#include <type_traits>
+
+#include <testsuite_hooks.h>
+
+template <typename T>
+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*> );
+ VERIFY( std::addressof(x) == a.address() );
+}
+
+template <typename T>
+void testAtomicRefAddressForCV()
+{
+ testAtomicRefAddress<T>();
+ testAtomicRefAddress<const T>();
+ testAtomicRefAddress<volatile T>();
+ testAtomicRefAddress<const volatile T>();
+}
+
+int
+main ()
+{
+ struct X { int c; };
+ testAtomicRefAddressForCV<X>();
+ testAtomicRefAddressForCV<int>();
+ testAtomicRefAddressForCV<float>();
+ testAtomicRefAddressForCV<char*>();
+}