From Jason Turner

[class.default.ctor]

Diff to HTML by rtfpessoa

Files changed (1) hide show
  1. tmp/tmpvrjpoygu/{from.md → to.md} +52 -50
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 for class `X`, a
7
- non-explicit constructor having no parameters is implicitly declared as
8
- defaulted [[dcl.fct.def]]. An implicitly-declared default constructor is
9
- an inline public member of its class.
 
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 const-qualified type (or
22
- array thereof) with no *brace-or-equal-initializer* is not
23
- const-default-constructible [[dcl.init]],
24
- - `X` is a union and all of its variant members are of const-qualified
25
- type (or array thereof),
26
- - `X` is a non-union class and all members of any anonymous union member
27
- are of const-qualified type (or array thereof),
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 results in an ambiguity or in a function that is deleted
33
- or inaccessible from the defaulted default constructor, or
34
- - any potentially constructed subobject has a type with a destructor
35
- that is deleted or inaccessible from the defaulted default
36
- constructor.
 
37
 
38
- A default constructor is *trivial* if it is not user-provided and if:
 
39
 
40
- - its class has no virtual functions [[class.virtual]] and no virtual
41
- base classes [[class.mi]], and
42
- - no non-static data member of its class has a default member
43
- initializer [[class.mem]], and
44
- - all the direct base classes of its class have trivial default
45
- constructors, and
46
- - for all the non-static data members of its class that are of class
47
- type (or array thereof), each such class has a trivial default
48
- constructor.
49
 
50
  Otherwise, the default constructor is *non-trivial*.
51
 
52
- An implicitly-defined [[dcl.fct.def.default]] default constructor
53
- performs the set of initializations of the class that would be performed
54
- by a user-written default constructor for that class with no
55
- *ctor-initializer* [[class.base.init]] and an empty
 
 
 
 
 
 
 
 
 
56
  *compound-statement*. If that user-written default constructor would be
57
- ill-formed, the program is ill-formed. If that user-written default
58
- constructor would be constexpr-suitable [[dcl.constexpr]], the
59
- implicitly-defined default constructor is `constexpr`. Before the
60
- defaulted default constructor for a class is implicitly defined, all the
61
- non-user-provided default constructors for its base classes and its
62
- non-static data members are implicitly defined.
63
 
64
- [*Note 1*: An implicitly-declared default constructor has an exception
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 2*: A default constructor is implicitly invoked to initialize a
70
  class object when no initializer is specified [[dcl.init.general]]. Such
71
- a default constructor is required to be accessible
72
  [[class.access]]. — *end note*]
73
 
74
- [*Note 3*: [[class.base.init]] describes the order in which
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