From Jason Turner

[dcl.constexpr]

Diff to HTML by rtfpessoa

Files changed (1) hide show
  1. tmp/tmpd5bw3ykt/{from.md → to.md} +20 -13
tmp/tmpd5bw3ykt/{from.md → to.md} RENAMED
@@ -1,12 +1,13 @@
1
  ### The `constexpr` and `consteval` specifiers <a id="dcl.constexpr">[[dcl.constexpr]]</a>
2
 
3
  The `constexpr` specifier shall be applied only to the definition of a
4
- variable or variable template or the declaration of a function or
5
- function template. The `consteval` specifier shall be applied only to
6
- the declaration of a function or function template. A function or static
7
- data member declared with the `constexpr` or `consteval` specifier is
 
8
  implicitly an inline function or variable [[dcl.inline]]. If any
9
  declaration of a function or function template has a `constexpr` or
10
  `consteval` specifier, then all its declarations shall contain the same
11
  specifier.
12
 
@@ -46,21 +47,18 @@ extern constexpr int memsz; // error: not a definition
46
  — *end example*]
47
 
48
  A `constexpr` or `consteval` specifier used in the declaration of a
49
  function declares that function to be a *constexpr function*.
50
 
51
- [*Note 3*: A function or constructor declared with the `consteval`
52
- specifier is an immediate function [[expr.const]]. — *end note*]
53
 
54
  A destructor, an allocation function, or a deallocation function shall
55
  not be declared with the `consteval` specifier.
56
 
57
- A function is *constexpr-suitable* if:
58
-
59
- - it is not a coroutine [[dcl.fct.def.coroutine]], and
60
- - if the function is a constructor or destructor, its class does not
61
- have any virtual base classes.
62
 
63
  Except for instantiated constexpr functions, non-templated constexpr
64
  functions shall be constexpr-suitable.
65
 
66
  [*Example 2*:
@@ -130,12 +128,11 @@ int bar(int x, int y) // error: redefinition of bar
130
 
131
  — *end example*]
132
 
133
  A `constexpr` specifier used in an object declaration declares the
134
  object as const. Such an object shall have literal type and shall be
135
- initialized. In any `constexpr` variable declaration, the
136
- full-expression of the initialization shall be a constant expression
137
  [[expr.const]]. A `constexpr` variable that is an object, as well as any
138
  temporary to which a `constexpr` reference is bound, shall have constant
139
  destruction.
140
 
141
  [*Example 4*:
@@ -144,9 +141,19 @@ destruction.
144
  struct pixel {
145
  int x, y;
146
  };
147
  constexpr pixel ur = { 1294, 1024 }; // OK
148
  constexpr pixel origin; // error: initializer missing
 
 
 
 
 
 
 
 
 
 
149
  ```
150
 
151
  — *end example*]
152
 
 
1
  ### The `constexpr` and `consteval` specifiers <a id="dcl.constexpr">[[dcl.constexpr]]</a>
2
 
3
  The `constexpr` specifier shall be applied only to the definition of a
4
+ variable or variable template, a structured binding declaration, or the
5
+ declaration of a function or function template. The `consteval`
6
+ specifier shall be applied only to the declaration of a function or
7
+ function template. A function or static data member declared with the
8
+ `constexpr` or `consteval` specifier on its first declaration is
9
  implicitly an inline function or variable [[dcl.inline]]. If any
10
  declaration of a function or function template has a `constexpr` or
11
  `consteval` specifier, then all its declarations shall contain the same
12
  specifier.
13
 
 
47
  — *end example*]
48
 
49
  A `constexpr` or `consteval` specifier used in the declaration of a
50
  function declares that function to be a *constexpr function*.
51
 
52
+ [*Note 3*: A function declared with the `consteval` specifier is an
53
+ immediate function [[expr.const]]. — *end note*]
54
 
55
  A destructor, an allocation function, or a deallocation function shall
56
  not be declared with the `consteval` specifier.
57
 
58
+ A function is *constexpr-suitable* if it is not a coroutine
59
+ [[dcl.fct.def.coroutine]].
 
 
 
60
 
61
  Except for instantiated constexpr functions, non-templated constexpr
62
  functions shall be constexpr-suitable.
63
 
64
  [*Example 2*:
 
128
 
129
  — *end example*]
130
 
131
  A `constexpr` specifier used in an object declaration declares the
132
  object as const. Such an object shall have literal type and shall be
133
+ initialized. A `constexpr` variable shall be constant-initializable
 
134
  [[expr.const]]. A `constexpr` variable that is an object, as well as any
135
  temporary to which a `constexpr` reference is bound, shall have constant
136
  destruction.
137
 
138
  [*Example 4*:
 
141
  struct pixel {
142
  int x, y;
143
  };
144
  constexpr pixel ur = { 1294, 1024 }; // OK
145
  constexpr pixel origin; // error: initializer missing
146
+
147
+ namespace N {
148
+ void f() {
149
+ int x;
150
+ constexpr int& ar = x; // OK
151
+ static constexpr int& sr = x; // error: x is not constexpr-representable
152
+ // at the point indicated below
153
+ }
154
+ // immediate scope here is that of N
155
+ }
156
  ```
157
 
158
  — *end example*]
159