tmp/tmpqh2shcna/{from.md → to.md}
RENAMED
|
@@ -44,31 +44,32 @@ the destructor or if a *delete-expression* ([[expr.delete]]) is not
|
|
| 44 |
used to release the storage, the destructor shall not be implicitly
|
| 45 |
called and any program that depends on the side effects produced by the
|
| 46 |
destructor has undefined behavior.
|
| 47 |
|
| 48 |
Before the lifetime of an object has started but after the storage which
|
| 49 |
-
the object will occupy has been allocated[^
|
| 50 |
an object has ended and before the storage which the object occupied is
|
| 51 |
reused or released, any pointer that refers to the storage location
|
| 52 |
where the object will be or was located may be used but only in limited
|
| 53 |
ways. For an object under construction or destruction, see
|
| 54 |
[[class.cdtor]]. Otherwise, such a pointer refers to allocated storage (
|
| 55 |
[[basic.stc.dynamic.deallocation]]), and using the pointer as if the
|
| 56 |
-
pointer were of type `void*`, is well-defined.
|
| 57 |
-
|
| 58 |
-
as described below. The program has undefined behavior if:
|
| 59 |
|
| 60 |
- the object will be or was of a class type with a non-trivial
|
| 61 |
destructor and the pointer is used as the operand of a
|
| 62 |
*delete-expression*,
|
| 63 |
- the pointer is used to access a non-static data member or call a
|
| 64 |
non-static member function of the object, or
|
| 65 |
- the pointer is implicitly converted ([[conv.ptr]]) to a pointer to a
|
| 66 |
-
base class
|
| 67 |
- the pointer is used as the operand of a `static_cast` (
|
| 68 |
-
[[expr.static.cast]])
|
| 69 |
-
`void
|
|
|
|
| 70 |
- the pointer is used as the operand of a `dynamic_cast` (
|
| 71 |
[[expr.dynamic.cast]]).
|
| 72 |
``` cpp
|
| 73 |
#include <cstdlib>
|
| 74 |
|
|
@@ -110,15 +111,12 @@ undefined behavior if:
|
|
| 110 |
|
| 111 |
- an lvalue-to-rvalue conversion ([[conv.lval]]) is applied to such a
|
| 112 |
glvalue,
|
| 113 |
- the glvalue is used to access a non-static data member or call a
|
| 114 |
non-static member function of the object, or
|
| 115 |
-
- the glvalue is
|
| 116 |
-
|
| 117 |
-
- the glvalue is used as the operand of a `static_cast` (
|
| 118 |
-
[[expr.static.cast]]) except when the conversion is ultimately to *cv*
|
| 119 |
-
`char&` or *cv* `unsigned` `char&`, or
|
| 120 |
- the glvalue is used as the operand of a `dynamic_cast` (
|
| 121 |
[[expr.dynamic.cast]]) or as the operand of `typeid`.
|
| 122 |
|
| 123 |
If, after the lifetime of an object has ended and before the storage
|
| 124 |
which the object occupied is reused or released, a new object is created
|
|
@@ -161,11 +159,11 @@ started, can be used to manipulate the new object, if:
|
|
| 161 |
```
|
| 162 |
|
| 163 |
If a program ends the lifetime of an object of type `T` with static (
|
| 164 |
[[basic.stc.static]]), thread ([[basic.stc.thread]]), or automatic (
|
| 165 |
[[basic.stc.auto]]) storage duration and if `T` has a non-trivial
|
| 166 |
-
destructor,[^
|
| 167 |
type occupies that same storage location when the implicit destructor
|
| 168 |
call takes place; otherwise the behavior of the program is undefined.
|
| 169 |
This is true even if the block is exited with an exception.
|
| 170 |
|
| 171 |
``` cpp
|
|
|
|
| 44 |
used to release the storage, the destructor shall not be implicitly
|
| 45 |
called and any program that depends on the side effects produced by the
|
| 46 |
destructor has undefined behavior.
|
| 47 |
|
| 48 |
Before the lifetime of an object has started but after the storage which
|
| 49 |
+
the object will occupy has been allocated[^16] or, after the lifetime of
|
| 50 |
an object has ended and before the storage which the object occupied is
|
| 51 |
reused or released, any pointer that refers to the storage location
|
| 52 |
where the object will be or was located may be used but only in limited
|
| 53 |
ways. For an object under construction or destruction, see
|
| 54 |
[[class.cdtor]]. Otherwise, such a pointer refers to allocated storage (
|
| 55 |
[[basic.stc.dynamic.deallocation]]), and using the pointer as if the
|
| 56 |
+
pointer were of type `void*`, is well-defined. Indirection through such
|
| 57 |
+
a pointer is permitted but the resulting lvalue may only be used in
|
| 58 |
+
limited ways, as described below. The program has undefined behavior if:
|
| 59 |
|
| 60 |
- the object will be or was of a class type with a non-trivial
|
| 61 |
destructor and the pointer is used as the operand of a
|
| 62 |
*delete-expression*,
|
| 63 |
- the pointer is used to access a non-static data member or call a
|
| 64 |
non-static member function of the object, or
|
| 65 |
- the pointer is implicitly converted ([[conv.ptr]]) to a pointer to a
|
| 66 |
+
virtual base class, or
|
| 67 |
- the pointer is used as the operand of a `static_cast` (
|
| 68 |
+
[[expr.static.cast]]), except when the conversion is to pointer to
|
| 69 |
+
*cv* `void`, or to pointer to *cv* `void` and subsequently to pointer
|
| 70 |
+
to either *cv* `char` or *cv* `unsigned char`, or
|
| 71 |
- the pointer is used as the operand of a `dynamic_cast` (
|
| 72 |
[[expr.dynamic.cast]]).
|
| 73 |
``` cpp
|
| 74 |
#include <cstdlib>
|
| 75 |
|
|
|
|
| 111 |
|
| 112 |
- an lvalue-to-rvalue conversion ([[conv.lval]]) is applied to such a
|
| 113 |
glvalue,
|
| 114 |
- the glvalue is used to access a non-static data member or call a
|
| 115 |
non-static member function of the object, or
|
| 116 |
+
- the glvalue is bound to a reference to a virtual base class (
|
| 117 |
+
[[dcl.init.ref]]), or
|
|
|
|
|
|
|
|
|
|
| 118 |
- the glvalue is used as the operand of a `dynamic_cast` (
|
| 119 |
[[expr.dynamic.cast]]) or as the operand of `typeid`.
|
| 120 |
|
| 121 |
If, after the lifetime of an object has ended and before the storage
|
| 122 |
which the object occupied is reused or released, a new object is created
|
|
|
|
| 159 |
```
|
| 160 |
|
| 161 |
If a program ends the lifetime of an object of type `T` with static (
|
| 162 |
[[basic.stc.static]]), thread ([[basic.stc.thread]]), or automatic (
|
| 163 |
[[basic.stc.auto]]) storage duration and if `T` has a non-trivial
|
| 164 |
+
destructor,[^17] the program must ensure that an object of the original
|
| 165 |
type occupies that same storage location when the implicit destructor
|
| 166 |
call takes place; otherwise the behavior of the program is undefined.
|
| 167 |
This is true even if the block is exited with an exception.
|
| 168 |
|
| 169 |
``` cpp
|