File tree 2 files changed +1
-43
lines changed
2 files changed +1
-43
lines changed Original file line number Diff line number Diff line change 2289
2289
that is, if the object is not of the destructor's class type and
2290
2290
not of a class derived from the destructor's class type (including when
2291
2291
the destructor is invoked via a null pointer value), the program has
2292
- undefined behavior\ubdef {class.dtor.not.class.type} .
2292
+ undefined behavior.
2293
2293
\begin {note }
2294
2294
Invoking \keyword {delete} on a null pointer does not call the
2295
2295
destructor; see \ref {expr.delete }.
Original file line number Diff line number Diff line change 1180
1180
1181
1181
\rSec 2[ub.class.dtor]{Destructors}
1182
1182
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
-
1225
1183
\pnum
1226
1184
\ubxref {class.dtor.no.longer.exists } \\
1227
1185
Once 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