From Jason Turner

[class.ctor]

Diff to HTML by rtfpessoa

Files changed (1) hide show
  1. tmp/tmp_8dyt6bj/{from.md → to.md} +64 -66
tmp/tmp_8dyt6bj/{from.md → to.md} RENAMED
@@ -56,12 +56,10 @@ cprint( complex(7.8,1.2) );
56
  — *end example*]
57
 
58
  [*Note 2*: For initialization of objects of class type see 
59
  [[class.init]]. — *end note*]
60
 
61
- An object created in this way is unnamed.
62
-
63
  [*Note 3*: [[class.temporary]] describes the lifetime of temporary
64
  objects. — *end note*]
65
 
66
  [*Note 4*: Explicit constructor calls do not yield lvalues, see 
67
  [[basic.lval]]. — *end note*]
@@ -87,79 +85,81 @@ A constructor shall not have an explicit object parameter [[dcl.fct]].
87
  #### Default constructors <a id="class.default.ctor">[[class.default.ctor]]</a>
88
 
89
  A *default constructor* for a class `X` is a constructor of class `X`
90
  for which each parameter that is not a function parameter pack has a
91
  default argument (including the case of a constructor with no
92
- parameters). If there is no user-declared constructor for class `X`, a
93
- non-explicit constructor having no parameters is implicitly declared as
94
- defaulted [[dcl.fct.def]]. An implicitly-declared default constructor is
95
- an inline public member of its class.
 
96
 
97
- A defaulted default constructor for class `X` is defined as deleted if:
98
 
99
- - `X` is a union that has a variant member with a non-trivial default
100
- constructor and no variant member of `X` has a default member
101
- initializer,
102
- - `X` is a non-union class that has a variant member `M` with a
103
- non-trivial default constructor and no variant member of the anonymous
104
- union containing `M` has a default member initializer,
105
  - any non-static data member with no default member initializer
106
  [[class.mem]] is of reference type,
107
- - any non-variant non-static data member of const-qualified type (or
108
- array thereof) with no *brace-or-equal-initializer* is not
109
- const-default-constructible [[dcl.init]],
110
- - `X` is a union and all of its variant members are of const-qualified
111
- type (or array thereof),
112
- - `X` is a non-union class and all members of any anonymous union member
113
- are of const-qualified type (or array thereof),
114
- - any potentially constructed subobject, except for a non-static data
115
- member with a *brace-or-equal-initializer*, has class type `M` (or
116
- array thereof) and either `M` has no default constructor or overload
117
  resolution [[over.match]] as applied to find `M`’s corresponding
118
- constructor results in an ambiguity or in a function that is deleted
119
- or inaccessible from the defaulted default constructor, or
120
- - any potentially constructed subobject has a type with a destructor
121
- that is deleted or inaccessible from the defaulted default
122
- constructor.
 
123
 
124
- A default constructor is *trivial* if it is not user-provided and if:
 
125
 
126
- - its class has no virtual functions [[class.virtual]] and no virtual
127
- base classes [[class.mi]], and
128
- - no non-static data member of its class has a default member
129
- initializer [[class.mem]], and
130
- - all the direct base classes of its class have trivial default
131
- constructors, and
132
- - for all the non-static data members of its class that are of class
133
- type (or array thereof), each such class has a trivial default
134
- constructor.
135
 
136
  Otherwise, the default constructor is *non-trivial*.
137
 
138
- An implicitly-defined [[dcl.fct.def.default]] default constructor
139
- performs the set of initializations of the class that would be performed
140
- by a user-written default constructor for that class with no
141
- *ctor-initializer* [[class.base.init]] and an empty
 
 
 
 
 
 
 
 
 
142
  *compound-statement*. If that user-written default constructor would be
143
- ill-formed, the program is ill-formed. If that user-written default
144
- constructor would be constexpr-suitable [[dcl.constexpr]], the
145
- implicitly-defined default constructor is `constexpr`. Before the
146
- defaulted default constructor for a class is implicitly defined, all the
147
- non-user-provided default constructors for its base classes and its
148
- non-static data members are implicitly defined.
149
 
150
- [*Note 1*: An implicitly-declared default constructor has an exception
151
  specification [[except.spec]]. An explicitly-defaulted definition might
152
  have an implicit exception specification, see 
153
  [[dcl.fct.def]]. — *end note*]
154
 
155
- [*Note 2*: A default constructor is implicitly invoked to initialize a
156
  class object when no initializer is specified [[dcl.init.general]]. Such
157
- a default constructor is required to be accessible
158
  [[class.access]]. — *end note*]
159
 
160
- [*Note 3*: [[class.base.init]] describes the order in which
161
  constructors for base classes and non-static data members are called and
162
  describes how arguments can be specified for the calls to these
163
  constructors. — *end note*]
164
 
165
  #### Copy/move constructors <a id="class.copy.ctor">[[class.copy.ctor]]</a>
@@ -287,11 +287,11 @@ form
287
  X::X(const X&)
288
  ```
289
 
290
  if each potentially constructed subobject of a class type `M` (or array
291
  thereof) has a copy constructor whose first parameter is of type `const`
292
- `M&` or `const` `volatile` `M&`.[^3]
293
 
294
  Otherwise, the implicitly-declared copy constructor will have the form
295
 
296
  ``` cpp
297
  X::X(X&)
@@ -319,29 +319,28 @@ X::X(X&&)
319
 
320
  An implicitly-declared copy/move constructor is an inline public member
321
  of its class. A defaulted copy/move constructor for a class `X` is
322
  defined as deleted [[dcl.fct.def.delete]] if `X` has:
323
 
324
- - a potentially constructed subobject of type `M` (or array thereof)
325
- that cannot be copied/moved because overload resolution
326
  [[over.match]], as applied to find `M`’s corresponding constructor,
327
- results in an ambiguity or a function that is deleted or inaccessible
328
- from the defaulted constructor,
329
- - a variant member whose corresponding constructor as selected by
330
- overload resolution is non-trivial,
331
- - any potentially constructed subobject of a type with a destructor that
332
- is deleted or inaccessible from the defaulted constructor, or,
333
  - for the copy constructor, a non-static data member of rvalue reference
334
  type.
335
 
336
  [*Note 4*: A defaulted move constructor that is defined as deleted is
337
  ignored by overload resolution [[over.match]], [[over.over]]. Such a
338
  constructor would otherwise interfere with initialization from an rvalue
339
  which can use the copy constructor instead. — *end note*]
340
 
341
  A copy/move constructor for class `X` is trivial if it is not
342
- user-provided and if:
343
 
344
  - class `X` has no virtual functions [[class.virtual]] and no virtual
345
  base classes [[class.mi]], and
346
  - the constructor selected to copy/move each direct base class subobject
347
  is trivial, and
@@ -353,13 +352,12 @@ otherwise the copy/move constructor is *non-trivial*.
353
 
354
  [*Note 5*: The copy/move constructor is implicitly defined even if the
355
  implementation elided its odr-use
356
  [[term.odr.use]], [[class.temporary]]. — *end note*]
357
 
358
- If an implicitly-defined [[dcl.fct.def.default]] constructor would be
359
- constexpr-suitable [[dcl.constexpr]], the implicitly-defined constructor
360
- is `constexpr`.
361
 
362
  Before the defaulted copy/move constructor for a class is implicitly
363
  defined, all non-user-provided copy/move constructors for its
364
  potentially constructed subobjects are implicitly defined.
365
 
@@ -368,11 +366,11 @@ exception specification [[except.spec]]. — *end note*]
368
 
369
  The implicitly-defined copy/move constructor for a non-union class `X`
370
  performs a memberwise copy/move of its bases and members.
371
 
372
  [*Note 7*: Default member initializers of non-static data members are
373
- ignored. See also the example in  [[class.base.init]]. — *end note*]
374
 
375
  The order of initialization is the same as the order of initialization
376
  of bases and members in a user-defined constructor (see 
377
  [[class.base.init]]). Let `x` be either the parameter of the constructor
378
  or, for the move constructor, an xvalue referring to the parameter. Each
 
56
  — *end example*]
57
 
58
  [*Note 2*: For initialization of objects of class type see 
59
  [[class.init]]. — *end note*]
60
 
 
 
61
  [*Note 3*: [[class.temporary]] describes the lifetime of temporary
62
  objects. — *end note*]
63
 
64
  [*Note 4*: Explicit constructor calls do not yield lvalues, see 
65
  [[basic.lval]]. — *end note*]
 
85
  #### Default constructors <a id="class.default.ctor">[[class.default.ctor]]</a>
86
 
87
  A *default constructor* for a class `X` is a constructor of class `X`
88
  for which each parameter that is not a function parameter pack has a
89
  default argument (including the case of a constructor with no
90
+ parameters). If there is no user-declared constructor or constructor
91
+ template for class `X`, a non-explicit constructor having no parameters
92
+ is implicitly declared as defaulted [[dcl.fct.def]]. An
93
+ implicitly-declared default constructor is an inline public member of
94
+ its class.
95
 
96
+ A defaulted default constructor for class `X` is defined as deleted if
97
 
 
 
 
 
 
 
98
  - any non-static data member with no default member initializer
99
  [[class.mem]] is of reference type,
100
+ - `X` is a non-union class and any non-variant non-static data member of
101
+ const-qualified type (or possibly multidimensional array thereof) with
102
+ no *brace-or-equal-initializer* is not const-default-constructible
103
+ [[dcl.init]],
104
+ - any non-variant potentially constructed subobject, except for a
105
+ non-static data member with a *brace-or-equal-initializer*, has class
106
+ type `M` (or possibly multidimensional array thereof) and overload
 
 
 
107
  resolution [[over.match]] as applied to find `M`’s corresponding
108
+ constructor does not result in a usable candidate
109
+ [[over.match.general]], or
110
+ - any potentially constructed subobject S has class type `M` (or
111
+ possibly multidimensional array thereof), `M` has a destructor that is
112
+ deleted or inaccessible from the defaulted default constructor, and
113
+ either S is non-variant or S has a default member initializer.
114
 
115
+ A default constructor for a class `X` is *trivial* if it is not
116
+ user-provided and if
117
 
118
+ - `X` has no virtual functions [[class.virtual]] and no virtual base
119
+ classes [[class.mi]], and
120
+ - no non-static data member of `X` has a default member initializer
121
+ [[class.mem]], and
122
+ - all the direct base classes of `X` have trivial default constructors,
123
+ and
124
+ - either `X` is a union or for all the non-variant non-static data
125
+ members of `X` that are of class type (or array thereof), each such
126
+ class has a trivial default constructor.
127
 
128
  Otherwise, the default constructor is *non-trivial*.
129
 
130
+ If a default constructor of a union-like class `X` is trivial, then for
131
+ each union `U` that is either `X` or an anonymous union member of `X`,
132
+ if the first variant member, if any, of `U` has implicit-lifetime type
133
+ [[basic.types.general]], the default constructor of `X` begins the
134
+ lifetime of that member if it is not the active member of its union.
135
+
136
+ [*Note 1*: It is already the active member if `U` was
137
+ value-initialized. — *end note*]
138
+
139
+ Otherwise, an implicitly-defined [[dcl.fct.def.default]] default
140
+ constructor performs the set of initializations of the class that would
141
+ be performed by a user-written default constructor for that class with
142
+ no *ctor-initializer* [[class.base.init]] and an empty
143
  *compound-statement*. If that user-written default constructor would be
144
+ ill-formed, the program is ill-formed. The implicitly-defined default
145
+ constructor is `constexpr`. Before the defaulted default constructor for
146
+ a class is implicitly defined, all the non-user-provided default
147
+ constructors for its base classes and its non-static data members are
148
+ implicitly defined.
 
149
 
150
+ [*Note 2*: An implicitly-declared default constructor has an exception
151
  specification [[except.spec]]. An explicitly-defaulted definition might
152
  have an implicit exception specification, see 
153
  [[dcl.fct.def]]. — *end note*]
154
 
155
+ [*Note 3*: A default constructor is implicitly invoked to initialize a
156
  class object when no initializer is specified [[dcl.init.general]]. Such
157
+ a default constructor needs to be accessible
158
  [[class.access]]. — *end note*]
159
 
160
+ [*Note 4*: [[class.base.init]] describes the order in which
161
  constructors for base classes and non-static data members are called and
162
  describes how arguments can be specified for the calls to these
163
  constructors. — *end note*]
164
 
165
  #### Copy/move constructors <a id="class.copy.ctor">[[class.copy.ctor]]</a>
 
287
  X::X(const X&)
288
  ```
289
 
290
  if each potentially constructed subobject of a class type `M` (or array
291
  thereof) has a copy constructor whose first parameter is of type `const`
292
+ `M&` or `const` `volatile` `M&`.[^2]
293
 
294
  Otherwise, the implicitly-declared copy constructor will have the form
295
 
296
  ``` cpp
297
  X::X(X&)
 
319
 
320
  An implicitly-declared copy/move constructor is an inline public member
321
  of its class. A defaulted copy/move constructor for a class `X` is
322
  defined as deleted [[dcl.fct.def.delete]] if `X` has:
323
 
324
+ - a potentially constructed subobject of type `M` (or possibly
325
+ multidimensional array thereof) for which overload resolution
326
  [[over.match]], as applied to find `M`’s corresponding constructor,
327
+ either does not result in a usable candidate [[over.match.general]]
328
+ or, in the case of a variant member, selects a non-trivial function,
329
+ - any potentially constructed subobject of class type `M` (or possibly
330
+ multidimensional array thereof) where `M` has a destructor that is
331
+ deleted or inaccessible from the defaulted constructor, or,
 
332
  - for the copy constructor, a non-static data member of rvalue reference
333
  type.
334
 
335
  [*Note 4*: A defaulted move constructor that is defined as deleted is
336
  ignored by overload resolution [[over.match]], [[over.over]]. Such a
337
  constructor would otherwise interfere with initialization from an rvalue
338
  which can use the copy constructor instead. — *end note*]
339
 
340
  A copy/move constructor for class `X` is trivial if it is not
341
+ user-provided and if
342
 
343
  - class `X` has no virtual functions [[class.virtual]] and no virtual
344
  base classes [[class.mi]], and
345
  - the constructor selected to copy/move each direct base class subobject
346
  is trivial, and
 
352
 
353
  [*Note 5*: The copy/move constructor is implicitly defined even if the
354
  implementation elided its odr-use
355
  [[term.odr.use]], [[class.temporary]]. — *end note*]
356
 
357
+ The implicitly-defined [[dcl.fct.def.default]] constructor is
358
+ `constexpr`.
 
359
 
360
  Before the defaulted copy/move constructor for a class is implicitly
361
  defined, all non-user-provided copy/move constructors for its
362
  potentially constructed subobjects are implicitly defined.
363
 
 
366
 
367
  The implicitly-defined copy/move constructor for a non-union class `X`
368
  performs a memberwise copy/move of its bases and members.
369
 
370
  [*Note 7*: Default member initializers of non-static data members are
371
+ ignored. — *end note*]
372
 
373
  The order of initialization is the same as the order of initialization
374
  of bases and members in a user-defined constructor (see 
375
  [[class.base.init]]). Let `x` be either the parameter of the constructor
376
  or, for the move constructor, an xvalue referring to the parameter. Each