From Jason Turner

[class.ctor]

Diff to HTML by rtfpessoa

Files changed (1) hide show
  1. tmp/tmp1ge3kb9n/{from.md → to.md} +40 -34
tmp/tmp1ge3kb9n/{from.md → to.md} RENAMED
@@ -1,17 +1,34 @@
1
  ## Constructors <a id="class.ctor">[[class.ctor]]</a>
2
 
3
- Constructors do not have names. A special declarator syntax is used to
4
- declare or define the constructor. The syntax uses:
5
 
6
- - an optional *decl-specifier-seq* in which each *decl-specifier* is
7
- either a *function-specifier* or `constexpr`,
8
- - the constructor’s class name, and
9
- - a parameter list
10
 
11
- in that order. In such a declaration, optional parentheses around the
12
- constructor class name are ignored.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
13
 
14
  ``` cpp
15
  struct S {
16
  S(); // declares the constructor
17
  };
@@ -24,21 +41,15 @@ constructors do not have names, they are never found during name lookup;
24
  however an explicit type conversion using the functional notation (
25
  [[expr.type.conv]]) will cause a constructor to be called to initialize
26
  an object. For initialization of objects of class type see 
27
  [[class.init]].
28
 
29
- A *typedef-name* shall not be used as the *class-name* in the
30
- *declarator-id* for a constructor declaration.
31
-
32
- A constructor shall not be `virtual` ([[class.virtual]]) or `static` (
33
- [[class.static]]). A constructor can be invoked for a `const`,
34
- `volatile` or `const` `volatile` object. A constructor shall not be
35
- declared `const`, `volatile`, or `const` `volatile` ([[class.this]]).
36
- `const` and `volatile` semantics ([[dcl.type.cv]]) are not applied on
37
- an object under construction. They come into effect when the constructor
38
- for the most derived object ([[intro.object]]) ends. A constructor
39
- shall not be declared with a *ref-qualifier*.
40
 
41
  A *default* constructor for a class `X` is a constructor of class `X`
42
  that can be called without an argument. If there is no user-declared
43
  constructor for class `X`, a constructor having no parameters is
44
  implicitly declared as defaulted ([[dcl.fct.def]]). An
@@ -55,19 +66,19 @@ as deleted if:
55
  user-provided default constructor,
56
  - `X` is a union and all of its variant members are of const-qualified
57
  type (or array thereof),
58
  - `X` is a non-union class and all members of any anonymous union member
59
  are of const-qualified type (or array thereof),
60
- - any direct or virtual base class, or non-static data member with no
61
- *brace-or-equal-initializer*, has class type `M` (or array thereof)
62
- and either `M` has no default constructor or overload resolution (
63
- [[over.match]]) as applied to `M`’s default constructor results in an
64
- ambiguity or in a function that is deleted or inaccessible from the
65
- defaulted default constructor, or
66
- - any direct or virtual base class or non-static data member has a type
67
- with a destructor that is deleted or inaccessible from the defaulted
68
- default constructor.
69
 
70
  A default constructor is trivial if it is not user-provided and if:
71
 
72
  - its class has no virtual functions ([[class.virtual]]) and no virtual
73
  base classes ([[class.mi]]), and
@@ -113,16 +124,11 @@ accessible (Clause  [[class.access]]).
113
 
114
  [[class.base.init]] describes the order in which constructors for base
115
  classes and non-static data members are called and describes how
116
  arguments can be specified for the calls to these constructors.
117
 
118
- A copy constructor ([[class.copy]]) is used to copy objects of class
119
- type. A move constructor ([[class.copy]]) is used to move the contents
120
- of objects of class type.
121
-
122
- No return type (not even `void`) shall be specified for a constructor. A
123
- `return` statement in the body of a constructor shall not specify a
124
  return value. The address of a constructor shall not be taken.
125
 
126
  A functional notation type conversion ([[expr.type.conv]]) can be used
127
  to create new objects of its type. The syntax looks like an explicit
128
  call of the constructor.
 
1
  ## Constructors <a id="class.ctor">[[class.ctor]]</a>
2
 
3
+ Constructors do not have names. A declaration of a constructor uses a
4
+ function declarator ([[dcl.fct]]) of the form
5
 
6
+ ``` bnf
7
+ ptr-declarator '(' parameter-declaration-clause ')' exception-specificationₒₚₜ attribute-specifier-seqₒₚₜ
8
+ ```
 
9
 
10
+ where the *ptr-declarator* consists solely of an *id-expression*, an
11
+ optional *attribute-specifier-seq*, and optional surrounding
12
+ parentheses, and the *id-expression* has one of the following forms:
13
+
14
+ - in a *member-declaration* that belongs to the *member-specification*
15
+ of a class but is not a friend declaration ([[class.friend]]), the
16
+ *id-expression* is the injected-class-name (Clause  [[class]]) of the
17
+ immediately-enclosing class;
18
+ - in a *member-declaration* that belongs to the *member-specification*
19
+ of a class template but is not a friend declaration, the
20
+ *id-expression* is a *class-name* that names the current
21
+ instantiation ([[temp.dep.type]]) of the immediately-enclosing class
22
+ template; or
23
+ - in a declaration at namespace scope or in a friend declaration, the
24
+ *id-expression* is a *qualified-id* that names a constructor (
25
+ [[class.qual]]).
26
+
27
+ The *class-name* shall not be a *typedef-name*. In a constructor
28
+ declaration, each *decl-specifier* in the optional *decl-specifier-seq*
29
+ shall be `friend`, `inline`, `explicit`, or `constexpr`.
30
 
31
  ``` cpp
32
  struct S {
33
  S(); // declares the constructor
34
  };
 
41
  however an explicit type conversion using the functional notation (
42
  [[expr.type.conv]]) will cause a constructor to be called to initialize
43
  an object. For initialization of objects of class type see 
44
  [[class.init]].
45
 
46
+ A constructor can be invoked for a `const`, `volatile` or `const`
47
+ `volatile` object. `const` and `volatile` semantics ([[dcl.type.cv]])
48
+ are not applied on an object under construction. They come into effect
49
+ when the constructor for the most derived object ([[intro.object]])
50
+ ends.
 
 
 
 
 
 
51
 
52
  A *default* constructor for a class `X` is a constructor of class `X`
53
  that can be called without an argument. If there is no user-declared
54
  constructor for class `X`, a constructor having no parameters is
55
  implicitly declared as defaulted ([[dcl.fct.def]]). An
 
66
  user-provided default constructor,
67
  - `X` is a union and all of its variant members are of const-qualified
68
  type (or array thereof),
69
  - `X` is a non-union class and all members of any anonymous union member
70
  are of const-qualified type (or array thereof),
71
+ - any potentially constructed subobject, except for a non-static data
72
+ member with a *brace-or-equal-initializer*, has class type `M` (or
73
+ array thereof) and either `M` has no default constructor or overload
74
+ resolution ([[over.match]]) as applied to `M`’s default constructor
75
+ results in an ambiguity or in a function that is deleted or
76
+ inaccessible from the defaulted default constructor, or
77
+ - any potentially constructed subobject has a type with a destructor
78
+ that is deleted or inaccessible from the defaulted default
79
+ constructor.
80
 
81
  A default constructor is trivial if it is not user-provided and if:
82
 
83
  - its class has no virtual functions ([[class.virtual]]) and no virtual
84
  base classes ([[class.mi]]), and
 
124
 
125
  [[class.base.init]] describes the order in which constructors for base
126
  classes and non-static data members are called and describes how
127
  arguments can be specified for the calls to these constructors.
128
 
129
+ A `return` statement in the body of a constructor shall not specify a
 
 
 
 
 
130
  return value. The address of a constructor shall not be taken.
131
 
132
  A functional notation type conversion ([[expr.type.conv]]) can be used
133
  to create new objects of its type. The syntax looks like an explicit
134
  call of the constructor.