Skip to content

Remove class.dtor.not.class.type #7835

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: ub-ifndr
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
2 changes: 1 addition & 1 deletion source/classes.tex
Original file line number Diff line number Diff line change
Expand Up @@ -2289,7 +2289,7 @@
that is, if the object is not of the destructor's class type and
not of a class derived from the destructor's class type (including when
the destructor is invoked via a null pointer value), the program has
undefined behavior\ubdef{class.dtor.not.class.type}.
undefined behavior.
\begin{note}
Invoking \keyword{delete} on a null pointer does not call the
destructor; see \ref{expr.delete}.
Expand Down
42 changes: 0 additions & 42 deletions source/ub.tex
Original file line number Diff line number Diff line change
Expand Up @@ -1180,48 +1180,6 @@

\rSec2[ub.class.dtor]{Destructors}

\pnum
\ubxref{class.dtor.not.class.type} \\
The invocation of a destructor is subject to the usual rules for
member functions \iref{class.mfct}; that is, if the object is not of the destructor's class type and not of a class derived
from the destructor's class type (including when the destructor is invoked via a null pointer value), the
program has undefined behavior.

\pnum
\begin{example}
\begin{codeblock}
#include <new>

struct X {};

void f() {
X *x = nullptr;
x->~X(); // undefined behavior, invoked using a null pointer value
}

struct Y {};
void h() {
alignas(X) char buf[sizeof(X)];
X *p = new (buf) X(); // use \tcode{buf[] }and initialize

Y *yp = reinterpret_cast<Y *>(p);
yp->Y::~Y(); // undefined behavior, destructor of \tcode{Y} called for object of type \tcode{X}
}

struct Base {
virtual ~Base();
};
struct Derived : Base {};

int k() {
Base *b = new Base;
Derived *d = static_cast<Derived *>(b);
d->~Derived(); // undefined behavior, destructor of Derived call for object of
// type \tcode{Base}
}
\end{codeblock}
\end{example}

\pnum
\ubxref{class.dtor.no.longer.exists} \\
Once a destructor is invoked for an object, the object no longer exists; the behavior is undefined if the
Expand Down