From de62f6ec68304a571600e52c298df6eea6fc9719 Mon Sep 17 00:00:00 2001 From: Jens Maurer Date: Sun, 13 Apr 2025 22:11:01 +0200 Subject: [PATCH] Remove class.dtor.not.class.type --- source/classes.tex | 2 +- source/ub.tex | 42 ------------------------------------------ 2 files changed, 1 insertion(+), 43 deletions(-) diff --git a/source/classes.tex b/source/classes.tex index 140534569b..0fa61ee9d7 100644 --- a/source/classes.tex +++ b/source/classes.tex @@ -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}. diff --git a/source/ub.tex b/source/ub.tex index e67b430d6c..d3f3acf29b 100644 --- a/source/ub.tex +++ b/source/ub.tex @@ -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 - -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(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(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