Skip to content

Commit 4dea05c

Browse files
committed
New issue from Jonathan: make_shared should not refer to a type U[N] for runtime N
1 parent c33fb38 commit 4dea05c

File tree

1 file changed

+151
-0
lines changed

1 file changed

+151
-0
lines changed

xml/issue4451.xml

Lines changed: 151 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,151 @@
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&lt;T[]&gt;</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&lt;class T&gt;
31+
constexpr shared_ptr&lt;T&gt; make_shared(size_t N); <i>// T is U[]</i>
32+
template&lt;class T, class A&gt;
33+
constexpr shared_ptr&lt;T&gt; allocate_shared(const A&amp; 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&lt;T&gt;</code></ins>
44+
with a default initial value<del>,
45+
where `U` is <code>remove_extent_t&lt;T&gt;</code></del>.
46+
</p>
47+
<p>-14- [<i>Example 2</i>: ...]</p>
48+
</blockquote>
49+
50+
<pre>
51+
template&lt;class T&gt;
52+
constexpr shared_ptr&lt;T&gt; make_shared(); <i>// T is U[N]</i>
53+
template&lt;class T, class A&gt;
54+
constexpr shared_ptr&lt;T&gt; allocate_shared(const A&amp; 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&lt;class T&gt;
69+
constexpr shared_ptr&lt;T&gt; make_shared(size_t N,
70+
const remove_extent_t&lt;T&gt;&amp; u); <i>// T is U[]</i>
71+
template&lt;class T, class A&gt;
72+
constexpr shared_ptr&lt;T&gt; allocate_shared(const A&amp; a, size_t N,
73+
const remove_extent_t&lt;T&gt;&amp; 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&lt;T&gt;</code></ins>
84+
where
85+
<del>`U` is <code>remove_extent_t&lt;T&gt;</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&lt;class T&gt;
93+
constexpr shared_ptr&lt;T&gt; make_shared(const remove_extent_t&lt;T&gt;&amp; u); <i>// T is U[N]</i>
94+
template&lt;class T, class A&gt;
95+
constexpr shared_ptr&lt;T&gt; allocate_shared(const A&amp; a,
96+
const remove_extent_t&lt;T&gt;&amp; 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&lt;T&gt;</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&lt;class T&gt;
113+
constexpr shared_ptr&lt;T&gt; make_shared_for_overwrite(); <i>// T is U[N]</i>
114+
template&lt;class T, class A&gt;
115+
constexpr shared_ptr&lt;T&gt; allocate_shared_for_overwrite(const A&amp; 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&lt;class T&gt;
129+
constexpr shared_ptr&lt;T&gt; make_shared_for_overwrite(size_t N); <i>// T is U[]</i>
130+
template&lt;class T, class A&gt;
131+
constexpr shared_ptr&lt;T&gt; allocate_shared_for_overwrite(const A&amp; 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&lt;T&gt;</code></ins>
140+
<del>, where `U` is <code>remove_extent_t&lt;T&gt;</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

Comments
 (0)