tmp/tmpf6ezu9qx/{from.md → to.md}
RENAMED
|
@@ -0,0 +1,26 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
### The `constinit` specifier <a id="dcl.constinit">[[dcl.constinit]]</a>
|
| 2 |
+
|
| 3 |
+
The `constinit` specifier shall be applied only to a declaration of a
|
| 4 |
+
variable with static or thread storage duration. If the specifier is
|
| 5 |
+
applied to any declaration of a variable, it shall be applied to the
|
| 6 |
+
initializing declaration. No diagnostic is required if no `constinit`
|
| 7 |
+
declaration is reachable at the point of the initializing declaration.
|
| 8 |
+
|
| 9 |
+
If a variable declared with the `constinit` specifier has dynamic
|
| 10 |
+
initialization [[basic.start.dynamic]], the program is ill-formed.
|
| 11 |
+
|
| 12 |
+
[*Note 1*: The `constinit` specifier ensures that the variable is
|
| 13 |
+
initialized during static initialization
|
| 14 |
+
[[basic.start.static]]. — *end note*]
|
| 15 |
+
|
| 16 |
+
[*Example 1*:
|
| 17 |
+
|
| 18 |
+
``` cpp
|
| 19 |
+
const char * g() { return "dynamic initialization"; }
|
| 20 |
+
constexpr const char * f(bool p) { return p ? "constant initializer" : g(); }
|
| 21 |
+
constinit const char * c = f(true); // OK
|
| 22 |
+
constinit const char * d = f(false); // error
|
| 23 |
+
```
|
| 24 |
+
|
| 25 |
+
— *end example*]
|
| 26 |
+
|