- tmp/tmp9fgiag2s/{from.md → to.md} +541 -399
tmp/tmp9fgiag2s/{from.md → to.md}
RENAMED
|
@@ -1,24 +1,26 @@
|
|
| 1 |
## Compound expressions <a id="expr.compound">[[expr.compound]]</a>
|
| 2 |
|
| 3 |
### Postfix expressions <a id="expr.post">[[expr.post]]</a>
|
| 4 |
|
|
|
|
|
|
|
| 5 |
Postfix expressions group left-to-right.
|
| 6 |
|
| 7 |
``` bnf
|
| 8 |
postfix-expression:
|
| 9 |
primary-expression
|
| 10 |
-
postfix-expression '['
|
| 11 |
postfix-expression '(' expression-listₒₚₜ ')'
|
| 12 |
simple-type-specifier '(' expression-listₒₚₜ ')'
|
| 13 |
typename-specifier '(' expression-listₒₚₜ ')'
|
| 14 |
simple-type-specifier braced-init-list
|
| 15 |
typename-specifier braced-init-list
|
| 16 |
postfix-expression '.' 'template'ₒₚₜ id-expression
|
| 17 |
postfix-expression '->' 'template'ₒₚₜ id-expression
|
| 18 |
postfix-expression '++'
|
| 19 |
-
postfix-expression '-
|
| 20 |
dynamic_cast '<' type-id '>' '(' expression ')'
|
| 21 |
static_cast '<' type-id '>' '(' expression ')'
|
| 22 |
reinterpret_cast '<' type-id '>' '(' expression ')'
|
| 23 |
const_cast '<' type-id '>' '(' expression ')'
|
| 24 |
typeid '(' expression ')'
|
|
@@ -29,38 +31,43 @@ postfix-expression:
|
|
| 29 |
expression-list:
|
| 30 |
initializer-list
|
| 31 |
```
|
| 32 |
|
| 33 |
[*Note 1*: The `>` token following the *type-id* in a `dynamic_cast`,
|
| 34 |
-
`static_cast`, `reinterpret_cast`, or `const_cast`
|
| 35 |
-
replacing a `>
|
| 36 |
[[temp.names]]. — *end note*]
|
| 37 |
|
| 38 |
#### Subscripting <a id="expr.sub">[[expr.sub]]</a>
|
| 39 |
|
| 40 |
-
A
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
|
|
|
|
| 49 |
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
|
|
|
|
|
|
|
|
|
|
| 53 |
|
| 54 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 55 |
commutative operation except for sequencing. See [[expr.unary]] and
|
| 56 |
[[expr.add]] for details of `*` and `+` and [[dcl.array]] for details
|
| 57 |
of array types. — *end note*]
|
| 58 |
|
| 59 |
-
A *braced-init-list* shall not be used with the built-in subscript
|
| 60 |
-
operator.
|
| 61 |
-
|
| 62 |
#### Function call <a id="expr.call">[[expr.call]]</a>
|
| 63 |
|
| 64 |
A function call is a postfix expression followed by parentheses
|
| 65 |
containing a possibly empty, comma-separated list of
|
| 66 |
*initializer-clause*s which constitute the arguments to the function.
|
|
@@ -74,72 +81,69 @@ type. For a call to a non-member function or to a static member
|
|
| 74 |
function, the postfix expression shall either be an lvalue that refers
|
| 75 |
to a function (in which case the function-to-pointer standard conversion
|
| 76 |
[[conv.func]] is suppressed on the postfix expression), or have function
|
| 77 |
pointer type.
|
| 78 |
|
| 79 |
-
For a call to a non-static member function, the postfix expression shall
|
| 80 |
-
be an implicit ([[class.mfct.non-static]], [[class.static]]) or
|
| 81 |
-
explicit class member access [[expr.ref]] whose *id-expression* is a
|
| 82 |
-
function member name, or a pointer-to-member expression
|
| 83 |
-
[[expr.mptr.oper]] selecting a function member; the call is as a member
|
| 84 |
-
of the class object referred to by the object expression. In the case of
|
| 85 |
-
an implicit class member access, the implied object is the one pointed
|
| 86 |
-
to by `this`.
|
| 87 |
-
|
| 88 |
-
[*Note 2*: A member function call of the form `f()` is interpreted as
|
| 89 |
-
`(*this).f()` (see [[class.mfct.non-static]]). — *end note*]
|
| 90 |
-
|
| 91 |
If the selected function is non-virtual, or if the *id-expression* in
|
| 92 |
the class member access expression is a *qualified-id*, that function is
|
| 93 |
called. Otherwise, its final overrider [[class.virtual]] in the dynamic
|
| 94 |
type of the object expression is called; such a call is referred to as a
|
| 95 |
*virtual function call*.
|
| 96 |
|
| 97 |
-
[*Note
|
| 98 |
the current value of the object expression. [[class.cdtor]] describes
|
| 99 |
the behavior of virtual function calls when the object expression refers
|
| 100 |
to an object under construction or destruction. — *end note*]
|
| 101 |
|
| 102 |
-
[*Note
|
| 103 |
lookup [[basic.lookup]] does not find a declaration of that name, the
|
| 104 |
program is ill-formed. No function is implicitly declared by such a
|
| 105 |
call. — *end note*]
|
| 106 |
|
| 107 |
If the *postfix-expression* names a destructor or pseudo-destructor
|
| 108 |
[[expr.prim.id.dtor]], the type of the function call expression is
|
| 109 |
`void`; otherwise, the type of the function call expression is the
|
| 110 |
return type of the statically chosen function (i.e., ignoring the
|
| 111 |
`virtual` keyword), even if the type of the function actually called is
|
| 112 |
-
different.
|
| 113 |
-
cv `void`. If the *postfix-expression* names a pseudo-destructor (in
|
| 114 |
which case the *postfix-expression* is a possibly-parenthesized class
|
| 115 |
member access), the function call destroys the object of scalar type
|
| 116 |
-
denoted by the object expression of the class member access
|
| 117 |
-
[[expr.ref]], [[basic.life]]
|
| 118 |
|
| 119 |
-
Calling a function through an expression whose function type is
|
| 120 |
-
different from the function type of the called function’s definition
|
| 121 |
-
results in undefined behavior
|
|
|
|
|
|
|
| 122 |
|
| 123 |
-
|
| 124 |
-
|
| 125 |
-
|
| 126 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 127 |
|
| 128 |
[*Example 1*:
|
| 129 |
|
| 130 |
``` cpp
|
| 131 |
template<typename ...T> int f(int n = 0, T ...t);
|
| 132 |
int x = f<int>(); // error: no argument for second function parameter
|
| 133 |
```
|
| 134 |
|
| 135 |
— *end example*]
|
| 136 |
|
| 137 |
-
If the function is
|
| 138 |
-
the function [[
|
| 139 |
-
of the call, converted as if by an explicit type
|
| 140 |
-
[[expr.cast]].
|
| 141 |
|
| 142 |
[*Note 5*: There is no access or ambiguity checking on this conversion;
|
| 143 |
the access checking and disambiguation are done as part of the (possibly
|
| 144 |
implicit) class member access operator. See [[class.member.lookup]],
|
| 145 |
[[class.access.base]], and [[expr.ref]]. — *end note*]
|
|
@@ -157,14 +161,14 @@ enclosing full-expression. The initialization and destruction of each
|
|
| 157 |
parameter occurs within the context of the calling function.
|
| 158 |
|
| 159 |
[*Example 2*: The access of the constructor, conversion functions or
|
| 160 |
destructor is checked at the point of call in the calling function. If a
|
| 161 |
constructor or destructor for a function parameter throws an exception,
|
| 162 |
-
the search for a handler starts in the
|
| 163 |
-
|
| 164 |
-
|
| 165 |
-
|
| 166 |
|
| 167 |
The *postfix-expression* is sequenced before each *expression* in the
|
| 168 |
*expression-list* and any default argument. The initialization of a
|
| 169 |
parameter, including every associated value computation and side effect,
|
| 170 |
is indeterminately sequenced with respect to that of any other
|
|
@@ -220,14 +224,14 @@ statically chosen function.
|
|
| 220 |
parameters, but these changes cannot affect the values of the arguments
|
| 221 |
except where a parameter is of a reference type [[dcl.ref]]; if the
|
| 222 |
reference is to a const-qualified type, `const_cast` is required to be
|
| 223 |
used to cast away the constness in order to modify the argument’s value.
|
| 224 |
Where a parameter is of `const` reference type a temporary object is
|
| 225 |
-
introduced if needed
|
| 226 |
-
[[dcl.
|
| 227 |
-
modify the values of non-constant objects
|
| 228 |
-
parameters. — *end note*]
|
| 229 |
|
| 230 |
A function can be declared to accept fewer arguments (by declaring
|
| 231 |
default arguments [[dcl.fct.default]]) or more arguments (by using the
|
| 232 |
ellipsis, `...`, or a function parameter pack [[dcl.fct]]) than the
|
| 233 |
number of parameters in the function definition [[dcl.fct.def]].
|
|
@@ -277,73 +281,93 @@ A *simple-type-specifier* [[dcl.type.simple]] or *typename-specifier*
|
|
| 277 |
by a *braced-init-list* (the initializer) constructs a value of the
|
| 278 |
specified type given the initializer. If the type is a placeholder for a
|
| 279 |
deduced class type, it is replaced by the return type of the function
|
| 280 |
selected by overload resolution for class template deduction
|
| 281 |
[[over.match.class.deduct]] for the remainder of this subclause.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 282 |
|
| 283 |
If the initializer is a parenthesized single expression, the type
|
| 284 |
conversion expression is equivalent to the corresponding cast expression
|
| 285 |
[[expr.cast]]. Otherwise, if the type is cv `void` and the initializer
|
| 286 |
is `()` or `{}` (after pack expansion, if any), the expression is a
|
| 287 |
-
prvalue of
|
| 288 |
-
|
| 289 |
-
|
| 290 |
-
|
| 291 |
-
|
| 292 |
|
| 293 |
#### Class member access <a id="expr.ref">[[expr.ref]]</a>
|
| 294 |
|
| 295 |
A postfix expression followed by a dot `.` or an arrow `->`, optionally
|
| 296 |
-
followed by the keyword `template`
|
| 297 |
-
|
| 298 |
-
|
| 299 |
-
|
| 300 |
-
the
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 301 |
|
| 302 |
For the first option (dot) the first expression shall be a glvalue. For
|
| 303 |
the second option (arrow) the first expression shall be a prvalue having
|
| 304 |
pointer type. The expression `E1->E2` is converted to the equivalent
|
| 305 |
form `(*(E1)).E2`; the remainder of [[expr.ref]] will address only the
|
| 306 |
first option (dot).[^13]
|
| 307 |
|
| 308 |
Abbreviating *postfix-expression*`.`*id-expression* as `E1.E2`, `E1` is
|
| 309 |
called the *object expression*. If the object expression is of scalar
|
| 310 |
type, `E2` shall name the pseudo-destructor of that same type (ignoring
|
| 311 |
-
cv-qualifications) and `E1.E2` is
|
| 312 |
returning `void`”.
|
| 313 |
|
| 314 |
-
[*Note
|
| 315 |
[[expr.prim.id.dtor]]. — *end note*]
|
| 316 |
|
| 317 |
Otherwise, the object expression shall be of class type. The class type
|
| 318 |
shall be complete unless the class member access appears in the
|
| 319 |
definition of that class.
|
| 320 |
|
| 321 |
-
[*Note
|
| 322 |
-
|
| 323 |
-
[[basic.scope.class]]. — *end note*]
|
| 324 |
|
| 325 |
-
|
| 326 |
-
base classes.
|
| 327 |
-
|
| 328 |
-
[*Note 3*: Because the name of a class is inserted in its class scope
|
| 329 |
-
[[class]], the name of a class is also considered a nested member of
|
| 330 |
-
that class. — *end note*]
|
| 331 |
-
|
| 332 |
-
[*Note 4*: [[basic.lookup.classref]] describes how names are looked up
|
| 333 |
after the `.` and `->` operators. — *end note*]
|
| 334 |
|
| 335 |
If `E2` is a bit-field, `E1.E2` is a bit-field. The type and value
|
| 336 |
category of `E1.E2` are determined as follows. In the remainder of
|
| 337 |
[[expr.ref]], *cq* represents either `const` or the absence of `const`
|
| 338 |
and *vq* represents either `volatile` or the absence of `volatile`. *cv*
|
| 339 |
represents an arbitrary set of cv-qualifiers, as defined in
|
| 340 |
[[basic.type.qualifier]].
|
| 341 |
|
| 342 |
If `E2` is declared to have type “reference to `T`”, then `E1.E2` is an
|
| 343 |
-
lvalue
|
| 344 |
-
|
|
|
|
|
|
|
|
|
|
| 345 |
|
| 346 |
- If `E2` is a static data member and the type of `E2` is `T`, then
|
| 347 |
`E1.E2` is an lvalue; the expression designates the named member of
|
| 348 |
the class. The type of `E1.E2` is `T`.
|
| 349 |
- If `E2` is a non-static data member and the type of `E1` is “*cq1 vq1*
|
|
@@ -356,33 +380,53 @@ rules applies.
|
|
| 356 |
*cq12* stand for the “union” of *cq1* and *cq2*; that is, if *cq1* or
|
| 357 |
*cq2* is `const`, then *cq12* is `const`. If `E2` is declared to be a
|
| 358 |
`mutable` member, then the type of `E1.E2` is “*vq12* `T`”. If `E2` is
|
| 359 |
not declared to be a `mutable` member, then the type of `E1.E2` is
|
| 360 |
“*cq12* *vq12* `T`”.
|
| 361 |
-
- If `E2` is
|
| 362 |
-
|
| 363 |
-
|
| 364 |
-
|
| 365 |
- If `E2` refers to a static member function, `E1.E2` is an lvalue.
|
| 366 |
- Otherwise (when `E2` refers to a non-static member function),
|
| 367 |
`E1.E2` is a prvalue. The expression can be used only as the
|
| 368 |
left-hand operand of a member function call [[class.mfct]].
|
| 369 |
\[*Note 5*: Any redundant set of parentheses surrounding the
|
| 370 |
expression is ignored [[expr.prim.paren]]. — *end note*]
|
| 371 |
- If `E2` is a nested type, the expression `E1.E2` is ill-formed.
|
| 372 |
- If `E2` is a member enumerator and the type of `E2` is `T`, the
|
| 373 |
-
expression `E1.E2` is a prvalue
|
|
|
|
| 374 |
|
| 375 |
-
If `E2` is a non-static
|
| 376 |
-
|
| 377 |
-
|
| 378 |
-
|
| 379 |
|
| 380 |
[*Note 6*: The program is also ill-formed if the naming class is an
|
| 381 |
ambiguous base of the class type of the object expression; see
|
| 382 |
[[class.access.base]]. — *end note*]
|
| 383 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 384 |
#### Increment and decrement <a id="expr.post.incr">[[expr.post.incr]]</a>
|
| 385 |
|
| 386 |
The value of a postfix `++` expression is the value of its operand.
|
| 387 |
|
| 388 |
[*Note 1*: The value obtained is a copy of the original
|
|
@@ -405,11 +449,11 @@ The result is a prvalue. The type of the result is the cv-unqualified
|
|
| 405 |
version of the type of the operand. If the operand is a bit-field that
|
| 406 |
cannot represent the incremented value, the resulting value of the
|
| 407 |
bit-field is *implementation-defined*. See also [[expr.add]] and
|
| 408 |
[[expr.ass]].
|
| 409 |
|
| 410 |
-
The operand of postfix `
|
| 411 |
`++` operator.
|
| 412 |
|
| 413 |
[*Note 3*: For prefix increment and decrement, see
|
| 414 |
[[expr.pre.incr]]. — *end note*]
|
| 415 |
|
|
@@ -435,13 +479,14 @@ If `T` is “pointer to *cv1* `B`” and `v` has type “pointer to *cv2* `D`”
|
|
| 435 |
such that `B` is a base class of `D`, the result is a pointer to the
|
| 436 |
unique `B` subobject of the `D` object pointed to by `v`, or a null
|
| 437 |
pointer value if `v` is a null pointer value. Similarly, if `T` is
|
| 438 |
“reference to *cv1* `B`” and `v` has type *cv2* `D` such that `B` is a
|
| 439 |
base class of `D`, the result is the unique `B` subobject of the `D`
|
| 440 |
-
object referred to by `v`.[^14]
|
| 441 |
-
|
| 442 |
-
|
|
|
|
| 443 |
|
| 444 |
[*Example 1*:
|
| 445 |
|
| 446 |
``` cpp
|
| 447 |
struct B { };
|
|
@@ -461,11 +506,11 @@ If `v` is a null pointer value, the result is a null pointer value.
|
|
| 461 |
If `T` is “pointer to cv `void`”, then the result is a pointer to the
|
| 462 |
most derived object pointed to by `v`. Otherwise, a runtime check is
|
| 463 |
applied to see if the object pointed or referred to by `v` can be
|
| 464 |
converted to the type pointed or referred to by `T`.
|
| 465 |
|
| 466 |
-
|
| 467 |
check logically executes as follows:
|
| 468 |
|
| 469 |
- If, in the most derived object pointed (referred) to by `v`, `v`
|
| 470 |
points (refers) to a public base class subobject of a `C` object, and
|
| 471 |
if only one object of type `C` is derived from the subobject pointed
|
|
@@ -519,40 +564,44 @@ destruction. — *end note*]
|
|
| 519 |
|
| 520 |
The result of a `typeid` expression is an lvalue of static type `const`
|
| 521 |
`std::type_info` [[type.info]] and dynamic type `const` `std::type_info`
|
| 522 |
or `const` *name* where *name* is an *implementation-defined* class
|
| 523 |
publicly derived from `std::type_info` which preserves the behavior
|
| 524 |
-
described in [[type.info]].[^15]
|
| 525 |
-
|
| 526 |
-
|
| 527 |
-
program is
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 528 |
|
| 529 |
When `typeid` is applied to a glvalue whose type is a polymorphic class
|
| 530 |
type [[class.virtual]], the result refers to a `std::type_info` object
|
| 531 |
representing the type of the most derived object [[intro.object]] (that
|
| 532 |
is, the dynamic type) to which the glvalue refers. If the glvalue is
|
| 533 |
-
obtained by applying the unary `*` operator to a pointer[^16]
|
| 534 |
-
|
|
|
|
| 535 |
expression throws an exception [[except.throw]] of a type that would
|
| 536 |
match a handler of type `std::bad_typeid` exception [[bad.typeid]].
|
| 537 |
|
| 538 |
When `typeid` is applied to an expression other than a glvalue of a
|
| 539 |
polymorphic class type, the result refers to a `std::type_info` object
|
| 540 |
representing the static type of the expression. Lvalue-to-rvalue
|
| 541 |
[[conv.lval]], array-to-pointer [[conv.array]], and function-to-pointer
|
| 542 |
[[conv.func]] conversions are not applied to the expression. If the
|
| 543 |
expression is a prvalue, the temporary materialization conversion
|
| 544 |
[[conv.rval]] is applied. The expression is an unevaluated operand
|
| 545 |
-
[[
|
| 546 |
|
| 547 |
When `typeid` is applied to a *type-id*, the result refers to a
|
| 548 |
`std::type_info` object representing the type of the *type-id*. If the
|
| 549 |
type of the *type-id* is a reference to a possibly cv-qualified type,
|
| 550 |
the result of the `typeid` expression refers to a `std::type_info`
|
| 551 |
-
object representing the cv-unqualified referenced type.
|
| 552 |
-
the *type-id* is a class type or a reference to a class type, the class
|
| 553 |
-
shall be completely-defined.
|
| 554 |
|
| 555 |
[*Note 1*: The *type-id* cannot denote a function type with a
|
| 556 |
*cv-qualifier-seq* or a *ref-qualifier* [[dcl.fct]]. — *end note*]
|
| 557 |
|
| 558 |
If the type of the expression or *type-id* is a cv-qualified type, the
|
|
@@ -572,12 +621,14 @@ typeid(D) == typeid(d2); // yields true
|
|
| 572 |
typeid(D) == typeid(const D&); // yields true
|
| 573 |
```
|
| 574 |
|
| 575 |
— *end example*]
|
| 576 |
|
| 577 |
-
|
| 578 |
-
|
|
|
|
|
|
|
| 579 |
|
| 580 |
[*Note 2*: Subclause [[class.cdtor]] describes the behavior of `typeid`
|
| 581 |
applied to an object under construction or destruction. — *end note*]
|
| 582 |
|
| 583 |
#### Static cast <a id="expr.static.cast">[[expr.static.cast]]</a>
|
|
@@ -613,19 +664,19 @@ B &br = d;
|
|
| 613 |
static_cast<D&>(br); // produces lvalue denoting the original d object
|
| 614 |
```
|
| 615 |
|
| 616 |
— *end example*]
|
| 617 |
|
| 618 |
-
An lvalue of type
|
| 619 |
-
|
| 620 |
-
|
| 621 |
-
|
| 622 |
-
|
| 623 |
-
|
| 624 |
-
|
| 625 |
-
|
| 626 |
-
|
| 627 |
|
| 628 |
An expression E can be explicitly converted to a type `T` if there is an
|
| 629 |
implicit conversion sequence [[over.best.ics]] from E to `T`, if
|
| 630 |
overload resolution for a direct-initialization [[dcl.init]] of an
|
| 631 |
object or reference of type `T` from E would find at least one viable
|
|
@@ -654,13 +705,16 @@ direct-initialization defines the type of the expression as
|
|
| 654 |
Otherwise, the `static_cast` shall perform one of the conversions listed
|
| 655 |
below. No other conversion shall be performed explicitly using a
|
| 656 |
`static_cast`.
|
| 657 |
|
| 658 |
Any expression can be explicitly converted to type cv `void`, in which
|
| 659 |
-
case
|
| 660 |
|
| 661 |
-
[*Note 3*:
|
|
|
|
|
|
|
|
|
|
| 662 |
[[class.temporary]], the destructor for that object is not executed
|
| 663 |
until the usual time, and the value of the object is preserved for the
|
| 664 |
purpose of executing the destructor. — *end note*]
|
| 665 |
|
| 666 |
The inverse of any standard conversion sequence [[conv]] not containing
|
|
@@ -698,39 +752,48 @@ explicitly converted to a floating-point type; the result is the same as
|
|
| 698 |
that of converting from the original value to the floating-point type.
|
| 699 |
|
| 700 |
A value of integral or enumeration type can be explicitly converted to a
|
| 701 |
complete enumeration type. If the enumeration type has a fixed
|
| 702 |
underlying type, the value is first converted to that type by integral
|
| 703 |
-
|
| 704 |
-
|
| 705 |
-
|
| 706 |
-
|
| 707 |
-
|
| 708 |
-
|
| 709 |
-
|
| 710 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 711 |
|
| 712 |
A prvalue of type “pointer to *cv1* `B`”, where `B` is a class type, can
|
| 713 |
be converted to a prvalue of type “pointer to *cv2* `D`”, where `D` is a
|
| 714 |
complete class derived [[class.derived]] from `B`, if *cv2* is the same
|
| 715 |
cv-qualification as, or greater cv-qualification than, *cv1*. If `B` is
|
| 716 |
a virtual base class of `D` or a base class of a virtual base class of
|
| 717 |
`D`, or if no valid standard conversion from “pointer to `D`” to
|
| 718 |
“pointer to `B`” exists [[conv.ptr]], the program is ill-formed. The
|
| 719 |
null pointer value [[basic.compound]] is converted to the null pointer
|
| 720 |
value of the destination type. If the prvalue of type “pointer to *cv1*
|
| 721 |
-
`B`” points to a `B` that is actually a
|
| 722 |
-
`D`, the resulting pointer points to the enclosing object
|
| 723 |
-
Otherwise, the behavior is undefined.
|
| 724 |
|
| 725 |
A prvalue of type “pointer to member of `D` of type *cv1* `T`” can be
|
| 726 |
converted to a prvalue of type “pointer to member of `B` of type *cv2*
|
| 727 |
`T`”, where `D` is a complete class type and `B` is a base class
|
| 728 |
[[class.derived]] of `D`, if *cv2* is the same cv-qualification as, or
|
| 729 |
greater cv-qualification than, *cv1*.
|
| 730 |
|
| 731 |
-
[*Note
|
| 732 |
pointer-to-member-function types) are never cv-qualified
|
| 733 |
[[dcl.fct]]. — *end note*]
|
| 734 |
|
| 735 |
If no valid standard conversion from “pointer to member of `B` of type
|
| 736 |
`T`” to “pointer to member of `D` of type `T`” exists [[conv.mem]], the
|
|
@@ -739,11 +802,11 @@ converted to the null member pointer value of the destination type. If
|
|
| 739 |
class `B` contains the original member, or is a base or derived class of
|
| 740 |
the class containing the original member, the resulting pointer to
|
| 741 |
member points to the original member. Otherwise, the behavior is
|
| 742 |
undefined.
|
| 743 |
|
| 744 |
-
[*Note
|
| 745 |
dynamic type of the object with which indirection through the pointer to
|
| 746 |
member is performed must contain the original member; see
|
| 747 |
[[expr.mptr.oper]]. — *end note*]
|
| 748 |
|
| 749 |
A prvalue of type “pointer to *cv1* `void`” can be converted to a
|
|
@@ -751,14 +814,13 @@ prvalue of type “pointer to *cv2* `T`”, where `T` is an object type and
|
|
| 751 |
*cv2* is the same cv-qualification as, or greater cv-qualification than,
|
| 752 |
*cv1*. If the original pointer value represents the address `A` of a
|
| 753 |
byte in memory and `A` does not satisfy the alignment requirement of
|
| 754 |
`T`, then the resulting pointer value is unspecified. Otherwise, if the
|
| 755 |
original pointer value points to an object *a*, and there is an object
|
| 756 |
-
*b* of type `T`
|
| 757 |
-
|
| 758 |
-
|
| 759 |
-
conversion.
|
| 760 |
|
| 761 |
[*Example 3*:
|
| 762 |
|
| 763 |
``` cpp
|
| 764 |
T* p1 = new T;
|
|
@@ -808,39 +870,37 @@ A value of integral type or enumeration type can be explicitly converted
|
|
| 808 |
to a pointer. A pointer converted to an integer of sufficient size (if
|
| 809 |
any such exists on the implementation) and back to the same pointer type
|
| 810 |
will have its original value; mappings between pointers and integers are
|
| 811 |
otherwise *implementation-defined*.
|
| 812 |
|
| 813 |
-
[*Note 4*: Except as described in [[basic.stc.dynamic.safety]], the
|
| 814 |
-
result of such a conversion will not be a safely-derived pointer
|
| 815 |
-
value. — *end note*]
|
| 816 |
-
|
| 817 |
A function pointer can be explicitly converted to a function pointer of
|
| 818 |
a different type.
|
| 819 |
|
| 820 |
-
[*Note
|
| 821 |
function type [[dcl.fct]] that is not the same as the type used in the
|
| 822 |
definition of the function is undefined [[expr.call]]. — *end note*]
|
| 823 |
|
| 824 |
Except that converting a prvalue of type “pointer to `T1`” to the type
|
| 825 |
“pointer to `T2`” (where `T1` and `T2` are function types) and back to
|
| 826 |
its original type yields the original pointer value, the result of such
|
| 827 |
a pointer conversion is unspecified.
|
| 828 |
|
| 829 |
-
[*Note
|
| 830 |
conversions. — *end note*]
|
| 831 |
|
| 832 |
An object pointer can be explicitly converted to an object pointer of a
|
| 833 |
-
different type.[^17]
|
| 834 |
-
|
|
|
|
|
|
|
| 835 |
`static_cast<cv T*>(static_cast<cv~void*>(v))`.
|
| 836 |
|
| 837 |
-
[*Note
|
| 838 |
-
“pointer to `T2`” (where `
|
| 839 |
-
alignment requirements of `T2` are no stricter
|
| 840 |
-
back to its original type yields the original
|
| 841 |
-
value. — *end note*]
|
| 842 |
|
| 843 |
Converting a function pointer to an object pointer type or vice versa is
|
| 844 |
conditionally-supported. The meaning of such a conversion is
|
| 845 |
*implementation-defined*, except that if an implementation supports
|
| 846 |
conversions in both directions, converting a prvalue of one type to the
|
|
@@ -848,21 +908,23 @@ other type and back, possibly with different cv-qualification, shall
|
|
| 848 |
yield the original pointer value.
|
| 849 |
|
| 850 |
The null pointer value [[basic.compound]] is converted to the null
|
| 851 |
pointer value of the destination type.
|
| 852 |
|
| 853 |
-
[*Note
|
| 854 |
converted to a pointer type, and a null pointer constant of integral
|
| 855 |
type is not necessarily converted to a null pointer
|
| 856 |
value. — *end note*]
|
| 857 |
|
| 858 |
A prvalue of type “pointer to member of `X` of type `T1`” can be
|
| 859 |
explicitly converted to a prvalue of a different type “pointer to member
|
| 860 |
of `Y` of type `T2`” if `T1` and `T2` are both function types or both
|
| 861 |
-
object types.[^18]
|
| 862 |
-
|
| 863 |
-
|
|
|
|
|
|
|
| 864 |
|
| 865 |
- Converting a prvalue of type “pointer to member function” to a
|
| 866 |
different pointer-to-member-function type and back to its original
|
| 867 |
type yields the original pointer-to-member value.
|
| 868 |
- Converting a prvalue of type “pointer to data member of `X` of type
|
|
@@ -890,17 +952,17 @@ otherwise, the result is a prvalue and the lvalue-to-rvalue
|
|
| 890 |
Conversions that can be performed explicitly using `const_cast` are
|
| 891 |
listed below. No other conversion shall be performed explicitly using
|
| 892 |
`const_cast`.
|
| 893 |
|
| 894 |
[*Note 1*: Subject to the restrictions in this subclause, an expression
|
| 895 |
-
|
| 896 |
operator. — *end note*]
|
| 897 |
|
| 898 |
For two similar types `T1` and `T2` [[conv.qual]], a prvalue of type
|
| 899 |
`T1` may be explicitly converted to the type `T2` using a `const_cast`
|
| 900 |
-
if, considering the
|
| 901 |
-
same as P²ᵢ for all i. The result of a `const_cast` refers to the
|
| 902 |
original entity.
|
| 903 |
|
| 904 |
[*Example 1*:
|
| 905 |
|
| 906 |
``` cpp
|
|
@@ -933,46 +995,56 @@ materialization conversion [[conv.rval]] otherwise.
|
|
| 933 |
A null pointer value [[basic.compound]] is converted to the null pointer
|
| 934 |
value of the destination type. The null member pointer value
|
| 935 |
[[conv.mem]] is converted to the null member pointer value of the
|
| 936 |
destination type.
|
| 937 |
|
| 938 |
-
[*Note 2*:
|
| 939 |
-
|
| 940 |
-
|
| 941 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 942 |
|
| 943 |
A conversion from a type `T1` to a type `T2` *casts away constness* if
|
| 944 |
-
`T1` and `T2` are different, there is a
|
| 945 |
-
of `T1` yielding *n* such that `T2` has a
|
|
|
|
| 946 |
|
| 947 |
and there is no qualification conversion that converts `T1` to
|
| 948 |
|
| 949 |
Casting from an lvalue of type `T1` to an lvalue of type `T2` using an
|
| 950 |
lvalue reference cast or casting from an expression of type `T1` to an
|
| 951 |
xvalue of type `T2` using an rvalue reference cast casts away constness
|
| 952 |
if a cast from a prvalue of type “pointer to `T1`” to the type “pointer
|
| 953 |
to `T2`” casts away constness.
|
| 954 |
|
| 955 |
[*Note 3*: Some conversions which involve only changes in
|
| 956 |
-
cv-qualification cannot be done using `const_cast
|
| 957 |
conversions between pointers to functions are not covered because such
|
| 958 |
conversions lead to values whose use causes undefined behavior. For the
|
| 959 |
same reasons, conversions between pointers to member functions, and in
|
| 960 |
particular, the conversion from a pointer to a const member function to
|
| 961 |
a pointer to a non-const member function, are not
|
| 962 |
covered. — *end note*]
|
| 963 |
|
| 964 |
### Unary expressions <a id="expr.unary">[[expr.unary]]</a>
|
| 965 |
|
|
|
|
|
|
|
| 966 |
Expressions with unary operators group right-to-left.
|
| 967 |
|
| 968 |
``` bnf
|
|
|
|
|
|
|
| 969 |
unary-expression:
|
| 970 |
postfix-expression
|
| 971 |
unary-operator cast-expression
|
| 972 |
'++' cast-expression
|
| 973 |
-
'-
|
| 974 |
await-expression
|
| 975 |
sizeof unary-expression
|
| 976 |
sizeof '(' type-id ')'
|
| 977 |
sizeof '...' '(' identifier ')'
|
| 978 |
alignof '(' type-id ')'
|
|
@@ -980,41 +1052,43 @@ unary-expression:
|
|
| 980 |
new-expression
|
| 981 |
delete-expression
|
| 982 |
```
|
| 983 |
|
| 984 |
``` bnf
|
|
|
|
|
|
|
| 985 |
unary-operator: one of
|
| 986 |
'* & + - ! ~'
|
| 987 |
```
|
| 988 |
|
| 989 |
#### Unary operators <a id="expr.unary.op">[[expr.unary.op]]</a>
|
| 990 |
|
| 991 |
-
The unary `*` operator performs *indirection*
|
| 992 |
-
|
| 993 |
-
|
| 994 |
-
function to which the
|
| 995 |
-
is “pointer to `T`”, the type of the result is “`T`”.
|
| 996 |
|
| 997 |
[*Note 1*: Indirection through a pointer to an incomplete type (other
|
| 998 |
than cv `void`) is valid. The lvalue thus obtained can be used in
|
| 999 |
limited ways (to initialize a reference, for example); this lvalue must
|
| 1000 |
not be converted to a prvalue, see [[conv.lval]]. — *end note*]
|
| 1001 |
|
| 1002 |
-
|
| 1003 |
|
| 1004 |
-
The
|
|
|
|
| 1005 |
|
| 1006 |
- If the operand is a *qualified-id* naming a non-static or variant
|
| 1007 |
-
member `m` of some class `C`
|
| 1008 |
-
“pointer to member of class `C` of type
|
| 1009 |
-
|
| 1010 |
-
- Otherwise,
|
| 1011 |
-
|
| 1012 |
-
|
| 1013 |
-
\[*Note 2*: In particular, taking
|
| 1014 |
-
|
| 1015 |
-
|
| 1016 |
|
| 1017 |
[*Example 1*:
|
| 1018 |
|
| 1019 |
``` cpp
|
| 1020 |
struct A { int i; };
|
|
@@ -1047,44 +1121,53 @@ the *unqualified-id*’s class. — *end note*]
|
|
| 1047 |
If `&` is applied to an lvalue of incomplete class type and the complete
|
| 1048 |
type declares `operator&()`, it is unspecified whether the operator has
|
| 1049 |
the built-in meaning or the operator function is called. The operand of
|
| 1050 |
`&` shall not be a bit-field.
|
| 1051 |
|
| 1052 |
-
[*Note 5*: The address of an
|
| 1053 |
-
|
| 1054 |
-
|
| 1055 |
-
|
| 1056 |
-
|
| 1057 |
-
|
| 1058 |
-
function”. — *end note*]
|
| 1059 |
|
| 1060 |
The operand of the unary `+` operator shall have arithmetic, unscoped
|
| 1061 |
enumeration, or pointer type and the result is the value of the
|
| 1062 |
argument. Integral promotion is performed on integral or enumeration
|
| 1063 |
operands. The type of the result is the type of the promoted operand.
|
| 1064 |
|
| 1065 |
The operand of the unary `-` operator shall have arithmetic or unscoped
|
| 1066 |
-
enumeration type and the result is the
|
| 1067 |
promotion is performed on integral or enumeration operands. The negative
|
| 1068 |
of an unsigned quantity is computed by subtracting its value from 2ⁿ,
|
| 1069 |
where n is the number of bits in the promoted operand. The type of the
|
| 1070 |
result is the type of the promoted operand.
|
| 1071 |
|
|
|
|
|
|
|
|
|
|
| 1072 |
The operand of the logical negation operator `!` is contextually
|
| 1073 |
converted to `bool` [[conv]]; its value is `true` if the converted
|
| 1074 |
operand is `false` and `false` otherwise. The type of the result is
|
| 1075 |
`bool`.
|
| 1076 |
|
| 1077 |
-
The operand of `~` shall have integral or unscoped
|
| 1078 |
-
|
| 1079 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1080 |
There is an ambiguity in the grammar when `~` is followed by a
|
| 1081 |
*type-name* or *decltype-specifier*. The ambiguity is resolved by
|
| 1082 |
-
treating `~` as the
|
| 1083 |
-
|
| 1084 |
|
| 1085 |
-
[*Note
|
| 1086 |
the `.`, `->`, or `::` tokens, a `~` followed by a *type-name* or
|
| 1087 |
*decltype-specifier* in a member access expression or *qualified-id* is
|
| 1088 |
unambiguously parsed as a destructor name. — *end note*]
|
| 1089 |
|
| 1090 |
#### Increment and decrement <a id="expr.pre.incr">[[expr.pre.incr]]</a>
|
|
@@ -1098,12 +1181,12 @@ operand; it is an lvalue, and it is a bit-field if the operand is a
|
|
| 1098 |
bit-field. The expression `++x` is equivalent to `x+=1`.
|
| 1099 |
|
| 1100 |
[*Note 1*: See the discussions of addition [[expr.add]] and assignment
|
| 1101 |
operators [[expr.ass]] for information on conversions. — *end note*]
|
| 1102 |
|
| 1103 |
-
The operand of prefix `
|
| 1104 |
-
`1`. The requirements on the operand of prefix `
|
| 1105 |
of its result are otherwise the same as those of prefix `++`.
|
| 1106 |
|
| 1107 |
[*Note 2*: For postfix increment and decrement, see
|
| 1108 |
[[expr.post.incr]]. — *end note*]
|
| 1109 |
|
|
@@ -1119,30 +1202,30 @@ await-expression:
|
|
| 1119 |
```
|
| 1120 |
|
| 1121 |
An *await-expression* shall appear only in a potentially-evaluated
|
| 1122 |
expression within the *compound-statement* of a *function-body* outside
|
| 1123 |
of a *handler* [[except.pre]]. In a *declaration-statement* or in the
|
| 1124 |
-
*simple-declaration* (if any) of
|
| 1125 |
*await-expression* shall appear only in an *initializer* of that
|
| 1126 |
*declaration-statement* or *simple-declaration*. An *await-expression*
|
| 1127 |
shall not appear in a default argument [[dcl.fct.default]]. An
|
| 1128 |
-
*await-expression* shall not appear in the initializer of a block
|
| 1129 |
variable with static or thread storage duration. A context within a
|
| 1130 |
function where an *await-expression* can appear is called a *suspension
|
| 1131 |
context* of the function.
|
| 1132 |
|
| 1133 |
Evaluation of an *await-expression* involves the following auxiliary
|
| 1134 |
types, expressions, and objects:
|
| 1135 |
|
| 1136 |
- *p* is an lvalue naming the promise object [[dcl.fct.def.coroutine]]
|
| 1137 |
of the enclosing coroutine and `P` is the type of that object.
|
| 1138 |
-
-
|
| 1139 |
-
|
| 1140 |
-
|
| 1141 |
-
the
|
| 1142 |
-
|
| 1143 |
-
|
| 1144 |
*p*`.await_transform(`*cast-expression*`)`; otherwise, *a* is the
|
| 1145 |
*cast-expression*.
|
| 1146 |
- *o* is determined by enumerating the applicable `operator co_await`
|
| 1147 |
functions for an argument *a* [[over.match.oper]], and choosing the
|
| 1148 |
best one through overload resolution [[over.match]]. If overload
|
|
@@ -1170,25 +1253,31 @@ and the *await-ready* expression, then:
|
|
| 1170 |
- If the result of *await-ready* is `false`, the coroutine is considered
|
| 1171 |
suspended. Then:
|
| 1172 |
- If the type of *await-suspend* is `std::coroutine_handle<Z>`,
|
| 1173 |
*await-suspend*`.resume()` is evaluated. \[*Note 1*: This resumes
|
| 1174 |
the coroutine referred to by the result of *await-suspend*. Any
|
| 1175 |
-
number of coroutines
|
| 1176 |
eventually returning control flow to the current coroutine caller or
|
| 1177 |
resumer [[dcl.fct.def.coroutine]]. — *end note*]
|
| 1178 |
- Otherwise, if the type of *await-suspend* is `bool`, *await-suspend*
|
| 1179 |
is evaluated, and the coroutine is resumed if the result is `false`.
|
| 1180 |
- Otherwise, *await-suspend* is evaluated.
|
| 1181 |
|
| 1182 |
If the evaluation of *await-suspend* exits via an exception, the
|
| 1183 |
exception is caught, the coroutine is resumed, and the exception is
|
| 1184 |
-
immediately
|
| 1185 |
-
|
| 1186 |
-
|
|
|
|
|
|
|
| 1187 |
- If the result of *await-ready* is `true`, or when the coroutine is
|
| 1188 |
-
resumed
|
| 1189 |
-
the
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1190 |
|
| 1191 |
[*Example 1*:
|
| 1192 |
|
| 1193 |
``` cpp
|
| 1194 |
template <typename T>
|
|
@@ -1215,11 +1304,11 @@ auto operator co_await(std::chrono::duration<Rep, Period> d) {
|
|
| 1215 |
using namespace std::chrono;
|
| 1216 |
|
| 1217 |
my_future<int> h();
|
| 1218 |
|
| 1219 |
my_future<void> g() {
|
| 1220 |
-
std::cout << "just about go to sleep...\n";
|
| 1221 |
co_await 10ms;
|
| 1222 |
std::cout << "resumed\n";
|
| 1223 |
co_await h();
|
| 1224 |
}
|
| 1225 |
|
|
@@ -1232,33 +1321,40 @@ int a[] = { co_await h() }; // error: await-expression outside of function s
|
|
| 1232 |
#### Sizeof <a id="expr.sizeof">[[expr.sizeof]]</a>
|
| 1233 |
|
| 1234 |
The `sizeof` operator yields the number of bytes occupied by a
|
| 1235 |
non-potentially-overlapping object of the type of its operand. The
|
| 1236 |
operand is either an expression, which is an unevaluated operand
|
| 1237 |
-
[[
|
| 1238 |
-
not be applied to an expression that has function or
|
| 1239 |
-
the parenthesized name of such types, or to a
|
| 1240 |
-
bit-field. The result of `sizeof` applied to
|
| 1241 |
-
types is `1`. The result of `sizeof` applied
|
| 1242 |
-
type [[basic.fundamental]] is
|
|
|
|
| 1243 |
|
| 1244 |
-
[*Note 1*:
|
|
|
|
|
|
|
| 1245 |
`sizeof(char32_t)`, and `sizeof(wchar_t)` are
|
| 1246 |
-
implementation-defined.[^21]
|
|
|
|
|
|
|
| 1247 |
|
| 1248 |
[*Note 2*: See [[intro.memory]] for the definition of byte and
|
| 1249 |
-
[[
|
| 1250 |
representation. — *end note*]
|
| 1251 |
|
| 1252 |
When applied to a reference type, the result is the size of the
|
| 1253 |
referenced type. When applied to a class, the result is the number of
|
| 1254 |
bytes in an object of that class including any padding required for
|
| 1255 |
placing objects of that type in an array. The result of applying
|
| 1256 |
`sizeof` to a potentially-overlapping subobject is the size of the type,
|
| 1257 |
-
not the size of the subobject.
|
| 1258 |
-
|
| 1259 |
-
|
|
|
|
|
|
|
| 1260 |
|
| 1261 |
The lvalue-to-rvalue [[conv.lval]], array-to-pointer [[conv.array]], and
|
| 1262 |
function-to-pointer [[conv.func]] standard conversions are not applied
|
| 1263 |
to the operand of `sizeof`. If the operand is a prvalue, the temporary
|
| 1264 |
materialization conversion [[conv.rval]] is applied.
|
|
@@ -1282,11 +1378,11 @@ struct count {
|
|
| 1282 |
The result of `sizeof` and `sizeof...` is a prvalue of type
|
| 1283 |
`std::size_t`.
|
| 1284 |
|
| 1285 |
[*Note 3*: A `sizeof` expression is an integral constant expression
|
| 1286 |
[[expr.const]]. The type `std::size_t` is defined in the standard header
|
| 1287 |
-
`<cstddef>`
|
| 1288 |
|
| 1289 |
#### Alignof <a id="expr.alignof">[[expr.alignof]]</a>
|
| 1290 |
|
| 1291 |
An `alignof` expression yields the alignment requirement of its operand
|
| 1292 |
type. The operand shall be a *type-id* representing a complete object
|
|
@@ -1294,21 +1390,21 @@ type, or an array thereof, or a reference to one of those types.
|
|
| 1294 |
|
| 1295 |
The result is a prvalue of type `std::size_t`.
|
| 1296 |
|
| 1297 |
[*Note 1*: An `alignof` expression is an integral constant expression
|
| 1298 |
[[expr.const]]. The type `std::size_t` is defined in the standard header
|
| 1299 |
-
`<cstddef>`
|
| 1300 |
|
| 1301 |
When `alignof` is applied to a reference type, the result is the
|
| 1302 |
alignment of the referenced type. When `alignof` is applied to an array
|
| 1303 |
type, the result is the alignment of the element type.
|
| 1304 |
|
| 1305 |
#### `noexcept` operator <a id="expr.unary.noexcept">[[expr.unary.noexcept]]</a>
|
| 1306 |
|
| 1307 |
The `noexcept` operator determines whether the evaluation of its
|
| 1308 |
-
operand, which is an unevaluated operand [[
|
| 1309 |
-
exception [[except.throw]].
|
| 1310 |
|
| 1311 |
``` bnf
|
| 1312 |
noexcept-expression:
|
| 1313 |
noexcept '(' expression ')'
|
| 1314 |
```
|
|
@@ -1324,17 +1420,17 @@ is potentially-throwing [[except.spec]].
|
|
| 1324 |
#### New <a id="expr.new">[[expr.new]]</a>
|
| 1325 |
|
| 1326 |
The *new-expression* attempts to create an object of the *type-id*
|
| 1327 |
[[dcl.name]] or *new-type-id* to which it is applied. The type of that
|
| 1328 |
object is the *allocated type*. This type shall be a complete object
|
| 1329 |
-
type, but not an abstract class type
|
| 1330 |
-
[[
|
| 1331 |
|
| 1332 |
[*Note 1*: Because references are not objects, references cannot be
|
| 1333 |
created by *new-expression*s. — *end note*]
|
| 1334 |
|
| 1335 |
-
[*Note 2*: The *type-id*
|
| 1336 |
object created by the *new-expression* has a cv-qualified
|
| 1337 |
type. — *end note*]
|
| 1338 |
|
| 1339 |
``` bnf
|
| 1340 |
new-expression:
|
|
@@ -1440,27 +1536,10 @@ returning `int`).
|
|
| 1440 |
|
| 1441 |
— *end example*]
|
| 1442 |
|
| 1443 |
— *end note*]
|
| 1444 |
|
| 1445 |
-
Objects created by a *new-expression* have dynamic storage duration
|
| 1446 |
-
[[basic.stc.dynamic]].
|
| 1447 |
-
|
| 1448 |
-
[*Note 5*: The lifetime of such an object is not necessarily
|
| 1449 |
-
restricted to the scope in which it is created. — *end note*]
|
| 1450 |
-
|
| 1451 |
-
When the allocated object is not an array, the result of the
|
| 1452 |
-
*new-expression* is a pointer to the object created.
|
| 1453 |
-
|
| 1454 |
-
When the allocated object is an array (that is, the
|
| 1455 |
-
*noptr-new-declarator* syntax is used or the *new-type-id* or *type-id*
|
| 1456 |
-
denotes an array type), the *new-expression* yields a pointer to the
|
| 1457 |
-
initial element (if any) of the array.
|
| 1458 |
-
|
| 1459 |
-
[*Note 6*: Both `new int` and `new int[10]` have type `int*` and the
|
| 1460 |
-
type of `new int[i][10]` is `int (*)[10]` — *end note*]
|
| 1461 |
-
|
| 1462 |
The *attribute-specifier-seq* in a *noptr-new-declarator* appertains to
|
| 1463 |
the associated array type.
|
| 1464 |
|
| 1465 |
Every *constant-expression* in a *noptr-new-declarator* shall be a
|
| 1466 |
converted constant expression [[expr.const]] of type `std::size_t` and
|
|
@@ -1472,12 +1551,12 @@ well-formed (because `n` is the *expression* of a
|
|
| 1472 |
`n` is not a constant expression). — *end example*]
|
| 1473 |
|
| 1474 |
If the *type-id* or *new-type-id* denotes an array type of unknown bound
|
| 1475 |
[[dcl.array]], the *new-initializer* shall not be omitted; the allocated
|
| 1476 |
object is an array with `n` elements, where `n` is determined from the
|
| 1477 |
-
number of initial elements supplied in the *new-initializer*
|
| 1478 |
-
[[dcl.init.aggr]], [[dcl.init.string]]
|
| 1479 |
|
| 1480 |
If the *expression* in a *noptr-new-declarator* is present, it is
|
| 1481 |
implicitly converted to `std::size_t`. The *expression* is erroneous if:
|
| 1482 |
|
| 1483 |
- the expression is of non-class type and its value before converting to
|
|
@@ -1492,12 +1571,12 @@ implicitly converted to `std::size_t`. The *expression* is erroneous if:
|
|
| 1492 |
terminating `'\0'` in a *string-literal* [[lex.string]]) exceeds the
|
| 1493 |
number of elements to initialize.
|
| 1494 |
|
| 1495 |
If the *expression* is erroneous after converting to `std::size_t`:
|
| 1496 |
|
| 1497 |
-
- if the *expression* is a core constant
|
| 1498 |
-
ill-formed;
|
| 1499 |
- otherwise, an allocation function is not called; instead
|
| 1500 |
- if the allocation function that would have been called has a
|
| 1501 |
non-throwing exception specification [[except.spec]], the value of
|
| 1502 |
the *new-expression* is the null pointer value of the required
|
| 1503 |
result type;
|
|
@@ -1506,10 +1585,26 @@ If the *expression* is erroneous after converting to `std::size_t`:
|
|
| 1506 |
`std::bad_array_new_length` [[new.badlength]].
|
| 1507 |
|
| 1508 |
When the value of the *expression* is zero, the allocation function is
|
| 1509 |
called to allocate an array with no elements.
|
| 1510 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1511 |
A *new-expression* may obtain storage for the object by calling an
|
| 1512 |
allocation function [[basic.stc.dynamic.allocation]]. If the
|
| 1513 |
*new-expression* terminates by throwing an exception, it may release
|
| 1514 |
storage by calling a deallocation function
|
| 1515 |
[[basic.stc.dynamic.deallocation]]. If the allocated type is a non-array
|
|
@@ -1517,28 +1612,28 @@ type, the allocation function’s name is `operator new` and the
|
|
| 1517 |
deallocation function’s name is `operator delete`. If the allocated type
|
| 1518 |
is an array type, the allocation function’s name is `operator new[]` and
|
| 1519 |
the deallocation function’s name is `operator delete[]`.
|
| 1520 |
|
| 1521 |
[*Note 7*: An implementation is required to provide default definitions
|
| 1522 |
-
for the global allocation functions
|
| 1523 |
-
[[new.delete.single]], [[new.delete.array]]
|
| 1524 |
-
alternative definitions of these functions
|
| 1525 |
-
and/or class-specific versions [[class.free]].
|
| 1526 |
-
deallocation functions that
|
| 1527 |
-
include functions that do not perform allocation or
|
| 1528 |
-
example, see [[new.delete.placement]]. — *end note*]
|
| 1529 |
|
| 1530 |
-
If the *new-expression*
|
| 1531 |
-
|
| 1532 |
-
|
| 1533 |
-
|
| 1534 |
-
|
| 1535 |
-
|
| 1536 |
|
| 1537 |
An implementation is allowed to omit a call to a replaceable global
|
| 1538 |
-
allocation function
|
| 1539 |
-
|
| 1540 |
provided by extending the allocation of another *new-expression*.
|
| 1541 |
|
| 1542 |
During an evaluation of a constant expression, a call to an allocation
|
| 1543 |
function is always omitted.
|
| 1544 |
|
|
@@ -1669,12 +1764,12 @@ from one invocation of `new` to another.
|
|
| 1669 |
|
| 1670 |
— *end example*]
|
| 1671 |
|
| 1672 |
[*Note 10*: Unless an allocation function has a non-throwing exception
|
| 1673 |
specification [[except.spec]], it indicates failure to allocate storage
|
| 1674 |
-
by throwing a `std::bad_alloc` exception
|
| 1675 |
-
[[basic.stc.dynamic.allocation]], [[except]], [[bad.alloc]]
|
| 1676 |
a non-null pointer otherwise. If the allocation function has a
|
| 1677 |
non-throwing exception specification, it returns null to indicate
|
| 1678 |
failure to allocate storage and a non-null pointer
|
| 1679 |
otherwise. — *end note*]
|
| 1680 |
|
|
@@ -1705,34 +1800,33 @@ evaluations of expressions in the *new-initializer*. Initialization of
|
|
| 1705 |
the allocated object is sequenced before the value computation of the
|
| 1706 |
*new-expression*.
|
| 1707 |
|
| 1708 |
If the *new-expression* creates an object or an array of objects of
|
| 1709 |
class type, access and ambiguity control are done for the allocation
|
| 1710 |
-
function, the deallocation function [[
|
| 1711 |
-
[[class.ctor]] selected for the initialization (if
|
| 1712 |
-
*new-expression* creates an array of objects of class type,
|
| 1713 |
-
destructor is potentially invoked [[class.dtor]].
|
| 1714 |
|
| 1715 |
-
If any part of the object initialization described above[^24]
|
| 1716 |
-
|
| 1717 |
-
|
| 1718 |
-
the
|
| 1719 |
-
|
| 1720 |
-
|
| 1721 |
-
|
|
|
|
| 1722 |
|
| 1723 |
[*Note 13*: This is appropriate when the called allocation function
|
| 1724 |
does not allocate memory; otherwise, it is likely to result in a memory
|
| 1725 |
leak. — *end note*]
|
| 1726 |
|
| 1727 |
-
If the *new-expression*
|
| 1728 |
-
|
| 1729 |
-
|
| 1730 |
-
|
| 1731 |
-
|
| 1732 |
-
not a class type or array thereof, the deallocation function’s name is
|
| 1733 |
-
looked up in the global scope.
|
| 1734 |
|
| 1735 |
A declaration of a placement deallocation function matches the
|
| 1736 |
declaration of a placement allocation function if it has the same number
|
| 1737 |
of parameters and, after parameter transformations [[dcl.fct]], all
|
| 1738 |
parameter types except the first are identical. If the lookup finds a
|
|
@@ -1783,26 +1877,32 @@ delete-expression:
|
|
| 1783 |
```
|
| 1784 |
|
| 1785 |
The first alternative is a *single-object delete expression*, and the
|
| 1786 |
second is an *array delete expression*. Whenever the `delete` keyword is
|
| 1787 |
immediately followed by empty square brackets, it shall be interpreted
|
| 1788 |
-
as the second alternative.[^25]
|
| 1789 |
-
|
| 1790 |
-
|
| 1791 |
-
type
|
|
|
|
|
|
|
|
|
|
| 1792 |
|
| 1793 |
If the operand has a class type, the operand is converted to a pointer
|
| 1794 |
type by calling the above-mentioned conversion function, and the
|
| 1795 |
converted operand is used in place of the original operand for the
|
| 1796 |
remainder of this subclause. In a single-object delete expression, the
|
| 1797 |
value of the operand of `delete` may be a null pointer value, a pointer
|
| 1798 |
-
|
| 1799 |
-
pointer to a subobject
|
| 1800 |
-
|
| 1801 |
-
|
| 1802 |
-
|
| 1803 |
-
|
|
|
|
|
|
|
|
|
|
| 1804 |
|
| 1805 |
[*Note 1*: This means that the syntax of the *delete-expression* must
|
| 1806 |
match the type of the object allocated by `new`, not the syntax of the
|
| 1807 |
*new-expression*. — *end note*]
|
| 1808 |
|
|
@@ -1810,17 +1910,17 @@ match the type of the object allocated by `new`, not the syntax of the
|
|
| 1810 |
*delete-expression*; it is not necessary to cast away the constness
|
| 1811 |
[[expr.const.cast]] of the pointer expression before it is used as the
|
| 1812 |
operand of the *delete-expression*. — *end note*]
|
| 1813 |
|
| 1814 |
In a single-object delete expression, if the static type of the object
|
| 1815 |
-
to be deleted is
|
| 1816 |
-
deallocation function (see below) is not a destroying operator
|
| 1817 |
-
the static type shall be a base class of the dynamic type of the
|
| 1818 |
-
to be deleted and the static type shall have a virtual destructor
|
| 1819 |
-
behavior is undefined. In an array delete expression, if the
|
| 1820 |
-
type of the object to be deleted
|
| 1821 |
-
behavior is undefined.
|
| 1822 |
|
| 1823 |
The *cast-expression* in a *delete-expression* shall be evaluated
|
| 1824 |
exactly once.
|
| 1825 |
|
| 1826 |
If the object being deleted has incomplete class type at the point of
|
|
@@ -1861,61 +1961,78 @@ exception. — *end note*]
|
|
| 1861 |
|
| 1862 |
If the value of the operand of the *delete-expression* is a null pointer
|
| 1863 |
value, it is unspecified whether a deallocation function will be called
|
| 1864 |
as described above.
|
| 1865 |
|
| 1866 |
-
|
| 1867 |
-
|
| 1868 |
-
|
| 1869 |
-
[[new.delete.array]]. A C++ program can provide alternative definitions
|
| 1870 |
-
of these functions [[replacement.functions]], and/or class-specific
|
| 1871 |
-
versions [[class.free]]. — *end note*]
|
| 1872 |
|
| 1873 |
-
|
| 1874 |
-
|
| 1875 |
-
|
| 1876 |
-
|
| 1877 |
-
|
| 1878 |
-
global scope.
|
| 1879 |
|
| 1880 |
-
If
|
| 1881 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1882 |
|
| 1883 |
- If any of the deallocation functions is a destroying operator delete,
|
| 1884 |
all deallocation functions that are not destroying operator deletes
|
| 1885 |
are eliminated from further consideration.
|
| 1886 |
- If the type has new-extended alignment, a function with a parameter of
|
| 1887 |
type `std::align_val_t` is preferred; otherwise a function without
|
| 1888 |
such a parameter is preferred. If any preferred functions are found,
|
| 1889 |
all non-preferred functions are eliminated from further consideration.
|
| 1890 |
- If exactly one function remains, that function is selected and the
|
| 1891 |
selection process terminates.
|
| 1892 |
-
- If the deallocation functions
|
| 1893 |
-
parameter of type `std::size_t` is selected.
|
| 1894 |
- If the type is complete and if, for an array delete expression only,
|
| 1895 |
the operand is a pointer to a class type with a non-trivial destructor
|
| 1896 |
-
or a (possibly
|
| 1897 |
parameter of type `std::size_t` is selected.
|
| 1898 |
- Otherwise, it is unspecified whether a deallocation function with a
|
| 1899 |
parameter of type `std::size_t` is selected.
|
| 1900 |
|
| 1901 |
For a single-object delete expression, the deleted object is the object
|
| 1902 |
-
|
| 1903 |
-
destructor, and
|
| 1904 |
|
| 1905 |
-
[*Note
|
| 1906 |
delete and the deleted object is not the most derived object in the
|
| 1907 |
former case, the behavior is undefined, as stated above. — *end note*]
|
| 1908 |
|
| 1909 |
For an array delete expression, the deleted object is the array object.
|
| 1910 |
When a *delete-expression* is executed, the selected deallocation
|
| 1911 |
function shall be called with the address of the deleted object in a
|
| 1912 |
single-object delete expression, or the address of the deleted object
|
| 1913 |
suitably adjusted for the array allocation overhead [[expr.new]] in an
|
| 1914 |
array delete expression, as its first argument.
|
| 1915 |
|
| 1916 |
-
[*Note
|
| 1917 |
ignored when forming this argument. — *end note*]
|
| 1918 |
|
| 1919 |
If a destroying operator delete is used, an unspecified value is passed
|
| 1920 |
as the argument corresponding to the parameter of type
|
| 1921 |
`std::destroying_delete_t`. If a deallocation function with a parameter
|
|
@@ -1924,19 +2041,18 @@ deleted object is passed as the corresponding argument. If a
|
|
| 1924 |
deallocation function with a parameter of type `std::size_t` is used,
|
| 1925 |
the size of the deleted object in a single-object delete expression, or
|
| 1926 |
of the array plus allocation overhead in an array delete expression, is
|
| 1927 |
passed as the corresponding argument.
|
| 1928 |
|
| 1929 |
-
[*Note
|
| 1930 |
function, and either the first argument was not the result of a prior
|
| 1931 |
call to a replaceable allocation function or the second or third
|
| 1932 |
argument was not the corresponding argument in said call, the behavior
|
| 1933 |
-
is undefined
|
| 1934 |
-
[[new.delete.array]]). — *end note*]
|
| 1935 |
|
| 1936 |
Access and ambiguity control are done for both the deallocation function
|
| 1937 |
-
and the destructor
|
| 1938 |
|
| 1939 |
### Explicit type conversion (cast notation) <a id="expr.cast">[[expr.cast]]</a>
|
| 1940 |
|
| 1941 |
The result of the expression `(T)` *cast-expression* is of type `T`. The
|
| 1942 |
result is an lvalue if `T` is an lvalue reference type or an rvalue
|
|
@@ -2040,13 +2156,14 @@ type “pointer to member of `T`” to its first operand, which shall be of
|
|
| 2040 |
type “pointer to `U`” where `U` is either `T` or a class of which `T` is
|
| 2041 |
an unambiguous and accessible base class. The expression `E1->*E2` is
|
| 2042 |
converted into the equivalent form `(*(E1)).*E2`.
|
| 2043 |
|
| 2044 |
Abbreviating *pm-expression*`.*`*cast-expression* as `E1.*E2`, `E1` is
|
| 2045 |
-
called the *object expression*. If the
|
| 2046 |
-
|
| 2047 |
-
|
|
|
|
| 2048 |
|
| 2049 |
The restrictions on cv-qualification, and the manner in which the
|
| 2050 |
cv-qualifiers of the operands are combined to produce the cv-qualifiers
|
| 2051 |
of the result, are the same as the rules for `E1.E2` given in
|
| 2052 |
[[expr.ref]].
|
|
@@ -2118,13 +2235,15 @@ The binary `*` operator indicates multiplication.
|
|
| 2118 |
|
| 2119 |
The binary `/` operator yields the quotient, and the binary `%` operator
|
| 2120 |
yields the remainder from the division of the first expression by the
|
| 2121 |
second. If the second operand of `/` or `%` is zero the behavior is
|
| 2122 |
undefined. For integral operands the `/` operator yields the algebraic
|
| 2123 |
-
quotient with any fractional part discarded;[^28]
|
| 2124 |
-
|
| 2125 |
-
|
|
|
|
|
|
|
| 2126 |
|
| 2127 |
### Additive operators <a id="expr.add">[[expr.add]]</a>
|
| 2128 |
|
| 2129 |
The additive operators `+` and `-` group left-to-right. The usual
|
| 2130 |
arithmetic conversions [[expr.arith.conv]] are performed for operands of
|
|
@@ -2165,30 +2284,41 @@ from an expression `P` of pointer type, the result has the type of `P`.
|
|
| 2165 |
(possibly-hypothetical) array element i + j of `x` if 0 ≤ i + j ≤ n
|
| 2166 |
and the expression `P - J` points to the (possibly-hypothetical) array
|
| 2167 |
element i - j of `x` if 0 ≤ i - j ≤ n.
|
| 2168 |
- Otherwise, the behavior is undefined.
|
| 2169 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2170 |
When two pointer expressions `P` and `Q` are subtracted, the type of the
|
| 2171 |
result is an *implementation-defined* signed integral type; this type
|
| 2172 |
shall be the same type that is defined as `std::ptrdiff_t` in the
|
| 2173 |
`<cstddef>` header [[support.types.layout]].
|
| 2174 |
|
| 2175 |
- If `P` and `Q` both evaluate to null pointer values, the result is 0.
|
| 2176 |
- Otherwise, if `P` and `Q` point to, respectively, array elements i and
|
| 2177 |
j of the same array object `x`, the expression `P - Q` has the value
|
| 2178 |
i - j.
|
| 2179 |
-
- Otherwise, the behavior is undefined. \[*Note
|
| 2180 |
is not in the range of representable values of type `std::ptrdiff_t`,
|
| 2181 |
the behavior is undefined. — *end note*]
|
| 2182 |
|
| 2183 |
For addition or subtraction, if the expressions `P` or `Q` have type
|
| 2184 |
“pointer to cv `T`”, where `T` and the array element type are not
|
| 2185 |
similar [[conv.qual]], the behavior is undefined.
|
| 2186 |
|
| 2187 |
-
[*
|
| 2188 |
-
|
| 2189 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2190 |
|
| 2191 |
### Shift operators <a id="expr.shift">[[expr.shift]]</a>
|
| 2192 |
|
| 2193 |
The shift operators `<<` and `>>` group left-to-right.
|
| 2194 |
|
|
@@ -2257,37 +2387,41 @@ Then:
|
|
| 2257 |
|
| 2258 |
If both operands have the same enumeration type `E`, the operator yields
|
| 2259 |
the result of converting the operands to the underlying type of `E` and
|
| 2260 |
applying `<=>` to the converted operands.
|
| 2261 |
|
| 2262 |
-
If at least one of the operands is of pointer type and the other
|
| 2263 |
-
is of pointer or array type, array-to-pointer conversions
|
| 2264 |
[[conv.array]], pointer conversions [[conv.ptr]], and qualification
|
| 2265 |
conversions [[conv.qual]] are performed on both operands to bring them
|
| 2266 |
to their composite pointer type [[expr.type]]. After the conversions,
|
| 2267 |
the operands shall have the same type.
|
| 2268 |
|
| 2269 |
[*Note 1*: If both of the operands are arrays, array-to-pointer
|
| 2270 |
conversions [[conv.array]] are not applied. — *end note*]
|
| 2271 |
|
| 2272 |
-
|
| 2273 |
-
|
| 2274 |
-
|
| 2275 |
-
`p` and `q` compare
|
|
|
|
|
|
|
| 2276 |
`std::strong_ordering::less` if `q` compares greater than `p` and
|
| 2277 |
`std::strong_ordering::greater` if `p` compares greater than `q`
|
| 2278 |
-
[[expr.rel]]
|
|
|
|
| 2279 |
|
| 2280 |
Otherwise, the program is ill-formed.
|
| 2281 |
|
| 2282 |
The three comparison category types [[cmp.categories]] (the types
|
| 2283 |
`std::strong_ordering`, `std::weak_ordering`, and
|
| 2284 |
-
`std::partial_ordering`) are not predefined; if
|
| 2285 |
-
|
| 2286 |
-
|
|
|
|
| 2287 |
specifier [[dcl.spec.auto]] in a defaulted three-way comparison
|
| 2288 |
-
[[class.spaceship]] or use of the built-in operator)
|
| 2289 |
ill-formed.
|
| 2290 |
|
| 2291 |
### Relational operators <a id="expr.rel">[[expr.rel]]</a>
|
| 2292 |
|
| 2293 |
The relational operators group left-to-right.
|
|
@@ -2319,30 +2453,36 @@ operands of arithmetic or enumeration type. If both operands are
|
|
| 2319 |
pointers, pointer conversions [[conv.ptr]] and qualification conversions
|
| 2320 |
[[conv.qual]] are performed to bring them to their composite pointer
|
| 2321 |
type [[expr.type]]. After conversions, the operands shall have the same
|
| 2322 |
type.
|
| 2323 |
|
| 2324 |
-
The result of comparing unequal pointers to objects
|
| 2325 |
-
|
|
|
|
|
|
|
| 2326 |
|
| 2327 |
- If two pointers point to different elements of the same array, or to
|
| 2328 |
subobjects thereof, the pointer to the element with the higher
|
| 2329 |
subscript is required to compare greater.
|
| 2330 |
- If two pointers point to different non-static data members of the same
|
| 2331 |
object, or to subobjects of such members, recursively, the pointer to
|
| 2332 |
-
the later declared member is required to compare greater provided
|
| 2333 |
-
|
| 2334 |
-
|
| 2335 |
- Otherwise, neither pointer is required to compare greater than the
|
| 2336 |
other.
|
| 2337 |
|
| 2338 |
If two operands `p` and `q` compare equal [[expr.eq]], `p<=q` and `p>=q`
|
| 2339 |
both yield `true` and `p<q` and `p>q` both yield `false`. Otherwise, if
|
| 2340 |
-
a pointer `p` compares greater than a pointer `q`, `p>=q`,
|
| 2341 |
-
`q<=p`, and `q<p` all yield `true` and `p<=q`, `p<q`, `q>=p`, and
|
| 2342 |
-
all yield `false`. Otherwise, the result of each of the operators
|
| 2343 |
-
unspecified.
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2344 |
|
| 2345 |
If both operands (after conversions) are of arithmetic or enumeration
|
| 2346 |
type, each of the operators shall yield `true` if the specified
|
| 2347 |
relationship is true and `false` if it is false.
|
| 2348 |
|
|
@@ -2480,11 +2620,11 @@ exclusive-or-expression:
|
|
| 2480 |
The `^` operator groups left-to-right. The operands shall be of integral
|
| 2481 |
or unscoped enumeration type. The usual arithmetic conversions
|
| 2482 |
[[expr.arith.conv]] are performed. Given the coefficients `xᵢ` and `yᵢ`
|
| 2483 |
of the base-2 representation [[basic.fundamental]] of the converted
|
| 2484 |
operands `x` and `y`, the coefficient `rᵢ` of the base-2 representation
|
| 2485 |
-
of the result `r` is 1 if either (but not both) of `xᵢ` and `yᵢ`
|
| 2486 |
and 0 otherwise.
|
| 2487 |
|
| 2488 |
[*Note 1*: The result is the bitwise exclusive function of the
|
| 2489 |
operands. — *end note*]
|
| 2490 |
|
|
@@ -2499,11 +2639,11 @@ inclusive-or-expression:
|
|
| 2499 |
The `|` operator groups left-to-right. The operands shall be of integral
|
| 2500 |
or unscoped enumeration type. The usual arithmetic conversions
|
| 2501 |
[[expr.arith.conv]] are performed. Given the coefficients `xᵢ` and `yᵢ`
|
| 2502 |
of the base-2 representation [[basic.fundamental]] of the converted
|
| 2503 |
operands `x` and `y`, the coefficient `rᵢ` of the base-2 representation
|
| 2504 |
-
of the result `r` is 1 if at least one of `xᵢ` and `yᵢ`
|
| 2505 |
otherwise.
|
| 2506 |
|
| 2507 |
[*Note 1*: The result is the bitwise inclusive function of the
|
| 2508 |
operands. — *end note*]
|
| 2509 |
|
|
@@ -2588,14 +2728,15 @@ that determination. — *end note*]
|
|
| 2588 |
Attempts are made to form an implicit conversion sequence from an
|
| 2589 |
operand expression `E1` of type `T1` to a target type related to the
|
| 2590 |
type `T2` of the operand expression `E2` as follows:
|
| 2591 |
|
| 2592 |
- If `E2` is an lvalue, the target type is “lvalue reference to `T2`”,
|
| 2593 |
-
|
| 2594 |
-
bind directly [[dcl.init.ref]] to a glvalue.
|
| 2595 |
- If `E2` is an xvalue, the target type is “rvalue reference to `T2`”,
|
| 2596 |
-
|
|
|
|
| 2597 |
- If `E2` is a prvalue or if neither of the conversion sequences above
|
| 2598 |
can be formed and at least one of the operands has (possibly
|
| 2599 |
cv-qualified) class type:
|
| 2600 |
- if `T1` and `T2` are the same class type (ignoring cv-qualification)
|
| 2601 |
and `T2` is at least as cv-qualified as `T1`, the target type is
|
|
@@ -2627,11 +2768,11 @@ and it is a bit-field if the second or the third operand is a bit-field,
|
|
| 2627 |
or if both are bit-fields.
|
| 2628 |
|
| 2629 |
Otherwise, the result is a prvalue. If the second and third operands do
|
| 2630 |
not have the same type, and either has (possibly cv-qualified) class
|
| 2631 |
type, overload resolution is used to determine the conversions (if any)
|
| 2632 |
-
to be applied to the operands
|
| 2633 |
the overload resolution fails, the program is ill-formed. Otherwise, the
|
| 2634 |
conversions thus determined are applied, and the converted operands are
|
| 2635 |
used in place of the original operands for the remainder of this
|
| 2636 |
subclause.
|
| 2637 |
|
|
@@ -2671,11 +2812,11 @@ yield-expression:
|
|
| 2671 |
A *yield-expression* shall appear only within a suspension context of a
|
| 2672 |
function [[expr.await]]. Let *e* be the operand of the
|
| 2673 |
*yield-expression* and *p* be an lvalue naming the promise object of the
|
| 2674 |
enclosing coroutine [[dcl.fct.def.coroutine]], then the
|
| 2675 |
*yield-expression* is equivalent to the expression
|
| 2676 |
-
`co_await
|
| 2677 |
|
| 2678 |
[*Example 1*:
|
| 2679 |
|
| 2680 |
``` cpp
|
| 2681 |
template <typename T>
|
|
@@ -2692,14 +2833,14 @@ struct my_generator {
|
|
| 2692 |
iterator begin();
|
| 2693 |
iterator end();
|
| 2694 |
};
|
| 2695 |
|
| 2696 |
my_generator<pair<int,int>> g1() {
|
| 2697 |
-
for (int i =
|
| 2698 |
}
|
| 2699 |
my_generator<pair<int,int>> g2() {
|
| 2700 |
-
for (int i =
|
| 2701 |
}
|
| 2702 |
|
| 2703 |
auto f(int x = co_yield 5); // error: yield-expression outside of function suspension context
|
| 2704 |
int a[] = { co_yield 1 }; // error: yield-expression outside of function suspension context
|
| 2705 |
|
|
@@ -2732,12 +2873,12 @@ exception [[except.handle]]. The exception is reactivated with the
|
|
| 2732 |
existing exception object; no new exception object is created. The
|
| 2733 |
exception is no longer considered to be caught.
|
| 2734 |
|
| 2735 |
[*Example 1*:
|
| 2736 |
|
| 2737 |
-
|
| 2738 |
-
|
| 2739 |
|
| 2740 |
``` cpp
|
| 2741 |
try {
|
| 2742 |
// ...
|
| 2743 |
} catch (...) { // catch all exceptions
|
|
@@ -2754,17 +2895,18 @@ If no exception is presently being handled, evaluating a
|
|
| 2754 |
|
| 2755 |
### Assignment and compound assignment operators <a id="expr.ass">[[expr.ass]]</a>
|
| 2756 |
|
| 2757 |
The assignment operator (`=`) and the compound assignment operators all
|
| 2758 |
group right-to-left. All require a modifiable lvalue as their left
|
| 2759 |
-
operand; their result is an lvalue
|
| 2760 |
-
|
| 2761 |
-
In all cases, the assignment is
|
| 2762 |
-
|
| 2763 |
-
|
| 2764 |
-
operand. With respect to an
|
| 2765 |
-
|
|
|
|
| 2766 |
|
| 2767 |
[*Note 1*: Therefore, a function call cannot intervene between the
|
| 2768 |
lvalue-to-rvalue conversion and the side effect associated with any
|
| 2769 |
single compound assignment operator. — *end note*]
|
| 2770 |
|
|
@@ -2790,42 +2932,44 @@ If the right operand is an expression, it is implicitly converted
|
|
| 2790 |
|
| 2791 |
When the left operand of an assignment operator is a bit-field that
|
| 2792 |
cannot represent the value of the expression, the resulting value of the
|
| 2793 |
bit-field is *implementation-defined*.
|
| 2794 |
|
| 2795 |
-
|
| 2796 |
-
|
| 2797 |
-
assignment is a discarded-value expression or an unevaluated operand
|
|
|
|
| 2798 |
|
| 2799 |
The behavior of an expression of the form `E1 op= E2` is equivalent to
|
| 2800 |
-
`E1 = E1 op E2` except that `E1` is evaluated only once.
|
| 2801 |
-
|
| 2802 |
-
[
|
| 2803 |
-
|
| 2804 |
-
|
| 2805 |
-
arithmetic type
|
|
|
|
|
|
|
| 2806 |
|
| 2807 |
If the value being stored in an object is read via another object that
|
| 2808 |
overlaps in any way the storage of the first object, then the overlap
|
| 2809 |
shall be exact and the two objects shall have the same type, otherwise
|
| 2810 |
the behavior is undefined.
|
| 2811 |
|
| 2812 |
-
[*Note
|
| 2813 |
left and right sides of the assignment operation; it is not a statement
|
| 2814 |
-
about how the target of the assignment
|
| 2815 |
[[basic.lval]]. — *end note*]
|
| 2816 |
|
| 2817 |
A *braced-init-list* may appear on the right-hand side of
|
| 2818 |
|
| 2819 |
- an assignment to a scalar, in which case the initializer list shall
|
| 2820 |
have at most a single element. The meaning of `x = {v}`, where `T` is
|
| 2821 |
the scalar type of the expression `x`, is that of `x = T{v}`. The
|
| 2822 |
meaning of `x = {}` is `x = T{}`.
|
| 2823 |
- an assignment to an object of class type, in which case the
|
| 2824 |
initializer list is passed as the argument to the assignment operator
|
| 2825 |
-
function selected by overload resolution
|
| 2826 |
-
[[over.match]]).
|
| 2827 |
|
| 2828 |
[*Example 1*:
|
| 2829 |
|
| 2830 |
``` cpp
|
| 2831 |
complex<double> z;
|
|
@@ -2854,27 +2998,25 @@ left expression is sequenced before the right expression
|
|
| 2854 |
[[intro.execution]]. The type and value of the result are the type and
|
| 2855 |
value of the right operand; the result is of the same value category as
|
| 2856 |
its right operand, and is a bit-field if its right operand is a
|
| 2857 |
bit-field.
|
| 2858 |
|
| 2859 |
-
|
| 2860 |
|
| 2861 |
-
|
| 2862 |
-
|
|
|
|
|
|
|
|
|
|
| 2863 |
|
| 2864 |
-
|
| 2865 |
-
parentheses.
|
| 2866 |
-
|
| 2867 |
-
[*Example 2*:
|
| 2868 |
|
| 2869 |
``` cpp
|
| 2870 |
f(a, (t=3, t+2), c);
|
| 2871 |
```
|
| 2872 |
|
| 2873 |
has three arguments, the second of which has the value `5`.
|
| 2874 |
|
| 2875 |
— *end example*]
|
| 2876 |
|
| 2877 |
-
|
| 2878 |
-
*expr-or-braced-init-list* of a subscripting expression [[expr.sub]] is
|
| 2879 |
-
deprecated; see [[depr.comma.subscript]]. — *end note*]
|
| 2880 |
|
|
|
|
| 1 |
## Compound expressions <a id="expr.compound">[[expr.compound]]</a>
|
| 2 |
|
| 3 |
### Postfix expressions <a id="expr.post">[[expr.post]]</a>
|
| 4 |
|
| 5 |
+
#### General <a id="expr.post.general">[[expr.post.general]]</a>
|
| 6 |
+
|
| 7 |
Postfix expressions group left-to-right.
|
| 8 |
|
| 9 |
``` bnf
|
| 10 |
postfix-expression:
|
| 11 |
primary-expression
|
| 12 |
+
postfix-expression '[' expression-listₒₚₜ ']'
|
| 13 |
postfix-expression '(' expression-listₒₚₜ ')'
|
| 14 |
simple-type-specifier '(' expression-listₒₚₜ ')'
|
| 15 |
typename-specifier '(' expression-listₒₚₜ ')'
|
| 16 |
simple-type-specifier braced-init-list
|
| 17 |
typename-specifier braced-init-list
|
| 18 |
postfix-expression '.' 'template'ₒₚₜ id-expression
|
| 19 |
postfix-expression '->' 'template'ₒₚₜ id-expression
|
| 20 |
postfix-expression '++'
|
| 21 |
+
postfix-expression '--'
|
| 22 |
dynamic_cast '<' type-id '>' '(' expression ')'
|
| 23 |
static_cast '<' type-id '>' '(' expression ')'
|
| 24 |
reinterpret_cast '<' type-id '>' '(' expression ')'
|
| 25 |
const_cast '<' type-id '>' '(' expression ')'
|
| 26 |
typeid '(' expression ')'
|
|
|
|
| 31 |
expression-list:
|
| 32 |
initializer-list
|
| 33 |
```
|
| 34 |
|
| 35 |
[*Note 1*: The `>` token following the *type-id* in a `dynamic_cast`,
|
| 36 |
+
`static_cast`, `reinterpret_cast`, or `const_cast` can be the product of
|
| 37 |
+
replacing a `>>` token by two consecutive `>` tokens
|
| 38 |
[[temp.names]]. — *end note*]
|
| 39 |
|
| 40 |
#### Subscripting <a id="expr.sub">[[expr.sub]]</a>
|
| 41 |
|
| 42 |
+
A *subscript expression* is a postfix expression followed by square
|
| 43 |
+
brackets containing a possibly empty, comma-separated list of
|
| 44 |
+
*initializer-clause*s that constitute the arguments to the subscript
|
| 45 |
+
operator. The *postfix-expression* and the initialization of the object
|
| 46 |
+
parameter of any applicable subscript operator function is sequenced
|
| 47 |
+
before each expression in the *expression-list* and also before any
|
| 48 |
+
default argument. The initialization of a non-object parameter of a
|
| 49 |
+
subscript operator function `S` [[over.sub]], including every associated
|
| 50 |
+
value computation and side effect, is indeterminately sequenced with
|
| 51 |
+
respect to that of any other non-object parameter of `S`.
|
| 52 |
|
| 53 |
+
With the built-in subscript operator, an *expression-list* shall be
|
| 54 |
+
present, consisting of a single *assignment-expression*. One of the
|
| 55 |
+
expressions shall be a glvalue of type “array of `T`” or a prvalue of
|
| 56 |
+
type “pointer to `T`” and the other shall be a prvalue of unscoped
|
| 57 |
+
enumeration or integral type. The result is of type “`T`”. The type
|
| 58 |
+
“`T`” shall be a completely-defined object type.[^11]
|
| 59 |
|
| 60 |
+
The expression `E1[E2]` is identical (by definition) to `*((E1)+(E2))`,
|
| 61 |
+
except that in the case of an array operand, the result is an lvalue if
|
| 62 |
+
that operand is an lvalue and an xvalue otherwise.
|
| 63 |
+
|
| 64 |
+
[*Note 1*: Despite its asymmetric appearance, subscripting is a
|
| 65 |
commutative operation except for sequencing. See [[expr.unary]] and
|
| 66 |
[[expr.add]] for details of `*` and `+` and [[dcl.array]] for details
|
| 67 |
of array types. — *end note*]
|
| 68 |
|
|
|
|
|
|
|
|
|
|
| 69 |
#### Function call <a id="expr.call">[[expr.call]]</a>
|
| 70 |
|
| 71 |
A function call is a postfix expression followed by parentheses
|
| 72 |
containing a possibly empty, comma-separated list of
|
| 73 |
*initializer-clause*s which constitute the arguments to the function.
|
|
|
|
| 81 |
function, the postfix expression shall either be an lvalue that refers
|
| 82 |
to a function (in which case the function-to-pointer standard conversion
|
| 83 |
[[conv.func]] is suppressed on the postfix expression), or have function
|
| 84 |
pointer type.
|
| 85 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 86 |
If the selected function is non-virtual, or if the *id-expression* in
|
| 87 |
the class member access expression is a *qualified-id*, that function is
|
| 88 |
called. Otherwise, its final overrider [[class.virtual]] in the dynamic
|
| 89 |
type of the object expression is called; such a call is referred to as a
|
| 90 |
*virtual function call*.
|
| 91 |
|
| 92 |
+
[*Note 2*: The dynamic type is the type of the object referred to by
|
| 93 |
the current value of the object expression. [[class.cdtor]] describes
|
| 94 |
the behavior of virtual function calls when the object expression refers
|
| 95 |
to an object under construction or destruction. — *end note*]
|
| 96 |
|
| 97 |
+
[*Note 3*: If a function or member function name is used, and name
|
| 98 |
lookup [[basic.lookup]] does not find a declaration of that name, the
|
| 99 |
program is ill-formed. No function is implicitly declared by such a
|
| 100 |
call. — *end note*]
|
| 101 |
|
| 102 |
If the *postfix-expression* names a destructor or pseudo-destructor
|
| 103 |
[[expr.prim.id.dtor]], the type of the function call expression is
|
| 104 |
`void`; otherwise, the type of the function call expression is the
|
| 105 |
return type of the statically chosen function (i.e., ignoring the
|
| 106 |
`virtual` keyword), even if the type of the function actually called is
|
| 107 |
+
different. If the *postfix-expression* names a pseudo-destructor (in
|
|
|
|
| 108 |
which case the *postfix-expression* is a possibly-parenthesized class
|
| 109 |
member access), the function call destroys the object of scalar type
|
| 110 |
+
denoted by the object expression of the class member access
|
| 111 |
+
[[expr.ref]], [[basic.life]].
|
| 112 |
|
| 113 |
+
Calling a function through an expression whose function type `E` is
|
| 114 |
+
different from the function type `F` of the called function’s definition
|
| 115 |
+
results in undefined behavior unless the type “pointer to `F`” can be
|
| 116 |
+
converted to the type “pointer to `E`” via a function pointer conversion
|
| 117 |
+
[[conv.fctptr]].
|
| 118 |
|
| 119 |
+
[*Note 4*: The exception applies when the expression has the type of a
|
| 120 |
+
potentially-throwing function, but the called function has a
|
| 121 |
+
non-throwing exception specification, and the function types are
|
| 122 |
+
otherwise the same. — *end note*]
|
| 123 |
+
|
| 124 |
+
When a function is called, each parameter [[dcl.fct]] is initialized
|
| 125 |
+
[[dcl.init]], [[class.copy.ctor]] with its corresponding argument. If
|
| 126 |
+
the function is an explicit object member function and there is an
|
| 127 |
+
implied object argument [[over.call.func]], the list of provided
|
| 128 |
+
arguments is preceded by the implied object argument for the purposes of
|
| 129 |
+
this correspondence. If there is no corresponding argument, the default
|
| 130 |
+
argument for the parameter is used.
|
| 131 |
|
| 132 |
[*Example 1*:
|
| 133 |
|
| 134 |
``` cpp
|
| 135 |
template<typename ...T> int f(int n = 0, T ...t);
|
| 136 |
int x = f<int>(); // error: no argument for second function parameter
|
| 137 |
```
|
| 138 |
|
| 139 |
— *end example*]
|
| 140 |
|
| 141 |
+
If the function is an implicit object member function, the `this`
|
| 142 |
+
parameter of the function [[expr.prim.this]] is initialized with a
|
| 143 |
+
pointer to the object of the call, converted as if by an explicit type
|
| 144 |
+
conversion [[expr.cast]].
|
| 145 |
|
| 146 |
[*Note 5*: There is no access or ambiguity checking on this conversion;
|
| 147 |
the access checking and disambiguation are done as part of the (possibly
|
| 148 |
implicit) class member access operator. See [[class.member.lookup]],
|
| 149 |
[[class.access.base]], and [[expr.ref]]. — *end note*]
|
|
|
|
| 161 |
parameter occurs within the context of the calling function.
|
| 162 |
|
| 163 |
[*Example 2*: The access of the constructor, conversion functions or
|
| 164 |
destructor is checked at the point of call in the calling function. If a
|
| 165 |
constructor or destructor for a function parameter throws an exception,
|
| 166 |
+
the search for a handler starts in the calling function; in particular,
|
| 167 |
+
if the function called has a *function-try-block* [[except.pre]] with a
|
| 168 |
+
handler that can handle the exception, this handler is not
|
| 169 |
+
considered. — *end example*]
|
| 170 |
|
| 171 |
The *postfix-expression* is sequenced before each *expression* in the
|
| 172 |
*expression-list* and any default argument. The initialization of a
|
| 173 |
parameter, including every associated value computation and side effect,
|
| 174 |
is indeterminately sequenced with respect to that of any other
|
|
|
|
| 224 |
parameters, but these changes cannot affect the values of the arguments
|
| 225 |
except where a parameter is of a reference type [[dcl.ref]]; if the
|
| 226 |
reference is to a const-qualified type, `const_cast` is required to be
|
| 227 |
used to cast away the constness in order to modify the argument’s value.
|
| 228 |
Where a parameter is of `const` reference type a temporary object is
|
| 229 |
+
introduced if needed
|
| 230 |
+
[[dcl.type]], [[lex.literal]], [[lex.string]], [[dcl.array]], [[class.temporary]].
|
| 231 |
+
In addition, it is possible to modify the values of non-constant objects
|
| 232 |
+
through pointer parameters. — *end note*]
|
| 233 |
|
| 234 |
A function can be declared to accept fewer arguments (by declaring
|
| 235 |
default arguments [[dcl.fct.default]]) or more arguments (by using the
|
| 236 |
ellipsis, `...`, or a function parameter pack [[dcl.fct]]) than the
|
| 237 |
number of parameters in the function definition [[dcl.fct.def]].
|
|
|
|
| 281 |
by a *braced-init-list* (the initializer) constructs a value of the
|
| 282 |
specified type given the initializer. If the type is a placeholder for a
|
| 283 |
deduced class type, it is replaced by the return type of the function
|
| 284 |
selected by overload resolution for class template deduction
|
| 285 |
[[over.match.class.deduct]] for the remainder of this subclause.
|
| 286 |
+
Otherwise, if the type contains a placeholder type, it is replaced by
|
| 287 |
+
the type determined by placeholder type deduction
|
| 288 |
+
[[dcl.type.auto.deduct]].
|
| 289 |
+
|
| 290 |
+
[*Example 1*:
|
| 291 |
+
|
| 292 |
+
``` cpp
|
| 293 |
+
struct A {};
|
| 294 |
+
void f(A&); // #1
|
| 295 |
+
void f(A&&); // #2
|
| 296 |
+
A& g();
|
| 297 |
+
void h() {
|
| 298 |
+
f(g()); // calls #1
|
| 299 |
+
f(A(g())); // calls #2 with a temporary object
|
| 300 |
+
f(auto(g())); // calls #2 with a temporary object
|
| 301 |
+
}
|
| 302 |
+
```
|
| 303 |
+
|
| 304 |
+
— *end example*]
|
| 305 |
|
| 306 |
If the initializer is a parenthesized single expression, the type
|
| 307 |
conversion expression is equivalent to the corresponding cast expression
|
| 308 |
[[expr.cast]]. Otherwise, if the type is cv `void` and the initializer
|
| 309 |
is `()` or `{}` (after pack expansion, if any), the expression is a
|
| 310 |
+
prvalue of type `void` that performs no initialization. Otherwise, the
|
| 311 |
+
expression is a prvalue of the specified type whose result object is
|
| 312 |
+
direct-initialized [[dcl.init]] with the initializer. If the initializer
|
| 313 |
+
is a parenthesized optional *expression-list*, the specified type shall
|
| 314 |
+
not be an array type.
|
| 315 |
|
| 316 |
#### Class member access <a id="expr.ref">[[expr.ref]]</a>
|
| 317 |
|
| 318 |
A postfix expression followed by a dot `.` or an arrow `->`, optionally
|
| 319 |
+
followed by the keyword `template`, and then followed by an
|
| 320 |
+
*id-expression*, is a postfix expression. The postfix expression before
|
| 321 |
+
the dot or arrow is evaluated;[^12]
|
| 322 |
+
|
| 323 |
+
the result of that evaluation, together with the *id-expression*,
|
| 324 |
+
determines the result of the entire postfix expression.
|
| 325 |
+
|
| 326 |
+
[*Note 1*: If the keyword `template` is used, the following unqualified
|
| 327 |
+
name is considered to refer to a template [[temp.names]]. If a
|
| 328 |
+
*simple-template-id* results and is followed by a `::`, the
|
| 329 |
+
*id-expression* is a *qualified-id*. — *end note*]
|
| 330 |
|
| 331 |
For the first option (dot) the first expression shall be a glvalue. For
|
| 332 |
the second option (arrow) the first expression shall be a prvalue having
|
| 333 |
pointer type. The expression `E1->E2` is converted to the equivalent
|
| 334 |
form `(*(E1)).E2`; the remainder of [[expr.ref]] will address only the
|
| 335 |
first option (dot).[^13]
|
| 336 |
|
| 337 |
Abbreviating *postfix-expression*`.`*id-expression* as `E1.E2`, `E1` is
|
| 338 |
called the *object expression*. If the object expression is of scalar
|
| 339 |
type, `E2` shall name the pseudo-destructor of that same type (ignoring
|
| 340 |
+
cv-qualifications) and `E1.E2` is a prvalue of type “function of ()
|
| 341 |
returning `void`”.
|
| 342 |
|
| 343 |
+
[*Note 2*: This value can only be used for a notional function call
|
| 344 |
[[expr.prim.id.dtor]]. — *end note*]
|
| 345 |
|
| 346 |
Otherwise, the object expression shall be of class type. The class type
|
| 347 |
shall be complete unless the class member access appears in the
|
| 348 |
definition of that class.
|
| 349 |
|
| 350 |
+
[*Note 3*: The program is ill-formed if the result differs from that
|
| 351 |
+
when the class is complete [[class.member.lookup]]. — *end note*]
|
|
|
|
| 352 |
|
| 353 |
+
[*Note 4*: [[basic.lookup.qual]] describes how names are looked up
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 354 |
after the `.` and `->` operators. — *end note*]
|
| 355 |
|
| 356 |
If `E2` is a bit-field, `E1.E2` is a bit-field. The type and value
|
| 357 |
category of `E1.E2` are determined as follows. In the remainder of
|
| 358 |
[[expr.ref]], *cq* represents either `const` or the absence of `const`
|
| 359 |
and *vq* represents either `volatile` or the absence of `volatile`. *cv*
|
| 360 |
represents an arbitrary set of cv-qualifiers, as defined in
|
| 361 |
[[basic.type.qualifier]].
|
| 362 |
|
| 363 |
If `E2` is declared to have type “reference to `T`”, then `E1.E2` is an
|
| 364 |
+
lvalue of type `T`. If `E2` is a static data member, `E1.E2` designates
|
| 365 |
+
the object or function to which the reference is bound, otherwise
|
| 366 |
+
`E1.E2` designates the object or function to which the corresponding
|
| 367 |
+
reference member of `E1` is bound. Otherwise, one of the following rules
|
| 368 |
+
applies.
|
| 369 |
|
| 370 |
- If `E2` is a static data member and the type of `E2` is `T`, then
|
| 371 |
`E1.E2` is an lvalue; the expression designates the named member of
|
| 372 |
the class. The type of `E1.E2` is `T`.
|
| 373 |
- If `E2` is a non-static data member and the type of `E1` is “*cq1 vq1*
|
|
|
|
| 380 |
*cq12* stand for the “union” of *cq1* and *cq2*; that is, if *cq1* or
|
| 381 |
*cq2* is `const`, then *cq12* is `const`. If `E2` is declared to be a
|
| 382 |
`mutable` member, then the type of `E1.E2` is “*vq12* `T`”. If `E2` is
|
| 383 |
not declared to be a `mutable` member, then the type of `E1.E2` is
|
| 384 |
“*cq12* *vq12* `T`”.
|
| 385 |
+
- If `E2` is an overload set, function overload resolution
|
| 386 |
+
[[over.match]] is used to select the function to which `E2` refers.
|
| 387 |
+
The type of `E1.E2` is the type of `E2` and `E1.E2` refers to the
|
| 388 |
+
function referred to by `E2`.
|
| 389 |
- If `E2` refers to a static member function, `E1.E2` is an lvalue.
|
| 390 |
- Otherwise (when `E2` refers to a non-static member function),
|
| 391 |
`E1.E2` is a prvalue. The expression can be used only as the
|
| 392 |
left-hand operand of a member function call [[class.mfct]].
|
| 393 |
\[*Note 5*: Any redundant set of parentheses surrounding the
|
| 394 |
expression is ignored [[expr.prim.paren]]. — *end note*]
|
| 395 |
- If `E2` is a nested type, the expression `E1.E2` is ill-formed.
|
| 396 |
- If `E2` is a member enumerator and the type of `E2` is `T`, the
|
| 397 |
+
expression `E1.E2` is a prvalue of type `T` whose value is the value
|
| 398 |
+
of the enumerator.
|
| 399 |
|
| 400 |
+
If `E2` is a non-static member, the program is ill-formed if the class
|
| 401 |
+
of which `E2` is directly a member is an ambiguous base
|
| 402 |
+
[[class.member.lookup]] of the naming class [[class.access.base]] of
|
| 403 |
+
`E2`.
|
| 404 |
|
| 405 |
[*Note 6*: The program is also ill-formed if the naming class is an
|
| 406 |
ambiguous base of the class type of the object expression; see
|
| 407 |
[[class.access.base]]. — *end note*]
|
| 408 |
|
| 409 |
+
If `E2` is a non-static member and the result of `E1` is an object whose
|
| 410 |
+
type is not similar [[conv.qual]] to the type of `E1`, the behavior is
|
| 411 |
+
undefined.
|
| 412 |
+
|
| 413 |
+
[*Example 1*:
|
| 414 |
+
|
| 415 |
+
``` cpp
|
| 416 |
+
struct A { int i; };
|
| 417 |
+
struct B { int j; };
|
| 418 |
+
struct D : A, B {};
|
| 419 |
+
void f() {
|
| 420 |
+
D d;
|
| 421 |
+
static_cast<B&>(d).j; // OK, object expression designates the B subobject of d
|
| 422 |
+
reinterpret_cast<B&>(d).j; // undefined behavior
|
| 423 |
+
}
|
| 424 |
+
```
|
| 425 |
+
|
| 426 |
+
— *end example*]
|
| 427 |
+
|
| 428 |
#### Increment and decrement <a id="expr.post.incr">[[expr.post.incr]]</a>
|
| 429 |
|
| 430 |
The value of a postfix `++` expression is the value of its operand.
|
| 431 |
|
| 432 |
[*Note 1*: The value obtained is a copy of the original
|
|
|
|
| 449 |
version of the type of the operand. If the operand is a bit-field that
|
| 450 |
cannot represent the incremented value, the resulting value of the
|
| 451 |
bit-field is *implementation-defined*. See also [[expr.add]] and
|
| 452 |
[[expr.ass]].
|
| 453 |
|
| 454 |
+
The operand of postfix `--` is decremented analogously to the postfix
|
| 455 |
`++` operator.
|
| 456 |
|
| 457 |
[*Note 3*: For prefix increment and decrement, see
|
| 458 |
[[expr.pre.incr]]. — *end note*]
|
| 459 |
|
|
|
|
| 479 |
such that `B` is a base class of `D`, the result is a pointer to the
|
| 480 |
unique `B` subobject of the `D` object pointed to by `v`, or a null
|
| 481 |
pointer value if `v` is a null pointer value. Similarly, if `T` is
|
| 482 |
“reference to *cv1* `B`” and `v` has type *cv2* `D` such that `B` is a
|
| 483 |
base class of `D`, the result is the unique `B` subobject of the `D`
|
| 484 |
+
object referred to by `v`.[^14]
|
| 485 |
+
|
| 486 |
+
In both the pointer and reference cases, the program is ill-formed if
|
| 487 |
+
`B` is an inaccessible or ambiguous base class of `D`.
|
| 488 |
|
| 489 |
[*Example 1*:
|
| 490 |
|
| 491 |
``` cpp
|
| 492 |
struct B { };
|
|
|
|
| 506 |
If `T` is “pointer to cv `void`”, then the result is a pointer to the
|
| 507 |
most derived object pointed to by `v`. Otherwise, a runtime check is
|
| 508 |
applied to see if the object pointed or referred to by `v` can be
|
| 509 |
converted to the type pointed or referred to by `T`.
|
| 510 |
|
| 511 |
+
Let `C` be the class type to which `T` points or refers. The runtime
|
| 512 |
check logically executes as follows:
|
| 513 |
|
| 514 |
- If, in the most derived object pointed (referred) to by `v`, `v`
|
| 515 |
points (refers) to a public base class subobject of a `C` object, and
|
| 516 |
if only one object of type `C` is derived from the subobject pointed
|
|
|
|
| 564 |
|
| 565 |
The result of a `typeid` expression is an lvalue of static type `const`
|
| 566 |
`std::type_info` [[type.info]] and dynamic type `const` `std::type_info`
|
| 567 |
or `const` *name* where *name* is an *implementation-defined* class
|
| 568 |
publicly derived from `std::type_info` which preserves the behavior
|
| 569 |
+
described in [[type.info]].[^15]
|
| 570 |
+
|
| 571 |
+
The lifetime of the object referred to by the lvalue extends to the end
|
| 572 |
+
of the program. Whether or not the destructor is called for the
|
| 573 |
+
`std::type_info` object at the end of the program is unspecified.
|
| 574 |
+
|
| 575 |
+
If the type of the *expression* or *type-id* operand is a (possibly
|
| 576 |
+
cv-qualified) class type or a reference to (possibly cv-qualified) class
|
| 577 |
+
type, that class shall be completely defined.
|
| 578 |
|
| 579 |
When `typeid` is applied to a glvalue whose type is a polymorphic class
|
| 580 |
type [[class.virtual]], the result refers to a `std::type_info` object
|
| 581 |
representing the type of the most derived object [[intro.object]] (that
|
| 582 |
is, the dynamic type) to which the glvalue refers. If the glvalue is
|
| 583 |
+
obtained by applying the unary `*` operator to a pointer[^16]
|
| 584 |
+
|
| 585 |
+
and the pointer is a null pointer value [[basic.compound]], the `typeid`
|
| 586 |
expression throws an exception [[except.throw]] of a type that would
|
| 587 |
match a handler of type `std::bad_typeid` exception [[bad.typeid]].
|
| 588 |
|
| 589 |
When `typeid` is applied to an expression other than a glvalue of a
|
| 590 |
polymorphic class type, the result refers to a `std::type_info` object
|
| 591 |
representing the static type of the expression. Lvalue-to-rvalue
|
| 592 |
[[conv.lval]], array-to-pointer [[conv.array]], and function-to-pointer
|
| 593 |
[[conv.func]] conversions are not applied to the expression. If the
|
| 594 |
expression is a prvalue, the temporary materialization conversion
|
| 595 |
[[conv.rval]] is applied. The expression is an unevaluated operand
|
| 596 |
+
[[term.unevaluated.operand]].
|
| 597 |
|
| 598 |
When `typeid` is applied to a *type-id*, the result refers to a
|
| 599 |
`std::type_info` object representing the type of the *type-id*. If the
|
| 600 |
type of the *type-id* is a reference to a possibly cv-qualified type,
|
| 601 |
the result of the `typeid` expression refers to a `std::type_info`
|
| 602 |
+
object representing the cv-unqualified referenced type.
|
|
|
|
|
|
|
| 603 |
|
| 604 |
[*Note 1*: The *type-id* cannot denote a function type with a
|
| 605 |
*cv-qualifier-seq* or a *ref-qualifier* [[dcl.fct]]. — *end note*]
|
| 606 |
|
| 607 |
If the type of the expression or *type-id* is a cv-qualified type, the
|
|
|
|
| 621 |
typeid(D) == typeid(const D&); // yields true
|
| 622 |
```
|
| 623 |
|
| 624 |
— *end example*]
|
| 625 |
|
| 626 |
+
The type `std::type_info` [[type.info]] is not predefined; if a standard
|
| 627 |
+
library declaration [[typeinfo.syn]], [[std.modules]] of
|
| 628 |
+
`std::type_info` does not precede [[basic.lookup.general]] a `typeid`
|
| 629 |
+
expression, the program is ill-formed.
|
| 630 |
|
| 631 |
[*Note 2*: Subclause [[class.cdtor]] describes the behavior of `typeid`
|
| 632 |
applied to an object under construction or destruction. — *end note*]
|
| 633 |
|
| 634 |
#### Static cast <a id="expr.static.cast">[[expr.static.cast]]</a>
|
|
|
|
| 664 |
static_cast<D&>(br); // produces lvalue denoting the original d object
|
| 665 |
```
|
| 666 |
|
| 667 |
— *end example*]
|
| 668 |
|
| 669 |
+
An lvalue of type `T1` can be cast to type “rvalue reference to `T2`” if
|
| 670 |
+
`T2` is reference-compatible with `T1` [[dcl.init.ref]]. If the value is
|
| 671 |
+
not a bit-field, the result refers to the object or the specified base
|
| 672 |
+
class subobject thereof; otherwise, the lvalue-to-rvalue conversion
|
| 673 |
+
[[conv.lval]] is applied to the bit-field and the resulting prvalue is
|
| 674 |
+
used as the operand of the `static_cast` for the remainder of this
|
| 675 |
+
subclause. If `T2` is an inaccessible [[class.access]] or ambiguous
|
| 676 |
+
[[class.member.lookup]] base class of `T1`, a program that necessitates
|
| 677 |
+
such a cast is ill-formed.
|
| 678 |
|
| 679 |
An expression E can be explicitly converted to a type `T` if there is an
|
| 680 |
implicit conversion sequence [[over.best.ics]] from E to `T`, if
|
| 681 |
overload resolution for a direct-initialization [[dcl.init]] of an
|
| 682 |
object or reference of type `T` from E would find at least one viable
|
|
|
|
| 705 |
Otherwise, the `static_cast` shall perform one of the conversions listed
|
| 706 |
below. No other conversion shall be performed explicitly using a
|
| 707 |
`static_cast`.
|
| 708 |
|
| 709 |
Any expression can be explicitly converted to type cv `void`, in which
|
| 710 |
+
case the operand is a discarded-value expression [[expr.prop]].
|
| 711 |
|
| 712 |
+
[*Note 3*: Such a `static_cast` has no result as it is a prvalue of
|
| 713 |
+
type `void`; see [[basic.lval]]. — *end note*]
|
| 714 |
+
|
| 715 |
+
[*Note 4*: However, if the value is in a temporary object
|
| 716 |
[[class.temporary]], the destructor for that object is not executed
|
| 717 |
until the usual time, and the value of the object is preserved for the
|
| 718 |
purpose of executing the destructor. — *end note*]
|
| 719 |
|
| 720 |
The inverse of any standard conversion sequence [[conv]] not containing
|
|
|
|
| 752 |
that of converting from the original value to the floating-point type.
|
| 753 |
|
| 754 |
A value of integral or enumeration type can be explicitly converted to a
|
| 755 |
complete enumeration type. If the enumeration type has a fixed
|
| 756 |
underlying type, the value is first converted to that type by integral
|
| 757 |
+
promotion [[conv.prom]] or integral conversion [[conv.integral]], if
|
| 758 |
+
necessary, and then to the enumeration type. If the enumeration type
|
| 759 |
+
does not have a fixed underlying type, the value is unchanged if the
|
| 760 |
+
original value is within the range of the enumeration values
|
| 761 |
+
[[dcl.enum]], and otherwise, the behavior is undefined. A value of
|
| 762 |
+
floating-point type can also be explicitly converted to an enumeration
|
| 763 |
+
type. The resulting value is the same as converting the original value
|
| 764 |
+
to the underlying type of the enumeration [[conv.fpint]], and
|
| 765 |
+
subsequently to the enumeration type.
|
| 766 |
+
|
| 767 |
+
A prvalue of floating-point type can be explicitly converted to any
|
| 768 |
+
other floating-point type. If the source value can be exactly
|
| 769 |
+
represented in the destination type, the result of the conversion has
|
| 770 |
+
that exact representation. If the source value is between two adjacent
|
| 771 |
+
destination values, the result of the conversion is an
|
| 772 |
+
*implementation-defined* choice of either of those values. Otherwise,
|
| 773 |
+
the behavior is undefined.
|
| 774 |
|
| 775 |
A prvalue of type “pointer to *cv1* `B`”, where `B` is a class type, can
|
| 776 |
be converted to a prvalue of type “pointer to *cv2* `D`”, where `D` is a
|
| 777 |
complete class derived [[class.derived]] from `B`, if *cv2* is the same
|
| 778 |
cv-qualification as, or greater cv-qualification than, *cv1*. If `B` is
|
| 779 |
a virtual base class of `D` or a base class of a virtual base class of
|
| 780 |
`D`, or if no valid standard conversion from “pointer to `D`” to
|
| 781 |
“pointer to `B`” exists [[conv.ptr]], the program is ill-formed. The
|
| 782 |
null pointer value [[basic.compound]] is converted to the null pointer
|
| 783 |
value of the destination type. If the prvalue of type “pointer to *cv1*
|
| 784 |
+
`B`” points to a `B` that is actually a base class subobject of an
|
| 785 |
+
object of type `D`, the resulting pointer points to the enclosing object
|
| 786 |
+
of type `D`. Otherwise, the behavior is undefined.
|
| 787 |
|
| 788 |
A prvalue of type “pointer to member of `D` of type *cv1* `T`” can be
|
| 789 |
converted to a prvalue of type “pointer to member of `B` of type *cv2*
|
| 790 |
`T`”, where `D` is a complete class type and `B` is a base class
|
| 791 |
[[class.derived]] of `D`, if *cv2* is the same cv-qualification as, or
|
| 792 |
greater cv-qualification than, *cv1*.
|
| 793 |
|
| 794 |
+
[*Note 5*: Function types (including those used in
|
| 795 |
pointer-to-member-function types) are never cv-qualified
|
| 796 |
[[dcl.fct]]. — *end note*]
|
| 797 |
|
| 798 |
If no valid standard conversion from “pointer to member of `B` of type
|
| 799 |
`T`” to “pointer to member of `D` of type `T`” exists [[conv.mem]], the
|
|
|
|
| 802 |
class `B` contains the original member, or is a base or derived class of
|
| 803 |
the class containing the original member, the resulting pointer to
|
| 804 |
member points to the original member. Otherwise, the behavior is
|
| 805 |
undefined.
|
| 806 |
|
| 807 |
+
[*Note 6*: Although class `B` need not contain the original member, the
|
| 808 |
dynamic type of the object with which indirection through the pointer to
|
| 809 |
member is performed must contain the original member; see
|
| 810 |
[[expr.mptr.oper]]. — *end note*]
|
| 811 |
|
| 812 |
A prvalue of type “pointer to *cv1* `void`” can be converted to a
|
|
|
|
| 814 |
*cv2* is the same cv-qualification as, or greater cv-qualification than,
|
| 815 |
*cv1*. If the original pointer value represents the address `A` of a
|
| 816 |
byte in memory and `A` does not satisfy the alignment requirement of
|
| 817 |
`T`, then the resulting pointer value is unspecified. Otherwise, if the
|
| 818 |
original pointer value points to an object *a*, and there is an object
|
| 819 |
+
*b* of type similar to `T` that is pointer-interconvertible
|
| 820 |
+
[[basic.compound]] with *a*, the result is a pointer to *b*. Otherwise,
|
| 821 |
+
the pointer value is unchanged by the conversion.
|
|
|
|
| 822 |
|
| 823 |
[*Example 3*:
|
| 824 |
|
| 825 |
``` cpp
|
| 826 |
T* p1 = new T;
|
|
|
|
| 870 |
to a pointer. A pointer converted to an integer of sufficient size (if
|
| 871 |
any such exists on the implementation) and back to the same pointer type
|
| 872 |
will have its original value; mappings between pointers and integers are
|
| 873 |
otherwise *implementation-defined*.
|
| 874 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 875 |
A function pointer can be explicitly converted to a function pointer of
|
| 876 |
a different type.
|
| 877 |
|
| 878 |
+
[*Note 4*: The effect of calling a function through a pointer to a
|
| 879 |
function type [[dcl.fct]] that is not the same as the type used in the
|
| 880 |
definition of the function is undefined [[expr.call]]. — *end note*]
|
| 881 |
|
| 882 |
Except that converting a prvalue of type “pointer to `T1`” to the type
|
| 883 |
“pointer to `T2`” (where `T1` and `T2` are function types) and back to
|
| 884 |
its original type yields the original pointer value, the result of such
|
| 885 |
a pointer conversion is unspecified.
|
| 886 |
|
| 887 |
+
[*Note 5*: See also [[conv.ptr]] for more details of pointer
|
| 888 |
conversions. — *end note*]
|
| 889 |
|
| 890 |
An object pointer can be explicitly converted to an object pointer of a
|
| 891 |
+
different type.[^17]
|
| 892 |
+
|
| 893 |
+
When a prvalue `v` of object pointer type is converted to the object
|
| 894 |
+
pointer type “pointer to cv `T`”, the result is
|
| 895 |
`static_cast<cv T*>(static_cast<cv~void*>(v))`.
|
| 896 |
|
| 897 |
+
[*Note 6*: Converting a pointer of type “pointer to `T1`” that points
|
| 898 |
+
to an object of type `T1` to the type “pointer to `T2`” (where `T2` is
|
| 899 |
+
an object type and the alignment requirements of `T2` are no stricter
|
| 900 |
+
than those of `T1`) and back to its original type yields the original
|
| 901 |
+
pointer value. — *end note*]
|
| 902 |
|
| 903 |
Converting a function pointer to an object pointer type or vice versa is
|
| 904 |
conditionally-supported. The meaning of such a conversion is
|
| 905 |
*implementation-defined*, except that if an implementation supports
|
| 906 |
conversions in both directions, converting a prvalue of one type to the
|
|
|
|
| 908 |
yield the original pointer value.
|
| 909 |
|
| 910 |
The null pointer value [[basic.compound]] is converted to the null
|
| 911 |
pointer value of the destination type.
|
| 912 |
|
| 913 |
+
[*Note 7*: A null pointer constant of type `std::nullptr_t` cannot be
|
| 914 |
converted to a pointer type, and a null pointer constant of integral
|
| 915 |
type is not necessarily converted to a null pointer
|
| 916 |
value. — *end note*]
|
| 917 |
|
| 918 |
A prvalue of type “pointer to member of `X` of type `T1`” can be
|
| 919 |
explicitly converted to a prvalue of a different type “pointer to member
|
| 920 |
of `Y` of type `T2`” if `T1` and `T2` are both function types or both
|
| 921 |
+
object types.[^18]
|
| 922 |
+
|
| 923 |
+
The null member pointer value [[conv.mem]] is converted to the null
|
| 924 |
+
member pointer value of the destination type. The result of this
|
| 925 |
+
conversion is unspecified, except in the following cases:
|
| 926 |
|
| 927 |
- Converting a prvalue of type “pointer to member function” to a
|
| 928 |
different pointer-to-member-function type and back to its original
|
| 929 |
type yields the original pointer-to-member value.
|
| 930 |
- Converting a prvalue of type “pointer to data member of `X` of type
|
|
|
|
| 952 |
Conversions that can be performed explicitly using `const_cast` are
|
| 953 |
listed below. No other conversion shall be performed explicitly using
|
| 954 |
`const_cast`.
|
| 955 |
|
| 956 |
[*Note 1*: Subject to the restrictions in this subclause, an expression
|
| 957 |
+
can be cast to its own type using a `const_cast`
|
| 958 |
operator. — *end note*]
|
| 959 |
|
| 960 |
For two similar types `T1` and `T2` [[conv.qual]], a prvalue of type
|
| 961 |
`T1` may be explicitly converted to the type `T2` using a `const_cast`
|
| 962 |
+
if, considering the qualification-decompositions of both types, each P¹ᵢ
|
| 963 |
+
is the same as P²ᵢ for all i. The result of a `const_cast` refers to the
|
| 964 |
original entity.
|
| 965 |
|
| 966 |
[*Example 1*:
|
| 967 |
|
| 968 |
``` cpp
|
|
|
|
| 995 |
A null pointer value [[basic.compound]] is converted to the null pointer
|
| 996 |
value of the destination type. The null member pointer value
|
| 997 |
[[conv.mem]] is converted to the null member pointer value of the
|
| 998 |
destination type.
|
| 999 |
|
| 1000 |
+
[*Note 2*:
|
| 1001 |
+
|
| 1002 |
+
Depending on the type of the object, a write operation through the
|
| 1003 |
+
pointer, lvalue or pointer to data member resulting from a `const_cast`
|
| 1004 |
+
that casts away a const-qualifier[^20]
|
| 1005 |
+
|
| 1006 |
+
can produce undefined behavior [[dcl.type.cv]].
|
| 1007 |
+
|
| 1008 |
+
— *end note*]
|
| 1009 |
|
| 1010 |
A conversion from a type `T1` to a type `T2` *casts away constness* if
|
| 1011 |
+
`T1` and `T2` are different, there is a qualification-decomposition
|
| 1012 |
+
[[conv.qual]] of `T1` yielding *n* such that `T2` has a
|
| 1013 |
+
qualification-decomposition of the form
|
| 1014 |
|
| 1015 |
and there is no qualification conversion that converts `T1` to
|
| 1016 |
|
| 1017 |
Casting from an lvalue of type `T1` to an lvalue of type `T2` using an
|
| 1018 |
lvalue reference cast or casting from an expression of type `T1` to an
|
| 1019 |
xvalue of type `T2` using an rvalue reference cast casts away constness
|
| 1020 |
if a cast from a prvalue of type “pointer to `T1`” to the type “pointer
|
| 1021 |
to `T2`” casts away constness.
|
| 1022 |
|
| 1023 |
[*Note 3*: Some conversions which involve only changes in
|
| 1024 |
+
cv-qualification cannot be done using `const_cast`. For instance,
|
| 1025 |
conversions between pointers to functions are not covered because such
|
| 1026 |
conversions lead to values whose use causes undefined behavior. For the
|
| 1027 |
same reasons, conversions between pointers to member functions, and in
|
| 1028 |
particular, the conversion from a pointer to a const member function to
|
| 1029 |
a pointer to a non-const member function, are not
|
| 1030 |
covered. — *end note*]
|
| 1031 |
|
| 1032 |
### Unary expressions <a id="expr.unary">[[expr.unary]]</a>
|
| 1033 |
|
| 1034 |
+
#### General <a id="expr.unary.general">[[expr.unary.general]]</a>
|
| 1035 |
+
|
| 1036 |
Expressions with unary operators group right-to-left.
|
| 1037 |
|
| 1038 |
``` bnf
|
| 1039 |
+
%% Ed. note: character protrusion would misalign operators.
|
| 1040 |
+
|
| 1041 |
unary-expression:
|
| 1042 |
postfix-expression
|
| 1043 |
unary-operator cast-expression
|
| 1044 |
'++' cast-expression
|
| 1045 |
+
'--' cast-expression
|
| 1046 |
await-expression
|
| 1047 |
sizeof unary-expression
|
| 1048 |
sizeof '(' type-id ')'
|
| 1049 |
sizeof '...' '(' identifier ')'
|
| 1050 |
alignof '(' type-id ')'
|
|
|
|
| 1052 |
new-expression
|
| 1053 |
delete-expression
|
| 1054 |
```
|
| 1055 |
|
| 1056 |
``` bnf
|
| 1057 |
+
%% Ed. note: character protrusion would misalign operators.
|
| 1058 |
+
|
| 1059 |
unary-operator: one of
|
| 1060 |
'* & + - ! ~'
|
| 1061 |
```
|
| 1062 |
|
| 1063 |
#### Unary operators <a id="expr.unary.op">[[expr.unary.op]]</a>
|
| 1064 |
|
| 1065 |
+
The unary `*` operator performs *indirection*. Its operand shall be a
|
| 1066 |
+
prvalue of type “pointer to `T`”, where `T` is an object or function
|
| 1067 |
+
type. The operator yields an lvalue of type `T` denoting the object or
|
| 1068 |
+
function to which the operand points.
|
|
|
|
| 1069 |
|
| 1070 |
[*Note 1*: Indirection through a pointer to an incomplete type (other
|
| 1071 |
than cv `void`) is valid. The lvalue thus obtained can be used in
|
| 1072 |
limited ways (to initialize a reference, for example); this lvalue must
|
| 1073 |
not be converted to a prvalue, see [[conv.lval]]. — *end note*]
|
| 1074 |
|
| 1075 |
+
Each of the following unary operators yields a prvalue.
|
| 1076 |
|
| 1077 |
+
The operand of the unary `&` operator shall be an lvalue of some type
|
| 1078 |
+
`T`. The result is a prvalue.
|
| 1079 |
|
| 1080 |
- If the operand is a *qualified-id* naming a non-static or variant
|
| 1081 |
+
member `m` of some class `C`, other than an explicit object member
|
| 1082 |
+
function, the result has type “pointer to member of class `C` of type
|
| 1083 |
+
`T`” and designates `C::m`.
|
| 1084 |
+
- Otherwise, the result has type “pointer to `T`” and points to the
|
| 1085 |
+
designated object [[intro.memory]] or function [[basic.compound]]. If
|
| 1086 |
+
the operand names an explicit object member function [[dcl.fct]], the
|
| 1087 |
+
operand shall be a *qualified-id*. \[*Note 2*: In particular, taking
|
| 1088 |
+
the address of a variable of type “cv `T`” yields a pointer of type
|
| 1089 |
+
“pointer to cv `T`”. — *end note*]
|
| 1090 |
|
| 1091 |
[*Example 1*:
|
| 1092 |
|
| 1093 |
``` cpp
|
| 1094 |
struct A { int i; };
|
|
|
|
| 1121 |
If `&` is applied to an lvalue of incomplete class type and the complete
|
| 1122 |
type declares `operator&()`, it is unspecified whether the operator has
|
| 1123 |
the built-in meaning or the operator function is called. The operand of
|
| 1124 |
`&` shall not be a bit-field.
|
| 1125 |
|
| 1126 |
+
[*Note 5*: The address of an overload set [[over]] can be taken only in
|
| 1127 |
+
a context that uniquely determines which function is referred to (see
|
| 1128 |
+
[[over.over]]). Since the context can affect whether the operand is a
|
| 1129 |
+
static or non-static member function, the context can also affect
|
| 1130 |
+
whether the expression has type “pointer to function” or “pointer to
|
| 1131 |
+
member function”. — *end note*]
|
|
|
|
| 1132 |
|
| 1133 |
The operand of the unary `+` operator shall have arithmetic, unscoped
|
| 1134 |
enumeration, or pointer type and the result is the value of the
|
| 1135 |
argument. Integral promotion is performed on integral or enumeration
|
| 1136 |
operands. The type of the result is the type of the promoted operand.
|
| 1137 |
|
| 1138 |
The operand of the unary `-` operator shall have arithmetic or unscoped
|
| 1139 |
+
enumeration type and the result is the negative of its operand. Integral
|
| 1140 |
promotion is performed on integral or enumeration operands. The negative
|
| 1141 |
of an unsigned quantity is computed by subtracting its value from 2ⁿ,
|
| 1142 |
where n is the number of bits in the promoted operand. The type of the
|
| 1143 |
result is the type of the promoted operand.
|
| 1144 |
|
| 1145 |
+
[*Note 6*: The result is the two’s complement of the operand (where
|
| 1146 |
+
operand and result are considered as unsigned). — *end note*]
|
| 1147 |
+
|
| 1148 |
The operand of the logical negation operator `!` is contextually
|
| 1149 |
converted to `bool` [[conv]]; its value is `true` if the converted
|
| 1150 |
operand is `false` and `false` otherwise. The type of the result is
|
| 1151 |
`bool`.
|
| 1152 |
|
| 1153 |
+
The operand of the `~` operator shall have integral or unscoped
|
| 1154 |
+
enumeration type. Integral promotions are performed. The type of the
|
| 1155 |
+
result is the type of the promoted operand. Given the coefficients `xᵢ`
|
| 1156 |
+
of the base-2 representation [[basic.fundamental]] of the promoted
|
| 1157 |
+
operand `x`, the coefficient `rᵢ` of the base-2 representation of the
|
| 1158 |
+
result `r` is 1 if `xᵢ` is 0, and 0 otherwise.
|
| 1159 |
+
|
| 1160 |
+
[*Note 7*: The result is the ones’ complement of the operand (where
|
| 1161 |
+
operand and result are considered as unsigned). — *end note*]
|
| 1162 |
+
|
| 1163 |
There is an ambiguity in the grammar when `~` is followed by a
|
| 1164 |
*type-name* or *decltype-specifier*. The ambiguity is resolved by
|
| 1165 |
+
treating `~` as the operator rather than as the start of an
|
| 1166 |
+
*unqualified-id* naming a destructor.
|
| 1167 |
|
| 1168 |
+
[*Note 8*: Because the grammar does not permit an operator to follow
|
| 1169 |
the `.`, `->`, or `::` tokens, a `~` followed by a *type-name* or
|
| 1170 |
*decltype-specifier* in a member access expression or *qualified-id* is
|
| 1171 |
unambiguously parsed as a destructor name. — *end note*]
|
| 1172 |
|
| 1173 |
#### Increment and decrement <a id="expr.pre.incr">[[expr.pre.incr]]</a>
|
|
|
|
| 1181 |
bit-field. The expression `++x` is equivalent to `x+=1`.
|
| 1182 |
|
| 1183 |
[*Note 1*: See the discussions of addition [[expr.add]] and assignment
|
| 1184 |
operators [[expr.ass]] for information on conversions. — *end note*]
|
| 1185 |
|
| 1186 |
+
The operand of prefix `--` is modified [[defns.access]] by subtracting
|
| 1187 |
+
`1`. The requirements on the operand of prefix `--` and the properties
|
| 1188 |
of its result are otherwise the same as those of prefix `++`.
|
| 1189 |
|
| 1190 |
[*Note 2*: For postfix increment and decrement, see
|
| 1191 |
[[expr.post.incr]]. — *end note*]
|
| 1192 |
|
|
|
|
| 1202 |
```
|
| 1203 |
|
| 1204 |
An *await-expression* shall appear only in a potentially-evaluated
|
| 1205 |
expression within the *compound-statement* of a *function-body* outside
|
| 1206 |
of a *handler* [[except.pre]]. In a *declaration-statement* or in the
|
| 1207 |
+
*simple-declaration* (if any) of an *init-statement*, an
|
| 1208 |
*await-expression* shall appear only in an *initializer* of that
|
| 1209 |
*declaration-statement* or *simple-declaration*. An *await-expression*
|
| 1210 |
shall not appear in a default argument [[dcl.fct.default]]. An
|
| 1211 |
+
*await-expression* shall not appear in the initializer of a block
|
| 1212 |
variable with static or thread storage duration. A context within a
|
| 1213 |
function where an *await-expression* can appear is called a *suspension
|
| 1214 |
context* of the function.
|
| 1215 |
|
| 1216 |
Evaluation of an *await-expression* involves the following auxiliary
|
| 1217 |
types, expressions, and objects:
|
| 1218 |
|
| 1219 |
- *p* is an lvalue naming the promise object [[dcl.fct.def.coroutine]]
|
| 1220 |
of the enclosing coroutine and `P` is the type of that object.
|
| 1221 |
+
- Unless the *await-expression* was implicitly produced by a
|
| 1222 |
+
*yield-expression* [[expr.yield]], an initial await expression, or a
|
| 1223 |
+
final await expression [[dcl.fct.def.coroutine]], a search is
|
| 1224 |
+
performed for the name `await_transform` in the scope of `P`
|
| 1225 |
+
[[class.member.lookup]]. If this search is performed and finds at
|
| 1226 |
+
least one declaration, then *a* is
|
| 1227 |
*p*`.await_transform(`*cast-expression*`)`; otherwise, *a* is the
|
| 1228 |
*cast-expression*.
|
| 1229 |
- *o* is determined by enumerating the applicable `operator co_await`
|
| 1230 |
functions for an argument *a* [[over.match.oper]], and choosing the
|
| 1231 |
best one through overload resolution [[over.match]]. If overload
|
|
|
|
| 1253 |
- If the result of *await-ready* is `false`, the coroutine is considered
|
| 1254 |
suspended. Then:
|
| 1255 |
- If the type of *await-suspend* is `std::coroutine_handle<Z>`,
|
| 1256 |
*await-suspend*`.resume()` is evaluated. \[*Note 1*: This resumes
|
| 1257 |
the coroutine referred to by the result of *await-suspend*. Any
|
| 1258 |
+
number of coroutines can be successively resumed in this fashion,
|
| 1259 |
eventually returning control flow to the current coroutine caller or
|
| 1260 |
resumer [[dcl.fct.def.coroutine]]. — *end note*]
|
| 1261 |
- Otherwise, if the type of *await-suspend* is `bool`, *await-suspend*
|
| 1262 |
is evaluated, and the coroutine is resumed if the result is `false`.
|
| 1263 |
- Otherwise, *await-suspend* is evaluated.
|
| 1264 |
|
| 1265 |
If the evaluation of *await-suspend* exits via an exception, the
|
| 1266 |
exception is caught, the coroutine is resumed, and the exception is
|
| 1267 |
+
immediately rethrown [[except.throw]]. Otherwise, control flow returns
|
| 1268 |
+
to the current coroutine caller or resumer [[dcl.fct.def.coroutine]]
|
| 1269 |
+
without exiting any scopes [[stmt.jump]]. The point in the coroutine
|
| 1270 |
+
immediately prior to control returning to its caller or resumer is a
|
| 1271 |
+
coroutine *suspend point*.
|
| 1272 |
- If the result of *await-ready* is `true`, or when the coroutine is
|
| 1273 |
+
resumed other than by rethrowing an exception from *await-suspend*,
|
| 1274 |
+
the *await-resume* expression is evaluated, and its result is the
|
| 1275 |
+
result of the *await-expression*.
|
| 1276 |
+
|
| 1277 |
+
[*Note 2*: With respect to sequencing, an *await-expression* is
|
| 1278 |
+
indivisible [[intro.execution]]. — *end note*]
|
| 1279 |
|
| 1280 |
[*Example 1*:
|
| 1281 |
|
| 1282 |
``` cpp
|
| 1283 |
template <typename T>
|
|
|
|
| 1304 |
using namespace std::chrono;
|
| 1305 |
|
| 1306 |
my_future<int> h();
|
| 1307 |
|
| 1308 |
my_future<void> g() {
|
| 1309 |
+
std::cout << "just about to go to sleep...\n";
|
| 1310 |
co_await 10ms;
|
| 1311 |
std::cout << "resumed\n";
|
| 1312 |
co_await h();
|
| 1313 |
}
|
| 1314 |
|
|
|
|
| 1321 |
#### Sizeof <a id="expr.sizeof">[[expr.sizeof]]</a>
|
| 1322 |
|
| 1323 |
The `sizeof` operator yields the number of bytes occupied by a
|
| 1324 |
non-potentially-overlapping object of the type of its operand. The
|
| 1325 |
operand is either an expression, which is an unevaluated operand
|
| 1326 |
+
[[term.unevaluated.operand]], or a parenthesized *type-id*. The `sizeof`
|
| 1327 |
+
operator shall not be applied to an expression that has function or
|
| 1328 |
+
incomplete type, to the parenthesized name of such types, or to a
|
| 1329 |
+
glvalue that designates a bit-field. The result of `sizeof` applied to
|
| 1330 |
+
any of the narrow character types is `1`. The result of `sizeof` applied
|
| 1331 |
+
to any other fundamental type [[basic.fundamental]] is
|
| 1332 |
+
*implementation-defined*.
|
| 1333 |
|
| 1334 |
+
[*Note 1*:
|
| 1335 |
+
|
| 1336 |
+
In particular, the values of `sizeof(bool)`, `sizeof(char16_t)`,
|
| 1337 |
`sizeof(char32_t)`, and `sizeof(wchar_t)` are
|
| 1338 |
+
implementation-defined.[^21]
|
| 1339 |
+
|
| 1340 |
+
— *end note*]
|
| 1341 |
|
| 1342 |
[*Note 2*: See [[intro.memory]] for the definition of byte and
|
| 1343 |
+
[[term.object.representation]] for the definition of object
|
| 1344 |
representation. — *end note*]
|
| 1345 |
|
| 1346 |
When applied to a reference type, the result is the size of the
|
| 1347 |
referenced type. When applied to a class, the result is the number of
|
| 1348 |
bytes in an object of that class including any padding required for
|
| 1349 |
placing objects of that type in an array. The result of applying
|
| 1350 |
`sizeof` to a potentially-overlapping subobject is the size of the type,
|
| 1351 |
+
not the size of the subobject.[^22]
|
| 1352 |
+
|
| 1353 |
+
When applied to an array, the result is the total number of bytes in the
|
| 1354 |
+
array. This implies that the size of an array of n elements is n times
|
| 1355 |
+
the size of an element.
|
| 1356 |
|
| 1357 |
The lvalue-to-rvalue [[conv.lval]], array-to-pointer [[conv.array]], and
|
| 1358 |
function-to-pointer [[conv.func]] standard conversions are not applied
|
| 1359 |
to the operand of `sizeof`. If the operand is a prvalue, the temporary
|
| 1360 |
materialization conversion [[conv.rval]] is applied.
|
|
|
|
| 1378 |
The result of `sizeof` and `sizeof...` is a prvalue of type
|
| 1379 |
`std::size_t`.
|
| 1380 |
|
| 1381 |
[*Note 3*: A `sizeof` expression is an integral constant expression
|
| 1382 |
[[expr.const]]. The type `std::size_t` is defined in the standard header
|
| 1383 |
+
`<cstddef>` [[cstddef.syn]], [[support.types.layout]]. — *end note*]
|
| 1384 |
|
| 1385 |
#### Alignof <a id="expr.alignof">[[expr.alignof]]</a>
|
| 1386 |
|
| 1387 |
An `alignof` expression yields the alignment requirement of its operand
|
| 1388 |
type. The operand shall be a *type-id* representing a complete object
|
|
|
|
| 1390 |
|
| 1391 |
The result is a prvalue of type `std::size_t`.
|
| 1392 |
|
| 1393 |
[*Note 1*: An `alignof` expression is an integral constant expression
|
| 1394 |
[[expr.const]]. The type `std::size_t` is defined in the standard header
|
| 1395 |
+
`<cstddef>` [[cstddef.syn]], [[support.types.layout]]. — *end note*]
|
| 1396 |
|
| 1397 |
When `alignof` is applied to a reference type, the result is the
|
| 1398 |
alignment of the referenced type. When `alignof` is applied to an array
|
| 1399 |
type, the result is the alignment of the element type.
|
| 1400 |
|
| 1401 |
#### `noexcept` operator <a id="expr.unary.noexcept">[[expr.unary.noexcept]]</a>
|
| 1402 |
|
| 1403 |
The `noexcept` operator determines whether the evaluation of its
|
| 1404 |
+
operand, which is an unevaluated operand [[term.unevaluated.operand]],
|
| 1405 |
+
can throw an exception [[except.throw]].
|
| 1406 |
|
| 1407 |
``` bnf
|
| 1408 |
noexcept-expression:
|
| 1409 |
noexcept '(' expression ')'
|
| 1410 |
```
|
|
|
|
| 1420 |
#### New <a id="expr.new">[[expr.new]]</a>
|
| 1421 |
|
| 1422 |
The *new-expression* attempts to create an object of the *type-id*
|
| 1423 |
[[dcl.name]] or *new-type-id* to which it is applied. The type of that
|
| 1424 |
object is the *allocated type*. This type shall be a complete object
|
| 1425 |
+
type [[term.incomplete.type]], but not an abstract class type
|
| 1426 |
+
[[class.abstract]] or array thereof [[intro.object]].
|
| 1427 |
|
| 1428 |
[*Note 1*: Because references are not objects, references cannot be
|
| 1429 |
created by *new-expression*s. — *end note*]
|
| 1430 |
|
| 1431 |
+
[*Note 2*: The *type-id* can be a cv-qualified type, in which case the
|
| 1432 |
object created by the *new-expression* has a cv-qualified
|
| 1433 |
type. — *end note*]
|
| 1434 |
|
| 1435 |
``` bnf
|
| 1436 |
new-expression:
|
|
|
|
| 1536 |
|
| 1537 |
— *end example*]
|
| 1538 |
|
| 1539 |
— *end note*]
|
| 1540 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1541 |
The *attribute-specifier-seq* in a *noptr-new-declarator* appertains to
|
| 1542 |
the associated array type.
|
| 1543 |
|
| 1544 |
Every *constant-expression* in a *noptr-new-declarator* shall be a
|
| 1545 |
converted constant expression [[expr.const]] of type `std::size_t` and
|
|
|
|
| 1551 |
`n` is not a constant expression). — *end example*]
|
| 1552 |
|
| 1553 |
If the *type-id* or *new-type-id* denotes an array type of unknown bound
|
| 1554 |
[[dcl.array]], the *new-initializer* shall not be omitted; the allocated
|
| 1555 |
object is an array with `n` elements, where `n` is determined from the
|
| 1556 |
+
number of initial elements supplied in the *new-initializer*
|
| 1557 |
+
[[dcl.init.aggr]], [[dcl.init.string]].
|
| 1558 |
|
| 1559 |
If the *expression* in a *noptr-new-declarator* is present, it is
|
| 1560 |
implicitly converted to `std::size_t`. The *expression* is erroneous if:
|
| 1561 |
|
| 1562 |
- the expression is of non-class type and its value before converting to
|
|
|
|
| 1571 |
terminating `'\0'` in a *string-literal* [[lex.string]]) exceeds the
|
| 1572 |
number of elements to initialize.
|
| 1573 |
|
| 1574 |
If the *expression* is erroneous after converting to `std::size_t`:
|
| 1575 |
|
| 1576 |
+
- if the *expression* is a potentially-evaluated core constant
|
| 1577 |
+
expression, the program is ill-formed;
|
| 1578 |
- otherwise, an allocation function is not called; instead
|
| 1579 |
- if the allocation function that would have been called has a
|
| 1580 |
non-throwing exception specification [[except.spec]], the value of
|
| 1581 |
the *new-expression* is the null pointer value of the required
|
| 1582 |
result type;
|
|
|
|
| 1585 |
`std::bad_array_new_length` [[new.badlength]].
|
| 1586 |
|
| 1587 |
When the value of the *expression* is zero, the allocation function is
|
| 1588 |
called to allocate an array with no elements.
|
| 1589 |
|
| 1590 |
+
Objects created by a *new-expression* have dynamic storage duration
|
| 1591 |
+
[[basic.stc.dynamic]].
|
| 1592 |
+
|
| 1593 |
+
[*Note 5*: The lifetime of such an object is not necessarily
|
| 1594 |
+
restricted to the scope in which it is created. — *end note*]
|
| 1595 |
+
|
| 1596 |
+
When the allocated type is “array of `N` `T`” (that is, the
|
| 1597 |
+
*noptr-new-declarator* syntax is used or the *new-type-id* or *type-id*
|
| 1598 |
+
denotes an array type), the *new-expression* yields a prvalue of type
|
| 1599 |
+
“pointer to `T`” that points to the initial element (if any) of the
|
| 1600 |
+
array. Otherwise, let `T` be the allocated type; the *new-expression* is
|
| 1601 |
+
a prvalue of type “pointer to T” that points to the object created.
|
| 1602 |
+
|
| 1603 |
+
[*Note 6*: Both `new int` and `new int[10]` have type `int*` and the
|
| 1604 |
+
type of `new int[i][10]` is `int (*)[10]`. — *end note*]
|
| 1605 |
+
|
| 1606 |
A *new-expression* may obtain storage for the object by calling an
|
| 1607 |
allocation function [[basic.stc.dynamic.allocation]]. If the
|
| 1608 |
*new-expression* terminates by throwing an exception, it may release
|
| 1609 |
storage by calling a deallocation function
|
| 1610 |
[[basic.stc.dynamic.deallocation]]. If the allocated type is a non-array
|
|
|
|
| 1612 |
deallocation function’s name is `operator delete`. If the allocated type
|
| 1613 |
is an array type, the allocation function’s name is `operator new[]` and
|
| 1614 |
the deallocation function’s name is `operator delete[]`.
|
| 1615 |
|
| 1616 |
[*Note 7*: An implementation is required to provide default definitions
|
| 1617 |
+
for the global allocation functions
|
| 1618 |
+
[[basic.stc.dynamic]], [[new.delete.single]], [[new.delete.array]]. A
|
| 1619 |
+
C++ program can provide alternative definitions of these functions
|
| 1620 |
+
[[replacement.functions]] and/or class-specific versions [[class.free]].
|
| 1621 |
+
The set of allocation and deallocation functions that can be called by a
|
| 1622 |
+
*new-expression* can include functions that do not perform allocation or
|
| 1623 |
+
deallocation; for example, see [[new.delete.placement]]. — *end note*]
|
| 1624 |
|
| 1625 |
+
If the *new-expression* does not begin with a unary `::` operator and
|
| 1626 |
+
the allocated type is a class type `T` or array thereof, a search is
|
| 1627 |
+
performed for the allocation function’s name in the scope of `T`
|
| 1628 |
+
[[class.member.lookup]]. Otherwise, or if nothing is found, the
|
| 1629 |
+
allocation function’s name is looked up by searching for it in the
|
| 1630 |
+
global scope.
|
| 1631 |
|
| 1632 |
An implementation is allowed to omit a call to a replaceable global
|
| 1633 |
+
allocation function [[new.delete.single]], [[new.delete.array]]. When it
|
| 1634 |
+
does so, the storage is instead provided by the implementation or
|
| 1635 |
provided by extending the allocation of another *new-expression*.
|
| 1636 |
|
| 1637 |
During an evaluation of a constant expression, a call to an allocation
|
| 1638 |
function is always omitted.
|
| 1639 |
|
|
|
|
| 1764 |
|
| 1765 |
— *end example*]
|
| 1766 |
|
| 1767 |
[*Note 10*: Unless an allocation function has a non-throwing exception
|
| 1768 |
specification [[except.spec]], it indicates failure to allocate storage
|
| 1769 |
+
by throwing a `std::bad_alloc` exception
|
| 1770 |
+
[[basic.stc.dynamic.allocation]], [[except]], [[bad.alloc]]; it returns
|
| 1771 |
a non-null pointer otherwise. If the allocation function has a
|
| 1772 |
non-throwing exception specification, it returns null to indicate
|
| 1773 |
failure to allocate storage and a non-null pointer
|
| 1774 |
otherwise. — *end note*]
|
| 1775 |
|
|
|
|
| 1800 |
the allocated object is sequenced before the value computation of the
|
| 1801 |
*new-expression*.
|
| 1802 |
|
| 1803 |
If the *new-expression* creates an object or an array of objects of
|
| 1804 |
class type, access and ambiguity control are done for the allocation
|
| 1805 |
+
function, the deallocation function [[basic.stc.dynamic.deallocation]],
|
| 1806 |
+
and the constructor [[class.ctor]] selected for the initialization (if
|
| 1807 |
+
any). If the *new-expression* creates an array of objects of class type,
|
| 1808 |
+
the destructor is potentially invoked [[class.dtor]].
|
| 1809 |
|
| 1810 |
+
If any part of the object initialization described above[^24]
|
| 1811 |
+
|
| 1812 |
+
terminates by throwing an exception and a suitable deallocation function
|
| 1813 |
+
can be found, the deallocation function is called to free the memory in
|
| 1814 |
+
which the object was being constructed, after which the exception
|
| 1815 |
+
continues to propagate in the context of the *new-expression*. If no
|
| 1816 |
+
unambiguous matching deallocation function can be found, propagating the
|
| 1817 |
+
exception does not cause the object’s memory to be freed.
|
| 1818 |
|
| 1819 |
[*Note 13*: This is appropriate when the called allocation function
|
| 1820 |
does not allocate memory; otherwise, it is likely to result in a memory
|
| 1821 |
leak. — *end note*]
|
| 1822 |
|
| 1823 |
+
If the *new-expression* does not begin with a unary `::` operator and
|
| 1824 |
+
the allocated type is a class type `T` or an array thereof, a search is
|
| 1825 |
+
performed for the deallocation function’s name in the scope of `T`.
|
| 1826 |
+
Otherwise, or if nothing is found, the deallocation function’s name is
|
| 1827 |
+
looked up by searching for it in the global scope.
|
|
|
|
|
|
|
| 1828 |
|
| 1829 |
A declaration of a placement deallocation function matches the
|
| 1830 |
declaration of a placement allocation function if it has the same number
|
| 1831 |
of parameters and, after parameter transformations [[dcl.fct]], all
|
| 1832 |
parameter types except the first are identical. If the lookup finds a
|
|
|
|
| 1877 |
```
|
| 1878 |
|
| 1879 |
The first alternative is a *single-object delete expression*, and the
|
| 1880 |
second is an *array delete expression*. Whenever the `delete` keyword is
|
| 1881 |
immediately followed by empty square brackets, it shall be interpreted
|
| 1882 |
+
as the second alternative.[^25]
|
| 1883 |
+
|
| 1884 |
+
The operand shall be of pointer to object type or of class type. If of
|
| 1885 |
+
class type, the operand is contextually implicitly converted [[conv]] to
|
| 1886 |
+
a pointer to object type.[^26]
|
| 1887 |
+
|
| 1888 |
+
The *delete-expression* has type `void`.
|
| 1889 |
|
| 1890 |
If the operand has a class type, the operand is converted to a pointer
|
| 1891 |
type by calling the above-mentioned conversion function, and the
|
| 1892 |
converted operand is used in place of the original operand for the
|
| 1893 |
remainder of this subclause. In a single-object delete expression, the
|
| 1894 |
value of the operand of `delete` may be a null pointer value, a pointer
|
| 1895 |
+
value that resulted from a previous non-array *new-expression*, or a
|
| 1896 |
+
pointer to a base class subobject of an object created by such a
|
| 1897 |
+
*new-expression*. If not, the behavior is undefined. In an array delete
|
| 1898 |
+
expression, the value of the operand of `delete` may be a null pointer
|
| 1899 |
+
value or a pointer value that resulted from a previous array
|
| 1900 |
+
*new-expression* whose allocation function was not a non-allocating form
|
| 1901 |
+
[[new.delete.placement]].[^27]
|
| 1902 |
+
|
| 1903 |
+
If not, the behavior is undefined.
|
| 1904 |
|
| 1905 |
[*Note 1*: This means that the syntax of the *delete-expression* must
|
| 1906 |
match the type of the object allocated by `new`, not the syntax of the
|
| 1907 |
*new-expression*. — *end note*]
|
| 1908 |
|
|
|
|
| 1910 |
*delete-expression*; it is not necessary to cast away the constness
|
| 1911 |
[[expr.const.cast]] of the pointer expression before it is used as the
|
| 1912 |
operand of the *delete-expression*. — *end note*]
|
| 1913 |
|
| 1914 |
In a single-object delete expression, if the static type of the object
|
| 1915 |
+
to be deleted is not similar [[conv.qual]] to its dynamic type and the
|
| 1916 |
+
selected deallocation function (see below) is not a destroying operator
|
| 1917 |
+
delete, the static type shall be a base class of the dynamic type of the
|
| 1918 |
+
object to be deleted and the static type shall have a virtual destructor
|
| 1919 |
+
or the behavior is undefined. In an array delete expression, if the
|
| 1920 |
+
dynamic type of the object to be deleted is not similar to its static
|
| 1921 |
+
type, the behavior is undefined.
|
| 1922 |
|
| 1923 |
The *cast-expression* in a *delete-expression* shall be evaluated
|
| 1924 |
exactly once.
|
| 1925 |
|
| 1926 |
If the object being deleted has incomplete class type at the point of
|
|
|
|
| 1961 |
|
| 1962 |
If the value of the operand of the *delete-expression* is a null pointer
|
| 1963 |
value, it is unspecified whether a deallocation function will be called
|
| 1964 |
as described above.
|
| 1965 |
|
| 1966 |
+
If a deallocation function is called, it is `operator delete` for a
|
| 1967 |
+
single-object delete expression or `operator delete[]` for an array
|
| 1968 |
+
delete expression.
|
|
|
|
|
|
|
|
|
|
| 1969 |
|
| 1970 |
+
[*Note 4*: An implementation provides default definitions of the
|
| 1971 |
+
global deallocation functions
|
| 1972 |
+
[[new.delete.single]], [[new.delete.array]]. A C++ program can provide
|
| 1973 |
+
alternative definitions of these functions [[replacement.functions]],
|
| 1974 |
+
and/or class-specific versions [[class.free]]. — *end note*]
|
|
|
|
| 1975 |
|
| 1976 |
+
If the keyword `delete` in a *delete-expression* is not preceded by the
|
| 1977 |
+
unary `::` operator and the type of the operand is a pointer to a
|
| 1978 |
+
(possibly cv-qualified) class type `T` or (possibly multidimensional)
|
| 1979 |
+
array thereof:
|
| 1980 |
+
|
| 1981 |
+
- For a single-object delete expression, if the operand is a pointer to
|
| 1982 |
+
cv `T` and `T` has a virtual destructor, the deallocation function is
|
| 1983 |
+
the one selected at the point of definition of the dynamic type’s
|
| 1984 |
+
virtual destructor [[class.dtor]].
|
| 1985 |
+
- Otherwise, a search is performed for the deallocation function’s name
|
| 1986 |
+
in the scope of `T`.
|
| 1987 |
+
|
| 1988 |
+
Otherwise, or if nothing is found, the deallocation function’s name is
|
| 1989 |
+
looked up by searching for it in the global scope. In any case, any
|
| 1990 |
+
declarations other than of usual deallocation functions
|
| 1991 |
+
[[basic.stc.dynamic.deallocation]] are discarded.
|
| 1992 |
+
|
| 1993 |
+
[*Note 5*: If only a placement deallocation function is found in a
|
| 1994 |
+
class, the program is ill-formed because the lookup set is empty
|
| 1995 |
+
[[basic.lookup]]. — *end note*]
|
| 1996 |
+
|
| 1997 |
+
If more than one deallocation function is found, the function to be
|
| 1998 |
+
called is selected as follows:
|
| 1999 |
|
| 2000 |
- If any of the deallocation functions is a destroying operator delete,
|
| 2001 |
all deallocation functions that are not destroying operator deletes
|
| 2002 |
are eliminated from further consideration.
|
| 2003 |
- If the type has new-extended alignment, a function with a parameter of
|
| 2004 |
type `std::align_val_t` is preferred; otherwise a function without
|
| 2005 |
such a parameter is preferred. If any preferred functions are found,
|
| 2006 |
all non-preferred functions are eliminated from further consideration.
|
| 2007 |
- If exactly one function remains, that function is selected and the
|
| 2008 |
selection process terminates.
|
| 2009 |
+
- If the deallocation functions belong to a class scope, the one without
|
| 2010 |
+
a parameter of type `std::size_t` is selected.
|
| 2011 |
- If the type is complete and if, for an array delete expression only,
|
| 2012 |
the operand is a pointer to a class type with a non-trivial destructor
|
| 2013 |
+
or a (possibly multidimensional) array thereof, the function with a
|
| 2014 |
parameter of type `std::size_t` is selected.
|
| 2015 |
- Otherwise, it is unspecified whether a deallocation function with a
|
| 2016 |
parameter of type `std::size_t` is selected.
|
| 2017 |
|
| 2018 |
For a single-object delete expression, the deleted object is the object
|
| 2019 |
+
A pointed to by the operand if the static type of A does not have a
|
| 2020 |
+
virtual destructor, and the most-derived object of A otherwise.
|
| 2021 |
|
| 2022 |
+
[*Note 6*: If the deallocation function is not a destroying operator
|
| 2023 |
delete and the deleted object is not the most derived object in the
|
| 2024 |
former case, the behavior is undefined, as stated above. — *end note*]
|
| 2025 |
|
| 2026 |
For an array delete expression, the deleted object is the array object.
|
| 2027 |
When a *delete-expression* is executed, the selected deallocation
|
| 2028 |
function shall be called with the address of the deleted object in a
|
| 2029 |
single-object delete expression, or the address of the deleted object
|
| 2030 |
suitably adjusted for the array allocation overhead [[expr.new]] in an
|
| 2031 |
array delete expression, as its first argument.
|
| 2032 |
|
| 2033 |
+
[*Note 7*: Any cv-qualifiers in the type of the deleted object are
|
| 2034 |
ignored when forming this argument. — *end note*]
|
| 2035 |
|
| 2036 |
If a destroying operator delete is used, an unspecified value is passed
|
| 2037 |
as the argument corresponding to the parameter of type
|
| 2038 |
`std::destroying_delete_t`. If a deallocation function with a parameter
|
|
|
|
| 2041 |
deallocation function with a parameter of type `std::size_t` is used,
|
| 2042 |
the size of the deleted object in a single-object delete expression, or
|
| 2043 |
of the array plus allocation overhead in an array delete expression, is
|
| 2044 |
passed as the corresponding argument.
|
| 2045 |
|
| 2046 |
+
[*Note 8*: If this results in a call to a replaceable deallocation
|
| 2047 |
function, and either the first argument was not the result of a prior
|
| 2048 |
call to a replaceable allocation function or the second or third
|
| 2049 |
argument was not the corresponding argument in said call, the behavior
|
| 2050 |
+
is undefined [[new.delete.single]], [[new.delete.array]]. — *end note*]
|
|
|
|
| 2051 |
|
| 2052 |
Access and ambiguity control are done for both the deallocation function
|
| 2053 |
+
and the destructor [[class.dtor]], [[class.free]].
|
| 2054 |
|
| 2055 |
### Explicit type conversion (cast notation) <a id="expr.cast">[[expr.cast]]</a>
|
| 2056 |
|
| 2057 |
The result of the expression `(T)` *cast-expression* is of type `T`. The
|
| 2058 |
result is an lvalue if `T` is an lvalue reference type or an rvalue
|
|
|
|
| 2156 |
type “pointer to `U`” where `U` is either `T` or a class of which `T` is
|
| 2157 |
an unambiguous and accessible base class. The expression `E1->*E2` is
|
| 2158 |
converted into the equivalent form `(*(E1)).*E2`.
|
| 2159 |
|
| 2160 |
Abbreviating *pm-expression*`.*`*cast-expression* as `E1.*E2`, `E1` is
|
| 2161 |
+
called the *object expression*. If the result of `E1` is an object whose
|
| 2162 |
+
type is not similar to the type of `E1`, or whose most derived object
|
| 2163 |
+
does not contain the member to which `E2` refers, the behavior is
|
| 2164 |
+
undefined. The expression `E1` is sequenced before the expression `E2`.
|
| 2165 |
|
| 2166 |
The restrictions on cv-qualification, and the manner in which the
|
| 2167 |
cv-qualifiers of the operands are combined to produce the cv-qualifiers
|
| 2168 |
of the result, are the same as the rules for `E1.E2` given in
|
| 2169 |
[[expr.ref]].
|
|
|
|
| 2235 |
|
| 2236 |
The binary `/` operator yields the quotient, and the binary `%` operator
|
| 2237 |
yields the remainder from the division of the first expression by the
|
| 2238 |
second. If the second operand of `/` or `%` is zero the behavior is
|
| 2239 |
undefined. For integral operands the `/` operator yields the algebraic
|
| 2240 |
+
quotient with any fractional part discarded;[^28]
|
| 2241 |
+
|
| 2242 |
+
if the quotient `a/b` is representable in the type of the result,
|
| 2243 |
+
`(a/b)*b + a%b` is equal to `a`; otherwise, the behavior of both `a/b`
|
| 2244 |
+
and `a%b` is undefined.
|
| 2245 |
|
| 2246 |
### Additive operators <a id="expr.add">[[expr.add]]</a>
|
| 2247 |
|
| 2248 |
The additive operators `+` and `-` group left-to-right. The usual
|
| 2249 |
arithmetic conversions [[expr.arith.conv]] are performed for operands of
|
|
|
|
| 2284 |
(possibly-hypothetical) array element i + j of `x` if 0 ≤ i + j ≤ n
|
| 2285 |
and the expression `P - J` points to the (possibly-hypothetical) array
|
| 2286 |
element i - j of `x` if 0 ≤ i - j ≤ n.
|
| 2287 |
- Otherwise, the behavior is undefined.
|
| 2288 |
|
| 2289 |
+
[*Note 1*: Adding a value other than 0 or 1 to a pointer to a base
|
| 2290 |
+
class subobject, a member subobject, or a complete object results in
|
| 2291 |
+
undefined behavior. — *end note*]
|
| 2292 |
+
|
| 2293 |
When two pointer expressions `P` and `Q` are subtracted, the type of the
|
| 2294 |
result is an *implementation-defined* signed integral type; this type
|
| 2295 |
shall be the same type that is defined as `std::ptrdiff_t` in the
|
| 2296 |
`<cstddef>` header [[support.types.layout]].
|
| 2297 |
|
| 2298 |
- If `P` and `Q` both evaluate to null pointer values, the result is 0.
|
| 2299 |
- Otherwise, if `P` and `Q` point to, respectively, array elements i and
|
| 2300 |
j of the same array object `x`, the expression `P - Q` has the value
|
| 2301 |
i - j.
|
| 2302 |
+
- Otherwise, the behavior is undefined. \[*Note 2*: If the value i - j
|
| 2303 |
is not in the range of representable values of type `std::ptrdiff_t`,
|
| 2304 |
the behavior is undefined. — *end note*]
|
| 2305 |
|
| 2306 |
For addition or subtraction, if the expressions `P` or `Q` have type
|
| 2307 |
“pointer to cv `T`”, where `T` and the array element type are not
|
| 2308 |
similar [[conv.qual]], the behavior is undefined.
|
| 2309 |
|
| 2310 |
+
[*Example 1*:
|
| 2311 |
+
|
| 2312 |
+
``` cpp
|
| 2313 |
+
int arr[5] = {1, 2, 3, 4, 5};
|
| 2314 |
+
unsigned int *p = reinterpret_cast<unsigned int*>(arr + 1);
|
| 2315 |
+
unsigned int k = *p; // OK, value of k is 2[conv.lval]
|
| 2316 |
+
unsigned int *q = p + 1; // undefined behavior: p points to an int, not an unsigned int object
|
| 2317 |
+
```
|
| 2318 |
+
|
| 2319 |
+
— *end example*]
|
| 2320 |
|
| 2321 |
### Shift operators <a id="expr.shift">[[expr.shift]]</a>
|
| 2322 |
|
| 2323 |
The shift operators `<<` and `>>` group left-to-right.
|
| 2324 |
|
|
|
|
| 2387 |
|
| 2388 |
If both operands have the same enumeration type `E`, the operator yields
|
| 2389 |
the result of converting the operands to the underlying type of `E` and
|
| 2390 |
applying `<=>` to the converted operands.
|
| 2391 |
|
| 2392 |
+
If at least one of the operands is of object pointer type and the other
|
| 2393 |
+
operand is of object pointer or array type, array-to-pointer conversions
|
| 2394 |
[[conv.array]], pointer conversions [[conv.ptr]], and qualification
|
| 2395 |
conversions [[conv.qual]] are performed on both operands to bring them
|
| 2396 |
to their composite pointer type [[expr.type]]. After the conversions,
|
| 2397 |
the operands shall have the same type.
|
| 2398 |
|
| 2399 |
[*Note 1*: If both of the operands are arrays, array-to-pointer
|
| 2400 |
conversions [[conv.array]] are not applied. — *end note*]
|
| 2401 |
|
| 2402 |
+
In this case, `p <=> q` is of type `std::strong_ordering` and the result
|
| 2403 |
+
is defined by the following rules:
|
| 2404 |
+
|
| 2405 |
+
- If two pointer operands `p` and `q` compare equal [[expr.eq]],
|
| 2406 |
+
`p <=> q` yields `std::strong_ordering::equal`;
|
| 2407 |
+
- otherwise, if `p` and `q` compare unequal, `p <=> q` yields
|
| 2408 |
`std::strong_ordering::less` if `q` compares greater than `p` and
|
| 2409 |
`std::strong_ordering::greater` if `p` compares greater than `q`
|
| 2410 |
+
[[expr.rel]];
|
| 2411 |
+
- otherwise, the result is unspecified.
|
| 2412 |
|
| 2413 |
Otherwise, the program is ill-formed.
|
| 2414 |
|
| 2415 |
The three comparison category types [[cmp.categories]] (the types
|
| 2416 |
`std::strong_ordering`, `std::weak_ordering`, and
|
| 2417 |
+
`std::partial_ordering`) are not predefined; if a standard library
|
| 2418 |
+
declaration [[compare.syn]], [[std.modules]] of such a class type does
|
| 2419 |
+
not precede [[basic.lookup.general]] a use of that type — even an
|
| 2420 |
+
implicit use in which the type is not named (e.g., via the `auto`
|
| 2421 |
specifier [[dcl.spec.auto]] in a defaulted three-way comparison
|
| 2422 |
+
[[class.spaceship]] or use of the built-in operator) — the program is
|
| 2423 |
ill-formed.
|
| 2424 |
|
| 2425 |
### Relational operators <a id="expr.rel">[[expr.rel]]</a>
|
| 2426 |
|
| 2427 |
The relational operators group left-to-right.
|
|
|
|
| 2453 |
pointers, pointer conversions [[conv.ptr]] and qualification conversions
|
| 2454 |
[[conv.qual]] are performed to bring them to their composite pointer
|
| 2455 |
type [[expr.type]]. After conversions, the operands shall have the same
|
| 2456 |
type.
|
| 2457 |
|
| 2458 |
+
The result of comparing unequal pointers to objects[^30]
|
| 2459 |
+
|
| 2460 |
+
is defined in terms of a partial order consistent with the following
|
| 2461 |
+
rules:
|
| 2462 |
|
| 2463 |
- If two pointers point to different elements of the same array, or to
|
| 2464 |
subobjects thereof, the pointer to the element with the higher
|
| 2465 |
subscript is required to compare greater.
|
| 2466 |
- If two pointers point to different non-static data members of the same
|
| 2467 |
object, or to subobjects of such members, recursively, the pointer to
|
| 2468 |
+
the later declared member is required to compare greater provided
|
| 2469 |
+
neither member is a subobject of zero size and their class is not a
|
| 2470 |
+
union.
|
| 2471 |
- Otherwise, neither pointer is required to compare greater than the
|
| 2472 |
other.
|
| 2473 |
|
| 2474 |
If two operands `p` and `q` compare equal [[expr.eq]], `p<=q` and `p>=q`
|
| 2475 |
both yield `true` and `p<q` and `p>q` both yield `false`. Otherwise, if
|
| 2476 |
+
a pointer to object `p` compares greater than a pointer `q`, `p>=q`,
|
| 2477 |
+
`p>q`, `q<=p`, and `q<p` all yield `true` and `p<=q`, `p<q`, `q>=p`, and
|
| 2478 |
+
`q>p` all yield `false`. Otherwise, the result of each of the operators
|
| 2479 |
+
is unspecified.
|
| 2480 |
+
|
| 2481 |
+
[*Note 1*: A relational operator applied to unequal function pointers
|
| 2482 |
+
or to unequal pointers to `void` yields an unspecified
|
| 2483 |
+
result. — *end note*]
|
| 2484 |
|
| 2485 |
If both operands (after conversions) are of arithmetic or enumeration
|
| 2486 |
type, each of the operators shall yield `true` if the specified
|
| 2487 |
relationship is true and `false` if it is false.
|
| 2488 |
|
|
|
|
| 2620 |
The `^` operator groups left-to-right. The operands shall be of integral
|
| 2621 |
or unscoped enumeration type. The usual arithmetic conversions
|
| 2622 |
[[expr.arith.conv]] are performed. Given the coefficients `xᵢ` and `yᵢ`
|
| 2623 |
of the base-2 representation [[basic.fundamental]] of the converted
|
| 2624 |
operands `x` and `y`, the coefficient `rᵢ` of the base-2 representation
|
| 2625 |
+
of the result `r` is 1 if either (but not both) of `xᵢ` and `yᵢ` is 1,
|
| 2626 |
and 0 otherwise.
|
| 2627 |
|
| 2628 |
[*Note 1*: The result is the bitwise exclusive function of the
|
| 2629 |
operands. — *end note*]
|
| 2630 |
|
|
|
|
| 2639 |
The `|` operator groups left-to-right. The operands shall be of integral
|
| 2640 |
or unscoped enumeration type. The usual arithmetic conversions
|
| 2641 |
[[expr.arith.conv]] are performed. Given the coefficients `xᵢ` and `yᵢ`
|
| 2642 |
of the base-2 representation [[basic.fundamental]] of the converted
|
| 2643 |
operands `x` and `y`, the coefficient `rᵢ` of the base-2 representation
|
| 2644 |
+
of the result `r` is 1 if at least one of `xᵢ` and `yᵢ` is 1, and 0
|
| 2645 |
otherwise.
|
| 2646 |
|
| 2647 |
[*Note 1*: The result is the bitwise inclusive function of the
|
| 2648 |
operands. — *end note*]
|
| 2649 |
|
|
|
|
| 2728 |
Attempts are made to form an implicit conversion sequence from an
|
| 2729 |
operand expression `E1` of type `T1` to a target type related to the
|
| 2730 |
type `T2` of the operand expression `E2` as follows:
|
| 2731 |
|
| 2732 |
- If `E2` is an lvalue, the target type is “lvalue reference to `T2`”,
|
| 2733 |
+
but an implicit conversion sequence can only be formed if the
|
| 2734 |
+
reference would bind directly [[dcl.init.ref]] to a glvalue.
|
| 2735 |
- If `E2` is an xvalue, the target type is “rvalue reference to `T2`”,
|
| 2736 |
+
but an implicit conversion sequence can only be formed if the
|
| 2737 |
+
reference would bind directly.
|
| 2738 |
- If `E2` is a prvalue or if neither of the conversion sequences above
|
| 2739 |
can be formed and at least one of the operands has (possibly
|
| 2740 |
cv-qualified) class type:
|
| 2741 |
- if `T1` and `T2` are the same class type (ignoring cv-qualification)
|
| 2742 |
and `T2` is at least as cv-qualified as `T1`, the target type is
|
|
|
|
| 2768 |
or if both are bit-fields.
|
| 2769 |
|
| 2770 |
Otherwise, the result is a prvalue. If the second and third operands do
|
| 2771 |
not have the same type, and either has (possibly cv-qualified) class
|
| 2772 |
type, overload resolution is used to determine the conversions (if any)
|
| 2773 |
+
to be applied to the operands [[over.match.oper]], [[over.built]]. If
|
| 2774 |
the overload resolution fails, the program is ill-formed. Otherwise, the
|
| 2775 |
conversions thus determined are applied, and the converted operands are
|
| 2776 |
used in place of the original operands for the remainder of this
|
| 2777 |
subclause.
|
| 2778 |
|
|
|
|
| 2812 |
A *yield-expression* shall appear only within a suspension context of a
|
| 2813 |
function [[expr.await]]. Let *e* be the operand of the
|
| 2814 |
*yield-expression* and *p* be an lvalue naming the promise object of the
|
| 2815 |
enclosing coroutine [[dcl.fct.def.coroutine]], then the
|
| 2816 |
*yield-expression* is equivalent to the expression
|
| 2817 |
+
`co_await p.yield_value(e)`.
|
| 2818 |
|
| 2819 |
[*Example 1*:
|
| 2820 |
|
| 2821 |
``` cpp
|
| 2822 |
template <typename T>
|
|
|
|
| 2833 |
iterator begin();
|
| 2834 |
iterator end();
|
| 2835 |
};
|
| 2836 |
|
| 2837 |
my_generator<pair<int,int>> g1() {
|
| 2838 |
+
for (int i = 0; i < 10; ++i) co_yield {i,i};
|
| 2839 |
}
|
| 2840 |
my_generator<pair<int,int>> g2() {
|
| 2841 |
+
for (int i = 0; i < 10; ++i) co_yield make_pair(i,i);
|
| 2842 |
}
|
| 2843 |
|
| 2844 |
auto f(int x = co_yield 5); // error: yield-expression outside of function suspension context
|
| 2845 |
int a[] = { co_yield 1 }; // error: yield-expression outside of function suspension context
|
| 2846 |
|
|
|
|
| 2873 |
existing exception object; no new exception object is created. The
|
| 2874 |
exception is no longer considered to be caught.
|
| 2875 |
|
| 2876 |
[*Example 1*:
|
| 2877 |
|
| 2878 |
+
An exception handler that cannot completely handle the exception itself
|
| 2879 |
+
can be written like this:
|
| 2880 |
|
| 2881 |
``` cpp
|
| 2882 |
try {
|
| 2883 |
// ...
|
| 2884 |
} catch (...) { // catch all exceptions
|
|
|
|
| 2895 |
|
| 2896 |
### Assignment and compound assignment operators <a id="expr.ass">[[expr.ass]]</a>
|
| 2897 |
|
| 2898 |
The assignment operator (`=`) and the compound assignment operators all
|
| 2899 |
group right-to-left. All require a modifiable lvalue as their left
|
| 2900 |
+
operand; their result is an lvalue of the type of the left operand,
|
| 2901 |
+
referring to the left operand. The result in all cases is a bit-field if
|
| 2902 |
+
the left operand is a bit-field. In all cases, the assignment is
|
| 2903 |
+
sequenced after the value computation of the right and left operands,
|
| 2904 |
+
and before the value computation of the assignment expression. The right
|
| 2905 |
+
operand is sequenced before the left operand. With respect to an
|
| 2906 |
+
indeterminately-sequenced function call, the operation of a compound
|
| 2907 |
+
assignment is a single evaluation.
|
| 2908 |
|
| 2909 |
[*Note 1*: Therefore, a function call cannot intervene between the
|
| 2910 |
lvalue-to-rvalue conversion and the side effect associated with any
|
| 2911 |
single compound assignment operator. — *end note*]
|
| 2912 |
|
|
|
|
| 2932 |
|
| 2933 |
When the left operand of an assignment operator is a bit-field that
|
| 2934 |
cannot represent the value of the expression, the resulting value of the
|
| 2935 |
bit-field is *implementation-defined*.
|
| 2936 |
|
| 2937 |
+
An assignment whose left operand is of a volatile-qualified type is
|
| 2938 |
+
deprecated [[depr.volatile.type]] unless the (possibly parenthesized)
|
| 2939 |
+
assignment is a discarded-value expression or an unevaluated operand
|
| 2940 |
+
[[term.unevaluated.operand]].
|
| 2941 |
|
| 2942 |
The behavior of an expression of the form `E1 op= E2` is equivalent to
|
| 2943 |
+
`E1 = E1 op E2` except that `E1` is evaluated only once.
|
| 2944 |
+
|
| 2945 |
+
[*Note 2*: The object designated by `E1` is accessed
|
| 2946 |
+
twice. — *end note*]
|
| 2947 |
+
|
| 2948 |
+
For `+=` and `-=`, `E1` shall either have arithmetic type or be a
|
| 2949 |
+
pointer to a possibly cv-qualified completely-defined object type. In
|
| 2950 |
+
all other cases, `E1` shall have arithmetic type.
|
| 2951 |
|
| 2952 |
If the value being stored in an object is read via another object that
|
| 2953 |
overlaps in any way the storage of the first object, then the overlap
|
| 2954 |
shall be exact and the two objects shall have the same type, otherwise
|
| 2955 |
the behavior is undefined.
|
| 2956 |
|
| 2957 |
+
[*Note 3*: This restriction applies to the relationship between the
|
| 2958 |
left and right sides of the assignment operation; it is not a statement
|
| 2959 |
+
about how the target of the assignment can be aliased in general. See
|
| 2960 |
[[basic.lval]]. — *end note*]
|
| 2961 |
|
| 2962 |
A *braced-init-list* may appear on the right-hand side of
|
| 2963 |
|
| 2964 |
- an assignment to a scalar, in which case the initializer list shall
|
| 2965 |
have at most a single element. The meaning of `x = {v}`, where `T` is
|
| 2966 |
the scalar type of the expression `x`, is that of `x = T{v}`. The
|
| 2967 |
meaning of `x = {}` is `x = T{}`.
|
| 2968 |
- an assignment to an object of class type, in which case the
|
| 2969 |
initializer list is passed as the argument to the assignment operator
|
| 2970 |
+
function selected by overload resolution [[over.ass]], [[over.match]].
|
|
|
|
| 2971 |
|
| 2972 |
[*Example 1*:
|
| 2973 |
|
| 2974 |
``` cpp
|
| 2975 |
complex<double> z;
|
|
|
|
| 2998 |
[[intro.execution]]. The type and value of the result are the type and
|
| 2999 |
value of the right operand; the result is of the same value category as
|
| 3000 |
its right operand, and is a bit-field if its right operand is a
|
| 3001 |
bit-field.
|
| 3002 |
|
| 3003 |
+
[*Note 1*:
|
| 3004 |
|
| 3005 |
+
In contexts where the comma token is given special meaning (e.g.,
|
| 3006 |
+
function calls [[expr.call]], subscript expressions [[expr.sub]], lists
|
| 3007 |
+
of initializers [[dcl.init]], or *template-argument-list*s
|
| 3008 |
+
[[temp.names]]), the comma operator as described in this subclause can
|
| 3009 |
+
appear only in parentheses.
|
| 3010 |
|
| 3011 |
+
[*Example 1*:
|
|
|
|
|
|
|
|
|
|
| 3012 |
|
| 3013 |
``` cpp
|
| 3014 |
f(a, (t=3, t+2), c);
|
| 3015 |
```
|
| 3016 |
|
| 3017 |
has three arguments, the second of which has the value `5`.
|
| 3018 |
|
| 3019 |
— *end example*]
|
| 3020 |
|
| 3021 |
+
— *end note*]
|
|
|
|
|
|
|
| 3022 |
|