STL icon indicating copy to clipboard operation
STL copied to clipboard

P3860R1 Make `atomic_ref<T>` Convertible To `atomic_ref<const T>`

Open StephanTLavavej opened this issue 2 months ago • 1 comments

WG21-P3860R1 Make atomic_ref<T> Convertible To atomic_ref<const T>

This was officially voted in as a C++20 Defect Report during the November 2025 meeting.

No feature-test macro is being added, intentionally.

Followup to #5147, which we implemented unconditionally with #5213.

"I remember that we cleared this world out. We won. Is a future coming in which we will, eventually, truly, have won?" - Ra, by qntm

StephanTLavavej avatar Nov 10 '25 22:11 StephanTLavavej

I found that explicitly constructing atomic_ref<const T> from atomic_ref<T> was well-formed even before this DR, but it was broken because the constructor bound a temporary object (created due to operator T) to the stored reference.

This DR fixed such construction. However, it's still possible to explicitly construct atomic_ref<const T> from atomic_ref<volatile T> (when the latter is well-formed), which doesn't seem to make sense. I'm trying to file an LWG issue for this.

Edit: Perhaps adding an explicit atomic_ref(T&&) = delete; overload would be fine.

frederick-vs-ja avatar Nov 11 '25 09:11 frederick-vs-ja