|
4310 | 4310 | \pnum
|
4311 | 4311 | \indextext{\idxcode{delete}!undefined}%
|
4312 | 4312 | In a single-object delete expression, if the static type of the object to be
|
4313 |
| -deleted is different from its dynamic type, the static type shall be a base |
| 4313 | +deleted is different from its dynamic type |
| 4314 | +and the selected deallocation function (see below) |
| 4315 | +is not a destroying operator delete, |
| 4316 | +the static type shall be a base |
4314 | 4317 | class of the dynamic type of the object to be deleted and the static type shall
|
4315 | 4318 | have a virtual destructor or the behavior is undefined. In an array delete
|
4316 | 4319 | expression, if the dynamic type of the object to be deleted differs from its
|
|
4329 | 4332 | \pnum
|
4330 | 4333 | \indextext{\idxcode{delete}!destructor and}%
|
4331 | 4334 | If the value of the operand of the \grammarterm{delete-expression} is not a
|
4332 |
| -null pointer value, the \grammarterm{delete-expression} will invoke the |
| 4335 | +null pointer value |
| 4336 | +and the selected deallocation function (see below) |
| 4337 | +is not a destroying operator delete, |
| 4338 | +the \grammarterm{delete-expression} will invoke the |
4333 | 4339 | destructor (if any) for the object or the elements of the array being
|
4334 | 4340 | deleted. In the case of an array, the elements will be destroyed in
|
4335 | 4341 | order of decreasing address (that is, in reverse order of the completion
|
|
4395 | 4401 | the function to be called is selected as follows:
|
4396 | 4402 | \begin{itemize}
|
4397 | 4403 | \item
|
| 4404 | +If any of the deallocation functions is a destroying operator delete, |
| 4405 | +all deallocation functions that are not destroying operator deletes |
| 4406 | +are eliminated from further consideration. |
| 4407 | +\item |
4398 | 4408 | If the type has new-extended alignment,
|
4399 | 4409 | a function with a parameter of type \tcode{std::align_val_t} is preferred;
|
4400 | 4410 | otherwise a function without such a parameter is preferred.
|
4401 |
| -If exactly one preferred function is found, |
4402 |
| -that function is selected and the selection process terminates. |
4403 |
| -If more than one preferred function is found, |
| 4411 | +If any preferred functions are found, |
4404 | 4412 | all non-preferred functions are eliminated from further consideration.
|
4405 | 4413 | \item
|
| 4414 | +If exactly one function remains, |
| 4415 | +that function is selected and the selection process terminates. |
| 4416 | +\item |
4406 | 4417 | If the deallocation functions have class scope,
|
4407 | 4418 | the one without a parameter of type \tcode{std::size_t} is selected.
|
4408 | 4419 | \item
|
4409 |
| -If the type is complete and if, for the second alternative (delete |
4410 |
| -array) only, the operand is a pointer to a class type with a |
| 4420 | +If the type is complete |
| 4421 | +and if, for an array delete expression only, |
| 4422 | +the operand is a pointer to a class type with a |
4411 | 4423 | non-trivial destructor or a (possibly multi-dimensional) array thereof,
|
4412 | 4424 | the function with a parameter of type \tcode{std::size_t} is selected.
|
4413 | 4425 | \item
|
|
4417 | 4429 | \end{itemize}
|
4418 | 4430 |
|
4419 | 4431 | \pnum
|
| 4432 | +For a single-object delete expression, |
| 4433 | +the deleted object is |
| 4434 | +the object denoted by the operand |
| 4435 | +if its static type does not have a virtual destructor, |
| 4436 | +and its most-derived object otherwise. |
| 4437 | +\begin{note} |
| 4438 | +If the deallocation function is not a destroying operator delete |
| 4439 | +and the deleted object is not the most derived object in the former case, |
| 4440 | +the behavior is undefined, |
| 4441 | +as stated above. |
| 4442 | +\end{note} |
| 4443 | +For an array delete expression, |
| 4444 | +the deleted object is |
| 4445 | +the array object. |
4420 | 4446 | When a \grammarterm{delete-expression}
|
4421 | 4447 | is executed, the selected deallocation function shall be called with
|
4422 |
| -the address of the most-derived object in a single-object delete expression, or |
4423 |
| -the address of the object suitably adjusted for the array allocation |
| 4448 | +the address of the deleted object |
| 4449 | +in a single-object delete expression, or |
| 4450 | +the address of the deleted object |
| 4451 | +suitably adjusted for the array allocation |
4424 | 4452 | overhead\iref{expr.new} in an array delete expression,
|
4425 | 4453 | as its first argument.
|
| 4454 | +\begin{note} |
| 4455 | +Any cv-qualifiers in the type of the deleted object |
| 4456 | +are ignored when forming this argument. |
| 4457 | +\end{note} |
| 4458 | +If a destroying operator delete is used, |
| 4459 | +an unspecified value |
| 4460 | +is passed as the argument |
| 4461 | +corresponding to the parameter of type \tcode{std::destroying_delete_t}. |
4426 | 4462 | If a deallocation function
|
4427 | 4463 | with a parameter of type \tcode{std::align_val_t}
|
4428 | 4464 | is used,
|
4429 |
| -the alignment of the type of the object to be deleted |
| 4465 | +the alignment of the type of the deleted object |
4430 | 4466 | is passed as the corresponding argument.
|
4431 | 4467 | If a deallocation function
|
4432 | 4468 | with a parameter of type \tcode{std::size_t} is used,
|
4433 |
| -the size |
4434 |
| -of the most-derived type, or |
4435 |
| -of the array plus allocation overhead, respectively, |
4436 |
| -is passed as the corresponding argument.% |
4437 |
| -\footnote{If the static type of the object to be deleted is complete |
4438 |
| -and is different from the dynamic type, and the destructor is not virtual, the size might |
4439 |
| -be incorrect, but that case is already undefined, as stated above.} |
| 4469 | +the size of the deleted object |
| 4470 | +in a single-object delete expression, or |
| 4471 | +of the array plus allocation overhead |
| 4472 | +in an array delete expression, |
| 4473 | +is passed as the corresponding argument. |
4440 | 4474 | \begin{note}
|
4441 |
| -If this results in a call to a usual deallocation function, and either |
| 4475 | +If this results in a call to a replaceable deallocation function, |
| 4476 | +and either |
4442 | 4477 | the first argument was not the result of
|
4443 |
| -a prior call to a usual allocation function or |
4444 |
| -the second argument was not the corresponding argument in said call, |
| 4478 | +a prior call to a replaceable allocation function or |
| 4479 | +the second or third argument was not the corresponding argument in said call, |
4445 | 4480 | the behavior is undefined~(\ref{new.delete.single}, \ref{new.delete.array}).
|
4446 | 4481 | \end{note}
|
4447 | 4482 |
|
|
0 commit comments