- tmp/tmpjy5su6eb/{from.md → to.md} +326 -140
tmp/tmpjy5su6eb/{from.md → to.md}
RENAMED
|
@@ -18,10 +18,11 @@ unary-expression:
|
|
| 18 |
sizeof '...' '(' identifier ')'
|
| 19 |
alignof '(' type-id ')'
|
| 20 |
noexcept-expression
|
| 21 |
new-expression
|
| 22 |
delete-expression
|
|
|
|
| 23 |
```
|
| 24 |
|
| 25 |
``` bnf
|
| 26 |
%% Ed. note: character protrusion would misalign operators.
|
| 27 |
|
|
@@ -31,33 +32,42 @@ unary-operator: one of
|
|
| 31 |
|
| 32 |
#### Unary operators <a id="expr.unary.op">[[expr.unary.op]]</a>
|
| 33 |
|
| 34 |
The unary `*` operator performs *indirection*. Its operand shall be a
|
| 35 |
prvalue of type “pointer to `T`”, where `T` is an object or function
|
| 36 |
-
type. The operator yields an lvalue of type `T`
|
| 37 |
-
|
|
|
|
|
|
|
| 38 |
|
| 39 |
-
[*Note 1*:
|
|
|
|
|
|
|
|
|
|
| 40 |
than cv `void`) is valid. The lvalue thus obtained can be used in
|
| 41 |
limited ways (to initialize a reference, for example); this lvalue must
|
| 42 |
not be converted to a prvalue, see [[conv.lval]]. — *end note*]
|
| 43 |
|
| 44 |
Each of the following unary operators yields a prvalue.
|
| 45 |
|
| 46 |
The operand of the unary `&` operator shall be an lvalue of some type
|
| 47 |
-
`T`.
|
| 48 |
|
| 49 |
-
- If the operand is a *qualified-id*
|
| 50 |
-
member `m`
|
| 51 |
-
function,
|
| 52 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 53 |
- Otherwise, the result has type “pointer to `T`” and points to the
|
| 54 |
designated object [[intro.memory]] or function [[basic.compound]]. If
|
| 55 |
-
the operand
|
| 56 |
-
operand shall be a *qualified-id*
|
| 57 |
-
|
| 58 |
-
“pointer to cv `T`”. — *end note*]
|
| 59 |
|
| 60 |
[*Example 1*:
|
| 61 |
|
| 62 |
``` cpp
|
| 63 |
struct A { int i; };
|
|
@@ -69,18 +79,19 @@ int* p2 = p1 + 1; // defined behavior
|
|
| 69 |
bool b = p2 > p1; // defined behavior, with value true
|
| 70 |
```
|
| 71 |
|
| 72 |
— *end example*]
|
| 73 |
|
| 74 |
-
[*Note
|
| 75 |
member [[dcl.stc]] does not reflect the `mutable` specifier associated
|
| 76 |
with the non-static data member. — *end note*]
|
| 77 |
|
| 78 |
A pointer to member is only formed when an explicit `&` is used and its
|
| 79 |
-
operand is a *qualified-id* not enclosed in
|
|
|
|
| 80 |
|
| 81 |
-
[*Note
|
| 82 |
*qualified-id* is enclosed in parentheses, does not form an expression
|
| 83 |
of type “pointer to member”. Neither does `qualified-id`, because there
|
| 84 |
is no implicit conversion from a *qualified-id* for a non-static member
|
| 85 |
function to the type “pointer to member function” as there is from an
|
| 86 |
lvalue of function type to the type “pointer to function” [[conv.func]].
|
|
@@ -90,99 +101,96 @@ the *unqualified-id*’s class. — *end note*]
|
|
| 90 |
If `&` is applied to an lvalue of incomplete class type and the complete
|
| 91 |
type declares `operator&()`, it is unspecified whether the operator has
|
| 92 |
the built-in meaning or the operator function is called. The operand of
|
| 93 |
`&` shall not be a bit-field.
|
| 94 |
|
| 95 |
-
[*Note
|
| 96 |
a context that uniquely determines which function is referred to (see
|
| 97 |
[[over.over]]). Since the context can affect whether the operand is a
|
| 98 |
static or non-static member function, the context can also affect
|
| 99 |
whether the expression has type “pointer to function” or “pointer to
|
| 100 |
member function”. — *end note*]
|
| 101 |
|
| 102 |
-
The operand of the unary `+` operator shall
|
| 103 |
-
enumeration, or pointer type and the result is the value of the
|
| 104 |
argument. Integral promotion is performed on integral or enumeration
|
| 105 |
operands. The type of the result is the type of the promoted operand.
|
| 106 |
|
| 107 |
-
The operand of the unary `-` operator shall
|
| 108 |
-
enumeration type and the result is the negative of its
|
| 109 |
-
promotion is performed on integral or enumeration
|
| 110 |
-
of an unsigned quantity is computed by
|
| 111 |
-
where n is the number of bits in the
|
| 112 |
-
result is the type of the promoted
|
|
|
|
| 113 |
|
| 114 |
-
[*Note
|
| 115 |
operand and result are considered as unsigned). — *end note*]
|
| 116 |
|
| 117 |
The operand of the logical negation operator `!` is contextually
|
| 118 |
converted to `bool` [[conv]]; its value is `true` if the converted
|
| 119 |
operand is `false` and `false` otherwise. The type of the result is
|
| 120 |
`bool`.
|
| 121 |
|
| 122 |
-
The operand of the `~` operator shall
|
| 123 |
-
enumeration type. Integral promotions are performed. The type
|
| 124 |
-
result is the type of the promoted operand. Given the
|
| 125 |
-
of the base-2 representation [[basic.fundamental]] of
|
| 126 |
-
operand `x`, the coefficient `rᵢ` of the base-2
|
| 127 |
-
result `r` is 1 if `xᵢ` is 0, and 0 otherwise.
|
| 128 |
|
| 129 |
-
[*Note
|
| 130 |
operand and result are considered as unsigned). — *end note*]
|
| 131 |
|
| 132 |
There is an ambiguity in the grammar when `~` is followed by a
|
| 133 |
-
*type-name* or *
|
| 134 |
treating `~` as the operator rather than as the start of an
|
| 135 |
*unqualified-id* naming a destructor.
|
| 136 |
|
| 137 |
-
[*Note
|
| 138 |
the `.`, `->`, or `::` tokens, a `~` followed by a *type-name* or
|
| 139 |
-
*
|
| 140 |
-
unambiguously parsed as a destructor
|
|
|
|
| 141 |
|
| 142 |
#### Increment and decrement <a id="expr.pre.incr">[[expr.pre.incr]]</a>
|
| 143 |
|
| 144 |
-
The operand of prefix `++`
|
| 145 |
-
|
| 146 |
-
|
| 147 |
-
|
| 148 |
-
|
| 149 |
-
operand; it is an lvalue, and it is a bit-field if the operand is a
|
| 150 |
-
bit-field. The expression `++x` is equivalent to `x+=1`.
|
| 151 |
|
| 152 |
-
[*Note 1*:
|
| 153 |
-
operators [[expr.ass]] for information on conversions. — *end note*]
|
| 154 |
-
|
| 155 |
-
The operand of prefix `--` is modified [[defns.access]] by subtracting
|
| 156 |
-
`1`. The requirements on the operand of prefix `--` and the properties
|
| 157 |
-
of its result are otherwise the same as those of prefix `++`.
|
| 158 |
-
|
| 159 |
-
[*Note 2*: For postfix increment and decrement, see
|
| 160 |
[[expr.post.incr]]. — *end note*]
|
| 161 |
|
| 162 |
#### Await <a id="expr.await">[[expr.await]]</a>
|
| 163 |
|
| 164 |
The `co_await` expression is used to suspend evaluation of a coroutine
|
| 165 |
[[dcl.fct.def.coroutine]] while awaiting completion of the computation
|
| 166 |
-
represented by the operand expression.
|
|
|
|
| 167 |
|
| 168 |
``` bnf
|
| 169 |
await-expression:
|
| 170 |
-
|
| 171 |
```
|
| 172 |
|
| 173 |
-
An *await-expression* shall appear only
|
| 174 |
-
expression within the *compound-statement* of a *function-body*
|
| 175 |
-
|
|
|
|
| 176 |
*simple-declaration* (if any) of an *init-statement*, an
|
| 177 |
*await-expression* shall appear only in an *initializer* of that
|
| 178 |
*declaration-statement* or *simple-declaration*. An *await-expression*
|
| 179 |
shall not appear in a default argument [[dcl.fct.default]]. An
|
| 180 |
*await-expression* shall not appear in the initializer of a block
|
| 181 |
-
variable with static or thread storage duration.
|
| 182 |
-
|
| 183 |
-
context
|
|
|
|
|
|
|
| 184 |
|
| 185 |
Evaluation of an *await-expression* involves the following auxiliary
|
| 186 |
types, expressions, and objects:
|
| 187 |
|
| 188 |
- *p* is an lvalue naming the promise object [[dcl.fct.def.coroutine]]
|
|
@@ -302,11 +310,11 @@ to any other fundamental type [[basic.fundamental]] is
|
|
| 302 |
|
| 303 |
[*Note 1*:
|
| 304 |
|
| 305 |
In particular, the values of `sizeof(bool)`, `sizeof(char16_t)`,
|
| 306 |
`sizeof(char32_t)`, and `sizeof(wchar_t)` are
|
| 307 |
-
implementation-defined.[^
|
| 308 |
|
| 309 |
— *end note*]
|
| 310 |
|
| 311 |
[*Note 2*: See [[intro.memory]] for the definition of byte and
|
| 312 |
[[term.object.representation]] for the definition of object
|
|
@@ -315,83 +323,84 @@ representation. — *end note*]
|
|
| 315 |
When applied to a reference type, the result is the size of the
|
| 316 |
referenced type. When applied to a class, the result is the number of
|
| 317 |
bytes in an object of that class including any padding required for
|
| 318 |
placing objects of that type in an array. The result of applying
|
| 319 |
`sizeof` to a potentially-overlapping subobject is the size of the type,
|
| 320 |
-
not the size of the subobject.[^
|
| 321 |
|
| 322 |
When applied to an array, the result is the total number of bytes in the
|
| 323 |
array. This implies that the size of an array of n elements is n times
|
| 324 |
the size of an element.
|
| 325 |
|
| 326 |
The lvalue-to-rvalue [[conv.lval]], array-to-pointer [[conv.array]], and
|
| 327 |
function-to-pointer [[conv.func]] standard conversions are not applied
|
| 328 |
to the operand of `sizeof`. If the operand is a prvalue, the temporary
|
| 329 |
materialization conversion [[conv.rval]] is applied.
|
| 330 |
|
| 331 |
-
The identifier in a `sizeof...` expression shall name a pack. The
|
| 332 |
`sizeof...` operator yields the number of elements in the pack
|
| 333 |
[[temp.variadic]]. A `sizeof...` expression is a pack expansion
|
| 334 |
[[temp.variadic]].
|
| 335 |
|
| 336 |
[*Example 1*:
|
| 337 |
|
| 338 |
``` cpp
|
| 339 |
template<class... Types>
|
| 340 |
struct count {
|
| 341 |
-
static
|
| 342 |
};
|
| 343 |
```
|
| 344 |
|
| 345 |
— *end example*]
|
| 346 |
|
| 347 |
The result of `sizeof` and `sizeof...` is a prvalue of type
|
| 348 |
`std::size_t`.
|
| 349 |
|
| 350 |
[*Note 3*: A `sizeof` expression is an integral constant expression
|
| 351 |
-
[[expr.const]]. The
|
| 352 |
-
`<cstddef>`
|
|
|
|
| 353 |
|
| 354 |
#### Alignof <a id="expr.alignof">[[expr.alignof]]</a>
|
| 355 |
|
| 356 |
An `alignof` expression yields the alignment requirement of its operand
|
| 357 |
type. The operand shall be a *type-id* representing a complete object
|
| 358 |
type, or an array thereof, or a reference to one of those types.
|
| 359 |
|
| 360 |
The result is a prvalue of type `std::size_t`.
|
| 361 |
|
| 362 |
[*Note 1*: An `alignof` expression is an integral constant expression
|
| 363 |
-
[[expr.const]]. The
|
| 364 |
-
`<cstddef>`
|
|
|
|
| 365 |
|
| 366 |
When `alignof` is applied to a reference type, the result is the
|
| 367 |
alignment of the referenced type. When `alignof` is applied to an array
|
| 368 |
type, the result is the alignment of the element type.
|
| 369 |
|
| 370 |
#### `noexcept` operator <a id="expr.unary.noexcept">[[expr.unary.noexcept]]</a>
|
| 371 |
|
| 372 |
-
The `noexcept` operator determines whether the evaluation of its
|
| 373 |
-
operand, which is an unevaluated operand [[term.unevaluated.operand]],
|
| 374 |
-
can throw an exception [[except.throw]].
|
| 375 |
-
|
| 376 |
``` bnf
|
| 377 |
noexcept-expression:
|
| 378 |
noexcept '(' expression ')'
|
| 379 |
```
|
| 380 |
|
| 381 |
-
The
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 382 |
|
| 383 |
[*Note 1*: A *noexcept-expression* is an integral constant expression
|
| 384 |
[[expr.const]]. — *end note*]
|
| 385 |
|
| 386 |
-
The result of the `noexcept` operator is `true` unless the *expression*
|
| 387 |
-
is potentially-throwing [[except.spec]].
|
| 388 |
-
|
| 389 |
#### New <a id="expr.new">[[expr.new]]</a>
|
| 390 |
|
| 391 |
-
The *new-expression* attempts to create an object of the *type-id*
|
| 392 |
-
|
| 393 |
object is the *allocated type*. This type shall be a complete object
|
| 394 |
type [[term.incomplete.type]], but not an abstract class type
|
| 395 |
[[class.abstract]] or array thereof [[intro.object]].
|
| 396 |
|
| 397 |
[*Note 1*: Because references are not objects, references cannot be
|
|
@@ -433,17 +442,17 @@ noptr-new-declarator:
|
|
| 433 |
new-initializer:
|
| 434 |
'(' expression-listₒₚₜ ')'
|
| 435 |
braced-init-list
|
| 436 |
```
|
| 437 |
|
| 438 |
-
If a placeholder type [[dcl.spec.auto]]
|
| 439 |
-
|
| 440 |
-
*new-
|
| 441 |
-
|
| 442 |
-
*type-id* of the *new-expression*, then
|
| 443 |
-
deduced for the variable `x` in the
|
| 444 |
-
[[dcl.spec.auto]]:
|
| 445 |
|
| 446 |
``` cpp
|
| 447 |
T x init ;
|
| 448 |
```
|
| 449 |
|
|
@@ -515,34 +524,41 @@ converted constant expression [[expr.const]] of type `std::size_t` and
|
|
| 515 |
its value shall be greater than zero.
|
| 516 |
|
| 517 |
[*Example 4*: Given the definition `int n = 42`, `new float[n][5]` is
|
| 518 |
well-formed (because `n` is the *expression* of a
|
| 519 |
*noptr-new-declarator*), but `new float[5][n]` is ill-formed (because
|
| 520 |
-
`n` is not a constant expression).
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 521 |
|
| 522 |
If the *type-id* or *new-type-id* denotes an array type of unknown bound
|
| 523 |
[[dcl.array]], the *new-initializer* shall not be omitted; the allocated
|
| 524 |
object is an array with `n` elements, where `n` is determined from the
|
| 525 |
number of initial elements supplied in the *new-initializer*
|
| 526 |
[[dcl.init.aggr]], [[dcl.init.string]].
|
| 527 |
|
| 528 |
If the *expression* in a *noptr-new-declarator* is present, it is
|
| 529 |
-
implicitly converted to `std::size_t`. The *expression* is
|
|
|
|
| 530 |
|
| 531 |
- the expression is of non-class type and its value before converting to
|
| 532 |
`std::size_t` is less than zero;
|
| 533 |
- the expression is of class type and its value before application of
|
| 534 |
-
the second standard conversion [[over.ics.user]][^
|
| 535 |
zero;
|
| 536 |
- its value is such that the size of the allocated object would exceed
|
| 537 |
the *implementation-defined* limit [[implimits]]; or
|
| 538 |
- the *new-initializer* is a *braced-init-list* and the number of array
|
| 539 |
elements for which initializers are provided (including the
|
| 540 |
terminating `'\0'` in a *string-literal* [[lex.string]]) exceeds the
|
| 541 |
number of elements to initialize.
|
| 542 |
|
| 543 |
-
If the *expression* is
|
|
|
|
| 544 |
|
| 545 |
- if the *expression* is a potentially-evaluated core constant
|
| 546 |
expression, the program is ill-formed;
|
| 547 |
- otherwise, an allocation function is not called; instead
|
| 548 |
- if the allocation function that would have been called has a
|
|
@@ -554,24 +570,34 @@ If the *expression* is erroneous after converting to `std::size_t`:
|
|
| 554 |
`std::bad_array_new_length` [[new.badlength]].
|
| 555 |
|
| 556 |
When the value of the *expression* is zero, the allocation function is
|
| 557 |
called to allocate an array with no elements.
|
| 558 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 559 |
Objects created by a *new-expression* have dynamic storage duration
|
| 560 |
[[basic.stc.dynamic]].
|
| 561 |
|
| 562 |
-
[*Note
|
| 563 |
restricted to the scope in which it is created. — *end note*]
|
| 564 |
|
| 565 |
When the allocated type is “array of `N` `T`” (that is, the
|
| 566 |
*noptr-new-declarator* syntax is used or the *new-type-id* or *type-id*
|
| 567 |
denotes an array type), the *new-expression* yields a prvalue of type
|
| 568 |
“pointer to `T`” that points to the initial element (if any) of the
|
| 569 |
array. Otherwise, let `T` be the allocated type; the *new-expression* is
|
| 570 |
a prvalue of type “pointer to T” that points to the object created.
|
| 571 |
|
| 572 |
-
[*Note
|
| 573 |
type of `new int[i][10]` is `int (*)[10]`. — *end note*]
|
| 574 |
|
| 575 |
A *new-expression* may obtain storage for the object by calling an
|
| 576 |
allocation function [[basic.stc.dynamic.allocation]]. If the
|
| 577 |
*new-expression* terminates by throwing an exception, it may release
|
|
@@ -580,11 +606,11 @@ storage by calling a deallocation function
|
|
| 580 |
type, the allocation function’s name is `operator new` and the
|
| 581 |
deallocation function’s name is `operator delete`. If the allocated type
|
| 582 |
is an array type, the allocation function’s name is `operator new[]` and
|
| 583 |
the deallocation function’s name is `operator delete[]`.
|
| 584 |
|
| 585 |
-
[*Note
|
| 586 |
for the global allocation functions
|
| 587 |
[[basic.stc.dynamic]], [[new.delete.single]], [[new.delete.array]]. A
|
| 588 |
C++ program can provide alternative definitions of these functions
|
| 589 |
[[replacement.functions]] and/or class-specific versions [[class.free]].
|
| 590 |
The set of allocation and deallocation functions that can be called by a
|
|
@@ -601,16 +627,12 @@ global scope.
|
|
| 601 |
An implementation is allowed to omit a call to a replaceable global
|
| 602 |
allocation function [[new.delete.single]], [[new.delete.array]]. When it
|
| 603 |
does so, the storage is instead provided by the implementation or
|
| 604 |
provided by extending the allocation of another *new-expression*.
|
| 605 |
|
| 606 |
-
During an evaluation of a constant expression, a call to
|
| 607 |
-
function is always omitted.
|
| 608 |
-
|
| 609 |
-
[*Note 8*: Only *new-expression*s that would otherwise result in a call
|
| 610 |
-
to a replaceable global allocation function can be evaluated in constant
|
| 611 |
-
expressions [[expr.const]]. — *end note*]
|
| 612 |
|
| 613 |
The implementation may extend the allocation of a *new-expression* `e1`
|
| 614 |
to provide storage for a *new-expression* `e2` if the following would be
|
| 615 |
true were the allocation not extended:
|
| 616 |
|
|
@@ -749,13 +771,13 @@ not be done, the deallocation function shall not be called, and the
|
|
| 749 |
value of the *new-expression* shall be null.
|
| 750 |
|
| 751 |
[*Note 11*: When the allocation function returns a value other than
|
| 752 |
null, it must be a pointer to a block of storage in which space for the
|
| 753 |
object has been reserved. The block of storage is assumed to be
|
| 754 |
-
appropriately aligned and of the requested size. The
|
| 755 |
-
created object will not necessarily be the same as that
|
| 756 |
-
the object is an array. — *end note*]
|
| 757 |
|
| 758 |
A *new-expression* that creates an object of type `T` initializes that
|
| 759 |
object as follows:
|
| 760 |
|
| 761 |
- If the *new-initializer* is omitted, the object is default-initialized
|
|
@@ -767,18 +789,14 @@ object as follows:
|
|
| 767 |
The invocation of the allocation function is sequenced before the
|
| 768 |
evaluations of expressions in the *new-initializer*. Initialization of
|
| 769 |
the allocated object is sequenced before the value computation of the
|
| 770 |
*new-expression*.
|
| 771 |
|
| 772 |
-
If the *new-expression* creates an
|
| 773 |
-
|
| 774 |
-
function, the deallocation function [[basic.stc.dynamic.deallocation]],
|
| 775 |
-
and the constructor [[class.ctor]] selected for the initialization (if
|
| 776 |
-
any). If the *new-expression* creates an array of objects of class type,
|
| 777 |
-
the destructor is potentially invoked [[class.dtor]].
|
| 778 |
|
| 779 |
-
If any part of the object initialization described above[^
|
| 780 |
|
| 781 |
terminates by throwing an exception and a suitable deallocation function
|
| 782 |
can be found, the deallocation function is called to free the memory in
|
| 783 |
which the object was being constructed, after which the exception
|
| 784 |
continues to propagate in the context of the *new-expression*. If no
|
|
@@ -803,11 +821,13 @@ single matching deallocation function, that function will be called;
|
|
| 803 |
otherwise, no deallocation function will be called. If the lookup finds
|
| 804 |
a usual deallocation function and that function, considered as a
|
| 805 |
placement deallocation function, would have been selected as a match for
|
| 806 |
the allocation function, the program is ill-formed. For a non-placement
|
| 807 |
allocation function, the normal deallocation function lookup is used to
|
| 808 |
-
find the matching deallocation function [[expr.delete]].
|
|
|
|
|
|
|
| 809 |
|
| 810 |
[*Example 7*:
|
| 811 |
|
| 812 |
``` cpp
|
| 813 |
struct S {
|
|
@@ -846,30 +866,26 @@ delete-expression:
|
|
| 846 |
```
|
| 847 |
|
| 848 |
The first alternative is a *single-object delete expression*, and the
|
| 849 |
second is an *array delete expression*. Whenever the `delete` keyword is
|
| 850 |
immediately followed by empty square brackets, it shall be interpreted
|
| 851 |
-
as the second alternative.[^
|
| 852 |
|
| 853 |
-
|
| 854 |
-
|
| 855 |
-
|
|
|
|
|
|
|
| 856 |
|
| 857 |
-
|
| 858 |
-
|
| 859 |
-
|
| 860 |
-
|
| 861 |
-
|
| 862 |
-
|
| 863 |
-
|
| 864 |
-
|
| 865 |
-
pointer to a base class subobject of an object created by such a
|
| 866 |
-
*new-expression*. If not, the behavior is undefined. In an array delete
|
| 867 |
-
expression, the value of the operand of `delete` may be a null pointer
|
| 868 |
-
value or a pointer value that resulted from a previous array
|
| 869 |
-
*new-expression* whose allocation function was not a non-allocating form
|
| 870 |
-
[[new.delete.placement]].[^27]
|
| 871 |
|
| 872 |
If not, the behavior is undefined.
|
| 873 |
|
| 874 |
[*Note 1*: This means that the syntax of the *delete-expression* must
|
| 875 |
match the type of the object allocated by `new`, not the syntax of the
|
|
@@ -887,24 +903,21 @@ delete, the static type shall be a base class of the dynamic type of the
|
|
| 887 |
object to be deleted and the static type shall have a virtual destructor
|
| 888 |
or the behavior is undefined. In an array delete expression, if the
|
| 889 |
dynamic type of the object to be deleted is not similar to its static
|
| 890 |
type, the behavior is undefined.
|
| 891 |
|
| 892 |
-
The *cast-expression* in a *delete-expression* shall be evaluated
|
| 893 |
-
exactly once.
|
| 894 |
-
|
| 895 |
If the object being deleted has incomplete class type at the point of
|
| 896 |
-
deletion
|
| 897 |
-
deallocation function, the behavior is undefined.
|
| 898 |
|
| 899 |
If the value of the operand of the *delete-expression* is not a null
|
| 900 |
pointer value and the selected deallocation function (see below) is not
|
| 901 |
-
a destroying operator delete, the *delete-expression*
|
| 902 |
-
destructor (if any) for the object or the elements of the array
|
| 903 |
-
deleted.
|
| 904 |
-
|
| 905 |
-
of
|
|
|
|
| 906 |
|
| 907 |
If the value of the operand of the *delete-expression* is not a null
|
| 908 |
pointer value, then:
|
| 909 |
|
| 910 |
- If the allocation call for the *new-expression* for the object to be
|
|
@@ -961,12 +974,11 @@ declarations other than of usual deallocation functions
|
|
| 961 |
|
| 962 |
[*Note 5*: If only a placement deallocation function is found in a
|
| 963 |
class, the program is ill-formed because the lookup set is empty
|
| 964 |
[[basic.lookup]]. — *end note*]
|
| 965 |
|
| 966 |
-
|
| 967 |
-
called is selected as follows:
|
| 968 |
|
| 969 |
- If any of the deallocation functions is a destroying operator delete,
|
| 970 |
all deallocation functions that are not destroying operator deletes
|
| 971 |
are eliminated from further consideration.
|
| 972 |
- If the type has new-extended alignment, a function with a parameter of
|
|
@@ -982,10 +994,15 @@ called is selected as follows:
|
|
| 982 |
or a (possibly multidimensional) array thereof, the function with a
|
| 983 |
parameter of type `std::size_t` is selected.
|
| 984 |
- Otherwise, it is unspecified whether a deallocation function with a
|
| 985 |
parameter of type `std::size_t` is selected.
|
| 986 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 987 |
For a single-object delete expression, the deleted object is the object
|
| 988 |
A pointed to by the operand if the static type of A does not have a
|
| 989 |
virtual destructor, and the most-derived object of A otherwise.
|
| 990 |
|
| 991 |
[*Note 6*: If the deallocation function is not a destroying operator
|
|
@@ -1016,8 +1033,177 @@ passed as the corresponding argument.
|
|
| 1016 |
function, and either the first argument was not the result of a prior
|
| 1017 |
call to a replaceable allocation function or the second or third
|
| 1018 |
argument was not the corresponding argument in said call, the behavior
|
| 1019 |
is undefined [[new.delete.single]], [[new.delete.array]]. — *end note*]
|
| 1020 |
|
| 1021 |
-
|
| 1022 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1023 |
|
|
|
|
| 18 |
sizeof '...' '(' identifier ')'
|
| 19 |
alignof '(' type-id ')'
|
| 20 |
noexcept-expression
|
| 21 |
new-expression
|
| 22 |
delete-expression
|
| 23 |
+
reflect-expression
|
| 24 |
```
|
| 25 |
|
| 26 |
``` bnf
|
| 27 |
%% Ed. note: character protrusion would misalign operators.
|
| 28 |
|
|
|
|
| 32 |
|
| 33 |
#### Unary operators <a id="expr.unary.op">[[expr.unary.op]]</a>
|
| 34 |
|
| 35 |
The unary `*` operator performs *indirection*. Its operand shall be a
|
| 36 |
prvalue of type “pointer to `T`”, where `T` is an object or function
|
| 37 |
+
type. The operator yields an lvalue of type `T`. If the operand points
|
| 38 |
+
to an object or function, the result denotes that object or function;
|
| 39 |
+
otherwise, the behavior is undefined except as specified in
|
| 40 |
+
[[expr.typeid]].
|
| 41 |
|
| 42 |
+
[*Note 1*: Indirection through a pointer to an out-of-lifetime object
|
| 43 |
+
is valid [[basic.life]]. — *end note*]
|
| 44 |
+
|
| 45 |
+
[*Note 2*: Indirection through a pointer to an incomplete type (other
|
| 46 |
than cv `void`) is valid. The lvalue thus obtained can be used in
|
| 47 |
limited ways (to initialize a reference, for example); this lvalue must
|
| 48 |
not be converted to a prvalue, see [[conv.lval]]. — *end note*]
|
| 49 |
|
| 50 |
Each of the following unary operators yields a prvalue.
|
| 51 |
|
| 52 |
The operand of the unary `&` operator shall be an lvalue of some type
|
| 53 |
+
`T`.
|
| 54 |
|
| 55 |
+
- If the operand is a *qualified-id* or *splice-expression* designating
|
| 56 |
+
a non-static member `m`, other than an explicit object member
|
| 57 |
+
function, `m` shall be a direct member of some class `C` that is not
|
| 58 |
+
an anonymous union. The result has type “pointer to member of class
|
| 59 |
+
`C` of type `T`” and designates `C::m`. \[*Note 3*: A *qualified-id*
|
| 60 |
+
that names a member of a namespace-scope anonymous union is considered
|
| 61 |
+
to be a class member access expression [[expr.prim.id.general]] and
|
| 62 |
+
cannot be used to form a pointer to member. — *end note*]
|
| 63 |
- Otherwise, the result has type “pointer to `T`” and points to the
|
| 64 |
designated object [[intro.memory]] or function [[basic.compound]]. If
|
| 65 |
+
the operand designates an explicit object member function [[dcl.fct]],
|
| 66 |
+
the operand shall be a *qualified-id* or a *splice-expression*.
|
| 67 |
+
\[*Note 4*: In particular, taking the address of a variable of type
|
| 68 |
+
“cv `T`” yields a pointer of type “pointer to cv `T`”. — *end note*]
|
| 69 |
|
| 70 |
[*Example 1*:
|
| 71 |
|
| 72 |
``` cpp
|
| 73 |
struct A { int i; };
|
|
|
|
| 79 |
bool b = p2 > p1; // defined behavior, with value true
|
| 80 |
```
|
| 81 |
|
| 82 |
— *end example*]
|
| 83 |
|
| 84 |
+
[*Note 5*: A pointer to member formed from a `mutable` non-static data
|
| 85 |
member [[dcl.stc]] does not reflect the `mutable` specifier associated
|
| 86 |
with the non-static data member. — *end note*]
|
| 87 |
|
| 88 |
A pointer to member is only formed when an explicit `&` is used and its
|
| 89 |
+
operand is a *qualified-id* or *splice-expression* not enclosed in
|
| 90 |
+
parentheses.
|
| 91 |
|
| 92 |
+
[*Note 6*: That is, the expression `&(qualified-id)`, where the
|
| 93 |
*qualified-id* is enclosed in parentheses, does not form an expression
|
| 94 |
of type “pointer to member”. Neither does `qualified-id`, because there
|
| 95 |
is no implicit conversion from a *qualified-id* for a non-static member
|
| 96 |
function to the type “pointer to member function” as there is from an
|
| 97 |
lvalue of function type to the type “pointer to function” [[conv.func]].
|
|
|
|
| 101 |
If `&` is applied to an lvalue of incomplete class type and the complete
|
| 102 |
type declares `operator&()`, it is unspecified whether the operator has
|
| 103 |
the built-in meaning or the operator function is called. The operand of
|
| 104 |
`&` shall not be a bit-field.
|
| 105 |
|
| 106 |
+
[*Note 7*: The address of an overload set [[over]] can be taken only in
|
| 107 |
a context that uniquely determines which function is referred to (see
|
| 108 |
[[over.over]]). Since the context can affect whether the operand is a
|
| 109 |
static or non-static member function, the context can also affect
|
| 110 |
whether the expression has type “pointer to function” or “pointer to
|
| 111 |
member function”. — *end note*]
|
| 112 |
|
| 113 |
+
The operand of the unary `+` operator shall be a prvalue of arithmetic,
|
| 114 |
+
unscoped enumeration, or pointer type and the result is the value of the
|
| 115 |
argument. Integral promotion is performed on integral or enumeration
|
| 116 |
operands. The type of the result is the type of the promoted operand.
|
| 117 |
|
| 118 |
+
The operand of the unary `-` operator shall be a prvalue of arithmetic
|
| 119 |
+
or unscoped enumeration type and the result is the negative of its
|
| 120 |
+
operand. Integral promotion is performed on integral or enumeration
|
| 121 |
+
operands. The negative of an unsigned quantity is computed by
|
| 122 |
+
subtracting its value from 2ⁿ, where n is the number of bits in the
|
| 123 |
+
promoted operand. The type of the result is the type of the promoted
|
| 124 |
+
operand.
|
| 125 |
|
| 126 |
+
[*Note 8*: The result is the two’s complement of the operand (where
|
| 127 |
operand and result are considered as unsigned). — *end note*]
|
| 128 |
|
| 129 |
The operand of the logical negation operator `!` is contextually
|
| 130 |
converted to `bool` [[conv]]; its value is `true` if the converted
|
| 131 |
operand is `false` and `false` otherwise. The type of the result is
|
| 132 |
`bool`.
|
| 133 |
|
| 134 |
+
The operand of the `~` operator shall be a prvalue of integral or
|
| 135 |
+
unscoped enumeration type. Integral promotions are performed. The type
|
| 136 |
+
of the result is the type of the promoted operand. Given the
|
| 137 |
+
coefficients `xᵢ` of the base-2 representation [[basic.fundamental]] of
|
| 138 |
+
the promoted operand `x`, the coefficient `rᵢ` of the base-2
|
| 139 |
+
representation of the result `r` is 1 if `xᵢ` is 0, and 0 otherwise.
|
| 140 |
|
| 141 |
+
[*Note 9*: The result is the ones’ complement of the operand (where
|
| 142 |
operand and result are considered as unsigned). — *end note*]
|
| 143 |
|
| 144 |
There is an ambiguity in the grammar when `~` is followed by a
|
| 145 |
+
*type-name* or *computed-type-specifier*. The ambiguity is resolved by
|
| 146 |
treating `~` as the operator rather than as the start of an
|
| 147 |
*unqualified-id* naming a destructor.
|
| 148 |
|
| 149 |
+
[*Note 10*: Because the grammar does not permit an operator to follow
|
| 150 |
the `.`, `->`, or `::` tokens, a `~` followed by a *type-name* or
|
| 151 |
+
*computed-type-specifier* in a member access expression or
|
| 152 |
+
*qualified-id* is unambiguously parsed as a destructor
|
| 153 |
+
name. — *end note*]
|
| 154 |
|
| 155 |
#### Increment and decrement <a id="expr.pre.incr">[[expr.pre.incr]]</a>
|
| 156 |
|
| 157 |
+
The operand of prefix `++` or `--` shall not be of type cv `bool`. An
|
| 158 |
+
operand with volatile-qualified type is deprecated; see
|
| 159 |
+
[[depr.volatile.type]]. The expression `++x` is otherwise equivalent to
|
| 160 |
+
`x+=1` and the expression `--x` is otherwise equivalent to `x-=1`
|
| 161 |
+
[[expr.assign]].
|
|
|
|
|
|
|
| 162 |
|
| 163 |
+
[*Note 1*: For postfix increment and decrement, see
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 164 |
[[expr.post.incr]]. — *end note*]
|
| 165 |
|
| 166 |
#### Await <a id="expr.await">[[expr.await]]</a>
|
| 167 |
|
| 168 |
The `co_await` expression is used to suspend evaluation of a coroutine
|
| 169 |
[[dcl.fct.def.coroutine]] while awaiting completion of the computation
|
| 170 |
+
represented by the operand expression. Suspending the evaluation of a
|
| 171 |
+
coroutine transfers control to its caller or resumer.
|
| 172 |
|
| 173 |
``` bnf
|
| 174 |
await-expression:
|
| 175 |
+
co_await cast-expression
|
| 176 |
```
|
| 177 |
|
| 178 |
+
An *await-expression* shall appear only as a potentially-evaluated
|
| 179 |
+
expression within the *compound-statement* of a *function-body* or
|
| 180 |
+
*lambda-expression*, in either case outside of a *handler*
|
| 181 |
+
[[except.pre]]. In a *declaration-statement* or in the
|
| 182 |
*simple-declaration* (if any) of an *init-statement*, an
|
| 183 |
*await-expression* shall appear only in an *initializer* of that
|
| 184 |
*declaration-statement* or *simple-declaration*. An *await-expression*
|
| 185 |
shall not appear in a default argument [[dcl.fct.default]]. An
|
| 186 |
*await-expression* shall not appear in the initializer of a block
|
| 187 |
+
variable with static or thread storage duration. An *await-expression*
|
| 188 |
+
shall not be a potentially-evaluated subexpression of the predicate of a
|
| 189 |
+
contract assertion [[basic.contract]]. A context within a function where
|
| 190 |
+
an *await-expression* can appear is called a *suspension context* of the
|
| 191 |
+
function.
|
| 192 |
|
| 193 |
Evaluation of an *await-expression* involves the following auxiliary
|
| 194 |
types, expressions, and objects:
|
| 195 |
|
| 196 |
- *p* is an lvalue naming the promise object [[dcl.fct.def.coroutine]]
|
|
|
|
| 310 |
|
| 311 |
[*Note 1*:
|
| 312 |
|
| 313 |
In particular, the values of `sizeof(bool)`, `sizeof(char16_t)`,
|
| 314 |
`sizeof(char32_t)`, and `sizeof(wchar_t)` are
|
| 315 |
+
implementation-defined.[^19]
|
| 316 |
|
| 317 |
— *end note*]
|
| 318 |
|
| 319 |
[*Note 2*: See [[intro.memory]] for the definition of byte and
|
| 320 |
[[term.object.representation]] for the definition of object
|
|
|
|
| 323 |
When applied to a reference type, the result is the size of the
|
| 324 |
referenced type. When applied to a class, the result is the number of
|
| 325 |
bytes in an object of that class including any padding required for
|
| 326 |
placing objects of that type in an array. The result of applying
|
| 327 |
`sizeof` to a potentially-overlapping subobject is the size of the type,
|
| 328 |
+
not the size of the subobject.[^20]
|
| 329 |
|
| 330 |
When applied to an array, the result is the total number of bytes in the
|
| 331 |
array. This implies that the size of an array of n elements is n times
|
| 332 |
the size of an element.
|
| 333 |
|
| 334 |
The lvalue-to-rvalue [[conv.lval]], array-to-pointer [[conv.array]], and
|
| 335 |
function-to-pointer [[conv.func]] standard conversions are not applied
|
| 336 |
to the operand of `sizeof`. If the operand is a prvalue, the temporary
|
| 337 |
materialization conversion [[conv.rval]] is applied.
|
| 338 |
|
| 339 |
+
The *identifier* in a `sizeof...` expression shall name a pack. The
|
| 340 |
`sizeof...` operator yields the number of elements in the pack
|
| 341 |
[[temp.variadic]]. A `sizeof...` expression is a pack expansion
|
| 342 |
[[temp.variadic]].
|
| 343 |
|
| 344 |
[*Example 1*:
|
| 345 |
|
| 346 |
``` cpp
|
| 347 |
template<class... Types>
|
| 348 |
struct count {
|
| 349 |
+
static constexpr std::size_t value = sizeof...(Types);
|
| 350 |
};
|
| 351 |
```
|
| 352 |
|
| 353 |
— *end example*]
|
| 354 |
|
| 355 |
The result of `sizeof` and `sizeof...` is a prvalue of type
|
| 356 |
`std::size_t`.
|
| 357 |
|
| 358 |
[*Note 3*: A `sizeof` expression is an integral constant expression
|
| 359 |
+
[[expr.const]]. The *typedef-name* `std::size_t` is declared in the
|
| 360 |
+
standard header `<cstddef>`
|
| 361 |
+
[[cstddef.syn]], [[support.types.layout]]. — *end note*]
|
| 362 |
|
| 363 |
#### Alignof <a id="expr.alignof">[[expr.alignof]]</a>
|
| 364 |
|
| 365 |
An `alignof` expression yields the alignment requirement of its operand
|
| 366 |
type. The operand shall be a *type-id* representing a complete object
|
| 367 |
type, or an array thereof, or a reference to one of those types.
|
| 368 |
|
| 369 |
The result is a prvalue of type `std::size_t`.
|
| 370 |
|
| 371 |
[*Note 1*: An `alignof` expression is an integral constant expression
|
| 372 |
+
[[expr.const]]. The *typedef-name* `std::size_t` is declared in the
|
| 373 |
+
standard header `<cstddef>`
|
| 374 |
+
[[cstddef.syn]], [[support.types.layout]]. — *end note*]
|
| 375 |
|
| 376 |
When `alignof` is applied to a reference type, the result is the
|
| 377 |
alignment of the referenced type. When `alignof` is applied to an array
|
| 378 |
type, the result is the alignment of the element type.
|
| 379 |
|
| 380 |
#### `noexcept` operator <a id="expr.unary.noexcept">[[expr.unary.noexcept]]</a>
|
| 381 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 382 |
``` bnf
|
| 383 |
noexcept-expression:
|
| 384 |
noexcept '(' expression ')'
|
| 385 |
```
|
| 386 |
|
| 387 |
+
The operand of the `noexcept` operator is an unevaluated operand
|
| 388 |
+
[[term.unevaluated.operand]]. If the operand is a prvalue, the temporary
|
| 389 |
+
materialization conversion [[conv.rval]] is applied.
|
| 390 |
+
|
| 391 |
+
The result of the `noexcept` operator is a prvalue of type `bool`. The
|
| 392 |
+
result is `false` if the full-expression of the operand is
|
| 393 |
+
potentially-throwing [[except.spec]], and `true` otherwise.
|
| 394 |
|
| 395 |
[*Note 1*: A *noexcept-expression* is an integral constant expression
|
| 396 |
[[expr.const]]. — *end note*]
|
| 397 |
|
|
|
|
|
|
|
|
|
|
| 398 |
#### New <a id="expr.new">[[expr.new]]</a>
|
| 399 |
|
| 400 |
+
The *new-expression* attempts to create an object of the *type-id* or
|
| 401 |
+
*new-type-id* [[dcl.name]] to which it is applied. The type of that
|
| 402 |
object is the *allocated type*. This type shall be a complete object
|
| 403 |
type [[term.incomplete.type]], but not an abstract class type
|
| 404 |
[[class.abstract]] or array thereof [[intro.object]].
|
| 405 |
|
| 406 |
[*Note 1*: Because references are not objects, references cannot be
|
|
|
|
| 442 |
new-initializer:
|
| 443 |
'(' expression-listₒₚₜ ')'
|
| 444 |
braced-init-list
|
| 445 |
```
|
| 446 |
|
| 447 |
+
If a placeholder type [[dcl.spec.auto]] or a placeholder for a deduced
|
| 448 |
+
class type [[dcl.type.class.deduct]] appears in the *type-specifier-seq*
|
| 449 |
+
of a *new-type-id* or *type-id* of a *new-expression*, the allocated
|
| 450 |
+
type is deduced as follows: Let *init* be the *new-initializer*, if any,
|
| 451 |
+
and `T` be the *new-type-id* or *type-id* of the *new-expression*, then
|
| 452 |
+
the allocated type is the type deduced for the variable `x` in the
|
| 453 |
+
invented declaration [[dcl.spec.auto]]:
|
| 454 |
|
| 455 |
``` cpp
|
| 456 |
T x init ;
|
| 457 |
```
|
| 458 |
|
|
|
|
| 524 |
its value shall be greater than zero.
|
| 525 |
|
| 526 |
[*Example 4*: Given the definition `int n = 42`, `new float[n][5]` is
|
| 527 |
well-formed (because `n` is the *expression* of a
|
| 528 |
*noptr-new-declarator*), but `new float[5][n]` is ill-formed (because
|
| 529 |
+
`n` is not a constant expression). Furthermore, `new float[0]` is
|
| 530 |
+
well-formed (because `0` is the *expression* of a
|
| 531 |
+
*noptr-new-declarator*, where a value of zero results in the allocation
|
| 532 |
+
of an array with no elements), but `new float[n][0]` is ill-formed
|
| 533 |
+
(because `0` is the *constant-expression* of a *noptr-new-declarator*,
|
| 534 |
+
where only values greater than zero are allowed). — *end example*]
|
| 535 |
|
| 536 |
If the *type-id* or *new-type-id* denotes an array type of unknown bound
|
| 537 |
[[dcl.array]], the *new-initializer* shall not be omitted; the allocated
|
| 538 |
object is an array with `n` elements, where `n` is determined from the
|
| 539 |
number of initial elements supplied in the *new-initializer*
|
| 540 |
[[dcl.init.aggr]], [[dcl.init.string]].
|
| 541 |
|
| 542 |
If the *expression* in a *noptr-new-declarator* is present, it is
|
| 543 |
+
implicitly converted to `std::size_t`. The value of the *expression* is
|
| 544 |
+
invalid if
|
| 545 |
|
| 546 |
- the expression is of non-class type and its value before converting to
|
| 547 |
`std::size_t` is less than zero;
|
| 548 |
- the expression is of class type and its value before application of
|
| 549 |
+
the second standard conversion [[over.ics.user]][^21] is less than
|
| 550 |
zero;
|
| 551 |
- its value is such that the size of the allocated object would exceed
|
| 552 |
the *implementation-defined* limit [[implimits]]; or
|
| 553 |
- the *new-initializer* is a *braced-init-list* and the number of array
|
| 554 |
elements for which initializers are provided (including the
|
| 555 |
terminating `'\0'` in a *string-literal* [[lex.string]]) exceeds the
|
| 556 |
number of elements to initialize.
|
| 557 |
|
| 558 |
+
If the value of the *expression* is invalid after converting to
|
| 559 |
+
`std::size_t`:
|
| 560 |
|
| 561 |
- if the *expression* is a potentially-evaluated core constant
|
| 562 |
expression, the program is ill-formed;
|
| 563 |
- otherwise, an allocation function is not called; instead
|
| 564 |
- if the allocation function that would have been called has a
|
|
|
|
| 570 |
`std::bad_array_new_length` [[new.badlength]].
|
| 571 |
|
| 572 |
When the value of the *expression* is zero, the allocation function is
|
| 573 |
called to allocate an array with no elements.
|
| 574 |
|
| 575 |
+
If the allocated type is an array, the *new-initializer* is a
|
| 576 |
+
*braced-init-list*, and the *expression* is potentially-evaluated and
|
| 577 |
+
not a core constant expression, the semantic constraints of
|
| 578 |
+
copy-initializing a hypothetical element of the array from an empty
|
| 579 |
+
initializer list are checked [[dcl.init.list]].
|
| 580 |
+
|
| 581 |
+
[*Note 5*: The array can contain more elements than there are elements
|
| 582 |
+
in the *braced-init-list*, requiring initialization of the remainder of
|
| 583 |
+
the array elements from an empty initializer list. — *end note*]
|
| 584 |
+
|
| 585 |
Objects created by a *new-expression* have dynamic storage duration
|
| 586 |
[[basic.stc.dynamic]].
|
| 587 |
|
| 588 |
+
[*Note 6*: The lifetime of such an object is not necessarily
|
| 589 |
restricted to the scope in which it is created. — *end note*]
|
| 590 |
|
| 591 |
When the allocated type is “array of `N` `T`” (that is, the
|
| 592 |
*noptr-new-declarator* syntax is used or the *new-type-id* or *type-id*
|
| 593 |
denotes an array type), the *new-expression* yields a prvalue of type
|
| 594 |
“pointer to `T`” that points to the initial element (if any) of the
|
| 595 |
array. Otherwise, let `T` be the allocated type; the *new-expression* is
|
| 596 |
a prvalue of type “pointer to T” that points to the object created.
|
| 597 |
|
| 598 |
+
[*Note 7*: Both `new int` and `new int[10]` have type `int*` and the
|
| 599 |
type of `new int[i][10]` is `int (*)[10]`. — *end note*]
|
| 600 |
|
| 601 |
A *new-expression* may obtain storage for the object by calling an
|
| 602 |
allocation function [[basic.stc.dynamic.allocation]]. If the
|
| 603 |
*new-expression* terminates by throwing an exception, it may release
|
|
|
|
| 606 |
type, the allocation function’s name is `operator new` and the
|
| 607 |
deallocation function’s name is `operator delete`. If the allocated type
|
| 608 |
is an array type, the allocation function’s name is `operator new[]` and
|
| 609 |
the deallocation function’s name is `operator delete[]`.
|
| 610 |
|
| 611 |
+
[*Note 8*: An implementation is expected to provide default definitions
|
| 612 |
for the global allocation functions
|
| 613 |
[[basic.stc.dynamic]], [[new.delete.single]], [[new.delete.array]]. A
|
| 614 |
C++ program can provide alternative definitions of these functions
|
| 615 |
[[replacement.functions]] and/or class-specific versions [[class.free]].
|
| 616 |
The set of allocation and deallocation functions that can be called by a
|
|
|
|
| 627 |
An implementation is allowed to omit a call to a replaceable global
|
| 628 |
allocation function [[new.delete.single]], [[new.delete.array]]. When it
|
| 629 |
does so, the storage is instead provided by the implementation or
|
| 630 |
provided by extending the allocation of another *new-expression*.
|
| 631 |
|
| 632 |
+
During an evaluation of a constant expression, a call to a replaceable
|
| 633 |
+
allocation function is always omitted [[expr.const]].
|
|
|
|
|
|
|
|
|
|
|
|
|
| 634 |
|
| 635 |
The implementation may extend the allocation of a *new-expression* `e1`
|
| 636 |
to provide storage for a *new-expression* `e2` if the following would be
|
| 637 |
true were the allocation not extended:
|
| 638 |
|
|
|
|
| 771 |
value of the *new-expression* shall be null.
|
| 772 |
|
| 773 |
[*Note 11*: When the allocation function returns a value other than
|
| 774 |
null, it must be a pointer to a block of storage in which space for the
|
| 775 |
object has been reserved. The block of storage is assumed to be
|
| 776 |
+
appropriately aligned [[basic.align]] and of the requested size. The
|
| 777 |
+
address of the created object will not necessarily be the same as that
|
| 778 |
+
of the block if the object is an array. — *end note*]
|
| 779 |
|
| 780 |
A *new-expression* that creates an object of type `T` initializes that
|
| 781 |
object as follows:
|
| 782 |
|
| 783 |
- If the *new-initializer* is omitted, the object is default-initialized
|
|
|
|
| 789 |
The invocation of the allocation function is sequenced before the
|
| 790 |
evaluations of expressions in the *new-initializer*. Initialization of
|
| 791 |
the allocated object is sequenced before the value computation of the
|
| 792 |
*new-expression*.
|
| 793 |
|
| 794 |
+
If the *new-expression* creates an array of objects of class type, the
|
| 795 |
+
destructor is potentially invoked [[class.dtor]].
|
|
|
|
|
|
|
|
|
|
|
|
|
| 796 |
|
| 797 |
+
If any part of the object initialization described above[^22]
|
| 798 |
|
| 799 |
terminates by throwing an exception and a suitable deallocation function
|
| 800 |
can be found, the deallocation function is called to free the memory in
|
| 801 |
which the object was being constructed, after which the exception
|
| 802 |
continues to propagate in the context of the *new-expression*. If no
|
|
|
|
| 821 |
otherwise, no deallocation function will be called. If the lookup finds
|
| 822 |
a usual deallocation function and that function, considered as a
|
| 823 |
placement deallocation function, would have been selected as a match for
|
| 824 |
the allocation function, the program is ill-formed. For a non-placement
|
| 825 |
allocation function, the normal deallocation function lookup is used to
|
| 826 |
+
find the matching deallocation function [[expr.delete]]. In any case,
|
| 827 |
+
the matching deallocation function (if any) shall be non-deleted and
|
| 828 |
+
accessible from the point where the *new-expression* appears.
|
| 829 |
|
| 830 |
[*Example 7*:
|
| 831 |
|
| 832 |
``` cpp
|
| 833 |
struct S {
|
|
|
|
| 866 |
```
|
| 867 |
|
| 868 |
The first alternative is a *single-object delete expression*, and the
|
| 869 |
second is an *array delete expression*. Whenever the `delete` keyword is
|
| 870 |
immediately followed by empty square brackets, it shall be interpreted
|
| 871 |
+
as the second alternative.[^23]
|
| 872 |
|
| 873 |
+
If the operand is of class type, it is contextually implicitly converted
|
| 874 |
+
[[conv]] to a pointer to object type and the converted operand is used
|
| 875 |
+
in place of the original operand for the remainder of this subclause.
|
| 876 |
+
Otherwise, it shall be a prvalue of pointer to object type. The
|
| 877 |
+
*delete-expression* has type `void`.
|
| 878 |
|
| 879 |
+
In a single-object delete expression, the value of the operand of
|
| 880 |
+
`delete` may be a null pointer value, a pointer value that resulted from
|
| 881 |
+
a previous non-array *new-expression*, or a pointer to a base class
|
| 882 |
+
subobject of an object created by such a *new-expression*. If not, the
|
| 883 |
+
behavior is undefined. In an array delete expression, the value of the
|
| 884 |
+
operand of `delete` may be a null pointer value or a pointer value that
|
| 885 |
+
resulted from a previous array *new-expression* whose allocation
|
| 886 |
+
function was not a non-allocating form [[new.delete.placement]].[^24]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 887 |
|
| 888 |
If not, the behavior is undefined.
|
| 889 |
|
| 890 |
[*Note 1*: This means that the syntax of the *delete-expression* must
|
| 891 |
match the type of the object allocated by `new`, not the syntax of the
|
|
|
|
| 903 |
object to be deleted and the static type shall have a virtual destructor
|
| 904 |
or the behavior is undefined. In an array delete expression, if the
|
| 905 |
dynamic type of the object to be deleted is not similar to its static
|
| 906 |
type, the behavior is undefined.
|
| 907 |
|
|
|
|
|
|
|
|
|
|
| 908 |
If the object being deleted has incomplete class type at the point of
|
| 909 |
+
deletion, the program is ill-formed.
|
|
|
|
| 910 |
|
| 911 |
If the value of the operand of the *delete-expression* is not a null
|
| 912 |
pointer value and the selected deallocation function (see below) is not
|
| 913 |
+
a destroying operator delete, evaluating the *delete-expression* invokes
|
| 914 |
+
the destructor (if any) for the object or the elements of the array
|
| 915 |
+
being deleted. The destructor shall be accessible from the point where
|
| 916 |
+
the *delete-expression* appears. In the case of an array, the elements
|
| 917 |
+
are destroyed in order of decreasing address (that is, in reverse order
|
| 918 |
+
of the completion of their constructor; see [[class.base.init]]).
|
| 919 |
|
| 920 |
If the value of the operand of the *delete-expression* is not a null
|
| 921 |
pointer value, then:
|
| 922 |
|
| 923 |
- If the allocation call for the *new-expression* for the object to be
|
|
|
|
| 974 |
|
| 975 |
[*Note 5*: If only a placement deallocation function is found in a
|
| 976 |
class, the program is ill-formed because the lookup set is empty
|
| 977 |
[[basic.lookup]]. — *end note*]
|
| 978 |
|
| 979 |
+
The deallocation function to be called is selected as follows:
|
|
|
|
| 980 |
|
| 981 |
- If any of the deallocation functions is a destroying operator delete,
|
| 982 |
all deallocation functions that are not destroying operator deletes
|
| 983 |
are eliminated from further consideration.
|
| 984 |
- If the type has new-extended alignment, a function with a parameter of
|
|
|
|
| 994 |
or a (possibly multidimensional) array thereof, the function with a
|
| 995 |
parameter of type `std::size_t` is selected.
|
| 996 |
- Otherwise, it is unspecified whether a deallocation function with a
|
| 997 |
parameter of type `std::size_t` is selected.
|
| 998 |
|
| 999 |
+
Unless the deallocation function is selected at the point of definition
|
| 1000 |
+
of the dynamic type’s virtual destructor, the selected deallocation
|
| 1001 |
+
function shall be accessible from the point where the
|
| 1002 |
+
*delete-expression* appears.
|
| 1003 |
+
|
| 1004 |
For a single-object delete expression, the deleted object is the object
|
| 1005 |
A pointed to by the operand if the static type of A does not have a
|
| 1006 |
virtual destructor, and the most-derived object of A otherwise.
|
| 1007 |
|
| 1008 |
[*Note 6*: If the deallocation function is not a destroying operator
|
|
|
|
| 1033 |
function, and either the first argument was not the result of a prior
|
| 1034 |
call to a replaceable allocation function or the second or third
|
| 1035 |
argument was not the corresponding argument in said call, the behavior
|
| 1036 |
is undefined [[new.delete.single]], [[new.delete.array]]. — *end note*]
|
| 1037 |
|
| 1038 |
+
#### The reflection operator <a id="expr.reflect">[[expr.reflect]]</a>
|
| 1039 |
+
|
| 1040 |
+
``` bnf
|
| 1041 |
+
reflect-expression:
|
| 1042 |
+
'^^' '::'
|
| 1043 |
+
'^^' reflection-name
|
| 1044 |
+
'^^' type-id
|
| 1045 |
+
'^^' id-expression
|
| 1046 |
+
```
|
| 1047 |
+
|
| 1048 |
+
``` bnf
|
| 1049 |
+
reflection-name:
|
| 1050 |
+
nested-name-specifierₒₚₜ identifier
|
| 1051 |
+
nested-name-specifier template identifier
|
| 1052 |
+
```
|
| 1053 |
+
|
| 1054 |
+
The unary `^^` operator, called the *reflection operator*, yields a
|
| 1055 |
+
prvalue of type `std::meta::info` [[basic.fundamental]].
|
| 1056 |
+
|
| 1057 |
+
[*Note 1*: This document places no restriction on representing, by
|
| 1058 |
+
reflections, constructs not described by this document or using the
|
| 1059 |
+
names of such constructs as operands of
|
| 1060 |
+
*reflect-expression*s. — *end note*]
|
| 1061 |
+
|
| 1062 |
+
The component names of a *reflection-name* are those of its
|
| 1063 |
+
*nested-name-specifier* (if any) and its *identifier*. The terminal name
|
| 1064 |
+
of a *reflection-name* of the form *nested-name-specifier* `template`
|
| 1065 |
+
*identifier* shall denote a template.
|
| 1066 |
+
|
| 1067 |
+
A *reflect-expression* is parsed as the longest possible sequence of
|
| 1068 |
+
tokens that could syntactically form a *reflect-expression*. An
|
| 1069 |
+
unparenthesized *reflect-expression* that represents a template shall
|
| 1070 |
+
not be followed by `<`.
|
| 1071 |
+
|
| 1072 |
+
[*Example 1*:
|
| 1073 |
+
|
| 1074 |
+
``` cpp
|
| 1075 |
+
static_assert(std::meta::is_type(^^int())); // ^^ applies to the type-id int()
|
| 1076 |
+
|
| 1077 |
+
template<bool> struct X {};
|
| 1078 |
+
consteval bool operator<(std::meta::info, X<false>) { return false; }
|
| 1079 |
+
consteval void g(std::meta::info r, X<false> xv) {
|
| 1080 |
+
r == ^^int && true; // error: ^^ applies to the type-id int&&
|
| 1081 |
+
r == ^^int & true; // error: ^^ applies to the type-id int&
|
| 1082 |
+
r == (^^int) && true; // OK
|
| 1083 |
+
r == ^^int &&&& true; // error: int &&&& is not a valid type-id
|
| 1084 |
+
^^X < xv; // error: reflect-expression that represents a template is followed by <
|
| 1085 |
+
(^^X) < xv; // OK
|
| 1086 |
+
^^X<true> < xv; // OK
|
| 1087 |
+
}
|
| 1088 |
+
```
|
| 1089 |
+
|
| 1090 |
+
— *end example*]
|
| 1091 |
+
|
| 1092 |
+
A *reflect-expression* of the form `^^ ::` represents the global
|
| 1093 |
+
namespace.
|
| 1094 |
+
|
| 1095 |
+
If a *reflect-expression* R matches the form `^^ reflection-name`, it is
|
| 1096 |
+
interpreted as such; the *identifier* is looked up and the
|
| 1097 |
+
representation of R is determined as follows:
|
| 1098 |
+
|
| 1099 |
+
- If lookup finds a declaration that replaced a *using-declarator*
|
| 1100 |
+
during a single search [[basic.lookup.general]], [[namespace.udecl]],
|
| 1101 |
+
R is ill-formed.
|
| 1102 |
+
\[*Example 2*:
|
| 1103 |
+
``` cpp
|
| 1104 |
+
struct A { struct S {}; };
|
| 1105 |
+
struct B : A { using A::S; };
|
| 1106 |
+
constexpr std::meta::info r1 = ^^B::S; // error: A::S found through using-declarator
|
| 1107 |
+
|
| 1108 |
+
struct C : virtual B { struct S {}; };
|
| 1109 |
+
struct D : virtual B, C {};
|
| 1110 |
+
D::S s; // OK, names C::S per [class.member.lookup]
|
| 1111 |
+
constexpr std::meta::info r2 = ^^D::S; // OK, result C::S not found through using-declarator
|
| 1112 |
+
```
|
| 1113 |
+
|
| 1114 |
+
— *end example*]
|
| 1115 |
+
- Otherwise, if lookup finds a namespace alias [[namespace.alias]], R
|
| 1116 |
+
represents that namespace alias.
|
| 1117 |
+
- Otherwise, if lookup finds a namespace [[basic.namespace]], R
|
| 1118 |
+
represents that namespace.
|
| 1119 |
+
- Otherwise, if lookup finds a concept [[temp.concept]], R represents
|
| 1120 |
+
the denoted concept.
|
| 1121 |
+
- Otherwise, if lookup finds a template [[temp.names]], the
|
| 1122 |
+
representation of R is determined as follows:
|
| 1123 |
+
- If lookup finds an injected-class-name [[class.pre]], then:
|
| 1124 |
+
- If the *reflection-name* is of the form
|
| 1125 |
+
`nested-name-specifier template identifier`, then R represents the
|
| 1126 |
+
class template named by the injected-class-name.
|
| 1127 |
+
- Otherwise, the injected-class-name shall be unambiguous when
|
| 1128 |
+
considered as a *type-name* and R represents the class template
|
| 1129 |
+
specialization so named.
|
| 1130 |
+
- Otherwise, if lookup finds an overload set, that overload set shall
|
| 1131 |
+
contain only declarations of a unique function template F; R
|
| 1132 |
+
represents F.
|
| 1133 |
+
- Otherwise, if lookup finds a class template, variable template, or
|
| 1134 |
+
alias template, R represents that template. \[*Note 2*: Lookup never
|
| 1135 |
+
finds a partial or explicit specialization. — *end note*]
|
| 1136 |
+
- Otherwise, if lookup finds a type alias A, R represents the underlying
|
| 1137 |
+
entity of A if A was introduced by the declaration of a template
|
| 1138 |
+
parameter; otherwise, R represents A.
|
| 1139 |
+
- Otherwise, if lookup finds a class or an enumeration, R represents the
|
| 1140 |
+
denoted type.
|
| 1141 |
+
- Otherwise, if lookup finds a class member of an anonymous union
|
| 1142 |
+
[[class.union.anon]], R represents that class member.
|
| 1143 |
+
- Otherwise, the *reflection-name* shall be an *id-expression* `I` and R
|
| 1144 |
+
is `^^ I` (see below).
|
| 1145 |
+
|
| 1146 |
+
A *reflect-expression* R of the form `^^ type-id` represents an entity
|
| 1147 |
+
determined as follows:
|
| 1148 |
+
|
| 1149 |
+
- If the *type-id* designates a placeholder type
|
| 1150 |
+
[[dcl.spec.auto.general]], R is ill-formed.
|
| 1151 |
+
- Otherwise, if the *type-id* names a type alias that is a
|
| 1152 |
+
specialization of an alias template [[temp.alias]], R represents that
|
| 1153 |
+
type alias.
|
| 1154 |
+
- Otherwise, R represents the type denoted by the *type-id*.
|
| 1155 |
+
|
| 1156 |
+
A *reflect-expression* R of the form `^^ id-expression` represents an
|
| 1157 |
+
entity determined as follows:
|
| 1158 |
+
|
| 1159 |
+
- If the *id-expression* denotes
|
| 1160 |
+
- a variable declared by an *init-capture*
|
| 1161 |
+
[[expr.prim.lambda.capture]],
|
| 1162 |
+
- a function-local predefined variable [[dcl.fct.def.general]],
|
| 1163 |
+
- a local parameter introduced by a *requires-expression*
|
| 1164 |
+
[[expr.prim.req]], or
|
| 1165 |
+
- a local entity E [[basic.pre]] for which a lambda scope intervenes
|
| 1166 |
+
between the point at which E was introduced and R,
|
| 1167 |
+
|
| 1168 |
+
then R is ill-formed.
|
| 1169 |
+
- Otherwise, if the *id-expression* denotes an overload set S, overload
|
| 1170 |
+
resolution for the expression `&S` with no target shall select a
|
| 1171 |
+
unique function [[over.over]]; R represents that function.
|
| 1172 |
+
- Otherwise, if the *id-expression* denotes a variable, structured
|
| 1173 |
+
binding, enumerator, or non-static data member, R represents that
|
| 1174 |
+
entity.
|
| 1175 |
+
- Otherwise, R is ill-formed. \[*Note 3*: This includes
|
| 1176 |
+
*unqualified-id*s that name a constant template parameter and
|
| 1177 |
+
*pack-index-expression*s. — *end note*]
|
| 1178 |
+
|
| 1179 |
+
The *id-expression* of a *reflect-expression* is an unevaluated operand
|
| 1180 |
+
[[expr.context]].
|
| 1181 |
+
|
| 1182 |
+
[*Example 3*:
|
| 1183 |
+
|
| 1184 |
+
``` cpp
|
| 1185 |
+
template<typename T> void fn() requires (^^T != ^^int);
|
| 1186 |
+
template<typename T> void fn() requires (^^T == ^^int);
|
| 1187 |
+
template<typename T> void fn() requires (sizeof(T) == sizeof(int));
|
| 1188 |
+
|
| 1189 |
+
constexpr std::meta::info a = ^^fn<char>; // OK
|
| 1190 |
+
constexpr std::meta::info b = ^^fn<int>; // error: ambiguous
|
| 1191 |
+
|
| 1192 |
+
constexpr std::meta::info c = ^^std::vector; // OK
|
| 1193 |
+
|
| 1194 |
+
template<typename T>
|
| 1195 |
+
struct S {
|
| 1196 |
+
static constexpr std::meta::info r = ^^T;
|
| 1197 |
+
using type = T;
|
| 1198 |
+
};
|
| 1199 |
+
static_assert(S<int>::r == ^^int);
|
| 1200 |
+
static_assert(^^S<int>::type != ^^int);
|
| 1201 |
+
|
| 1202 |
+
typedef struct X {} Y;
|
| 1203 |
+
typedef struct Z {} Z;
|
| 1204 |
+
constexpr std::meta::info e = ^^Y; // OK, represents the type alias Y
|
| 1205 |
+
constexpr std::meta::info f = ^^Z; // OK, represents the type alias Z, not the type[basic.lookup.general]
|
| 1206 |
+
```
|
| 1207 |
+
|
| 1208 |
+
— *end example*]
|
| 1209 |
|