From Jason Turner

[dcl.init.general]

Diff to HTML by rtfpessoa

Files changed (1) hide show
  1. tmp/tmpzdd13k25/{from.md → to.md} +40 -36
tmp/tmpzdd13k25/{from.md → to.md} RENAMED
@@ -90,11 +90,13 @@ duration is described in  [[basic.start]] and 
90
  A declaration D of a variable with linkage shall not have an
91
  *initializer* if D inhabits a block scope.
92
 
93
  To *zero-initialize* an object or reference of type `T` means:
94
 
95
- - if `T` is a scalar type [[term.scalar.type]], the object is
 
 
96
  initialized to the value obtained by converting the integer literal
97
  `0` (zero) to `T`;[^5]
98
  - if `T` is a (possibly cv-qualified) non-union class type, its padding
99
  bits [[term.padding.bits]] are initialized to zero bits and each
100
  non-static data member, each non-virtual base class subobject, and, if
@@ -112,11 +114,14 @@ To *default-initialize* an object of type `T` means:
112
  are considered. The applicable constructors are enumerated
113
  [[over.match.ctor]], and the best one for the *initializer* `()` is
114
  chosen through overload resolution [[over.match]]. The constructor
115
  thus selected is called, with an empty argument list, to initialize
116
  the object.
117
- - If `T` is an array type, each element is default-initialized.
 
 
 
118
  - Otherwise, no initialization is performed.
119
 
120
  A class type `T` is *const-default-constructible* if
121
  default-initialization of `T` would invoke a user-provided constructor
122
  of `T` (not inherited from a base class) or if
@@ -131,37 +136,36 @@ of `T` (not inherited from a base class) or if
131
  member has a default member initializer, and
132
  - each potentially constructed base class of `T` is
133
  const-default-constructible.
134
 
135
  If a program calls for the default-initialization of an object of a
136
- const-qualified type `T`, `T` shall be a const-default-constructible
137
- class type or array thereof.
138
 
139
  To *value-initialize* an object of type `T` means:
140
 
141
- - if `T` is a (possibly cv-qualified) class type [[class]], then
142
- - if `T` has either no default constructor [[class.default.ctor]] or a
143
- default constructor that is user-provided or deleted, then the
144
- object is default-initialized;
145
- - otherwise, the object is zero-initialized and the semantic
146
- constraints for default-initialization are checked, and if `T` has a
147
- non-trivial default constructor, the object is default-initialized;
148
- - if `T` is an array type, then each element is value-initialized;
149
- - otherwise, the object is zero-initialized.
150
 
151
  A program that calls for default-initialization or value-initialization
152
  of an entity of reference type is ill-formed.
153
 
154
- [*Note 4*: For every object of static storage duration, static
155
  initialization [[basic.start.static]] is performed at program startup
156
  before any other initialization takes place. In some cases, additional
157
  initialization is done later. — *end note*]
158
 
159
  If no initializer is specified for an object, the object is
160
  default-initialized.
161
 
162
- If the entity being initialized does not have class type, the
163
  *expression-list* in a parenthesized initializer shall be a single
164
  expression.
165
 
166
  The initialization that occurs in the `=` form of a
167
  *brace-or-equal-initializer* or *condition* [[stmt.select]], as well as
@@ -183,14 +187,14 @@ The initialization that occurs
183
  - in the *braced-init-list* form of a *condition*
184
 
185
  is called *direct-initialization*.
186
 
187
  The semantics of initializers are as follows. The *destination type* is
188
- the type of the object or reference being initialized and the *source
189
- type* is the type of the initializer expression. If the initializer is
190
- not a single (possibly parenthesized) expression, the source type is not
191
- defined.
192
 
193
  - If the initializer is a (non-parenthesized) *braced-init-list* or is
194
  `=` *braced-init-list*, the object or reference is list-initialized
195
  [[dcl.init.list]].
196
  - If the destination type is a reference type, see  [[dcl.init.ref]].
@@ -205,35 +209,35 @@ defined.
205
  X a();
206
  ```
207
 
208
  is not the declaration of an object of class `X`, but the declaration
209
  of a function taking no arguments and returning an `X`. The form `()`
210
- is permitted in certain other initialization contexts
211
  [[expr.new]], [[expr.type.conv]], [[class.base.init]].
212
  — *end note*]
213
  - Otherwise, if the destination type is an array, the object is
214
- initialized as follows. Let x₁, …, xₖ be the elements of the
 
215
  *expression-list*. If the destination type is an array of unknown
216
  bound, it is defined as having k elements. Let n denote the array size
217
  after this potential adjustment. If k is greater than n, the program
218
  is ill-formed. Otherwise, the iᵗʰ array element is copy-initialized
219
  with xᵢ for each 1 ≤ i ≤ k, and value-initialized for each k < i ≤ n.
220
  For each 1 ≤ i < j ≤ n, every value computation and side effect
221
  associated with the initialization of the iᵗʰ element of the array is
222
  sequenced before those associated with the initialization of the jᵗʰ
223
  element.
224
- - Otherwise, if the destination type is a (possibly cv-qualified) class
225
- type:
226
  - If the initializer expression is a prvalue and the cv-unqualified
227
- version of the source type is the same class as the class of the
228
- destination, the initializer expression is used to initialize the
229
- destination object. \[*Example 2*: `T x = T(T(T()));`
230
- value-initializes `x`. — *end example*]
231
  - Otherwise, if the initialization is direct-initialization, or if it
232
  is copy-initialization where the cv-unqualified version of the
233
- source type is the same class as, or a derived class of, the class
234
- of the destination, constructors are considered. The applicable
235
  constructors are enumerated [[over.match.ctor]], and the best one is
236
  chosen through overload resolution [[over.match]]. Then:
237
  - If overload resolution is successful, the selected constructor is
238
  called to initialize the object, with the initializer expression
239
  or *expression-list* as its argument(s).
@@ -249,11 +253,11 @@ defined.
249
  value computation and side effect associated with the
250
  initialization of eᵢ is sequenced before those associated with the
251
  initialization of eⱼ.
252
  \[*Note 7*:
253
  By contrast with direct-list-initialization, narrowing conversions
254
- [[dcl.init.list]] are permitted, designators are not permitted, a
255
  temporary object bound to a reference does not have its lifetime
256
  extended [[class.temporary]], and there is no brace elision.
257
  \[*Example 3*:
258
  ``` cpp
259
  struct A {
@@ -297,16 +301,16 @@ defined.
297
  - Otherwise, if the initialization is direct-initialization, the source
298
  type is `std::nullptr_t`, and the destination type is `bool`, the
299
  initial value of the object being initialized is `false`.
300
  - Otherwise, the initial value of the object being initialized is the
301
  (possibly converted) value of the initializer expression. A standard
302
- conversion sequence [[conv]] will be used, if necessary, to convert
303
- the initializer expression to the cv-unqualified version of the
304
- destination type; no user-defined conversions are considered. If the
305
- conversion cannot be done, the initialization is ill-formed. When
306
- initializing a bit-field with a value that it cannot represent, the
307
- resulting value of the bit-field is *implementation-defined*.
308
  \[*Note 8*:
309
  An expression of type “*cv1* `T`” can initialize an object of type
310
  “*cv2* `T`” independently of the cv-qualifiers *cv1* and *cv2*.
311
  ``` cpp
312
  int a;
 
90
  A declaration D of a variable with linkage shall not have an
91
  *initializer* if D inhabits a block scope.
92
 
93
  To *zero-initialize* an object or reference of type `T` means:
94
 
95
+ - if `T` is `std::meta::info`, the object is initialized to a null
96
+ reflection value;
97
+ - if `T` is any other scalar type [[term.scalar.type]], the object is
98
  initialized to the value obtained by converting the integer literal
99
  `0` (zero) to `T`;[^5]
100
  - if `T` is a (possibly cv-qualified) non-union class type, its padding
101
  bits [[term.padding.bits]] are initialized to zero bits and each
102
  non-static data member, each non-virtual base class subobject, and, if
 
114
  are considered. The applicable constructors are enumerated
115
  [[over.match.ctor]], and the best one for the *initializer* `()` is
116
  chosen through overload resolution [[over.match]]. The constructor
117
  thus selected is called, with an empty argument list, to initialize
118
  the object.
119
+ - If `T` is an array type, the semantic constraints of
120
+ default-initializing a hypothetical element shall be met and each
121
+ element is default-initialized.
122
+ - If `T` is `std::meta::info`, the object is zero-initialized.
123
  - Otherwise, no initialization is performed.
124
 
125
  A class type `T` is *const-default-constructible* if
126
  default-initialization of `T` would invoke a user-provided constructor
127
  of `T` (not inherited from a base class) or if
 
136
  member has a default member initializer, and
137
  - each potentially constructed base class of `T` is
138
  const-default-constructible.
139
 
140
  If a program calls for the default-initialization of an object of a
141
+ const-qualified type `T`, `T` shall be `std::meta::info` or a
142
+ const-default-constructible class type, or array thereof.
143
 
144
  To *value-initialize* an object of type `T` means:
145
 
146
+ - If `T` is a (possibly cv-qualified) class type [[class]], then let `C`
147
+ be the constructor selected to default-initialize the object, if any.
148
+ If `C` is not user-provided, the object is first zero-initialized. In
149
+ all cases, the object is then default-initialized.
150
+ - If `T` is an array type, the semantic constraints of
151
+ value-initializing a hypothetical element shall be met and each
152
+ element is value-initialized.
153
+ - Otherwise, the object is zero-initialized.
 
154
 
155
  A program that calls for default-initialization or value-initialization
156
  of an entity of reference type is ill-formed.
157
 
158
+ [*Note 4*: For every object with static storage duration, static
159
  initialization [[basic.start.static]] is performed at program startup
160
  before any other initialization takes place. In some cases, additional
161
  initialization is done later. — *end note*]
162
 
163
  If no initializer is specified for an object, the object is
164
  default-initialized.
165
 
166
+ If the entity being initialized does not have class or array type, the
167
  *expression-list* in a parenthesized initializer shall be a single
168
  expression.
169
 
170
  The initialization that occurs in the `=` form of a
171
  *brace-or-equal-initializer* or *condition* [[stmt.select]], as well as
 
187
  - in the *braced-init-list* form of a *condition*
188
 
189
  is called *direct-initialization*.
190
 
191
  The semantics of initializers are as follows. The *destination type* is
192
+ the cv-unqualified type of the object or reference being initialized and
193
+ the *source type* is the type of the initializer expression. If the
194
+ initializer is not a single (possibly parenthesized) expression, the
195
+ source type is not defined.
196
 
197
  - If the initializer is a (non-parenthesized) *braced-init-list* or is
198
  `=` *braced-init-list*, the object or reference is list-initialized
199
  [[dcl.init.list]].
200
  - If the destination type is a reference type, see  [[dcl.init.ref]].
 
209
  X a();
210
  ```
211
 
212
  is not the declaration of an object of class `X`, but the declaration
213
  of a function taking no arguments and returning an `X`. The form `()`
214
+ can appear in certain other initialization contexts
215
  [[expr.new]], [[expr.type.conv]], [[class.base.init]].
216
  — *end note*]
217
  - Otherwise, if the destination type is an array, the object is
218
+ initialized as follows. The *initializer* shall be of the form `(`
219
+ *expression-list* `)`. Let x₁, …, xₖ be the elements of the
220
  *expression-list*. If the destination type is an array of unknown
221
  bound, it is defined as having k elements. Let n denote the array size
222
  after this potential adjustment. If k is greater than n, the program
223
  is ill-formed. Otherwise, the iᵗʰ array element is copy-initialized
224
  with xᵢ for each 1 ≤ i ≤ k, and value-initialized for each k < i ≤ n.
225
  For each 1 ≤ i < j ≤ n, every value computation and side effect
226
  associated with the initialization of the iᵗʰ element of the array is
227
  sequenced before those associated with the initialization of the jᵗʰ
228
  element.
229
+ - Otherwise, if the destination type is a class type:
 
230
  - If the initializer expression is a prvalue and the cv-unqualified
231
+ version of the source type is the same as the destination type, the
232
+ initializer expression is used to initialize the destination object.
233
+ \[*Example 2*: `T x = T(T(T()));` value-initializes `x`
234
+ [[basic.lval]], [[expr.type.conv]]. — *end example*]
235
  - Otherwise, if the initialization is direct-initialization, or if it
236
  is copy-initialization where the cv-unqualified version of the
237
+ source type is the same as or is derived from the class of the
238
+ destination type, constructors are considered. The applicable
239
  constructors are enumerated [[over.match.ctor]], and the best one is
240
  chosen through overload resolution [[over.match]]. Then:
241
  - If overload resolution is successful, the selected constructor is
242
  called to initialize the object, with the initializer expression
243
  or *expression-list* as its argument(s).
 
253
  value computation and side effect associated with the
254
  initialization of eᵢ is sequenced before those associated with the
255
  initialization of eⱼ.
256
  \[*Note 7*:
257
  By contrast with direct-list-initialization, narrowing conversions
258
+ [[dcl.init.list]] can appear, designators are not permitted, a
259
  temporary object bound to a reference does not have its lifetime
260
  extended [[class.temporary]], and there is no brace elision.
261
  \[*Example 3*:
262
  ``` cpp
263
  struct A {
 
301
  - Otherwise, if the initialization is direct-initialization, the source
302
  type is `std::nullptr_t`, and the destination type is `bool`, the
303
  initial value of the object being initialized is `false`.
304
  - Otherwise, the initial value of the object being initialized is the
305
  (possibly converted) value of the initializer expression. A standard
306
+ conversion sequence [[conv]] is used to convert the initializer
307
+ expression to a prvalue of the destination type; no user-defined
308
+ conversions are considered. If the conversion cannot be done, the
309
+ initialization is ill-formed. When initializing a bit-field with a
310
+ value that it cannot represent, the resulting value of the bit-field
311
+ is *implementation-defined*.
312
  \[*Note 8*:
313
  An expression of type “*cv1* `T`” can initialize an object of type
314
  “*cv2* `T`” independently of the cv-qualifiers *cv1* and *cv2*.
315
  ``` cpp
316
  int a;