tmp/tmpvrjpoygu/{from.md → to.md}
RENAMED
|
@@ -1,78 +1,80 @@
|
|
| 1 |
#### Default constructors <a id="class.default.ctor">[[class.default.ctor]]</a>
|
| 2 |
|
| 3 |
A *default constructor* for a class `X` is a constructor of class `X`
|
| 4 |
for which each parameter that is not a function parameter pack has a
|
| 5 |
default argument (including the case of a constructor with no
|
| 6 |
-
parameters). If there is no user-declared constructor
|
| 7 |
-
non-explicit constructor having no parameters
|
| 8 |
-
defaulted [[dcl.fct.def]]. An
|
| 9 |
-
an inline public member of
|
|
|
|
| 10 |
|
| 11 |
-
A defaulted default constructor for class `X` is defined as deleted if
|
| 12 |
|
| 13 |
-
- `X` is a union that has a variant member with a non-trivial default
|
| 14 |
-
constructor and no variant member of `X` has a default member
|
| 15 |
-
initializer,
|
| 16 |
-
- `X` is a non-union class that has a variant member `M` with a
|
| 17 |
-
non-trivial default constructor and no variant member of the anonymous
|
| 18 |
-
union containing `M` has a default member initializer,
|
| 19 |
- any non-static data member with no default member initializer
|
| 20 |
[[class.mem]] is of reference type,
|
| 21 |
-
- any non-variant non-static data member of
|
| 22 |
-
|
| 23 |
-
const-default-constructible
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
-
|
| 27 |
-
|
| 28 |
-
- any potentially constructed subobject, except for a non-static data
|
| 29 |
-
member with a *brace-or-equal-initializer*, has class type `M` (or
|
| 30 |
-
array thereof) and either `M` has no default constructor or overload
|
| 31 |
resolution [[over.match]] as applied to find `M`’s corresponding
|
| 32 |
-
constructor
|
| 33 |
-
|
| 34 |
-
- any potentially constructed subobject has
|
| 35 |
-
|
| 36 |
-
constructor
|
|
|
|
| 37 |
|
| 38 |
-
A default constructor is *trivial* if it is not
|
|
|
|
| 39 |
|
| 40 |
-
-
|
| 41 |
-
|
| 42 |
-
- no non-static data member of
|
| 43 |
-
|
| 44 |
-
- all the direct base classes of
|
| 45 |
-
|
| 46 |
-
-
|
| 47 |
-
type (or array thereof), each such
|
| 48 |
-
constructor.
|
| 49 |
|
| 50 |
Otherwise, the default constructor is *non-trivial*.
|
| 51 |
|
| 52 |
-
|
| 53 |
-
|
| 54 |
-
|
| 55 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 56 |
*compound-statement*. If that user-written default constructor would be
|
| 57 |
-
ill-formed, the program is ill-formed.
|
| 58 |
-
constructor
|
| 59 |
-
|
| 60 |
-
|
| 61 |
-
|
| 62 |
-
non-static data members are implicitly defined.
|
| 63 |
|
| 64 |
-
[*Note
|
| 65 |
specification [[except.spec]]. An explicitly-defaulted definition might
|
| 66 |
have an implicit exception specification, see
|
| 67 |
[[dcl.fct.def]]. — *end note*]
|
| 68 |
|
| 69 |
-
[*Note
|
| 70 |
class object when no initializer is specified [[dcl.init.general]]. Such
|
| 71 |
-
a default constructor
|
| 72 |
[[class.access]]. — *end note*]
|
| 73 |
|
| 74 |
-
[*Note
|
| 75 |
constructors for base classes and non-static data members are called and
|
| 76 |
describes how arguments can be specified for the calls to these
|
| 77 |
constructors. — *end note*]
|
| 78 |
|
|
|
|
| 1 |
#### Default constructors <a id="class.default.ctor">[[class.default.ctor]]</a>
|
| 2 |
|
| 3 |
A *default constructor* for a class `X` is a constructor of class `X`
|
| 4 |
for which each parameter that is not a function parameter pack has a
|
| 5 |
default argument (including the case of a constructor with no
|
| 6 |
+
parameters). If there is no user-declared constructor or constructor
|
| 7 |
+
template for class `X`, a non-explicit constructor having no parameters
|
| 8 |
+
is implicitly declared as defaulted [[dcl.fct.def]]. An
|
| 9 |
+
implicitly-declared default constructor is an inline public member of
|
| 10 |
+
its class.
|
| 11 |
|
| 12 |
+
A defaulted default constructor for class `X` is defined as deleted if
|
| 13 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 14 |
- any non-static data member with no default member initializer
|
| 15 |
[[class.mem]] is of reference type,
|
| 16 |
+
- `X` is a non-union class and any non-variant non-static data member of
|
| 17 |
+
const-qualified type (or possibly multidimensional array thereof) with
|
| 18 |
+
no *brace-or-equal-initializer* is not const-default-constructible
|
| 19 |
+
[[dcl.init]],
|
| 20 |
+
- any non-variant potentially constructed subobject, except for a
|
| 21 |
+
non-static data member with a *brace-or-equal-initializer*, has class
|
| 22 |
+
type `M` (or possibly multidimensional array thereof) and overload
|
|
|
|
|
|
|
|
|
|
| 23 |
resolution [[over.match]] as applied to find `M`’s corresponding
|
| 24 |
+
constructor does not result in a usable candidate
|
| 25 |
+
[[over.match.general]], or
|
| 26 |
+
- any potentially constructed subobject S has class type `M` (or
|
| 27 |
+
possibly multidimensional array thereof), `M` has a destructor that is
|
| 28 |
+
deleted or inaccessible from the defaulted default constructor, and
|
| 29 |
+
either S is non-variant or S has a default member initializer.
|
| 30 |
|
| 31 |
+
A default constructor for a class `X` is *trivial* if it is not
|
| 32 |
+
user-provided and if
|
| 33 |
|
| 34 |
+
- `X` has no virtual functions [[class.virtual]] and no virtual base
|
| 35 |
+
classes [[class.mi]], and
|
| 36 |
+
- no non-static data member of `X` has a default member initializer
|
| 37 |
+
[[class.mem]], and
|
| 38 |
+
- all the direct base classes of `X` have trivial default constructors,
|
| 39 |
+
and
|
| 40 |
+
- either `X` is a union or for all the non-variant non-static data
|
| 41 |
+
members of `X` that are of class type (or array thereof), each such
|
| 42 |
+
class has a trivial default constructor.
|
| 43 |
|
| 44 |
Otherwise, the default constructor is *non-trivial*.
|
| 45 |
|
| 46 |
+
If a default constructor of a union-like class `X` is trivial, then for
|
| 47 |
+
each union `U` that is either `X` or an anonymous union member of `X`,
|
| 48 |
+
if the first variant member, if any, of `U` has implicit-lifetime type
|
| 49 |
+
[[basic.types.general]], the default constructor of `X` begins the
|
| 50 |
+
lifetime of that member if it is not the active member of its union.
|
| 51 |
+
|
| 52 |
+
[*Note 1*: It is already the active member if `U` was
|
| 53 |
+
value-initialized. — *end note*]
|
| 54 |
+
|
| 55 |
+
Otherwise, an implicitly-defined [[dcl.fct.def.default]] default
|
| 56 |
+
constructor performs the set of initializations of the class that would
|
| 57 |
+
be performed by a user-written default constructor for that class with
|
| 58 |
+
no *ctor-initializer* [[class.base.init]] and an empty
|
| 59 |
*compound-statement*. If that user-written default constructor would be
|
| 60 |
+
ill-formed, the program is ill-formed. The implicitly-defined default
|
| 61 |
+
constructor is `constexpr`. Before the defaulted default constructor for
|
| 62 |
+
a class is implicitly defined, all the non-user-provided default
|
| 63 |
+
constructors for its base classes and its non-static data members are
|
| 64 |
+
implicitly defined.
|
|
|
|
| 65 |
|
| 66 |
+
[*Note 2*: An implicitly-declared default constructor has an exception
|
| 67 |
specification [[except.spec]]. An explicitly-defaulted definition might
|
| 68 |
have an implicit exception specification, see
|
| 69 |
[[dcl.fct.def]]. — *end note*]
|
| 70 |
|
| 71 |
+
[*Note 3*: A default constructor is implicitly invoked to initialize a
|
| 72 |
class object when no initializer is specified [[dcl.init.general]]. Such
|
| 73 |
+
a default constructor needs to be accessible
|
| 74 |
[[class.access]]. — *end note*]
|
| 75 |
|
| 76 |
+
[*Note 4*: [[class.base.init]] describes the order in which
|
| 77 |
constructors for base classes and non-static data members are called and
|
| 78 |
describes how arguments can be specified for the calls to these
|
| 79 |
constructors. — *end note*]
|
| 80 |
|