From Jason Turner

[expr.new]

Diff to HTML by rtfpessoa

Files changed (1) hide show
  1. tmp/tmponnombgo/{from.md → to.md} +57 -59
tmp/tmponnombgo/{from.md → to.md} RENAMED
@@ -1,17 +1,17 @@
1
  #### New <a id="expr.new">[[expr.new]]</a>
2
 
3
  The *new-expression* attempts to create an object of the *type-id*
4
  [[dcl.name]] or *new-type-id* to which it is applied. The type of that
5
  object is the *allocated type*. This type shall be a complete object
6
- type, but not an abstract class type or array thereof (
7
- [[intro.object]], [[basic.types]], [[class.abstract]]).
8
 
9
  [*Note 1*: Because references are not objects, references cannot be
10
  created by *new-expression*s. — *end note*]
11
 
12
- [*Note 2*: The *type-id* may be a cv-qualified type, in which case the
13
  object created by the *new-expression* has a cv-qualified
14
  type. — *end note*]
15
 
16
  ``` bnf
17
  new-expression:
@@ -117,27 +117,10 @@ returning `int`).
117
 
118
  — *end example*]
119
 
120
  — *end note*]
121
 
122
- Objects created by a *new-expression* have dynamic storage duration
123
- [[basic.stc.dynamic]].
124
-
125
- [*Note 5*: The lifetime of such an object is not necessarily
126
- restricted to the scope in which it is created. — *end note*]
127
-
128
- When the allocated object is not an array, the result of the
129
- *new-expression* is a pointer to the object created.
130
-
131
- When the allocated object is an array (that is, the
132
- *noptr-new-declarator* syntax is used or the *new-type-id* or *type-id*
133
- denotes an array type), the *new-expression* yields a pointer to the
134
- initial element (if any) of the array.
135
-
136
- [*Note 6*: Both `new int` and `new int[10]` have type `int*` and the
137
- type of `new int[i][10]` is `int (*)[10]` — *end note*]
138
-
139
  The *attribute-specifier-seq* in a *noptr-new-declarator* appertains to
140
  the associated array type.
141
 
142
  Every *constant-expression* in a *noptr-new-declarator* shall be a
143
  converted constant expression [[expr.const]] of type `std::size_t` and
@@ -149,12 +132,12 @@ well-formed (because `n` is the *expression* of a
149
  `n` is not a constant expression). — *end example*]
150
 
151
  If the *type-id* or *new-type-id* denotes an array type of unknown bound
152
  [[dcl.array]], the *new-initializer* shall not be omitted; the allocated
153
  object is an array with `n` elements, where `n` is determined from the
154
- number of initial elements supplied in the *new-initializer* (
155
- [[dcl.init.aggr]], [[dcl.init.string]]).
156
 
157
  If the *expression* in a *noptr-new-declarator* is present, it is
158
  implicitly converted to `std::size_t`. The *expression* is erroneous if:
159
 
160
  - the expression is of non-class type and its value before converting to
@@ -169,12 +152,12 @@ implicitly converted to `std::size_t`. The *expression* is erroneous if:
169
  terminating `'\0'` in a *string-literal* [[lex.string]]) exceeds the
170
  number of elements to initialize.
171
 
172
  If the *expression* is erroneous after converting to `std::size_t`:
173
 
174
- - if the *expression* is a core constant expression, the program is
175
- ill-formed;
176
  - otherwise, an allocation function is not called; instead
177
  - if the allocation function that would have been called has a
178
  non-throwing exception specification [[except.spec]], the value of
179
  the *new-expression* is the null pointer value of the required
180
  result type;
@@ -183,10 +166,26 @@ If the *expression* is erroneous after converting to `std::size_t`:
183
  `std::bad_array_new_length` [[new.badlength]].
184
 
185
  When the value of the *expression* is zero, the allocation function is
186
  called to allocate an array with no elements.
187
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
188
  A *new-expression* may obtain storage for the object by calling an
189
  allocation function [[basic.stc.dynamic.allocation]]. If the
190
  *new-expression* terminates by throwing an exception, it may release
191
  storage by calling a deallocation function
192
  [[basic.stc.dynamic.deallocation]]. If the allocated type is a non-array
@@ -194,28 +193,28 @@ type, the allocation function’s name is `operator new` and the
194
  deallocation function’s name is `operator delete`. If the allocated type
195
  is an array type, the allocation function’s name is `operator new[]` and
196
  the deallocation function’s name is `operator delete[]`.
197
 
198
  [*Note 7*: An implementation is required to provide default definitions
199
- for the global allocation functions ([[basic.stc.dynamic]],
200
- [[new.delete.single]], [[new.delete.array]]). A C++ program can provide
201
- alternative definitions of these functions [[replacement.functions]]
202
- and/or class-specific versions [[class.free]]. The set of allocation and
203
- deallocation functions that may be called by a *new-expression* may
204
- include functions that do not perform allocation or deallocation; for
205
- example, see [[new.delete.placement]]. — *end note*]
206
 
207
- If the *new-expression* begins with a unary `::` operator, the
208
- allocation function’s name is looked up in the global scope. Otherwise,
209
- if the allocated type is a class type `T` or array thereof, the
210
- allocation function’s name is looked up in the scope of `T`. If this
211
- lookup fails to find the name, or if the allocated type is not a class
212
- type, the allocation function’s name is looked up in the global scope.
213
 
214
  An implementation is allowed to omit a call to a replaceable global
215
- allocation function ([[new.delete.single]], [[new.delete.array]]). When
216
- it does so, the storage is instead provided by the implementation or
217
  provided by extending the allocation of another *new-expression*.
218
 
219
  During an evaluation of a constant expression, a call to an allocation
220
  function is always omitted.
221
 
@@ -346,12 +345,12 @@ from one invocation of `new` to another.
346
 
347
  — *end example*]
348
 
349
  [*Note 10*: Unless an allocation function has a non-throwing exception
350
  specification [[except.spec]], it indicates failure to allocate storage
351
- by throwing a `std::bad_alloc` exception (
352
- [[basic.stc.dynamic.allocation]], [[except]], [[bad.alloc]]); it returns
353
  a non-null pointer otherwise. If the allocation function has a
354
  non-throwing exception specification, it returns null to indicate
355
  failure to allocate storage and a non-null pointer
356
  otherwise. — *end note*]
357
 
@@ -382,34 +381,33 @@ evaluations of expressions in the *new-initializer*. Initialization of
382
  the allocated object is sequenced before the value computation of the
383
  *new-expression*.
384
 
385
  If the *new-expression* creates an object or an array of objects of
386
  class type, access and ambiguity control are done for the allocation
387
- function, the deallocation function [[class.free]], and the constructor
388
- [[class.ctor]] selected for the initialization (if any). If the
389
- *new-expression* creates an array of objects of class type, the
390
- destructor is potentially invoked [[class.dtor]].
391
 
392
- If any part of the object initialization described above[^24] terminates
393
- by throwing an exception and a suitable deallocation function can be
394
- found, the deallocation function is called to free the memory in which
395
- the object was being constructed, after which the exception continues to
396
- propagate in the context of the *new-expression*. If no unambiguous
397
- matching deallocation function can be found, propagating the exception
398
- does not cause the object’s memory to be freed.
 
399
 
400
  [*Note 13*: This is appropriate when the called allocation function
401
  does not allocate memory; otherwise, it is likely to result in a memory
402
  leak. — *end note*]
403
 
404
- If the *new-expression* begins with a unary `::` operator, the
405
- deallocation function’s name is looked up in the global scope.
406
- Otherwise, if the allocated type is a class type `T` or an array
407
- thereof, the deallocation function’s name is looked up in the scope of
408
- `T`. If this lookup fails to find the name, or if the allocated type is
409
- not a class type or array thereof, the deallocation function’s name is
410
- looked up in the global scope.
411
 
412
  A declaration of a placement deallocation function matches the
413
  declaration of a placement allocation function if it has the same number
414
  of parameters and, after parameter transformations [[dcl.fct]], all
415
  parameter types except the first are identical. If the lookup finds a
 
1
  #### New <a id="expr.new">[[expr.new]]</a>
2
 
3
  The *new-expression* attempts to create an object of the *type-id*
4
  [[dcl.name]] or *new-type-id* to which it is applied. The type of that
5
  object is the *allocated type*. This type shall be a complete object
6
+ type [[term.incomplete.type]], but not an abstract class type
7
+ [[class.abstract]] or array thereof [[intro.object]].
8
 
9
  [*Note 1*: Because references are not objects, references cannot be
10
  created by *new-expression*s. — *end note*]
11
 
12
+ [*Note 2*: The *type-id* can be a cv-qualified type, in which case the
13
  object created by the *new-expression* has a cv-qualified
14
  type. — *end note*]
15
 
16
  ``` bnf
17
  new-expression:
 
117
 
118
  — *end example*]
119
 
120
  — *end note*]
121
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
122
  The *attribute-specifier-seq* in a *noptr-new-declarator* appertains to
123
  the associated array type.
124
 
125
  Every *constant-expression* in a *noptr-new-declarator* shall be a
126
  converted constant expression [[expr.const]] of type `std::size_t` and
 
132
  `n` is not a constant expression). — *end example*]
133
 
134
  If the *type-id* or *new-type-id* denotes an array type of unknown bound
135
  [[dcl.array]], the *new-initializer* shall not be omitted; the allocated
136
  object is an array with `n` elements, where `n` is determined from the
137
+ number of initial elements supplied in the *new-initializer*
138
+ [[dcl.init.aggr]], [[dcl.init.string]].
139
 
140
  If the *expression* in a *noptr-new-declarator* is present, it is
141
  implicitly converted to `std::size_t`. The *expression* is erroneous if:
142
 
143
  - the expression is of non-class type and its value before converting to
 
152
  terminating `'\0'` in a *string-literal* [[lex.string]]) exceeds the
153
  number of elements to initialize.
154
 
155
  If the *expression* is erroneous after converting to `std::size_t`:
156
 
157
+ - if the *expression* is a potentially-evaluated core constant
158
+ expression, the program is ill-formed;
159
  - otherwise, an allocation function is not called; instead
160
  - if the allocation function that would have been called has a
161
  non-throwing exception specification [[except.spec]], the value of
162
  the *new-expression* is the null pointer value of the required
163
  result type;
 
166
  `std::bad_array_new_length` [[new.badlength]].
167
 
168
  When the value of the *expression* is zero, the allocation function is
169
  called to allocate an array with no elements.
170
 
171
+ Objects created by a *new-expression* have dynamic storage duration
172
+ [[basic.stc.dynamic]].
173
+
174
+ [*Note 5*: The lifetime of such an object is not necessarily
175
+ restricted to the scope in which it is created. — *end note*]
176
+
177
+ When the allocated type is “array of `N` `T`” (that is, the
178
+ *noptr-new-declarator* syntax is used or the *new-type-id* or *type-id*
179
+ denotes an array type), the *new-expression* yields a prvalue of type
180
+ “pointer to `T`” that points to the initial element (if any) of the
181
+ array. Otherwise, let `T` be the allocated type; the *new-expression* is
182
+ a prvalue of type “pointer to T” that points to the object created.
183
+
184
+ [*Note 6*: Both `new int` and `new int[10]` have type `int*` and the
185
+ type of `new int[i][10]` is `int (*)[10]`. — *end note*]
186
+
187
  A *new-expression* may obtain storage for the object by calling an
188
  allocation function [[basic.stc.dynamic.allocation]]. If the
189
  *new-expression* terminates by throwing an exception, it may release
190
  storage by calling a deallocation function
191
  [[basic.stc.dynamic.deallocation]]. If the allocated type is a non-array
 
193
  deallocation function’s name is `operator delete`. If the allocated type
194
  is an array type, the allocation function’s name is `operator new[]` and
195
  the deallocation function’s name is `operator delete[]`.
196
 
197
  [*Note 7*: An implementation is required to provide default definitions
198
+ for the global allocation functions
199
+ [[basic.stc.dynamic]], [[new.delete.single]], [[new.delete.array]]. A
200
+ C++ program can provide alternative definitions of these functions
201
+ [[replacement.functions]] and/or class-specific versions [[class.free]].
202
+ The set of allocation and deallocation functions that can be called by a
203
+ *new-expression* can include functions that do not perform allocation or
204
+ deallocation; for example, see [[new.delete.placement]]. — *end note*]
205
 
206
+ If the *new-expression* does not begin with a unary `::` operator and
207
+ the allocated type is a class type `T` or array thereof, a search is
208
+ performed for the allocation function’s name in the scope of `T`
209
+ [[class.member.lookup]]. Otherwise, or if nothing is found, the
210
+ allocation function’s name is looked up by searching for it in the
211
+ global scope.
212
 
213
  An implementation is allowed to omit a call to a replaceable global
214
+ allocation function [[new.delete.single]], [[new.delete.array]]. When it
215
+ does so, the storage is instead provided by the implementation or
216
  provided by extending the allocation of another *new-expression*.
217
 
218
  During an evaluation of a constant expression, a call to an allocation
219
  function is always omitted.
220
 
 
345
 
346
  — *end example*]
347
 
348
  [*Note 10*: Unless an allocation function has a non-throwing exception
349
  specification [[except.spec]], it indicates failure to allocate storage
350
+ by throwing a `std::bad_alloc` exception
351
+ [[basic.stc.dynamic.allocation]], [[except]], [[bad.alloc]]; it returns
352
  a non-null pointer otherwise. If the allocation function has a
353
  non-throwing exception specification, it returns null to indicate
354
  failure to allocate storage and a non-null pointer
355
  otherwise. — *end note*]
356
 
 
381
  the allocated object is sequenced before the value computation of the
382
  *new-expression*.
383
 
384
  If the *new-expression* creates an object or an array of objects of
385
  class type, access and ambiguity control are done for the allocation
386
+ function, the deallocation function [[basic.stc.dynamic.deallocation]],
387
+ and the constructor [[class.ctor]] selected for the initialization (if
388
+ any). If the *new-expression* creates an array of objects of class type,
389
+ the destructor is potentially invoked [[class.dtor]].
390
 
391
+ If any part of the object initialization described above[^24]
392
+
393
+ terminates by throwing an exception and a suitable deallocation function
394
+ can be found, the deallocation function is called to free the memory in
395
+ which the object was being constructed, after which the exception
396
+ continues to propagate in the context of the *new-expression*. If no
397
+ unambiguous matching deallocation function can be found, propagating the
398
+ exception does not cause the object’s memory to be freed.
399
 
400
  [*Note 13*: This is appropriate when the called allocation function
401
  does not allocate memory; otherwise, it is likely to result in a memory
402
  leak. — *end note*]
403
 
404
+ If the *new-expression* does not begin with a unary `::` operator and
405
+ the allocated type is a class type `T` or an array thereof, a search is
406
+ performed for the deallocation function’s name in the scope of `T`.
407
+ Otherwise, or if nothing is found, the deallocation function’s name is
408
+ looked up by searching for it in the global scope.
 
 
409
 
410
  A declaration of a placement deallocation function matches the
411
  declaration of a placement allocation function if it has the same number
412
  of parameters and, after parameter transformations [[dcl.fct]], all
413
  parameter types except the first are identical. If the lookup finds a