Proposed Resolution for NB Comment GB13-309 atomic_ref<T> is not convertible to atomic_ref<const T>

Document #: P3860R0 [Latest] [Status]
Date: 2025-10-04
Project: Programming Language C++
Audience: LEWG, LWG
Reply-to: Hui Xie
<>
Damien Lebrun-Grandié
<>

1 Abstract

This paper proposes a converting constructor for atomic_ref as the resolution for UK NB Comment GB13-309.

2 Introduction

The UK NB Comment GB13-309 pointed out that atomic_ref<T> is not convertible to atomic_ref<const T>. [P3323R1] added cv qualifiers to atomic and atomic_ref. However, the conversion constructor of atomic_ref between different cv qualifiers is overlooked.

3 Wording

Change [atomics.ref.generic.general] as follows:

    constexpr explicit atomic_ref(T&);
    constexpr atomic_ref(const atomic_ref&) noexcept;
    template <class U>
    constexpr atomic_ref(const atomic_ref<U>&);

Add a new entry to [atomics.ref.ops] after paragraph 8:

template <class U>
constexpr atomic_ref(const atomic_ref<U>& ref);

9 Contraints:

  • (9.1) is_same_v<remove_cv_t<T>, remove_cv_t<U>> is true, and

  • (9.2) is_convertible_v<U*, T*> is true

10 Postconditions: *this references the object referenced by ref.

4 Implementation Experience

[P3323R1] is currently being implemented in libc++ and adding the proposed constructor is under way.

5 Feature Test Macro

[P3323R1] does not seem to mention Feature Test Macro

6 References

[P3323R1] Gonzalo Brito Gadeschi. 2024-11-18. cv-qualified types in atomic and atomic_ref.
https://wg21.link/p3323r1