回答編集履歴
3
update
answer
CHANGED
@@ -27,4 +27,29 @@
|
|
27
27
|
|
28
28
|
> For an object under construction or destruction, [...]
|
29
29
|
> Otherwise, such a pointer refers to allocated storage [...]
|
30
|
-
> Indirection through such a pointer is permitted but [...]
|
30
|
+
> Indirection through such a pointer is permitted but [...]
|
31
|
+
|
32
|
+
Exampleの解釈としては:
|
33
|
+
```C++
|
34
|
+
void B::mutate() {
|
35
|
+
new (this) D2; // reuses storage — ends the lifetime of *this
|
36
|
+
f(); // undefined behavior
|
37
|
+
// this->f(); つまり非staticメンバ関数呼び出し
|
38
|
+
// 条件(6.2)に該当するためundefined behavior
|
39
|
+
... = this; // OK, this points to valid memory
|
40
|
+
// ポインタ値 this の利用はOK(Otherwise~の文)
|
41
|
+
}
|
42
|
+
|
43
|
+
void g() {
|
44
|
+
void* p = std::malloc(sizeof(D1) + sizeof(D2));
|
45
|
+
B* pb = new (p) D1;
|
46
|
+
pb->mutate();
|
47
|
+
*pb; // OK: pb points to valid memory
|
48
|
+
// 条件(6.1)~(6.5)いずれも該当せずOK(Indirection~の文)
|
49
|
+
void* q = pb; // OK: pb points to valid memory
|
50
|
+
// ポインタ値 pb をvoid*と扱うのはOK(Otherwise~の文)
|
51
|
+
pb->f(); // undefined behavior, lifetime of *pb has ended
|
52
|
+
// pb->f(); は非staticメンバ関数呼び出し
|
53
|
+
// 条件(6.2)に該当するためundefined behavior
|
54
|
+
}
|
55
|
+
```
|
2
refinement
answer
CHANGED
@@ -7,7 +7,7 @@
|
|
7
7
|
- 生成(construction)から破壊(destruction)されるまでの 生存期間(lifetime) では、一定のストレージ(storage)を占有します。
|
8
8
|
- 名前(name) を付けられます。("名無しのオブジェクト"もあります)
|
9
9
|
|
10
|
-
近い概念としては、「あるオブジェクト#1の生存期間(lifetime)が終了したあとに、同オブジェクト#1が占めていたストレージ上に
|
10
|
+
近い概念としては、「あるオブジェクト#1の生存期間(lifetime)が終了したあとに、同オブジェクト#1が占めていたストレージ上にオブジェクト#2が生成されている、その同ストレージへのポインタ」でしょうか。
|
11
11
|
|
12
12
|
----
|
13
13
|
|
1
update
answer
CHANGED
@@ -7,8 +7,6 @@
|
|
7
7
|
- 生成(construction)から破壊(destruction)されるまでの 生存期間(lifetime) では、一定のストレージ(storage)を占有します。
|
8
8
|
- 名前(name) を付けられます。("名無しのオブジェクト"もあります)
|
9
9
|
|
10
|
-
つまり「lifetime が終了し、かつ storage が他のオブジェクトによって再利用されたオブジェクト」はそもそも存在えしません。
|
11
|
-
|
12
10
|
近い概念としては、「あるオブジェクト#1の生存期間(lifetime)が終了したあとに、同オブジェクト#1が占めていたストレージ上に生成したオブジェクト#2を指すポインタ」でしょうか。
|
13
11
|
|
14
12
|
----
|
@@ -21,7 +19,7 @@
|
|
21
19
|
> "after the lifetime of an object has ended and before the storage which the object occupied is reused or released,"
|
22
20
|
>
|
23
21
|
> (主語)
|
24
|
-
>
|
22
|
+
> **any pointer that represents the address of the storage location** where the object will be or was located
|
25
23
|
> (述語)
|
26
24
|
> **may be used** but only in limited ways.
|
27
25
|
|