From Jason Turner

[ptr.launder]

Diff to HTML by rtfpessoa

Files changed (1) hide show
  1. tmp/tmpkrlrq6jc/{from.md → to.md} +42 -0
tmp/tmpkrlrq6jc/{from.md → to.md} RENAMED
@@ -0,0 +1,42 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ### Pointer optimization barrier <a id="ptr.launder">[[ptr.launder]]</a>
2
+
3
+ ``` cpp
4
+ template <class T> constexpr T* launder(T* p) noexcept;
5
+ ```
6
+
7
+ *Requires:* `p` represents the address *A* of a byte in memory. An
8
+ object *X* that is within its lifetime ([[basic.life]]) and whose type
9
+ is similar ([[conv.qual]]) to `T` is located at the address *A*. All
10
+ bytes of storage that would be reachable through the result are
11
+ reachable through `p` (see below).
12
+
13
+ *Returns:* A value of type `T *` that points to `X`.
14
+
15
+ *Remarks:* An invocation of this function may be used in a core constant
16
+ expression whenever the value of its argument may be used in a core
17
+ constant expression. A byte of storage is reachable through a pointer
18
+ value that points to an object *Y* if it is within the storage occupied
19
+ by *Y*, an object that is pointer-interconvertible with *Y*, or the
20
+ immediately-enclosing array object if *Y* is an array element. The
21
+ program is ill-formed if `T` is a function type or cv `void`.
22
+
23
+ [*Note 1*: If a new object is created in storage occupied by an
24
+ existing object of the same type, a pointer to the original object can
25
+ be used to refer to the new object unless the type contains `const` or
26
+ reference members; in the latter cases, this function can be used to
27
+ obtain a usable pointer to the new object.
28
+ See  [[basic.life]]. — *end note*]
29
+
30
+ [*Example 1*:
31
+
32
+ ``` cpp
33
+ struct X { const int n; };
34
+ X *p = new X{3};
35
+ const int a = p->n;
36
+ new (p) X{5}; // p does not point to new object ([basic.life]) because X::n is const
37
+ const int b = p->n; // undefined behavior
38
+ const int c = std::launder(p)->n; // OK
39
+ ```
40
+
41
+ — *end example*]
42
+