|
| 1 | +<?xml version='1.0' encoding='utf-8' standalone='no'?> |
| 2 | +<!DOCTYPE issue SYSTEM "lwg-issue.dtd"> |
| 3 | + |
| 4 | +<issue num="4451" status="New"> |
| 5 | +<title>`make_shared` should not refer to a type `U[N]` for runtime N</title> |
| 6 | +<section><sref ref="[util.smartptr.shared.create]"/></section> |
| 7 | +<submitter>Jonathan Wakely</submitter> |
| 8 | +<date>05 Nov 2025</date> |
| 9 | +<priority>99</priority> |
| 10 | + |
| 11 | +<discussion> |
| 12 | +<b>Addresses <a href="https://github.com/cplusplus/nbballot/issues/718">US 76-139</a></b> |
| 13 | +<p> |
| 14 | +The overloads of `make_shared` and `allocate_shared` for creating |
| 15 | +<code>shared_ptr<T[]></code> refer to an object a type `U[N]` |
| 16 | +where `N` is a function parameter not a constant expression. |
| 17 | +</p> |
| 18 | +</discussion> |
| 19 | + |
| 20 | +<resolution> |
| 21 | +<p> |
| 22 | +This wording is relative to <paper num="N5014"/>. |
| 23 | +</p> |
| 24 | + |
| 25 | +<ol> |
| 26 | +<li><p>Modify <sref ref="[util.smartptr.shared.create]"/>, as indicated:</p> |
| 27 | + |
| 28 | +<blockquote> |
| 29 | +<pre> |
| 30 | +template<class T> |
| 31 | + constexpr shared_ptr<T> make_shared(size_t N); <i>// T is U[]</i> |
| 32 | +template<class T, class A> |
| 33 | + constexpr shared_ptr<T> allocate_shared(const A& a, size_t N); <i>// T is U[]</i> |
| 34 | +</pre> |
| 35 | +<blockquote> |
| 36 | +<p>-12- <i>Constraints</i>: |
| 37 | +`T` is |
| 38 | +<del>of the form `U[]`</del> |
| 39 | +<ins>an array of unknown bound</ins>. |
| 40 | +</p> |
| 41 | +<p>-13- <i>Returns</i>: |
| 42 | +A `shared_ptr` to an <del>object of type `U[N]`</del> |
| 43 | +<ins> array of `N` elements of type <code>remove_extent_t<T></code></ins> |
| 44 | +with a default initial value<del>, |
| 45 | +where `U` is <code>remove_extent_t<T></code></del>. |
| 46 | +</p> |
| 47 | +<p>-14- [<i>Example 2</i>: ...]</p> |
| 48 | +</blockquote> |
| 49 | + |
| 50 | +<pre> |
| 51 | +template<class T> |
| 52 | + constexpr shared_ptr<T> make_shared(); <i>// T is U[N]</i> |
| 53 | +template<class T, class A> |
| 54 | + constexpr shared_ptr<T> allocate_shared(const A& a); <i>// T is U[N]</i> |
| 55 | +</pre> |
| 56 | +<blockquote> |
| 57 | +<p>-15- <i>Constraints</i>: |
| 58 | +`T` is <del>of the form `U[N]`</del> |
| 59 | +<ins>an array of known bound</ins>. |
| 60 | +</p> |
| 61 | +<p>-16- <i>Returns</i>: |
| 62 | +A `shared_ptr` to an object of type `T` with a default initial value. |
| 63 | +</p> |
| 64 | +<p>-17- [<i>Example 3</i>: ...]</p> |
| 65 | +</blockquote> |
| 66 | + |
| 67 | +<pre> |
| 68 | +template<class T> |
| 69 | + constexpr shared_ptr<T> make_shared(size_t N, |
| 70 | + const remove_extent_t<T>& u); <i>// T is U[]</i> |
| 71 | +template<class T, class A> |
| 72 | + constexpr shared_ptr<T> allocate_shared(const A& a, size_t N, |
| 73 | + const remove_extent_t<T>& u); <i>// T is U[]</i> |
| 74 | +</pre> |
| 75 | +<blockquote> |
| 76 | +<p>-18- <i>Constraints</i>: |
| 77 | +`T` is |
| 78 | +<del>of the form `U[]`</del> |
| 79 | +<ins>an array of unknown bound</ins>. |
| 80 | +</p> |
| 81 | +<p>-19- <i>Returns</i>: |
| 82 | +A `shared_ptr` to an <del>object of type `U[N]`</del> |
| 83 | +<ins> array of `N` elements of type <code>remove_extent_t<T></code></ins> |
| 84 | +where |
| 85 | +<del>`U` is <code>remove_extent_t<T></code> and</del> |
| 86 | +each array element has an initial value of `u`. |
| 87 | +</p> |
| 88 | +<p>-20- [<i>Example 4</i>: ...]</p> |
| 89 | +</blockquote> |
| 90 | + |
| 91 | +<pre> |
| 92 | +template<class T> |
| 93 | + constexpr shared_ptr<T> make_shared(const remove_extent_t<T>& u); <i>// T is U[N]</i> |
| 94 | +template<class T, class A> |
| 95 | + constexpr shared_ptr<T> allocate_shared(const A& a, |
| 96 | + const remove_extent_t<T>& u); <i>// T is U[N]</i> |
| 97 | +</pre> |
| 98 | +<blockquote> |
| 99 | +<p>-21- <i>Constraints</i>: |
| 100 | +`T` is <del>of the form `U[N]`</del> |
| 101 | +<ins>an array of known bound</ins>. |
| 102 | +</p> |
| 103 | +<p>-22- <i>Returns</i>: |
| 104 | +A `shared_ptr` to an object of type `T`, where each array element of type |
| 105 | +<code>remove_extent_t<T></code> has an initial value of `u`. |
| 106 | +</p> |
| 107 | +<p>-23- [<i>Example 5</i>: ...]</p> |
| 108 | +</blockquote> |
| 109 | + |
| 110 | + |
| 111 | +<pre> |
| 112 | +template<class T> |
| 113 | + constexpr shared_ptr<T> make_shared_for_overwrite(); <i>// T is U[N]</i> |
| 114 | +template<class T, class A> |
| 115 | + constexpr shared_ptr<T> allocate_shared_for_overwrite(const A& a); <i>// T is U[N]</i> |
| 116 | +</pre> |
| 117 | +<blockquote> |
| 118 | +<p>-24- <i>Constraints</i>: |
| 119 | +`T` is not an array of unknown bound. |
| 120 | +</p> |
| 121 | +<p>-25- <i>Returns</i>: |
| 122 | +A `shared_ptr` to an object of type `T`. |
| 123 | +</p> |
| 124 | +<p>-26- [<i>Example 6</i>: ...]</p> |
| 125 | +</blockquote> |
| 126 | + |
| 127 | +<pre> |
| 128 | +template<class T> |
| 129 | + constexpr shared_ptr<T> make_shared_for_overwrite(size_t N); <i>// T is U[]</i> |
| 130 | +template<class T, class A> |
| 131 | + constexpr shared_ptr<T> allocate_shared_for_overwrite(const A& a, size_t N); <i>// T is U[]</i> |
| 132 | +</pre> |
| 133 | +<blockquote> |
| 134 | +<p>-27- <i>Constraints</i>: |
| 135 | +`T` is an array of unknown bound. |
| 136 | +</p> |
| 137 | +<p>-28- <i>Returns</i>: |
| 138 | +A `shared_ptr` to an <del>object of type `U[N]`</del> |
| 139 | +<ins> array of `N` elements of type <code>remove_extent_t<T></code></ins> |
| 140 | +<del>, where `U` is <code>remove_extent_t<T></code></del>. |
| 141 | +</p> |
| 142 | +<p>-29- [<i>Example 7</i>: ...]</p> |
| 143 | +</blockquote> |
| 144 | + |
| 145 | +</blockquote> |
| 146 | +</li> |
| 147 | +</ol> |
| 148 | + |
| 149 | +</resolution> |
| 150 | + |
| 151 | +</issue> |
0 commit comments