From Jason Turner

[class.default.ctor]

Diff to HTML by rtfpessoa

Files changed (1) hide show
  1. tmp/tmp2f9f0ojx/{from.md → to.md} +87 -0
tmp/tmp2f9f0ojx/{from.md → to.md} RENAMED
@@ -0,0 +1,87 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ A default constructor that is defaulted and not defined as deleted is
53
+ *implicitly defined* when it is odr-used [[basic.def.odr]] to create an
54
+ object of its class type [[intro.object]], when it is needed for
55
+ constant evaluation [[expr.const]], or when it is explicitly defaulted
56
+ after its first declaration. The implicitly-defined default constructor
57
+ performs the set of initializations of the class that would be performed
58
+ by a user-written default constructor for that class with no
59
+ *ctor-initializer* [[class.base.init]] and an empty
60
+ *compound-statement*. If that user-written default constructor would be
61
+ ill-formed, the program is ill-formed. If that user-written default
62
+ constructor would satisfy the requirements of a constexpr constructor
63
+ [[dcl.constexpr]], the implicitly-defined default constructor is
64
+ `constexpr`. Before the defaulted default constructor for a class is
65
+ implicitly defined, all the non-user-provided default constructors for
66
+ its base classes and its non-static data members are implicitly defined.
67
+
68
+ [*Note 1*: An implicitly-declared default constructor has an exception
69
+ specification [[except.spec]]. An explicitly-defaulted definition might
70
+ have an implicit exception specification, see 
71
+ [[dcl.fct.def]]. — *end note*]
72
+
73
+ Default constructors are called implicitly to create class objects of
74
+ static, thread, or automatic storage duration ([[basic.stc.static]],
75
+ [[basic.stc.thread]], [[basic.stc.auto]]) defined without an initializer
76
+ [[dcl.init]], are called to create class objects of dynamic storage
77
+ duration [[basic.stc.dynamic]] created by a *new-expression* in which
78
+ the *new-initializer* is omitted [[expr.new]], or are called when the
79
+ explicit type conversion syntax [[expr.type.conv]] is used. A program is
80
+ ill-formed if the default constructor for an object is implicitly used
81
+ and the constructor is not accessible [[class.access]].
82
+
83
+ [*Note 2*: [[class.base.init]] describes the order in which
84
+ constructors for base classes and non-static data members are called and
85
+ describes how arguments can be specified for the calls to these
86
+ constructors. — *end note*]
87
+