File tree Expand file tree Collapse file tree 2 files changed +1
-43
lines changed
Expand file tree Collapse file tree 2 files changed +1
-43
lines changed Original file line number Diff line number Diff line change 22892289that is, if the object is not of the destructor's class type and
22902290not of a class derived from the destructor's class type (including when
22912291the destructor is invoked via a null pointer value), the program has
2292- undefined behavior\ubdef {class.dtor.not.class.type} .
2292+ undefined behavior.
22932293\begin {note }
22942294Invoking \keyword {delete} on a null pointer does not call the
22952295destructor; see \ref {expr.delete }.
Original file line number Diff line number Diff line change 11801180
11811181\rSec 2[ub.class.dtor]{Destructors}
11821182
1183- \pnum
1184- \ubxref {class.dtor.not.class.type } \\
1185- The invocation of a destructor is subject to the usual rules for
1186- member functions \iref {class.mfct }; that is, if the object is not of the destructor's class type and not of a class derived
1187- from the destructor's class type (including when the destructor is invoked via a null pointer value), the
1188- program has undefined behavior.
1189-
1190- \pnum
1191- \begin {example }
1192- \begin {codeblock }
1193- #include <new>
1194-
1195- struct X {};
1196-
1197- void f() {
1198- X *x = nullptr;
1199- x->~X(); // undefined behavior, invoked using a null pointer value
1200- }
1201-
1202- struct Y {};
1203- void h() {
1204- alignas(X) char buf[sizeof(X)];
1205- X *p = new (buf) X(); // use \tcode {buf[] }and initialize
1206-
1207- Y *yp = reinterpret_cast<Y *>(p);
1208- yp->Y::~Y(); // undefined behavior, destructor of \tcode {Y} called for object of type \tcode {X}
1209- }
1210-
1211- struct Base {
1212- virtual ~Base();
1213- };
1214- struct Derived : Base {};
1215-
1216- int k() {
1217- Base *b = new Base;
1218- Derived *d = static_cast<Derived *>(b);
1219- d->~Derived(); // undefined behavior, destructor of Derived call for object of
1220- // type \tcode {Base}
1221- }
1222- \end {codeblock }
1223- \end {example }
1224-
12251183\pnum
12261184\ubxref {class.dtor.no.longer.exists } \\
12271185Once a destructor is invoked for an object, the object no longer exists; the behavior is undefined if the
You can’t perform that action at this time.
0 commit comments