Skip to content

Commit 166af4d

Browse files
jensmaurertkoeppe
authored andcommitted
[expr.new] Clarify result type and value category
Also move the relevant text to after the syntactic constraints.
1 parent a054daf commit 166af4d

File tree

1 file changed

+26
-22
lines changed

1 file changed

+26
-22
lines changed

source/expressions.tex

Lines changed: 26 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -4931,28 +4931,6 @@
49314931
\end{note}
49324932

49334933
\pnum
4934-
\indextext{storage duration!dynamic}%
4935-
Objects created by a \grammarterm{new-expression} have dynamic storage
4936-
duration\iref{basic.stc.dynamic}.
4937-
\begin{note}
4938-
\indextext{\idxcode{new}!scoping and}%
4939-
The lifetime of such an object is not necessarily restricted to the
4940-
scope in which it is created.
4941-
\end{note}
4942-
When the allocated object is not an array, the result of the \grammarterm{new-expression}
4943-
is a pointer to the object created.
4944-
4945-
\pnum
4946-
\indextext{array!\idxcode{new}}%
4947-
When the allocated object is an array (that is, the
4948-
\grammarterm{noptr-new-declarator} syntax is used or the
4949-
\grammarterm{new-type-id} or \grammarterm{type-id} denotes an array type), the
4950-
\grammarterm{new-expression} yields a pointer to the initial element (if
4951-
any) of the array.
4952-
\begin{note}
4953-
Both \tcode{\keyword{new} \keyword{int}} and \tcode{\keyword{new} \keyword{int}[10]} have type \tcode{\keyword{int}*} and
4954-
the type of \tcode{\keyword{new} \keyword{int}[i][10]} is \tcode{\keyword{int} (*)[10]}
4955-
\end{note}
49564934
The \grammarterm{attribute-specifier-seq} in a \grammarterm{noptr-new-declarator} appertains
49574935
to the associated array type.
49584936

@@ -5033,6 +5011,32 @@
50335011
When the value of the \grammarterm{expression} is zero, the allocation
50345012
function is called to allocate an array with no elements.
50355013

5014+
\pnum
5015+
\indextext{storage duration!dynamic}%
5016+
Objects created by a \grammarterm{new-expression} have dynamic storage
5017+
duration\iref{basic.stc.dynamic}.
5018+
\begin{note}
5019+
\indextext{\idxcode{new}!scoping and}%
5020+
The lifetime of such an object is not necessarily restricted to the
5021+
scope in which it is created.
5022+
\end{note}
5023+
5024+
\pnum
5025+
\indextext{array!\idxcode{new}}%
5026+
When the allocated type is ``array of \tcode{N} \tcode{T}''
5027+
(that is, the \grammarterm{noptr-new-declarator} syntax is used or the
5028+
\grammarterm{new-type-id} or \grammarterm{type-id} denotes an array type),
5029+
the \grammarterm{new-expression} yields a prvalue of type ``pointer to \tcode{T}''
5030+
that points to the initial element (if any) of the array.
5031+
Otherwise, let \tcode{T} be the allocated type;
5032+
the \grammarterm{new-expression}
5033+
is a prvalue of type ``pointer to T''
5034+
that points to the object created.
5035+
\begin{note}
5036+
Both \tcode{\keyword{new} \keyword{int}} and \tcode{\keyword{new} \keyword{int}[10]} have type \tcode{\keyword{int}*} and
5037+
the type of \tcode{\keyword{new} \keyword{int}[i][10]} is \tcode{\keyword{int} (*)[10]}.
5038+
\end{note}
5039+
50365040
\pnum
50375041
A \grammarterm{new-expression} may obtain storage for the object by calling an
50385042
allocation function\iref{basic.stc.dynamic.allocation}. If

0 commit comments

Comments
 (0)