|
266 | 266 | \end{note}
|
267 | 267 |
|
268 | 268 | \pnum
|
269 |
| -Whenever a prvalue appears as an operand of an operator that |
| 269 | +Unless otherwise specified\iref{expr.const.cast}, |
| 270 | +whenever a prvalue appears as an operand of an operator that |
270 | 271 | expects a glvalue for that operand, the
|
271 | 272 | temporary materialization conversion\iref{conv.rval} is
|
272 | 273 | applied to convert the expression to an xvalue.
|
|
4497 | 4498 | otherwise, the result is a prvalue and the
|
4498 | 4499 | lvalue-to-rvalue\iref{conv.lval}, array-to-pointer\iref{conv.array},
|
4499 | 4500 | and function-to-pointer\iref{conv.func} standard conversions are
|
4500 |
| -performed on the expression \tcode{v}. Conversions that can be performed explicitly using |
| 4501 | +performed on the expression \tcode{v}. |
| 4502 | +The temporary materialization conversion\iref{conv.rval} is not |
| 4503 | +performed on \tcode{v}, other than as specified below. |
| 4504 | +Conversions that can be performed explicitly using |
4501 | 4505 | \keyword{const_cast} are listed below. No other conversion shall be
|
4502 | 4506 | performed explicitly using \keyword{const_cast}.
|
4503 | 4507 |
|
|
4508 | 4512 | \end{note}
|
4509 | 4513 |
|
4510 | 4514 | \pnum
|
4511 |
| -For two similar types \tcode{T1} and \tcode{T2}\iref{conv.qual}, |
4512 |
| -a prvalue of type \tcode{T1} may be explicitly |
| 4515 | +For two similar object pointer or pointer to data member types |
| 4516 | +\tcode{T1} and \tcode{T2}\iref{conv.qual}, |
| 4517 | +a prvalue of type \tcode{T1} can be explicitly |
4513 | 4518 | converted to the type \tcode{T2} using a \keyword{const_cast}
|
4514 | 4519 | if, considering the qualification-decompositions of both types,
|
4515 | 4520 | each $P^1_i$ is the same as $P^2_i$ for all $i$.
|
4516 |
| -The result of a \keyword{const_cast} refers to the original entity. |
4517 |
| -\begin{example} |
4518 |
| -\begin{codeblock} |
4519 |
| -typedef int *A[3]; // array of 3 pointer to \tcode{int} |
4520 |
| -typedef const int *const CA[3]; // array of 3 const pointer to \tcode{const int} |
4521 |
| - |
4522 |
| -CA &&r = A{}; // OK, reference binds to temporary array object |
4523 |
| - // after qualification conversion to type \tcode{CA} |
4524 |
| -A &&r1 = const_cast<A>(CA{}); // error: temporary array decayed to pointer |
4525 |
| -A &&r2 = const_cast<A&&>(CA{}); // OK |
4526 |
| -\end{codeblock} |
4527 |
| -\end{example} |
| 4521 | +If \tcode{v} is a null pointer or null member pointer, |
| 4522 | +the result is a null pointer or null member pointer, respectively. |
| 4523 | +Otherwise, the result points to or past the end of the same object, or |
| 4524 | +points to the same member, respectively, as \tcode{v}. |
4528 | 4525 |
|
4529 | 4526 | \pnum
|
4530 | 4527 | For two object types \tcode{T1} and \tcode{T2}, if a pointer to \tcode{T1} can
|
|
4537 | 4534 | \item a glvalue of type \tcode{T1} can be explicitly converted to an xvalue
|
4538 | 4535 | of type \tcode{T2} using the cast \tcode{\keyword{const_cast}<T2\&\&>}; and
|
4539 | 4536 |
|
4540 |
| -\item if \tcode{T1} is a class type, a prvalue of type \tcode{T1} can be |
| 4537 | +\item if \tcode{T1} is a class or array type, |
| 4538 | +a prvalue of type \tcode{T1} can be |
4541 | 4539 | explicitly converted to an xvalue of type \tcode{T2} using the cast
|
4542 | 4540 | \tcode{\keyword{const_cast}<T2\&\&>}.
|
| 4541 | +The temporary materialization conversion is performed on \tcode{v}. |
4543 | 4542 | \end{itemize}
|
4544 | 4543 |
|
4545 |
| -The result of a reference \keyword{const_cast} refers |
4546 |
| -to the original object if the operand is a glvalue and |
4547 |
| -to the result of applying the temporary materialization conversion\iref{conv.rval} otherwise. |
| 4544 | +The result refers to the same object as the (possibly converted) operand. |
| 4545 | +\begin{example} |
| 4546 | +\begin{codeblock} |
| 4547 | +typedef int *A[3]; // array of 3 pointer to \tcode{int} |
| 4548 | +typedef const int *const CA[3]; // array of 3 const pointer to \tcode{const int} |
4548 | 4549 |
|
4549 |
| -\pnum |
4550 |
| -A null pointer value\iref{basic.compound} is converted to the null pointer |
4551 |
| -value of the destination type. The null member pointer |
4552 |
| -value\iref{conv.mem} is converted to the null member pointer value of |
4553 |
| -the destination type. |
| 4550 | +auto &&r2 = const_cast<A&&>(CA{}); // OK, temporary materialization conversion is performed |
| 4551 | +\end{codeblock} |
| 4552 | +\end{example} |
4554 | 4553 |
|
4555 | 4554 | \pnum
|
4556 | 4555 | \begin{note}
|
|
0 commit comments