[libcxx-commits] [libcxx] [libc++] Implement LWG4472: std::atomic_ref<const T> can be construct… (PR #208131)
Avi Patel via libcxx-commits
libcxx-commits at lists.llvm.org
Tue Jul 7 19:16:32 PDT 2026
https://github.com/firedog1234 updated https://github.com/llvm/llvm-project/pull/208131
>From 54aa6b59fd6e6964ea351f7dd12a4ed0358ae454 Mon Sep 17 00:00:00 2001
From: avipatel <aviipatel06 at gmail.com>
Date: Tue, 7 Jul 2026 21:19:43 -0400
Subject: [PATCH 1/2] [libc++] Implement LWG4472: std::atomic_ref<const T> can
be constructed from temporaries
---
libcxx/docs/Status/Cxx26Issues.csv | 2 +-
libcxx/include/__atomic/atomic_ref.h | 8 ++++++++
libcxx/test/std/atomics/atomics.ref/ctor.pass.cpp | 6 +++++-
3 files changed, 14 insertions(+), 2 deletions(-)
diff --git a/libcxx/docs/Status/Cxx26Issues.csv b/libcxx/docs/Status/Cxx26Issues.csv
index 23adfde5bd4d7..ade40adc499fe 100644
--- a/libcxx/docs/Status/Cxx26Issues.csv
+++ b/libcxx/docs/Status/Cxx26Issues.csv
@@ -295,7 +295,7 @@
"`LWG4467 <https://wg21.link/LWG4467>`__","``hive::splice`` can throw ``bad_alloc``","2026-03 (Croydon)","","","`#189837 <https://github.com/llvm/llvm-project/issues/189837>`__",""
"`LWG4468 <https://wg21.link/LWG4468>`__","§[const.wrap.class] ""``operator decltype(auto)``"" is ill-formed","2026-03 (Croydon)","|Complete|","23","`#189838 <https://github.com/llvm/llvm-project/issues/189838>`__",""
"`LWG4469 <https://wg21.link/LWG4469>`__","Names of parameters of addressable function shall remain unspecified","2026-03 (Croydon)","","","`#189839 <https://github.com/llvm/llvm-project/issues/189839>`__",""
-"`LWG4472 <https://wg21.link/LWG4472>`__","``std::atomic_ref<const T>`` can be constructed from temporaries","2026-03 (Croydon)","","","`#189840 <https://github.com/llvm/llvm-project/issues/189840>`__",""
+"`LWG4472 <https://wg21.link/LWG4472>`__","``std::atomic_ref<const T>`` can be constructed from temporaries","2026-03 (Croydon)","|Complete|","23","`#189840 <https://github.com/llvm/llvm-project/issues/189840>`__",""
"`LWG4474 <https://wg21.link/LWG4474>`__","""``round_to_nearest``"" rounding mode is unclear","2026-03 (Croydon)","","","`#189841 <https://github.com/llvm/llvm-project/issues/189841>`__",""
"`LWG4476 <https://wg21.link/LWG4476>`__","``run_loop`` should not have a ``set_error`` completion","2026-03 (Croydon)","","","`#189842 <https://github.com/llvm/llvm-project/issues/189842>`__",""
"`LWG4477 <https://wg21.link/LWG4477>`__","Placement ``operator delete`` should be constexpr","2026-03 (Croydon)","|Complete|","23","`#189843 <https://github.com/llvm/llvm-project/issues/189843>`__",""
diff --git a/libcxx/include/__atomic/atomic_ref.h b/libcxx/include/__atomic/atomic_ref.h
index c551f99024931..93f19a740ba3a 100644
--- a/libcxx/include/__atomic/atomic_ref.h
+++ b/libcxx/include/__atomic/atomic_ref.h
@@ -259,6 +259,8 @@ struct atomic_ref : public __atomic_ref_base<_Tp> {
"atomic_ref ctor: referenced object must be aligned to required_alignment");
}
+ _LIBCPP_HIDE_FROM_ABI explicit atomic_ref(_Tp&&) = delete;
+
_LIBCPP_HIDE_FROM_ABI atomic_ref(const atomic_ref&) noexcept = default;
_LIBCPP_HIDE_FROM_ABI _Tp operator=(_Tp __desired) const noexcept { return __base::operator=(__desired); }
@@ -279,6 +281,8 @@ struct atomic_ref<_Tp> : public __atomic_ref_base<_Tp> {
"atomic_ref ctor: referenced object must be aligned to required_alignment");
}
+ _LIBCPP_HIDE_FROM_ABI explicit atomic_ref(_Tp&&) = delete;
+
_LIBCPP_HIDE_FROM_ABI atomic_ref(const atomic_ref&) noexcept = default;
_LIBCPP_HIDE_FROM_ABI _Tp operator=(_Tp __desired) const noexcept { return __base::operator=(__desired); }
@@ -325,6 +329,8 @@ struct atomic_ref<_Tp> : public __atomic_ref_base<_Tp> {
"atomic_ref ctor: referenced object must be aligned to required_alignment");
}
+ _LIBCPP_HIDE_FROM_ABI explicit atomic_ref(_Tp&&) = delete;
+
_LIBCPP_HIDE_FROM_ABI atomic_ref(const atomic_ref&) noexcept = default;
_LIBCPP_HIDE_FROM_ABI _Tp operator=(_Tp __desired) const noexcept { return __base::operator=(__desired); }
@@ -368,6 +374,8 @@ struct atomic_ref<_Tp*> : public __atomic_ref_base<_Tp*> {
_LIBCPP_HIDE_FROM_ABI explicit atomic_ref(_Tp*& __ptr) : __base(__ptr) {}
+ _LIBCPP_HIDE_FROM_ABI explicit atomic_ref(_Tp*&&) = delete;
+
_LIBCPP_HIDE_FROM_ABI _Tp* operator=(_Tp* __desired) const noexcept { return __base::operator=(__desired); }
atomic_ref& operator=(const atomic_ref&) = delete;
diff --git a/libcxx/test/std/atomics/atomics.ref/ctor.pass.cpp b/libcxx/test/std/atomics/atomics.ref/ctor.pass.cpp
index 9fb06de357eb4..d37fa245d974e 100644
--- a/libcxx/test/std/atomics/atomics.ref/ctor.pass.cpp
+++ b/libcxx/test/std/atomics/atomics.ref/ctor.pass.cpp
@@ -11,6 +11,7 @@
// <atomic>
// explicit atomic_ref(T&);
+// explicit atomic_ref(T&&) = delete;
#include <atomic>
#include <type_traits>
@@ -21,10 +22,13 @@
template <typename T>
struct TestCtor {
void operator()() const {
- // check that the constructor is explicit
static_assert(!std::is_convertible_v<T, std::atomic_ref<T>>);
static_assert(std::is_constructible_v<std::atomic_ref<T>, T&>);
+ static_assert(!std::is_constructible_v<std::atomic_ref<T>, T&&>);
+ static_assert(!std::is_constructible_v<std::atomic_ref<const T>, T&&>);
+ static_assert(!std::is_constructible_v<std::atomic_ref<const T>, const T&&>);
+
alignas(std::atomic_ref<T>::required_alignment) T x(T(0));
std::atomic_ref<T> a(x);
(void)a;
>From e833ab2e98cd1d970e1bee45d2f04ef2a5384f54 Mon Sep 17 00:00:00 2001
From: avipatel <aviipatel06 at gmail.com>
Date: Tue, 7 Jul 2026 22:15:28 -0400
Subject: [PATCH 2/2] chore: added back comment for clarity
---
libcxx/test/std/atomics/atomics.ref/ctor.pass.cpp | 1 +
1 file changed, 1 insertion(+)
diff --git a/libcxx/test/std/atomics/atomics.ref/ctor.pass.cpp b/libcxx/test/std/atomics/atomics.ref/ctor.pass.cpp
index d37fa245d974e..3eca6a139d061 100644
--- a/libcxx/test/std/atomics/atomics.ref/ctor.pass.cpp
+++ b/libcxx/test/std/atomics/atomics.ref/ctor.pass.cpp
@@ -22,6 +22,7 @@
template <typename T>
struct TestCtor {
void operator()() const {
+ // check that the constructor is explicit
static_assert(!std::is_convertible_v<T, std::atomic_ref<T>>);
static_assert(std::is_constructible_v<std::atomic_ref<T>, T&>);
More information about the libcxx-commits
mailing list