|
| 1 | +--- |
| 2 | +title: "Proposed Resolution for NB Comment GB13-309 `atomic_ref<T>` is not convertible to `atomic_ref<const T>`" |
| 3 | +document: PXXXXR0 |
| 4 | +date: 2025-10-04 |
| 5 | +audience: LEWG, LWG |
| 6 | +author: |
| 7 | + - name: Hui Xie |
| 8 | + email: <hui.xie1990@gmail.com> |
| 9 | + - name: Damien Lebrun-Grandié |
| 10 | + email: <lebrungrandt@ornl.gov> |
| 11 | +toc: true |
| 12 | +--- |
| 13 | + |
| 14 | + |
| 15 | +# Abstract |
| 16 | + |
| 17 | +This paper proposes a converting constructor for `atomic_ref` as the resolution for UK NB Comment GB13-309. |
| 18 | + |
| 19 | +# Introduction |
| 20 | + |
| 21 | +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. |
| 22 | + |
| 23 | +# Wording |
| 24 | + |
| 25 | +Change [atomics.ref.generic.general]{.sref} as follows: |
| 26 | + |
| 27 | +```cpp |
| 28 | + constexpr explicit atomic_ref(T&); |
| 29 | + constexpr atomic_ref(const atomic_ref&) noexcept; |
| 30 | + @[`template <class U>`]{.add}@ |
| 31 | + @[`constexpr atomic_ref(const atomic_ref<U>&);`]{.add}@ |
| 32 | +``` |
| 33 | +
|
| 34 | +Add a new entry to [atomics.ref.ops]{.sref} after paragraph 8: |
| 35 | +
|
| 36 | +:::add |
| 37 | +
|
| 38 | +```cpp |
| 39 | +template <class U> |
| 40 | +constexpr atomic_ref(const atomic_ref<U>& ref); |
| 41 | +``` |
| 42 | + |
| 43 | +[9]{.pnum} *Contraints*: |
| 44 | + |
| 45 | +- [9.1]{.pnum} `is_same_v<remove_cv_t<T>, remove_cv_t<U>>` is `true`, and |
| 46 | + |
| 47 | +- [9.2]{.pnum} `is_convertible_v<U*, T*>` is `true` |
| 48 | + |
| 49 | +[10]{.pnum} *Postconditions*: `*this` references the object referenced by `ref`. |
| 50 | + |
| 51 | +::: |
| 52 | + |
| 53 | +# Implementation Experience |
| 54 | + |
| 55 | +[@P3323R1] is currently being implemented in libc++ and adding the proposed constructor is under way. |
| 56 | + |
| 57 | +# Feature Test Macro |
| 58 | + |
| 59 | +[@P3323R1] does not seem to mention Feature Test Macro |
| 60 | + |
| 61 | +<style> |
| 62 | +.bq{ |
| 63 | + display: block; |
| 64 | + margin-block-start: 1em; |
| 65 | + margin-block-end: 1em; |
| 66 | + margin-inline-start: 40px; |
| 67 | + margin-inline-end: 40px; |
| 68 | +} |
| 69 | +</style> |
0 commit comments