tmp/tmpsqrccbx5/{from.md → to.md}
RENAMED
|
@@ -27,21 +27,21 @@ Objects can contain other objects, called *subobjects*. A subobject can
|
|
| 27 |
be a *member subobject* [[class.mem]], a *base class subobject*
|
| 28 |
[[class.derived]], or an array element. An object that is not a
|
| 29 |
subobject of any other object is called a *complete object*. If an
|
| 30 |
object is created in storage associated with a member subobject or array
|
| 31 |
element *e* (which may or may not be within its lifetime), the created
|
| 32 |
-
object is a subobject of *e*’s containing object if
|
| 33 |
|
| 34 |
- the lifetime of *e*’s containing object has begun and not ended, and
|
| 35 |
- the storage for the new object exactly overlays the storage location
|
| 36 |
associated with *e*, and
|
| 37 |
- the new object is of the same type as *e* (ignoring cv-qualification).
|
| 38 |
|
| 39 |
If a complete object is created [[expr.new]] in storage associated with
|
| 40 |
another object *e* of type “array of N `unsigned char`” or of type
|
| 41 |
“array of N `std::byte`” [[cstddef.syn]], that array *provides storage*
|
| 42 |
-
for the created object if
|
| 43 |
|
| 44 |
- the lifetime of *e* has begun and not ended, and
|
| 45 |
- the storage for the new object fits entirely within *e*, and
|
| 46 |
- there is no array object that satisfies these constraints nested
|
| 47 |
within *e*.
|
|
@@ -51,10 +51,12 @@ another object, the lifetime of that object ends because its storage was
|
|
| 51 |
reused [[basic.life]]. — *end note*]
|
| 52 |
|
| 53 |
[*Example 1*:
|
| 54 |
|
| 55 |
``` cpp
|
|
|
|
|
|
|
| 56 |
template<typename ...T>
|
| 57 |
struct AlignedUnion {
|
| 58 |
alignas(T...) unsigned char data[max(sizeof(T)...)];
|
| 59 |
};
|
| 60 |
int f() {
|
|
@@ -65,20 +67,20 @@ int f() {
|
|
| 65 |
return *c + *d; // OK
|
| 66 |
}
|
| 67 |
|
| 68 |
struct A { unsigned char a[32]; };
|
| 69 |
struct B { unsigned char b[16]; };
|
| 70 |
-
A a;
|
| 71 |
B *b = new (a.a + 8) B; // a.a provides storage for *b
|
| 72 |
int *p = new (b->b + 4) int; // b->b provides storage for *p
|
| 73 |
// a.a does not provide storage for *p (directly),
|
| 74 |
// but *p is nested within a (see below)
|
| 75 |
```
|
| 76 |
|
| 77 |
— *end example*]
|
| 78 |
|
| 79 |
-
An object *a* is *nested within* another object *b* if
|
| 80 |
|
| 81 |
- *a* is a subobject of *b*, or
|
| 82 |
- *b* provides storage for *a*, or
|
| 83 |
- there exists an object *c* where *a* is nested within *c*, and *c* is
|
| 84 |
nested within *b*.
|
|
@@ -119,23 +121,45 @@ the circumstances under which the object has zero size are
|
|
| 119 |
object with nonzero size shall occupy one or more bytes of storage,
|
| 120 |
including every byte that is occupied in full or in part by any of its
|
| 121 |
subobjects. An object of trivially copyable or standard-layout type
|
| 122 |
[[basic.types.general]] shall occupy contiguous bytes of storage.
|
| 123 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 124 |
Unless an object is a bit-field or a subobject of zero size, the address
|
| 125 |
of that object is the address of the first byte it occupies. Two objects
|
| 126 |
with overlapping lifetimes that are not bit-fields may have the same
|
| 127 |
-
address if
|
| 128 |
-
|
| 129 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 130 |
|
| 131 |
[*Example 2*:
|
| 132 |
|
| 133 |
``` cpp
|
| 134 |
static const char test1 = 'x';
|
| 135 |
static const char test2 = 'x';
|
| 136 |
const bool b = &test1 != &test2; // always true
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 137 |
```
|
| 138 |
|
| 139 |
— *end example*]
|
| 140 |
|
| 141 |
The address of a non-bit-field subobject of zero size is the address of
|
|
@@ -144,16 +168,16 @@ subobject.
|
|
| 144 |
|
| 145 |
Some operations are described as *implicitly creating objects* within a
|
| 146 |
specified region of storage. For each operation that is specified as
|
| 147 |
implicitly creating objects, that operation implicitly creates and
|
| 148 |
starts the lifetime of zero or more objects of implicit-lifetime types
|
| 149 |
-
[[
|
| 150 |
-
would result in the program having defined behavior. If no such
|
| 151 |
-
objects would give the program defined behavior, the behavior of
|
| 152 |
-
program is undefined. If multiple such sets of objects would give
|
| 153 |
-
program defined behavior, it is unspecified which such set of
|
| 154 |
-
created.
|
| 155 |
|
| 156 |
[*Note 4*: Such operations do not start the lifetimes of subobjects of
|
| 157 |
such objects that are not themselves of implicit-lifetime
|
| 158 |
types. — *end note*]
|
| 159 |
|
|
@@ -186,20 +210,21 @@ X *make_x() {
|
|
| 186 |
}
|
| 187 |
```
|
| 188 |
|
| 189 |
— *end example*]
|
| 190 |
|
| 191 |
-
|
| 192 |
-
`std::byte` implicitly creates objects
|
| 193 |
-
occupied by the array.
|
| 194 |
|
| 195 |
[*Note 5*: The array object provides storage for these
|
| 196 |
objects. — *end note*]
|
| 197 |
|
| 198 |
-
|
| 199 |
-
or `operator new[]` implicitly
|
| 200 |
-
|
|
|
|
| 201 |
|
| 202 |
[*Note 6*: Some functions in the C++ standard library implicitly create
|
| 203 |
objects
|
| 204 |
-
[[obj.lifetime]], [[
|
| 205 |
|
|
|
|
| 27 |
be a *member subobject* [[class.mem]], a *base class subobject*
|
| 28 |
[[class.derived]], or an array element. An object that is not a
|
| 29 |
subobject of any other object is called a *complete object*. If an
|
| 30 |
object is created in storage associated with a member subobject or array
|
| 31 |
element *e* (which may or may not be within its lifetime), the created
|
| 32 |
+
object is a subobject of *e*’s containing object if
|
| 33 |
|
| 34 |
- the lifetime of *e*’s containing object has begun and not ended, and
|
| 35 |
- the storage for the new object exactly overlays the storage location
|
| 36 |
associated with *e*, and
|
| 37 |
- the new object is of the same type as *e* (ignoring cv-qualification).
|
| 38 |
|
| 39 |
If a complete object is created [[expr.new]] in storage associated with
|
| 40 |
another object *e* of type “array of N `unsigned char`” or of type
|
| 41 |
“array of N `std::byte`” [[cstddef.syn]], that array *provides storage*
|
| 42 |
+
for the created object if
|
| 43 |
|
| 44 |
- the lifetime of *e* has begun and not ended, and
|
| 45 |
- the storage for the new object fits entirely within *e*, and
|
| 46 |
- there is no array object that satisfies these constraints nested
|
| 47 |
within *e*.
|
|
|
|
| 51 |
reused [[basic.life]]. — *end note*]
|
| 52 |
|
| 53 |
[*Example 1*:
|
| 54 |
|
| 55 |
``` cpp
|
| 56 |
+
// assumes that sizeof(int) is equal to 4
|
| 57 |
+
|
| 58 |
template<typename ...T>
|
| 59 |
struct AlignedUnion {
|
| 60 |
alignas(T...) unsigned char data[max(sizeof(T)...)];
|
| 61 |
};
|
| 62 |
int f() {
|
|
|
|
| 67 |
return *c + *d; // OK
|
| 68 |
}
|
| 69 |
|
| 70 |
struct A { unsigned char a[32]; };
|
| 71 |
struct B { unsigned char b[16]; };
|
| 72 |
+
alignas(int) A a;
|
| 73 |
B *b = new (a.a + 8) B; // a.a provides storage for *b
|
| 74 |
int *p = new (b->b + 4) int; // b->b provides storage for *p
|
| 75 |
// a.a does not provide storage for *p (directly),
|
| 76 |
// but *p is nested within a (see below)
|
| 77 |
```
|
| 78 |
|
| 79 |
— *end example*]
|
| 80 |
|
| 81 |
+
An object *a* is *nested within* another object *b* if
|
| 82 |
|
| 83 |
- *a* is a subobject of *b*, or
|
| 84 |
- *b* provides storage for *a*, or
|
| 85 |
- there exists an object *c* where *a* is nested within *c*, and *c* is
|
| 86 |
nested within *b*.
|
|
|
|
| 121 |
object with nonzero size shall occupy one or more bytes of storage,
|
| 122 |
including every byte that is occupied in full or in part by any of its
|
| 123 |
subobjects. An object of trivially copyable or standard-layout type
|
| 124 |
[[basic.types.general]] shall occupy contiguous bytes of storage.
|
| 125 |
|
| 126 |
+
An object is a *potentially non-unique object* if it is
|
| 127 |
+
|
| 128 |
+
- a string literal object [[lex.string]],
|
| 129 |
+
- the backing array of an initializer list [[dcl.init.ref]], or
|
| 130 |
+
- the object introduced by a call to `std::meta::reflect_constant_array`
|
| 131 |
+
or `std::meta::reflect_constant_string` [[meta.define.static]], or
|
| 132 |
+
- a subobject thereof.
|
| 133 |
+
|
| 134 |
Unless an object is a bit-field or a subobject of zero size, the address
|
| 135 |
of that object is the address of the first byte it occupies. Two objects
|
| 136 |
with overlapping lifetimes that are not bit-fields may have the same
|
| 137 |
+
address if
|
| 138 |
+
|
| 139 |
+
- one is nested within the other,
|
| 140 |
+
- at least one is a subobject of zero size and they are not of similar
|
| 141 |
+
types [[conv.qual]], or
|
| 142 |
+
- they are both potentially non-unique objects;
|
| 143 |
+
|
| 144 |
+
otherwise, they have distinct addresses and occupy disjoint bytes of
|
| 145 |
+
storage.[^6]
|
| 146 |
|
| 147 |
[*Example 2*:
|
| 148 |
|
| 149 |
``` cpp
|
| 150 |
static const char test1 = 'x';
|
| 151 |
static const char test2 = 'x';
|
| 152 |
const bool b = &test1 != &test2; // always true
|
| 153 |
+
|
| 154 |
+
static const char (&r) [] = "x";
|
| 155 |
+
static const char *s = "x";
|
| 156 |
+
static std::initializer_list<char> il = { 'x' };
|
| 157 |
+
const bool b2 = r != il.begin(); // unspecified result
|
| 158 |
+
const bool b3 = r != s; // unspecified result
|
| 159 |
+
const bool b4 = il.begin() != &test1; // always true
|
| 160 |
+
const bool b5 = r != &test1; // always true
|
| 161 |
```
|
| 162 |
|
| 163 |
— *end example*]
|
| 164 |
|
| 165 |
The address of a non-bit-field subobject of zero size is the address of
|
|
|
|
| 168 |
|
| 169 |
Some operations are described as *implicitly creating objects* within a
|
| 170 |
specified region of storage. For each operation that is specified as
|
| 171 |
implicitly creating objects, that operation implicitly creates and
|
| 172 |
starts the lifetime of zero or more objects of implicit-lifetime types
|
| 173 |
+
[[term.implicit.lifetime.type]] in its specified region of storage if
|
| 174 |
+
doing so would result in the program having defined behavior. If no such
|
| 175 |
+
set of objects would give the program defined behavior, the behavior of
|
| 176 |
+
the program is undefined. If multiple such sets of objects would give
|
| 177 |
+
the program defined behavior, it is unspecified which such set of
|
| 178 |
+
objects is created.
|
| 179 |
|
| 180 |
[*Note 4*: Such operations do not start the lifetimes of subobjects of
|
| 181 |
such objects that are not themselves of implicit-lifetime
|
| 182 |
types. — *end note*]
|
| 183 |
|
|
|
|
| 210 |
}
|
| 211 |
```
|
| 212 |
|
| 213 |
— *end example*]
|
| 214 |
|
| 215 |
+
Except during constant evaluation, an operation that begins the lifetime
|
| 216 |
+
of an array of `unsigned char` or `std::byte` implicitly creates objects
|
| 217 |
+
within the region of storage occupied by the array.
|
| 218 |
|
| 219 |
[*Note 5*: The array object provides storage for these
|
| 220 |
objects. — *end note*]
|
| 221 |
|
| 222 |
+
Except during constant evaluation, any implicit or explicit invocation
|
| 223 |
+
of a function named `operator new` or `operator new[]` implicitly
|
| 224 |
+
creates objects in the returned region of storage and returns a pointer
|
| 225 |
+
to a suitable created object.
|
| 226 |
|
| 227 |
[*Note 6*: Some functions in the C++ standard library implicitly create
|
| 228 |
objects
|
| 229 |
+
[[obj.lifetime]], [[c.malloc]], [[mem.res.public]], [[bit.cast]], [[cstring.syn]]. — *end note*]
|
| 230 |
|