From Jason Turner

[expr.unary]

Diff to HTML by rtfpessoa

Files changed (1) hide show
  1. tmp/tmpmztxuygi/{from.md → to.md} +346 -219
tmp/tmpmztxuygi/{from.md → to.md} RENAMED
@@ -26,61 +26,79 @@ unary-operator: one of
26
 
27
  The unary `*` operator performs *indirection*: the expression to which
28
  it is applied shall be a pointer to an object type, or a pointer to a
29
  function type and the result is an lvalue referring to the object or
30
  function to which the expression points. If the type of the expression
31
- is “pointer to `T`,” the type of the result is “`T`. indirection
32
- through a pointer to an incomplete type (other than *cv* `void`) is
33
- valid. The lvalue thus obtained can be used in limited ways (to
34
- initialize a reference, for example); this lvalue must not be converted
35
- to a prvalue, see  [[conv.lval]].
 
36
 
37
  The result of each of the following unary operators is a prvalue.
38
 
39
  The result of the unary `&` operator is a pointer to its operand. The
40
  operand shall be an lvalue or a *qualified-id*. If the operand is a
41
- *qualified-id* naming a non-static member `m` of some class `C` with
42
- type `T`, the result has type “pointer to member of class `C` of type
43
- `T`” and is a prvalue designating `C::m`. Otherwise, if the type of the
44
- expression is `T`, the result has type “pointer to `T`” and is a prvalue
45
- that is the address of the designated object ([[intro.memory]]) or a
46
- pointer to the designated function. In particular, the address of an
47
- object of type “cv `T`” is “pointer to cv `T`”, with the same
48
- cv-qualification.
 
 
 
 
 
 
 
 
49
 
50
  ``` cpp
51
  struct A { int i; };
52
  struct B : A { };
53
  ... &B::i ... // has type int A::*
 
 
 
 
54
  ```
55
 
56
- a pointer to member formed from a `mutable` non-static data member (
57
- [[dcl.stc]]) does not reflect the `mutable` specifier associated with
58
- the non-static data member.
 
 
59
 
60
  A pointer to member is only formed when an explicit `&` is used and its
61
- operand is a *qualified-id* not enclosed in parentheses. that is, the
62
- expression `&(qualified-id)`, where the *qualified-id* is enclosed in
63
- parentheses, does not form an expression of type “pointer to member.”
64
- Neither does `qualified-id`, because there is no implicit conversion
65
- from a *qualified-id* for a non-static member function to the type
66
- “pointer to member function” as there is from an lvalue of function type
67
- to the type “pointer to function” ([[conv.func]]). Nor is
68
- `&unqualified-id` a pointer to member, even within the scope of the
69
- *unqualified-id*’s class.
 
70
 
71
  If `&` is applied to an lvalue of incomplete class type and the complete
72
  type declares `operator&()`, it is unspecified whether the operator has
73
  the built-in meaning or the operator function is called. The operand of
74
  `&` shall not be a bit-field.
75
 
76
  The address of an overloaded function (Clause  [[over]]) can be taken
77
  only in a context that uniquely determines which version of the
78
- overloaded function is referred to (see  [[over.over]]). since the
79
- context might determine whether the operand is a static or non-static
80
- member function, the context can also affect whether the expression has
81
- type “pointer to function or “pointer to member function.”
 
 
82
 
83
  The operand of the unary `+` operator shall have arithmetic, unscoped
84
  enumeration, or pointer type and the result is the value of the
85
  argument. Integral promotion is performed on integral or enumeration
86
  operands. The type of the result is the type of the promoted operand.
@@ -96,51 +114,61 @@ The operand of the logical negation operator `!` is contextually
96
  converted to `bool` (Clause  [[conv]]); its value is `true` if the
97
  converted operand is `false` and `false` otherwise. The type of the
98
  result is `bool`.
99
 
100
  The operand of `~` shall have integral or unscoped enumeration type; the
101
- result is the ones complement of its operand. Integral promotions are
102
  performed. The type of the result is the type of the promoted operand.
103
- There is an ambiguity in the *unary-expression* `~X()`, where `X` is a
104
- *class-name* or *decltype-specifier*. The ambiguity is resolved in favor
105
- of treating `~` as a unary complement rather than treating `~X` as
106
- referring to a destructor.
 
 
 
 
 
107
 
108
  ### Increment and decrement <a id="expr.pre.incr">[[expr.pre.incr]]</a>
109
 
110
- The operand of prefix `++` is modified by adding `1`, or set to `true`
111
- if it is `bool` (this use is deprecated). The operand shall be a
112
- modifiable lvalue. The type of the operand shall be an arithmetic type
113
- or a pointer to a completely-defined object type. The result is the
114
- updated operand; it is an lvalue, and it is a bit-field if the operand
115
- is a bit-field. If `x` is not of type `bool`, the expression `++x` is
116
- equivalent to `x+=1` See the discussions of addition ([[expr.add]]) and
117
- assignment operators ([[expr.ass]]) for information on conversions.
118
 
119
- The operand of prefix `\dcr` is modified by subtracting `1`. The operand
120
- shall not be of type `bool`. The requirements on the operand of prefix
121
- `\dcr` and the properties of its result are otherwise the same as those
122
- of prefix `++`. For postfix increment and decrement, see 
123
- [[expr.post.incr]].
 
 
 
 
 
124
 
125
  ### Sizeof <a id="expr.sizeof">[[expr.sizeof]]</a>
126
 
127
  The `sizeof` operator yields the number of bytes in the object
128
  representation of its operand. The operand is either an expression,
129
  which is an unevaluated operand (Clause  [[expr]]), or a parenthesized
130
  *type-id*. The `sizeof` operator shall not be applied to an expression
131
- that has function or incomplete type, to an enumeration type whose
132
- underlying type is not fixed before all its enumerators have been
133
- declared, to the parenthesized name of such types, or to a glvalue that
134
- designates a bit-field. `sizeof(char)`, `sizeof(signed char)` and
135
- `sizeof(unsigned char)` are `1`. The result of `sizeof` applied to any
136
- other fundamental type ([[basic.fundamental]]) is
137
- *implementation-defined*. in particular, `sizeof(bool)`,
138
- `sizeof(char16_t)`, `sizeof(char32_t)`, and `sizeof(wchar_t)` are
139
- implementation-defined.[^16] See  [[intro.memory]] for the definition of
140
- *byte* and  [[basic.types]] for the definition of *object
141
- representation*.
 
 
142
 
143
  When applied to a reference or a reference type, the result is the size
144
  of the referenced type. When applied to a class, the result is the
145
  number of bytes in an object of that class including any padding
146
  required for placing objects of that type in an array. The size of a
@@ -153,40 +181,50 @@ number of bytes in the array. This implies that the size of an array of
153
  The `sizeof` operator can be applied to a pointer to a function, but
154
  shall not be applied directly to a function.
155
 
156
  The lvalue-to-rvalue ([[conv.lval]]), array-to-pointer (
157
  [[conv.array]]), and function-to-pointer ([[conv.func]]) standard
158
- conversions are not applied to the operand of `sizeof`.
 
 
159
 
160
  The identifier in a `sizeof...` expression shall name a parameter pack.
161
  The `sizeof...` operator yields the number of arguments provided for the
162
  parameter pack *identifier*. A `sizeof...` expression is a pack
163
  expansion ([[temp.variadic]]).
164
 
 
 
165
  ``` cpp
166
  template<class... Types>
167
  struct count {
168
  static const std::size_t value = sizeof...(Types);
169
  };
170
  ```
171
 
 
 
172
  The result of `sizeof` and `sizeof...` is a constant of type
173
- `std::size_t`. `std::size_t` is defined in the standard header
174
- `<cstddef>` ([[support.types]]).
 
 
175
 
176
  ### New <a id="expr.new">[[expr.new]]</a>
177
 
178
  The *new-expression* attempts to create an object of the *type-id* (
179
  [[dcl.name]]) or *new-type-id* to which it is applied. The type of that
180
  object is the *allocated type*. This type shall be a complete object
181
  type, but not an abstract class type or array thereof (
182
- [[intro.object]],  [[basic.types]],  [[class.abstract]]). It is
183
- *implementation-defined* whether over-aligned types are supported (
184
- [[basic.align]]). because references are not objects, references cannot
185
- be created by *new-expression*s. the *type-id* may be a cv-qualified
186
- type, in which case the object created by the *new-expression* has a
187
- cv-qualified type.
 
 
188
 
189
  ``` bnf
190
  new-expression:
191
  '::'ₒₚₜ 'new' new-placementₒₚₜ new-type-id new-initializerₒₚₜ
192
  '::'ₒₚₜ 'new' new-placementₒₚₜ '(' type-id ')' new-initializerₒₚₜ
@@ -219,50 +257,67 @@ new-initializer:
219
  '(' expression-listₒₚₜ ')'
220
  braced-init-list
221
  ```
222
 
223
  Entities created by a *new-expression* have dynamic storage duration (
224
- [[basic.stc.dynamic]]). the lifetime of such an entity is not
225
- necessarily restricted to the scope in which it is created. If the
226
- entity is a non-array object, the *new-expression* returns a pointer to
227
- the object created. If it is an array, the *new-expression* returns a
228
- pointer to the initial element of the array.
229
 
230
- If the `auto` appears in the of a or of a , the shall contain a of the
231
- form
232
 
233
- ``` bnf
234
- '(' assignment-expression ')'
235
- ```
236
 
237
- The allocated type is deduced from the as follows: Let `e` be the
238
- *assignment-expression* in the and `T` be the or of the , then the
239
- allocated type is the type deduced for the variable `x` in the invented
240
- declaration ([[dcl.spec.auto]]):
 
 
 
241
 
242
  ``` cpp
243
- T x(e);
244
  ```
245
 
 
 
246
  ``` cpp
247
  new auto(1); // allocated type is int
248
  auto x = new auto('a'); // allocated type is char, x is of type char*
 
 
 
249
  ```
250
 
 
 
251
  The *new-type-id* in a *new-expression* is the longest possible sequence
252
- of *new-declarator*s. this prevents ambiguities between the declarator
253
- operators `&`, `&&`, `*`, and `[]` and their expression counterparts.
 
 
 
 
 
254
 
255
  ``` cpp
256
  new int * i; // syntax error: parsed as (new int*) i, not as (new int)*i
257
  ```
258
 
259
  The `*` is the pointer declarator and not the multiplication operator.
260
 
261
- parentheses in a *new-type-id* of a *new-expression* can have surprising
 
 
 
 
262
  effects.
263
 
 
 
264
  ``` cpp
265
  new int(*[10])(); // error
266
  ```
267
 
268
  is ill-formed because the binding is
@@ -277,66 +332,85 @@ be used to create objects of compound types ([[basic.compound]]):
277
  ``` cpp
278
  new (int (*[10])());
279
  ```
280
 
281
  allocates an array of `10` pointers to functions (taking no argument and
282
- returning `int`.
 
 
 
 
283
 
284
  When the allocated object is an array (that is, the
285
  *noptr-new-declarator* syntax is used or the *new-type-id* or *type-id*
286
  denotes an array type), the *new-expression* yields a pointer to the
287
- initial element (if any) of the array. both `new int` and `new int[10]`
288
- have type `int*` and the type of `new int[i][10]` is `int (*)[10]` The
289
- *attribute-specifier-seq* in a *noptr-new-declarator* appertains to the
290
- associated array type.
 
 
 
291
 
292
  Every *constant-expression* in a *noptr-new-declarator* shall be a
293
  converted constant expression ([[expr.const]]) of type `std::size_t`
294
  and shall evaluate to a strictly positive value. The *expression* in a
295
- *noptr-new-declarator*is implicitly converted to `std::size_t`. given
296
- the definition `int n = 42`, `new float[n][5]` is well-formed (because
297
- `n` is the *expression* of a *noptr-new-declarator*), but
298
- `new float[5][n]` is ill-formed (because `n` is not a constant
299
- expression).
 
300
 
301
  The *expression* in a *noptr-new-declarator* is erroneous if:
302
 
303
  - the expression is of non-class type and its value before converting to
304
  `std::size_t` is less than zero;
305
  - the expression is of class type and its value before application of
306
  the second standard conversion ([[over.ics.user]])[^18] is less than
307
  zero;
308
  - its value is such that the size of the allocated object would exceed
309
- the implementation-defined limit (annex  [[implimits]]); or
310
  - the *new-initializer* is a *braced-init-list* and the number of array
311
  elements for which initializers are provided (including the
312
  terminating `'\0'` in a string literal ([[lex.string]])) exceeds the
313
  number of elements to initialize.
314
 
315
- If the *expression*, after converting to `std::size_t`, is a core
316
- constant expression and the expression is erroneous, the program is
317
- ill-formed. Otherwise, a *new-expression* with an erroneous expression
318
- does not call an allocation function and terminates by throwing an
319
- exception of a type that would match a handler ([[except.handle]]) of
320
- type `std::bad_array_new_length` ([[new.badlength]]). When the value of
321
- the *expression* is zero, the allocation function is called to allocate
322
- an array with no elements.
 
 
 
 
 
 
 
323
 
324
  A *new-expression* may obtain storage for the object by calling an
325
- *allocation function* ([[basic.stc.dynamic.allocation]]). If the
326
  *new-expression* terminates by throwing an exception, it may release
327
  storage by calling a deallocation function (
328
  [[basic.stc.dynamic.deallocation]]). If the allocated type is a
329
  non-array type, the allocation function’s name is `operator new` and the
330
  deallocation function’s name is `operator delete`. If the allocated type
331
  is an array type, the allocation function’s name is `operator new[]` and
332
- the deallocation function’s name is `operator delete[]`. an
333
- implementation shall provide default definitions for the global
334
- allocation functions ([[basic.stc.dynamic]],  [[new.delete.single]], 
335
- [[new.delete.array]]). A C++program can provide alternative definitions
336
- of these functions ([[replacement.functions]]) and/or class-specific
337
- versions ([[class.free]]).
 
 
 
 
338
 
339
  If the *new-expression* begins with a unary `::` operator, the
340
  allocation function’s name is looked up in the global scope. Otherwise,
341
  if the allocated type is a class type `T` or array thereof, the
342
  allocation function’s name is looked up in the scope of `T`. If this
@@ -362,10 +436,12 @@ true were the allocation not extended:
362
  *delete-expression*s, and
363
  - the evaluation of `e2` is sequenced before the evaluation of the
364
  *delete-expression* whose operand is the pointer value produced by
365
  `e1`.
366
 
 
 
367
  ``` cpp
368
  void mergeable(int x) {
369
  // These allocations are safe for merging:
370
  std::unique_ptr<char[]> a{new (std::nothrow) char[8]};
371
  std::unique_ptr<char[]> b{new (std::nothrow) char[8]};
@@ -384,110 +460,140 @@ void mergeable(int x) {
384
  throw;
385
  }
386
  }
387
  ```
388
 
 
 
389
  When a *new-expression* calls an allocation function and that allocation
390
  has not been extended, the *new-expression* passes the amount of space
391
  requested to the allocation function as the first argument of type
392
  `std::size_t`. That argument shall be no less than the size of the
393
  object being created; it may be greater than the size of the object
394
- being created only if the object is an array. For arrays of `char` and
395
- `unsigned char`, the difference between the result of the
396
- *new-expression* and the address returned by the allocation function
397
  shall be an integral multiple of the strictest fundamental alignment
398
  requirement ([[basic.align]]) of any object type whose size is no
399
- greater than the size of the array being created. Because allocation
400
- functions are assumed to return pointers to storage that is
401
- appropriately aligned for objects of any type with fundamental
402
- alignment, this constraint on array allocation overhead permits the
403
- common idiom of allocating character arrays into which objects of other
404
- types will later be placed.
 
405
 
406
  When a *new-expression* calls an allocation function and that allocation
407
  has been extended, the size argument to the allocation call shall be no
408
  greater than the sum of the sizes for the omitted calls as specified
409
  above, plus the size for the extended call had it not been extended,
410
  plus any padding necessary to align the allocated objects within the
411
  allocated memory.
412
 
413
  The *new-placement* syntax is used to supply additional arguments to an
414
- allocation function. If used, overload resolution is performed on a
415
- function call created by assembling an argument list consisting of the
416
- amount of space requested (the first argument) and the expressions in
417
- the *new-placement* part of the *new-expression* (the second and
418
- succeeding arguments). The first of these arguments has type
419
- `std::size_t` and the remaining arguments have the corresponding types
420
- of the expressions in the *new-placement*.
421
-
422
- - `new T` results in a call of `operator
423
- new(sizeof(T))`,
424
- - `new(2,f) T` results in a call of `operator
425
- new(sizeof(T),2,f)`,
426
- - `new T[5]` results in a call of `operator
427
- new[](sizeof(T)*5+x)`, and
428
- - `new(2,f) T[5]` results in a call of `operator
429
- new[](sizeof(T)*5+y,2,f)`.
430
-
431
- Here, `x` and `y` are non-negative unspecified values representing array
432
- allocation overhead; the result of the *new-expression* will be offset
433
- by this amount from the value returned by `operator new[]`. This
434
- overhead may be applied in all array *new-expression*s, including those
435
- referencing the library function `operator new[](std::size_t, void*)`
436
- and other placement allocation functions. The amount of overhead may
437
- vary from one invocation of `new` to another.
438
-
439
- unless an allocation function is declared with a non-throwing
440
- *exception-specification* ([[except.spec]]), it indicates failure to
441
- allocate storage by throwing a `std::bad_alloc` exception (Clause 
442
- [[except]],  [[bad.alloc]]); it returns a non-null pointer otherwise. If
443
- the allocation function is declared with a non-throwing
444
- *exception-specification*, it returns null to indicate failure to
445
- allocate storage and a non-null pointer otherwise. If the allocation
446
- function returns null, initialization shall not be done, the
447
- deallocation function shall not be called, and the value of the
448
- *new-expression* shall be null.
449
-
450
- when the allocation function returns a value other than null, it must be
451
- a pointer to a block of storage in which space for the object has been
452
- reserved. The block of storage is assumed to be appropriately aligned
453
- and of the requested size. The address of the created object will not
454
- necessarily be the same as that of the block if the object is an array.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
455
 
456
  A *new-expression* that creates an object of type `T` initializes that
457
  object as follows:
458
 
459
  - If the *new-initializer* is omitted, the object is
460
- default-initialized ([[dcl.init]]). If no initialization is
461
- performed, the object has an indeterminate value.
462
  - Otherwise, the *new-initializer* is interpreted according to the
463
  initialization rules of  [[dcl.init]] for direct-initialization.
464
 
465
- The invocation of the allocation function is indeterminately sequenced
466
- with respect to the evaluations of expressions in the *new-initializer*.
467
- Initialization of the allocated object is sequenced before the value
468
- computation of the *new-expression*. It is unspecified whether
469
- expressions in the *new-initializer* are evaluated if the allocation
470
- function returns the null pointer or exits using an exception.
471
 
472
  If the *new-expression* creates an object or an array of objects of
473
  class type, access and ambiguity control are done for the allocation
474
  function, the deallocation function ([[class.free]]), and the
475
  constructor ([[class.ctor]]). If the *new-expression* creates an array
476
  of objects of class type, the destructor is potentially invoked (
477
  [[class.dtor]]).
478
 
479
  If any part of the object initialization described above[^19] terminates
480
- by throwing an exception, storage has been obtained for the object, and
481
- a suitable deallocation function can be found, the deallocation function
482
- is called to free the memory in which the object was being constructed,
483
- after which the exception continues to propagate in the context of the
484
- *new-expression*. If no unambiguous matching deallocation function can
485
- be found, propagating the exception does not cause the object’s memory
486
- to be freed. This is appropriate when the called allocation function
 
487
  does not allocate memory; otherwise, it is likely to result in a memory
488
- leak.
489
 
490
  If the *new-expression* begins with a unary `::` operator, the
491
  deallocation function’s name is looked up in the global scope.
492
  Otherwise, if the allocated type is a class type `T` or an array
493
  thereof, the deallocation function’s name is looked up in the scope of
@@ -499,17 +605,19 @@ A declaration of a placement deallocation function matches the
499
  declaration of a placement allocation function if it has the same number
500
  of parameters and, after parameter transformations ([[dcl.fct]]), all
501
  parameter types except the first are identical. If the lookup finds a
502
  single matching deallocation function, that function will be called;
503
  otherwise, no deallocation function will be called. If the lookup finds
504
- the two-parameter form of a usual deallocation function (
505
  [[basic.stc.dynamic.deallocation]]) and that function, considered as a
506
  placement deallocation function, would have been selected as a match for
507
  the allocation function, the program is ill-formed. For a non-placement
508
  allocation function, the normal deallocation function lookup is used to
509
  find the matching deallocation function ([[expr.delete]])
510
 
 
 
511
  ``` cpp
512
  struct S {
513
  // Placement allocation function:
514
  static void* operator new(std::size_t, std::size_t);
515
 
@@ -519,10 +627,12 @@ struct S {
519
 
520
  S* p = new (0) S; // ill-formed: non-placement deallocation function matches
521
  // placement allocation function
522
  ```
523
 
 
 
524
  If a *new-expression* calls a deallocation function, it passes the value
525
  returned from the allocation function call as the first argument of type
526
  `void*`. If a placement deallocation function is called, it is passed
527
  the same additional arguments as were passed to the placement allocation
528
  function, that is, the same arguments as those specified with the
@@ -561,16 +671,20 @@ pointer to a non-array object created by a previous *new-expression*, or
561
  a pointer to a subobject ([[intro.object]]) representing a base class
562
  of such an object (Clause  [[class.derived]]). If not, the behavior is
563
  undefined. In the second alternative (*delete array*), the value of the
564
  operand of `delete` may be a null pointer value or a pointer value that
565
  resulted from a previous array *new-expression*.[^22] If not, the
566
- behavior is undefined. this means that the syntax of the
567
- *delete-expression* must match the type of the object allocated by
568
- `new`, not the syntax of the *new-expression*. a pointer to a `const`
569
- type can be the operand of a *delete-expression*; it is not necessary to
570
- cast away the constness ([[expr.const.cast]]) of the pointer expression
571
- before it is used as the operand of the *delete-expression*.
 
 
 
 
572
 
573
  In the first alternative (*delete object*), if the static type of the
574
  object to be deleted is different from its dynamic type, the static type
575
  shall be a base class of the dynamic type of the object to be deleted
576
  and the static type shall have a virtual destructor or the behavior is
@@ -607,43 +721,70 @@ pointer value, then:
607
  *new-expression* that had storage provided by the extended
608
  *new-expression* has been evaluated, the *delete-expression* shall
609
  call a deallocation function. The value returned from the allocation
610
  call of the extended *new-expression* shall be passed as the first
611
  argument to the deallocation function.
612
- - Otherwise, the *delete-expression* will not call a *deallocation
613
- function* ([[basic.stc.dynamic.deallocation]]).
614
 
615
- Otherwise, it is unspecified whether the deallocation function will be
616
- called. The deallocation function is called regardless of whether the
617
- destructor for the object or some element of the array throws an
618
- exception.
619
 
620
- An implementation provides default definitions of the global
621
- deallocation functions `operator delete()` for non-arrays (
622
- [[new.delete.single]]) and `operator delete[]()` for arrays (
 
 
 
 
623
  [[new.delete.array]]). A C++ program can provide alternative definitions
624
  of these functions ([[replacement.functions]]), and/or class-specific
625
- versions ([[class.free]]).
626
 
627
  When the keyword `delete` in a *delete-expression* is preceded by the
628
  unary `::` operator, the deallocation function’s name is looked up in
629
  global scope. Otherwise, the lookup considers class-specific
630
  deallocation functions ([[class.free]]). If no class-specific
631
  deallocation function is found, the deallocation function’s name is
632
  looked up in global scope.
633
 
634
- If the type is complete and if deallocation function lookup finds both a
635
- usual deallocation function with only a pointer parameter and a usual
636
- deallocation function with both a pointer parameter and a size
637
- parameter, then the selected deallocation function shall be the one with
638
- two parameters. Otherwise, the selected deallocation function shall be
639
- the function with one parameter.
 
 
 
 
 
 
 
 
 
 
 
 
640
 
641
  When a *delete-expression* is executed, the selected deallocation
642
- function shall be called with the address of the block of storage to be
643
- reclaimed as its first argument and (if the two-parameter deallocation
644
- function is used) the size of the block as its second argument.[^23]
 
 
 
 
 
 
 
 
 
 
 
 
645
 
646
  Access and ambiguity control are done for both the deallocation function
647
  and the destructor ([[class.dtor]],  [[class.free]]).
648
 
649
  ### Alignof <a id="expr.alignof">[[expr.alignof]]</a>
@@ -670,22 +811,8 @@ noexcept-expression:
670
  ```
671
 
672
  The result of the `noexcept` operator is a constant of type `bool` and
673
  is a prvalue.
674
 
675
- The result of the `noexcept` operator is `false` if in a
676
- potentially-evaluated context the *expression* would contain
677
-
678
- - a potentially-evaluated call[^24] to a function, member function,
679
- function pointer, or member function pointer that does not have a
680
- non-throwing *exception-specification* ([[except.spec]]), unless the
681
- call is a constant expression ([[expr.const]]),
682
- - a potentially-evaluated *throw-expression* ([[except.throw]]),
683
- - a potentially-evaluated `dynamic_cast` expression
684
- `dynamic_cast<T>(v)`, where `T` is a reference type, that requires a
685
- run-time check ([[expr.dynamic.cast]]), or
686
- - a potentially-evaluated `typeid` expression ([[expr.typeid]]) applied
687
- to a glvalue expression whose type is a polymorphic class type (
688
- [[class.virtual]]).
689
-
690
- Otherwise, the result is `true`.
691
 
 
26
 
27
  The unary `*` operator performs *indirection*: the expression to which
28
  it is applied shall be a pointer to an object type, or a pointer to a
29
  function type and the result is an lvalue referring to the object or
30
  function to which the expression points. If the type of the expression
31
+ is “pointer to `T`”, the type of the result is “`T`”.
32
+
33
+ [*Note 1*: Indirection through a pointer to an incomplete type (other
34
+ than *cv* `void`) is valid. The lvalue thus obtained can be used in
35
+ limited ways (to initialize a reference, for example); this lvalue must
36
+ not be converted to a prvalue, see  [[conv.lval]]. — *end note*]
37
 
38
  The result of each of the following unary operators is a prvalue.
39
 
40
  The result of the unary `&` operator is a pointer to its operand. The
41
  operand shall be an lvalue or a *qualified-id*. If the operand is a
42
+ *qualified-id* naming a non-static or variant member `m` of some class
43
+ `C` with type `T`, the result has type “pointer to member of class `C`
44
+ of type `T`” and is a prvalue designating `C::m`. Otherwise, if the type
45
+ of the expression is `T`, the result has type “pointer to `T`” and is a
46
+ prvalue that is the address of the designated object ([[intro.memory]])
47
+ or a pointer to the designated function.
48
+
49
+ [*Note 2*: In particular, the address of an object of type “cv `T`” is
50
+ “pointer to cv `T`”, with the same cv-qualification. — *end note*]
51
+
52
+ For purposes of pointer arithmetic ([[expr.add]]) and comparison (
53
+ [[expr.rel]], [[expr.eq]]), an object that is not an array element whose
54
+ address is taken in this way is considered to belong to an array with
55
+ one element of type `T`.
56
+
57
+ [*Example 1*:
58
 
59
  ``` cpp
60
  struct A { int i; };
61
  struct B : A { };
62
  ... &B::i ... // has type int A::*
63
+ int a;
64
+ int* p1 = &a;
65
+ int* p2 = p1 + 1; // defined behavior
66
+ bool b = p2 > p1; // defined behavior, with value true
67
  ```
68
 
69
+ *end example*]
70
+
71
+ [*Note 3*: A pointer to member formed from a `mutable` non-static data
72
+ member ([[dcl.stc]]) does not reflect the `mutable` specifier
73
+ associated with the non-static data member. — *end note*]
74
 
75
  A pointer to member is only formed when an explicit `&` is used and its
76
+ operand is a *qualified-id* not enclosed in parentheses.
77
+
78
+ [*Note 4*: That is, the expression `&(qualified-id)`, where the
79
+ *qualified-id* is enclosed in parentheses, does not form an expression
80
+ of type “pointer to member”. Neither does `qualified-id`, because there
81
+ is no implicit conversion from a *qualified-id* for a non-static member
82
+ function to the type “pointer to member function” as there is from an
83
+ lvalue of function type to the type “pointer to function” (
84
+ [[conv.func]]). Nor is `&unqualified-id` a pointer to member, even
85
+ within the scope of the *unqualified-id*’s class. — *end note*]
86
 
87
  If `&` is applied to an lvalue of incomplete class type and the complete
88
  type declares `operator&()`, it is unspecified whether the operator has
89
  the built-in meaning or the operator function is called. The operand of
90
  `&` shall not be a bit-field.
91
 
92
  The address of an overloaded function (Clause  [[over]]) can be taken
93
  only in a context that uniquely determines which version of the
94
+ overloaded function is referred to (see  [[over.over]]).
95
+
96
+ [*Note 5*: Since the context might determine whether the operand is a
97
+ static or non-static member function, the context can also affect
98
+ whether the expression has type “pointer to function” or “pointer to
99
+ member function”. — *end note*]
100
 
101
  The operand of the unary `+` operator shall have arithmetic, unscoped
102
  enumeration, or pointer type and the result is the value of the
103
  argument. Integral promotion is performed on integral or enumeration
104
  operands. The type of the result is the type of the promoted operand.
 
114
  converted to `bool` (Clause  [[conv]]); its value is `true` if the
115
  converted operand is `false` and `false` otherwise. The type of the
116
  result is `bool`.
117
 
118
  The operand of `~` shall have integral or unscoped enumeration type; the
119
+ result is the ones’ complement of its operand. Integral promotions are
120
  performed. The type of the result is the type of the promoted operand.
121
+ There is an ambiguity in the grammar when `~` is followed by a
122
+ *class-name* or *decltype-specifier*. The ambiguity is resolved by
123
+ treating `~` as the unary complement operator rather than as the start
124
+ of an *unqualified-id* naming a destructor.
125
+
126
+ [*Note 6*: Because the grammar does not permit an operator to follow
127
+ the `.`, `->`, or `::` tokens, a `~` followed by a *class-name* or
128
+ *decltype-specifier* in a member access expression or *qualified-id* is
129
+ unambiguously parsed as a destructor name. — *end note*]
130
 
131
  ### Increment and decrement <a id="expr.pre.incr">[[expr.pre.incr]]</a>
132
 
133
+ The operand of prefix `++` is modified by adding `1`. The operand shall
134
+ be a modifiable lvalue. The type of the operand shall be an arithmetic
135
+ type other than cv `bool`, or a pointer to a completely-defined object
136
+ type. The result is the updated operand; it is an lvalue, and it is a
137
+ bit-field if the operand is a bit-field. The expression `++x` is
138
+ equivalent to `x+=1`.
 
 
139
 
140
+ [*Note 1*: See the discussions of addition ([[expr.add]]) and
141
+ assignment operators ([[expr.ass]]) for information on
142
+ conversions. *end note*]
143
+
144
+ The operand of prefix `\dcr` is modified by subtracting `1`. The
145
+ requirements on the operand of prefix `\dcr` and the properties of its
146
+ result are otherwise the same as those of prefix `++`.
147
+
148
+ [*Note 2*: For postfix increment and decrement, see 
149
+ [[expr.post.incr]]. — *end note*]
150
 
151
  ### Sizeof <a id="expr.sizeof">[[expr.sizeof]]</a>
152
 
153
  The `sizeof` operator yields the number of bytes in the object
154
  representation of its operand. The operand is either an expression,
155
  which is an unevaluated operand (Clause  [[expr]]), or a parenthesized
156
  *type-id*. The `sizeof` operator shall not be applied to an expression
157
+ that has function or incomplete type, to the parenthesized name of such
158
+ types, or to a glvalue that designates a bit-field. `sizeof(char)`,
159
+ `sizeof(signed char)` and `sizeof(unsigned char)` are `1`. The result of
160
+ `sizeof` applied to any other fundamental type ([[basic.fundamental]])
161
+ is *implementation-defined*.
162
+
163
+ [*Note 1*: In particular, `sizeof(bool)`, `sizeof(char16_t)`,
164
+ `sizeof(char32_t)`, and `sizeof(wchar_t)` are
165
+ implementation-defined.[^16] *end note*]
166
+
167
+ [*Note 2*: See  [[intro.memory]] for the definition of *byte* and 
168
+ [[basic.types]] for the definition of *object
169
+ representation*. — *end note*]
170
 
171
  When applied to a reference or a reference type, the result is the size
172
  of the referenced type. When applied to a class, the result is the
173
  number of bytes in an object of that class including any padding
174
  required for placing objects of that type in an array. The size of a
 
181
  The `sizeof` operator can be applied to a pointer to a function, but
182
  shall not be applied directly to a function.
183
 
184
  The lvalue-to-rvalue ([[conv.lval]]), array-to-pointer (
185
  [[conv.array]]), and function-to-pointer ([[conv.func]]) standard
186
+ conversions are not applied to the operand of `sizeof`. If the operand
187
+ is a prvalue, the temporary materialization conversion ([[conv.rval]])
188
+ is applied.
189
 
190
  The identifier in a `sizeof...` expression shall name a parameter pack.
191
  The `sizeof...` operator yields the number of arguments provided for the
192
  parameter pack *identifier*. A `sizeof...` expression is a pack
193
  expansion ([[temp.variadic]]).
194
 
195
+ [*Example 1*:
196
+
197
  ``` cpp
198
  template<class... Types>
199
  struct count {
200
  static const std::size_t value = sizeof...(Types);
201
  };
202
  ```
203
 
204
+ — *end example*]
205
+
206
  The result of `sizeof` and `sizeof...` is a constant of type
207
+ `std::size_t`.
208
+
209
+ [*Note 3*: `std::size_t` is defined in the standard header
210
+ `<cstddef>` ([[cstddef.syn]], [[support.types.layout]]). — *end note*]
211
 
212
  ### New <a id="expr.new">[[expr.new]]</a>
213
 
214
  The *new-expression* attempts to create an object of the *type-id* (
215
  [[dcl.name]]) or *new-type-id* to which it is applied. The type of that
216
  object is the *allocated type*. This type shall be a complete object
217
  type, but not an abstract class type or array thereof (
218
+ [[intro.object]],  [[basic.types]],  [[class.abstract]]).
219
+
220
+ [*Note 1*: Because references are not objects, references cannot be
221
+ created by *new-expression*s. *end note*]
222
+
223
+ [*Note 2*: The *type-id* may be a cv-qualified type, in which case the
224
+ object created by the *new-expression* has a cv-qualified
225
+ type. — *end note*]
226
 
227
  ``` bnf
228
  new-expression:
229
  '::'ₒₚₜ 'new' new-placementₒₚₜ new-type-id new-initializerₒₚₜ
230
  '::'ₒₚₜ 'new' new-placementₒₚₜ '(' type-id ')' new-initializerₒₚₜ
 
257
  '(' expression-listₒₚₜ ')'
258
  braced-init-list
259
  ```
260
 
261
  Entities created by a *new-expression* have dynamic storage duration (
262
+ [[basic.stc.dynamic]]).
 
 
 
 
263
 
264
+ [*Note 3*: The lifetime of such an entity is not necessarily
265
+ restricted to the scope in which it is created. — *end note*]
266
 
267
+ If the entity is a non-array object, the *new-expression* returns a
268
+ pointer to the object created. If it is an array, the *new-expression*
269
+ returns a pointer to the initial element of the array.
270
 
271
+ If a placeholder type ([[dcl.spec.auto]]) appears in the
272
+ *type-specifier-seq* of a *new-type-id* or *type-id* of a
273
+ *new-expression*, the allocated type is deduced as follows: Let *init*
274
+ be the *new-initializer*, if any, and `T` be the *new-type-id* or
275
+ *type-id* of the *new-expression*, then the allocated type is the type
276
+ deduced for the variable `x` in the invented declaration (
277
+ [[dcl.spec.auto]]):
278
 
279
  ``` cpp
280
+ T x init ;
281
  ```
282
 
283
+ [*Example 1*:
284
+
285
  ``` cpp
286
  new auto(1); // allocated type is int
287
  auto x = new auto('a'); // allocated type is char, x is of type char*
288
+
289
+ template<class T> struct A { A(T, T); };
290
+ auto y = new A{1, 2}; // allocated type is A<int>
291
  ```
292
 
293
+ — *end example*]
294
+
295
  The *new-type-id* in a *new-expression* is the longest possible sequence
296
+ of *new-declarator*s.
297
+
298
+ [*Note 4*: This prevents ambiguities between the declarator operators
299
+ `&`, `&&`, `*`, and `[]` and their expression
300
+ counterparts. — *end note*]
301
+
302
+ [*Example 2*:
303
 
304
  ``` cpp
305
  new int * i; // syntax error: parsed as (new int*) i, not as (new int)*i
306
  ```
307
 
308
  The `*` is the pointer declarator and not the multiplication operator.
309
 
310
+ *end example*]
311
+
312
+ [*Note 5*:
313
+
314
+ Parentheses in a *new-type-id* of a *new-expression* can have surprising
315
  effects.
316
 
317
+ [*Example 3*:
318
+
319
  ``` cpp
320
  new int(*[10])(); // error
321
  ```
322
 
323
  is ill-formed because the binding is
 
332
  ``` cpp
333
  new (int (*[10])());
334
  ```
335
 
336
  allocates an array of `10` pointers to functions (taking no argument and
337
+ returning `int`).
338
+
339
+ — *end example*]
340
+
341
+ — *end note*]
342
 
343
  When the allocated object is an array (that is, the
344
  *noptr-new-declarator* syntax is used or the *new-type-id* or *type-id*
345
  denotes an array type), the *new-expression* yields a pointer to the
346
+ initial element (if any) of the array.
347
+
348
+ [*Note 6*: Both `new int` and `new int[10]` have type `int*` and the
349
+ type of `new int[i][10]` is `int (*)[10]` — *end note*]
350
+
351
+ The *attribute-specifier-seq* in a *noptr-new-declarator* appertains to
352
+ the associated array type.
353
 
354
  Every *constant-expression* in a *noptr-new-declarator* shall be a
355
  converted constant expression ([[expr.const]]) of type `std::size_t`
356
  and shall evaluate to a strictly positive value. The *expression* in a
357
+ *noptr-new-declarator* is implicitly converted to `std::size_t`.
358
+
359
+ [*Example 4*: Given the definition `int n = 42`, `new float[n][5]` is
360
+ well-formed (because `n` is the *expression* of a
361
+ *noptr-new-declarator*), but `new float[5][n]` is ill-formed (because
362
+ `n` is not a constant expression). — *end example*]
363
 
364
  The *expression* in a *noptr-new-declarator* is erroneous if:
365
 
366
  - the expression is of non-class type and its value before converting to
367
  `std::size_t` is less than zero;
368
  - the expression is of class type and its value before application of
369
  the second standard conversion ([[over.ics.user]])[^18] is less than
370
  zero;
371
  - its value is such that the size of the allocated object would exceed
372
+ the *implementation-defined* limit (Annex  [[implimits]]); or
373
  - the *new-initializer* is a *braced-init-list* and the number of array
374
  elements for which initializers are provided (including the
375
  terminating `'\0'` in a string literal ([[lex.string]])) exceeds the
376
  number of elements to initialize.
377
 
378
+ If the *expression* is erroneous after converting to `std::size_t`:
379
+
380
+ - if the *expression* is a core constant expression, the program is
381
+ ill-formed;
382
+ - otherwise, an allocation function is not called; instead
383
+ - if the allocation function that would have been called has a
384
+ non-throwing exception specification ([[except.spec]]), the value
385
+ of the *new-expression* is the null pointer value of the required
386
+ result type;
387
+ - otherwise, the *new-expression* terminates by throwing an exception
388
+ of a type that would match a handler ([[except.handle]]) of type
389
+ `std::bad_array_new_length` ([[new.badlength]]).
390
+
391
+ When the value of the *expression* is zero, the allocation function is
392
+ called to allocate an array with no elements.
393
 
394
  A *new-expression* may obtain storage for the object by calling an
395
+ allocation function ([[basic.stc.dynamic.allocation]]). If the
396
  *new-expression* terminates by throwing an exception, it may release
397
  storage by calling a deallocation function (
398
  [[basic.stc.dynamic.deallocation]]). If the allocated type is a
399
  non-array type, the allocation function’s name is `operator new` and the
400
  deallocation function’s name is `operator delete`. If the allocated type
401
  is an array type, the allocation function’s name is `operator new[]` and
402
+ the deallocation function’s name is `operator delete[]`.
403
+
404
+ [*Note 7*: An implementation shall provide default definitions for the
405
+ global allocation functions ([[basic.stc.dynamic]]
406
+ [[new.delete.single]],  [[new.delete.array]]). A C++program can provide
407
+ alternative definitions of these functions ([[replacement.functions]])
408
+ and/or class-specific versions ([[class.free]]). The set of allocation
409
+ and deallocation functions that may be called by a *new-expression* may
410
+ include functions that do not perform allocation or deallocation; for
411
+ example, see [[new.delete.placement]]. — *end note*]
412
 
413
  If the *new-expression* begins with a unary `::` operator, the
414
  allocation function’s name is looked up in the global scope. Otherwise,
415
  if the allocated type is a class type `T` or array thereof, the
416
  allocation function’s name is looked up in the scope of `T`. If this
 
436
  *delete-expression*s, and
437
  - the evaluation of `e2` is sequenced before the evaluation of the
438
  *delete-expression* whose operand is the pointer value produced by
439
  `e1`.
440
 
441
+ [*Example 5*:
442
+
443
  ``` cpp
444
  void mergeable(int x) {
445
  // These allocations are safe for merging:
446
  std::unique_ptr<char[]> a{new (std::nothrow) char[8]};
447
  std::unique_ptr<char[]> b{new (std::nothrow) char[8]};
 
460
  throw;
461
  }
462
  }
463
  ```
464
 
465
+ — *end example*]
466
+
467
  When a *new-expression* calls an allocation function and that allocation
468
  has not been extended, the *new-expression* passes the amount of space
469
  requested to the allocation function as the first argument of type
470
  `std::size_t`. That argument shall be no less than the size of the
471
  object being created; it may be greater than the size of the object
472
+ being created only if the object is an array. For arrays of `char`,
473
+ `unsigned char`, and `std::byte`, the difference between the result of
474
+ the *new-expression* and the address returned by the allocation function
475
  shall be an integral multiple of the strictest fundamental alignment
476
  requirement ([[basic.align]]) of any object type whose size is no
477
+ greater than the size of the array being created.
478
+
479
+ [*Note 8*: Because allocation functions are assumed to return pointers
480
+ to storage that is appropriately aligned for objects of any type with
481
+ fundamental alignment, this constraint on array allocation overhead
482
+ permits the common idiom of allocating character arrays into which
483
+ objects of other types will later be placed. — *end note*]
484
 
485
  When a *new-expression* calls an allocation function and that allocation
486
  has been extended, the size argument to the allocation call shall be no
487
  greater than the sum of the sizes for the omitted calls as specified
488
  above, plus the size for the extended call had it not been extended,
489
  plus any padding necessary to align the allocated objects within the
490
  allocated memory.
491
 
492
  The *new-placement* syntax is used to supply additional arguments to an
493
+ allocation function; such an expression is called a *placement
494
+ *new-expression**.
495
+
496
+ Overload resolution is performed on a function call created by
497
+ assembling an argument list. The first argument is the amount of space
498
+ requested, and has type `std::size_t`. If the type of the allocated
499
+ object has new-extended alignment, the next argument is the type’s
500
+ alignment, and has type `std::align_val_t`. If the *new-placement*
501
+ syntax is used, the *initializer-clause*s in its *expression-list* are
502
+ the succeeding arguments. If no matching function is found and the
503
+ allocated object type has new-extended alignment, the alignment argument
504
+ is removed from the argument list, and overload resolution is performed
505
+ again.
506
+
507
+ [*Example 6*:
508
+
509
+ - `new T` results in one of the following calls:
510
+ ``` cpp
511
+ operator new(sizeof(T))
512
+ operator new(sizeof(T), std::align_val_t(alignof(T)))
513
+ ```
514
+ - `new(2,f) T` results in one of the following calls:
515
+ ``` cpp
516
+ operator new(sizeof(T), 2, f)
517
+ operator new(sizeof(T), std::align_val_t(alignof(T)), 2, f)
518
+ ```
519
+ - `new T[5]` results in one of the following calls:
520
+ ``` cpp
521
+ operator new[](sizeof(T) * 5 + x)
522
+ operator new[](sizeof(T) * 5 + x, std::align_val_t(alignof(T)))
523
+ ```
524
+ - `new(2,f) T[5]` results in one of the following calls:
525
+ ``` cpp
526
+ operator new[](sizeof(T) * 5 + x, 2, f)
527
+ operator new[](sizeof(T) * 5 + x, std::align_val_t(alignof(T)), 2, f)
528
+ ```
529
+
530
+ Here, each instance of `x` is a non-negative unspecified value
531
+ representing array allocation overhead; the result of the
532
+ *new-expression* will be offset by this amount from the value returned
533
+ by `operator new[]`. This overhead may be applied in all array
534
+ *new-expression*s, including those referencing the library function
535
+ `operator new[](std::size_t, void*)` and other placement allocation
536
+ functions. The amount of overhead may vary from one invocation of `new`
537
+ to another.
538
+
539
+ — *end example*]
540
+
541
+ [*Note 9*: Unless an allocation function has a non-throwing exception
542
+ specification ([[except.spec]]), it indicates failure to allocate
543
+ storage by throwing a `std::bad_alloc` exception (
544
+ [[basic.stc.dynamic.allocation]], Clause  [[except]],  [[bad.alloc]]);
545
+ it returns a non-null pointer otherwise. If the allocation function has
546
+ a non-throwing exception specification, it returns null to indicate
547
+ failure to allocate storage and a non-null pointer
548
+ otherwise. — *end note*]
549
+
550
+ If the allocation function is a non-allocating form (
551
+ [[new.delete.placement]]) that returns null, the behavior is undefined.
552
+ Otherwise, if the allocation function returns null, initialization shall
553
+ not be done, the deallocation function shall not be called, and the
554
+ value of the *new-expression* shall be null.
555
+
556
+ [*Note 10*: When the allocation function returns a value other than
557
+ null, it must be a pointer to a block of storage in which space for the
558
+ object has been reserved. The block of storage is assumed to be
559
+ appropriately aligned and of the requested size. The address of the
560
+ created object will not necessarily be the same as that of the block if
561
+ the object is an array. — *end note*]
562
 
563
  A *new-expression* that creates an object of type `T` initializes that
564
  object as follows:
565
 
566
  - If the *new-initializer* is omitted, the object is
567
+ default-initialized ([[dcl.init]]). \[*Note 11*: If no initialization
568
+ is performed, the object has an indeterminate value. — *end note*]
569
  - Otherwise, the *new-initializer* is interpreted according to the
570
  initialization rules of  [[dcl.init]] for direct-initialization.
571
 
572
+ The invocation of the allocation function is sequenced before the
573
+ evaluations of expressions in the *new-initializer*. Initialization of
574
+ the allocated object is sequenced before the value computation of the
575
+ *new-expression*.
 
 
576
 
577
  If the *new-expression* creates an object or an array of objects of
578
  class type, access and ambiguity control are done for the allocation
579
  function, the deallocation function ([[class.free]]), and the
580
  constructor ([[class.ctor]]). If the *new-expression* creates an array
581
  of objects of class type, the destructor is potentially invoked (
582
  [[class.dtor]]).
583
 
584
  If any part of the object initialization described above[^19] terminates
585
+ by throwing an exception and a suitable deallocation function can be
586
+ found, the deallocation function is called to free the memory in which
587
+ the object was being constructed, after which the exception continues to
588
+ propagate in the context of the *new-expression*. If no unambiguous
589
+ matching deallocation function can be found, propagating the exception
590
+ does not cause the object’s memory to be freed.
591
+
592
+ [*Note 12*: This is appropriate when the called allocation function
593
  does not allocate memory; otherwise, it is likely to result in a memory
594
+ leak. — *end note*]
595
 
596
  If the *new-expression* begins with a unary `::` operator, the
597
  deallocation function’s name is looked up in the global scope.
598
  Otherwise, if the allocated type is a class type `T` or an array
599
  thereof, the deallocation function’s name is looked up in the scope of
 
605
  declaration of a placement allocation function if it has the same number
606
  of parameters and, after parameter transformations ([[dcl.fct]]), all
607
  parameter types except the first are identical. If the lookup finds a
608
  single matching deallocation function, that function will be called;
609
  otherwise, no deallocation function will be called. If the lookup finds
610
+ a usual deallocation function with a parameter of type `std::size_t` (
611
  [[basic.stc.dynamic.deallocation]]) and that function, considered as a
612
  placement deallocation function, would have been selected as a match for
613
  the allocation function, the program is ill-formed. For a non-placement
614
  allocation function, the normal deallocation function lookup is used to
615
  find the matching deallocation function ([[expr.delete]])
616
 
617
+ [*Example 7*:
618
+
619
  ``` cpp
620
  struct S {
621
  // Placement allocation function:
622
  static void* operator new(std::size_t, std::size_t);
623
 
 
627
 
628
  S* p = new (0) S; // ill-formed: non-placement deallocation function matches
629
  // placement allocation function
630
  ```
631
 
632
+ — *end example*]
633
+
634
  If a *new-expression* calls a deallocation function, it passes the value
635
  returned from the allocation function call as the first argument of type
636
  `void*`. If a placement deallocation function is called, it is passed
637
  the same additional arguments as were passed to the placement allocation
638
  function, that is, the same arguments as those specified with the
 
671
  a pointer to a subobject ([[intro.object]]) representing a base class
672
  of such an object (Clause  [[class.derived]]). If not, the behavior is
673
  undefined. In the second alternative (*delete array*), the value of the
674
  operand of `delete` may be a null pointer value or a pointer value that
675
  resulted from a previous array *new-expression*.[^22] If not, the
676
+ behavior is undefined.
677
+
678
+ [*Note 1*: This means that the syntax of the *delete-expression* must
679
+ match the type of the object allocated by `new`, not the syntax of the
680
+ *new-expression*. *end note*]
681
+
682
+ [*Note 2*: A pointer to a `const` type can be the operand of a
683
+ *delete-expression*; it is not necessary to cast away the constness (
684
+ [[expr.const.cast]]) of the pointer expression before it is used as the
685
+ operand of the *delete-expression*. — *end note*]
686
 
687
  In the first alternative (*delete object*), if the static type of the
688
  object to be deleted is different from its dynamic type, the static type
689
  shall be a base class of the dynamic type of the object to be deleted
690
  and the static type shall have a virtual destructor or the behavior is
 
721
  *new-expression* that had storage provided by the extended
722
  *new-expression* has been evaluated, the *delete-expression* shall
723
  call a deallocation function. The value returned from the allocation
724
  call of the extended *new-expression* shall be passed as the first
725
  argument to the deallocation function.
726
+ - Otherwise, the *delete-expression* will not call a deallocation
727
+ function.
728
 
729
+ [*Note 3*: The deallocation function is called regardless of whether
730
+ the destructor for the object or some element of the array throws an
731
+ exception. *end note*]
 
732
 
733
+ If the value of the operand of the *delete-expression* is a null pointer
734
+ value, it is unspecified whether a deallocation function will be called
735
+ as described above.
736
+
737
+ [*Note 4*: An implementation provides default definitions of the global
738
+ deallocation functions `operator delete` for non-arrays (
739
+ [[new.delete.single]]) and `operator delete[]` for arrays (
740
  [[new.delete.array]]). A C++ program can provide alternative definitions
741
  of these functions ([[replacement.functions]]), and/or class-specific
742
+ versions ([[class.free]]). — *end note*]
743
 
744
  When the keyword `delete` in a *delete-expression* is preceded by the
745
  unary `::` operator, the deallocation function’s name is looked up in
746
  global scope. Otherwise, the lookup considers class-specific
747
  deallocation functions ([[class.free]]). If no class-specific
748
  deallocation function is found, the deallocation function’s name is
749
  looked up in global scope.
750
 
751
+ If deallocation function lookup finds more than one usual deallocation
752
+ function, the function to be called is selected as follows:
753
+
754
+ - If the type has new-extended alignment, a function with a parameter of
755
+ type `std::align_val_t` is preferred; otherwise a function without
756
+ such a parameter is preferred. If exactly one preferred function is
757
+ found, that function is selected and the selection process terminates.
758
+ If more than one preferred function is found, all non-preferred
759
+ functions are eliminated from further consideration.
760
+ - If the deallocation functions have class scope, the one without a
761
+ parameter of type `std::size_t` is selected.
762
+ - If the type is complete and if, for the second alternative (delete
763
+ array) only, the operand is a pointer to a class type with a
764
+ non-trivial destructor or a (possibly multi-dimensional) array
765
+ thereof, the function with a parameter of type `std::size_t` is
766
+ selected.
767
+ - Otherwise, it is unspecified whether a deallocation function with a
768
+ parameter of type `std::size_t` is selected.
769
 
770
  When a *delete-expression* is executed, the selected deallocation
771
+ function shall be called with the address of the most-derived object in
772
+ the *delete object* case, or the address of the object suitably adjusted
773
+ for the array allocation overhead ([[expr.new]]) in the *delete array*
774
+ case, as its first argument. If a deallocation function with a parameter
775
+ of type `std::align_val_t` is used, the alignment of the type of the
776
+ object to be deleted is passed as the corresponding argument. If a
777
+ deallocation function with a parameter of type `std::size_t` is used,
778
+ the size of the most-derived type, or of the array plus allocation
779
+ overhead, respectively, is passed as the corresponding argument. [^23]
780
+
781
+ [*Note 5*: If this results in a call to a usual deallocation function,
782
+ and either the first argument was not the result of a prior call to a
783
+ usual allocation function or the second argument was not the
784
+ corresponding argument in said call, the behavior is undefined (
785
+ [[new.delete.single]], [[new.delete.array]]). — *end note*]
786
 
787
  Access and ambiguity control are done for both the deallocation function
788
  and the destructor ([[class.dtor]],  [[class.free]]).
789
 
790
  ### Alignof <a id="expr.alignof">[[expr.alignof]]</a>
 
811
  ```
812
 
813
  The result of the `noexcept` operator is a constant of type `bool` and
814
  is a prvalue.
815
 
816
+ The result of the `noexcept` operator is `true` unless the *expression*
817
+ is potentially-throwing ([[except.spec]]).
 
 
 
 
 
 
 
 
 
 
 
 
 
 
818