From Jason Turner

[dcl.spec.auto.general]

Diff to HTML by rtfpessoa

Files changed (1) hide show
  1. tmp/tmpufaplyxi/{from.md → to.md} +56 -29
tmp/tmpufaplyxi/{from.md → to.md} RENAMED
@@ -5,64 +5,76 @@ placeholder-type-specifier:
5
  type-constraintₒₚₜ auto
6
  type-constraintₒₚₜ decltype '(' auto ')'
7
  ```
8
 
9
  A *placeholder-type-specifier* designates a placeholder type that will
10
- be replaced later by deduction from an initializer.
11
 
12
- A *placeholder-type-specifier* of the form *type-constraint*ₒₚₜ `auto`
13
- can be used as a *decl-specifier* of the *decl-specifier-seq* of a
14
- *parameter-declaration* of a function declaration or *lambda-expression*
15
- and, if it is not the `auto` *type-specifier* introducing a
16
- *trailing-return-type* (see below), is a *generic parameter type
17
- placeholder* of the function declaration or *lambda-expression*.
 
 
 
 
 
 
 
18
 
19
  [*Note 1*: Having a generic parameter type placeholder signifies that
20
  the function is an abbreviated function template [[dcl.fct]] or the
21
  lambda is a generic lambda [[expr.prim.lambda]]. — *end note*]
22
 
23
- A placeholder type can appear with a function declarator in the
24
- *decl-specifier-seq*, *type-specifier-seq*, *conversion-function-id*, or
25
- *trailing-return-type*, in any context where such a declarator is valid.
26
- If the function declarator includes a *trailing-return-type*
27
- [[dcl.fct]], that *trailing-return-type* specifies the declared return
28
- type of the function. Otherwise, the function declarator shall declare a
29
- function. If the declared return type of the function contains a
30
- placeholder type, the return type of the function is deduced from
31
- non-discarded `return` statements, if any, in the body of the function
32
- [[stmt.if]].
33
 
34
  The type of a variable declared using a placeholder type is deduced from
35
  its initializer. This use is allowed in an initializing declaration
36
  [[dcl.init]] of a variable. The placeholder type shall appear as one of
37
- the *decl-specifier*s in the *decl-specifier-seq* and the
38
- *decl-specifier-seq* shall be followed by one or more *declarator*s,
39
- each of which shall be followed by a non-empty *initializer*.
 
 
40
 
41
  [*Example 1*:
42
 
43
  ``` cpp
44
  auto x = 5; // OK, x has type int
45
  const auto *v = &x, u = 6; // OK, v has type const int*, u has type const int
46
  static auto y = 0.0; // OK, y has type double
47
  auto int r; // error: auto is not a storage-class-specifier
48
  auto f() -> int; // OK, f returns int
49
  auto g() { return 0.0; } // OK, g returns double
 
50
  auto h(); // OK, h's return type will be deduced when it is defined
51
  ```
52
 
53
  — *end example*]
54
 
55
  The `auto` *type-specifier* can also be used to introduce a structured
56
  binding declaration [[dcl.struct.bind]].
57
 
58
- A placeholder type can also be used in the *type-specifier-seq* in the
59
- *new-type-id* or *type-id* of a *new-expression* [[expr.new]] and as a
60
- *decl-specifier* of the *parameter-declaration*'s *decl-specifier-seq*
61
- in a *template-parameter* [[temp.param]]. The `auto` *type-specifier*
62
- can also be used as the *simple-type-specifier* in an explicit type
63
- conversion (functional notation) [[expr.type.conv]].
 
 
 
 
64
 
65
  A program that uses a placeholder type in a context not explicitly
66
  allowed in [[dcl.spec.auto]] is ill-formed.
67
 
68
  If the *init-declarator-list* contains more than one *init-declarator*,
@@ -126,10 +138,25 @@ auto sum(int i) {
126
  }
127
  ```
128
 
129
  — *end example*]
130
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
131
  Return type deduction for a templated function with a placeholder in its
132
  declared type occurs when the definition is instantiated even if the
133
  function body contains a `return` statement with a non-type-dependent
134
  operand.
135
 
@@ -137,11 +164,11 @@ operand.
137
  template will cause an implicit instantiation. Any errors that arise
138
  from this instantiation are not in the immediate context of the function
139
  type and can result in the program being ill-formed
140
  [[temp.deduct]]. — *end note*]
141
 
142
- [*Example 5*:
143
 
144
  ``` cpp
145
  template <class T> auto f(T t) { return t; } // return type deduced at instantiation time
146
  typedef decltype(f(1)) fint_t; // instantiates f<int> to deduce return type
147
  template<class T> auto f(T* t) { return *t; }
@@ -154,11 +181,11 @@ void g() { int (*p)(int*) = &f; } // instantiates both fs to deter
154
  If a function or function template F has a declared return type that
155
  uses a placeholder type, redeclarations or specializations of F shall
156
  use that placeholder type, not a deduced type; otherwise, they shall not
157
  use a placeholder type.
158
 
159
- [*Example 6*:
160
 
161
  ``` cpp
162
  auto f();
163
  auto f() { return 42; } // return type is int
164
  auto f(); // OK
@@ -199,11 +226,11 @@ shall not be a coroutine [[dcl.fct.def.coroutine]].
199
  An explicit instantiation declaration [[temp.explicit]] does not cause
200
  the instantiation of an entity declared using a placeholder type, but it
201
  also does not prevent that entity from being instantiated as needed to
202
  determine its type.
203
 
204
- [*Example 7*:
205
 
206
  ``` cpp
207
  template <typename T> auto f(T t) { return t; }
208
  extern template auto f(int); // does not instantiate f<int>
209
  int (*p)(int) = f; // instantiates f<int> to determine its return type, but an explicit
 
5
  type-constraintₒₚₜ auto
6
  type-constraintₒₚₜ decltype '(' auto ')'
7
  ```
8
 
9
  A *placeholder-type-specifier* designates a placeholder type that will
10
+ be replaced later, typically by deduction from an initializer.
11
 
12
+ The type of a *parameter-declaration* of a
13
+
14
+ - function declaration [[dcl.fct]],
15
+ - *lambda-expression* [[expr.prim.lambda]], or
16
+ - *template-parameter* [[temp.param]]
17
+
18
+ can be declared using a *placeholder-type-specifier* of the form
19
+ *type-constraint*ₒₚₜ `auto`. The placeholder type shall appear as one
20
+ of the *decl-specifier*s in the *decl-specifier-seq* or as one of the
21
+ *type-specifier*s in a *trailing-return-type* that specifies the type
22
+ that replaces such a *decl-specifier* (see below); the placeholder type
23
+ is a *generic parameter type placeholder* of the function declaration,
24
+ *lambda-expression*, or *template-parameter*, respectively.
25
 
26
  [*Note 1*: Having a generic parameter type placeholder signifies that
27
  the function is an abbreviated function template [[dcl.fct]] or the
28
  lambda is a generic lambda [[expr.prim.lambda]]. — *end note*]
29
 
30
+ A placeholder type can appear in the *decl-specifier-seq* for a function
31
+ declarator that includes a *trailing-return-type* [[dcl.fct]].
32
+
33
+ A placeholder type can appear in the *decl-specifier-seq* or
34
+ *type-specifier-seq* in the declared return type of a function
35
+ declarator that declares a function; the return type of the function is
36
+ deduced from non-discarded `return` statements, if any, in the body of
37
+ the function [[stmt.if]].
 
 
38
 
39
  The type of a variable declared using a placeholder type is deduced from
40
  its initializer. This use is allowed in an initializing declaration
41
  [[dcl.init]] of a variable. The placeholder type shall appear as one of
42
+ the *decl-specifier*s in the *decl-specifier-seq* or as one of the
43
+ *type-specifier*s in a *trailing-return-type* that specifies the type
44
+ that replaces such a *decl-specifier*; the *decl-specifier-seq* shall be
45
+ followed by one or more *declarator*s, each of which shall be followed
46
+ by a non-empty *initializer*.
47
 
48
  [*Example 1*:
49
 
50
  ``` cpp
51
  auto x = 5; // OK, x has type int
52
  const auto *v = &x, u = 6; // OK, v has type const int*, u has type const int
53
  static auto y = 0.0; // OK, y has type double
54
  auto int r; // error: auto is not a storage-class-specifier
55
  auto f() -> int; // OK, f returns int
56
  auto g() { return 0.0; } // OK, g returns double
57
+ auto (*fp)() -> auto = f; // OK
58
  auto h(); // OK, h's return type will be deduced when it is defined
59
  ```
60
 
61
  — *end example*]
62
 
63
  The `auto` *type-specifier* can also be used to introduce a structured
64
  binding declaration [[dcl.struct.bind]].
65
 
66
+ A placeholder type can also be used in the *type-specifier-seq* of the
67
+ *new-type-id* or in the *type-id* of a *new-expression* [[expr.new]]. In
68
+ such a *type-id*, the placeholder type shall appear as one of the
69
+ *type-specifier*s in the *type-specifier-seq* or as one of the
70
+ *type-specifier*s in a *trailing-return-type* that specifies the type
71
+ that replaces such a *type-specifier*.
72
+
73
+ The `auto` *type-specifier* can also be used as the
74
+ *simple-type-specifier* in an explicit type conversion (functional
75
+ notation) [[expr.type.conv]].
76
 
77
  A program that uses a placeholder type in a context not explicitly
78
  allowed in [[dcl.spec.auto]] is ill-formed.
79
 
80
  If the *init-declarator-list* contains more than one *init-declarator*,
 
138
  }
139
  ```
140
 
141
  — *end example*]
142
 
143
+ A result binding never has an undeduced placeholder type
144
+ [[dcl.contract.res]].
145
+
146
+ [*Example 5*:
147
+
148
+ ``` cpp
149
+ auto f()
150
+ post(r : r == 7) // OK
151
+ {
152
+ return 7;
153
+ }
154
+ ```
155
+
156
+ — *end example*]
157
+
158
  Return type deduction for a templated function with a placeholder in its
159
  declared type occurs when the definition is instantiated even if the
160
  function body contains a `return` statement with a non-type-dependent
161
  operand.
162
 
 
164
  template will cause an implicit instantiation. Any errors that arise
165
  from this instantiation are not in the immediate context of the function
166
  type and can result in the program being ill-formed
167
  [[temp.deduct]]. — *end note*]
168
 
169
+ [*Example 6*:
170
 
171
  ``` cpp
172
  template <class T> auto f(T t) { return t; } // return type deduced at instantiation time
173
  typedef decltype(f(1)) fint_t; // instantiates f<int> to deduce return type
174
  template<class T> auto f(T* t) { return *t; }
 
181
  If a function or function template F has a declared return type that
182
  uses a placeholder type, redeclarations or specializations of F shall
183
  use that placeholder type, not a deduced type; otherwise, they shall not
184
  use a placeholder type.
185
 
186
+ [*Example 7*:
187
 
188
  ``` cpp
189
  auto f();
190
  auto f() { return 42; } // return type is int
191
  auto f(); // OK
 
226
  An explicit instantiation declaration [[temp.explicit]] does not cause
227
  the instantiation of an entity declared using a placeholder type, but it
228
  also does not prevent that entity from being instantiated as needed to
229
  determine its type.
230
 
231
+ [*Example 8*:
232
 
233
  ``` cpp
234
  template <typename T> auto f(T t) { return t; }
235
  extern template auto f(int); // does not instantiate f<int>
236
  int (*p)(int) = f; // instantiates f<int> to determine its return type, but an explicit