diff --git a/source/basic.tex b/source/basic.tex index 9b12f0d8a5..557d41b32c 100644 --- a/source/basic.tex +++ b/source/basic.tex @@ -3383,8 +3383,8 @@ program has undefined behavior if: \begin{itemize} \item - the object will be or was of a class type with a non-trivial destructor - and the pointer is used as the operand of a \grammarterm{delete-expression}, + the pointer is used to destroy the object + (\ref{expr.prim.id.dtor}, \ref{expr.delete}) \item the pointer is used to access a non-static data member or call a non-static member function of the object, or @@ -3447,6 +3447,7 @@ well-defined. The program has undefined behavior if: \begin{itemize} \item the glvalue is used to access the object, or +\item the glvalue is used to destroy the object\iref{expr.prim.id.dtor}, or \item the glvalue is used to call a non-static member function of the object, or \item the glvalue is bound to a reference to a virtual base class\iref{dcl.init.ref}, or \item the glvalue is used as the operand of a @@ -3516,17 +3517,17 @@ If a program ends the lifetime of an object of type \tcode{T} with static\iref{basic.stc.static}, thread\iref{basic.stc.thread}, or automatic\iref{basic.stc.auto} -storage duration and if \tcode{T} has a non-trivial destructor, +storage duration, \begin{footnote} That -is, an object for which a destructor will be called +is, an object that is destroyed implicitly---upon exit from the block for an object with automatic storage duration, upon exit from the thread for an object with thread storage duration, or upon exit from the program for an object with static storage duration. \end{footnote} and another object of the original type does not occupy -that same storage location when the implicit destructor call takes +that same storage location when the implicit destruction takes place, the behavior of the program is undefined. This is true even if the block is exited with an exception. \begin{example} @@ -6633,11 +6634,11 @@ \pnum If the completion of the constructor or dynamic initialization of an object with static -storage duration strongly happens before that of another, the completion of the destructor -of the second is sequenced before the initiation of the destructor of the first. +storage duration strongly happens before that of another, the completion of the destruction +of the second is sequenced before the initiation of the destruction of the first. If the completion of the constructor or dynamic initialization of an object with thread -storage duration is sequenced before that of another, the completion of the destructor -of the second is sequenced before the initiation of the destructor of the first. +storage duration is sequenced before that of another, the completion of the destruction +of the second is sequenced before the initiation of the destruction of the first. If an object is initialized statically, the object is destroyed in the same order as if the object was dynamically initialized. For an object of array or class @@ -6665,9 +6666,9 @@ If the completion of the initialization of an object with static storage duration strongly happens before a call to \tcode{std::atexit}~(see \libheader{cstdlib}, \ref{support.start.term}), the call to the function passed to -\tcode{std::atexit} is sequenced before the call to the destructor for the object. If a +\tcode{std::atexit} is sequenced before the destruction of the object. If a call to \tcode{std::atexit} strongly happens before the completion of the initialization of -an object with static storage duration, the call to the destructor for the +an object with static storage duration, the destruction of the object is sequenced before the call to the function passed to \tcode{std::atexit}. If a call to \tcode{std::atexit} strongly happens before another call to \tcode{std::atexit}, the call to the function passed to the second \tcode{std::atexit} call is sequenced before diff --git a/source/classes.tex b/source/classes.tex index ed6aff3024..33a680d303 100644 --- a/source/classes.tex +++ b/source/classes.tex @@ -2198,6 +2198,10 @@ construction (see~\ref{class.init}). \pnum +\indextext{destroy}% +Whenever an object of class type is destroyed, +its destructor is invoked for that object. +\begin{note} \indextext{destructor!implicit call}% \indextext{destructor!program termination and}% A destructor is invoked implicitly @@ -2210,6 +2214,7 @@ \item for a constructed temporary object when its lifetime ends~(\ref{conv.rval}, \ref{class.temporary}). \end{itemize} +\end{note} \indextext{\idxcode{delete}!destructor and}% \indextext{destructor!explicit call}% diff --git a/source/expressions.tex b/source/expressions.tex index bec10aaceb..484c2d7dff 100644 --- a/source/expressions.tex +++ b/source/expressions.tex @@ -1630,7 +1630,7 @@ pc->C::~C2(); // OK, destroys \tcode{*pc} C().C::~C(); // undefined behavior: temporary of type \tcode{C} destroyed twice using T = int; - 0 .T::~T(); // OK, no effect + 0 .T::~T(); // undefined behavior: temporary of type \tcode{int} is destroyed twice 0.T::~T(); // error: \tcode{0.T} is a \grammarterm{user-defined-floating-point-literal}\iref{lex.ext} } \end{codeblock} @@ -5492,9 +5492,9 @@ null pointer value and the selected deallocation function (see below) is not a destroying operator delete, -the \grammarterm{delete-expression} will invoke the -destructor (if any) for the object or the elements of the array being -deleted. In the case of an array, the elements will be destroyed in +the \grammarterm{delete-expression} destroys the object or +the elements of the array being +deleted. In the case of an array, the elements are destroyed in order of decreasing address (that is, in reverse order of the completion of their constructor; see~\ref{class.base.init}).