Skip to content

[basic.life,basic.start.term,expr.delete] Clarify destruction of scalars #4953

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 12 additions & 11 deletions source/basic.tex
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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}
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
5 changes: 5 additions & 0 deletions source/classes.tex
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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}%
Expand Down
8 changes: 4 additions & 4 deletions source/expressions.tex
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand Down Expand Up @@ -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}).

Expand Down