From Jason Turner

[dcl.type]

Diff to HTML by rtfpessoa

Files changed (1) hide show
  1. tmp/tmpniic6ffj/{from.md → to.md} +141 -93
tmp/tmpniic6ffj/{from.md → to.md} RENAMED
@@ -1,7 +1,9 @@
1
  ### Type specifiers <a id="dcl.type">[[dcl.type]]</a>
2
 
 
 
3
  The type-specifiers are
4
 
5
  ``` bnf
6
  type-specifier:
7
  simple-type-specifier
@@ -56,11 +58,11 @@ function, at least one *defining-type-specifier* that is not a
56
  complete *decl-specifier-seq*.[^1]
57
 
58
  [*Note 1*: *enum-specifier*s, *class-specifier*s, and
59
  *typename-specifier*s are discussed in [[dcl.enum]], [[class]], and
60
  [[temp.res]], respectively. The remaining *type-specifier*s are
61
- discussed in the rest of this subclause. — *end note*]
62
 
63
  #### The *cv-qualifier*s <a id="dcl.type.cv">[[dcl.type.cv]]</a>
64
 
65
  There are two *cv-qualifier*s, `const` and `volatile`. Each
66
  *cv-qualifier* shall appear at most once in a *cv-qualifier-seq*. If a
@@ -89,23 +91,24 @@ the object referenced is a non-const object and can be modified through
89
  some other access path.
90
 
91
  [*Note 4*: Cv-qualifiers are supported by the type system so that they
92
  cannot be subverted without casting [[expr.const.cast]]. — *end note*]
93
 
94
- Any attempt to modify ([[expr.ass]], [[expr.post.incr]],
95
- [[expr.pre.incr]]) a const object [[basic.type.qualifier]] during its
96
- lifetime [[basic.life]] results in undefined behavior.
 
97
 
98
  [*Example 1*:
99
 
100
  ``` cpp
101
  const int ci = 3; // cv-qualified (initialized as required)
102
  ci = 4; // error: attempt to modify const
103
 
104
  int i = 2; // not cv-qualified
105
  const int* cip; // pointer to const int
106
- cip = &i; // OK: cv-qualified access path to unqualified
107
  *cip = 4; // error: attempt to modify through ptr to const
108
 
109
  int* ip;
110
  ip = const_cast<int*>(cip); // cast needed to convert const int* to int*
111
  *ip = 4; // defined: *ip points to i, a non-const object
@@ -183,10 +186,16 @@ type-name:
183
  class-name
184
  enum-name
185
  typedef-name
186
  ```
187
 
 
 
 
 
 
 
188
  A *placeholder-type-specifier* is a placeholder for a type to be deduced
189
  [[dcl.spec.auto]]. A *type-specifier* of the form `typename`ₒₚₜ
190
  *nested-name-specifier*ₒₚₜ *template-name* is a placeholder for a
191
  deduced class type [[dcl.type.class.deduct]]. The
192
  *nested-name-specifier*, if any, shall be non-dependent and the
@@ -269,49 +278,72 @@ contexts. — *end note*]
269
  ``` bnf
270
  elaborated-type-specifier:
271
  class-key attribute-specifier-seqₒₚₜ nested-name-specifierₒₚₜ identifier
272
  class-key simple-template-id
273
  class-key nested-name-specifier templateₒₚₜ simple-template-id
274
- elaborated-enum-specifier
275
- ```
276
-
277
- ``` bnf
278
- elaborated-enum-specifier:
279
  enum nested-name-specifierₒₚₜ identifier
280
  ```
281
 
282
- An *attribute-specifier-seq* shall not appear in an
283
- *elaborated-type-specifier* unless the latter is the sole constituent of
284
- a declaration. If an *elaborated-type-specifier* is the sole constituent
285
- of a declaration, the declaration is ill-formed unless it is an explicit
 
 
286
  specialization [[temp.expl.spec]], an explicit instantiation
287
  [[temp.explicit]] or it has one of the following forms:
288
 
289
  ``` bnf
290
  class-key attribute-specifier-seqₒₚₜ identifier ';'
291
- friend class-key '::ₒₚₜ ' identifier ';'
292
- friend class-key '::ₒₚₜ ' simple-template-id ';'
293
- friend class-key nested-name-specifier identifier ';'
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
294
  friend class-key nested-name-specifier templateₒₚₜ simple-template-id ';'
295
  ```
296
 
297
- In the first case, the *attribute-specifier-seq*, if any, appertains to
298
- the class being declared; the attributes in the
299
- *attribute-specifier-seq* are thereafter considered attributes of the
300
- class whenever it is named.
301
 
302
- [*Note 1*: [[basic.lookup.elab]] describes how name lookup proceeds
303
- for the *identifier* in an *elaborated-type-specifier*. *end note*]
 
 
 
 
 
 
304
 
305
  If the *identifier* or *simple-template-id* resolves to a *class-name*
306
  or *enum-name*, the *elaborated-type-specifier* introduces it into the
307
  declaration the same way a *simple-type-specifier* introduces its
308
  *type-name* [[dcl.type.simple]]. If the *identifier* or
309
- *simple-template-id* resolves to a *typedef-name* ([[dcl.typedef]],
310
- [[temp.names]]), the *elaborated-type-specifier* is ill-formed.
 
311
 
312
- [*Note 2*:
313
 
314
  This implies that, within a class template with a template
315
  *type-parameter* `T`, the declaration
316
 
317
  ``` cpp
@@ -359,23 +391,23 @@ follows:
359
  [[dcl.struct.bind]], `decltype(E)` is the referenced type as given in
360
  the specification of the structured binding declaration;
361
  - otherwise, if E is an unparenthesized *id-expression* naming a
362
  non-type *template-parameter* [[temp.param]], `decltype(E)` is the
363
  type of the *template-parameter* after performing any necessary type
364
- deduction ([[dcl.spec.auto]], [[dcl.type.class.deduct]]);
365
  - otherwise, if E is an unparenthesized *id-expression* or an
366
  unparenthesized class member access [[expr.ref]], `decltype(E)` is the
367
- type of the entity named by E. If there is no such entity, or if E
368
- names a set of overloaded functions, the program is ill-formed;
369
  - otherwise, if E is an xvalue, `decltype(E)` is `T&&`, where `T` is the
370
  type of E;
371
  - otherwise, if E is an lvalue, `decltype(E)` is `T&`, where `T` is the
372
  type of E;
373
  - otherwise, `decltype(E)` is the type of E.
374
 
375
  The operand of the `decltype` specifier is an unevaluated operand
376
- [[expr.prop]].
377
 
378
  [*Example 1*:
379
 
380
  ``` cpp
381
  const int&& foo();
@@ -425,11 +457,11 @@ template<class T> auto f(T) // #1
425
  // for the temporary introduced by the use of h().
426
  // (A temporary is not introduced as a result of the use of i().)
427
  template<class T> auto f(T) // #2
428
  -> void;
429
  auto g() -> void {
430
- f(42); // OK: calls #2. (#1 is not a viable candidate: type deduction
431
  // fails[temp.deduct] because A<int>::~A() is implicitly used in its
432
  // decltype-specifier)
433
  }
434
  template<class T> auto q(T)
435
  -> decltype((h<T>())); // does not force completion of A<T>; A<T>::~A() is not implicitly
@@ -444,10 +476,12 @@ void r() {
444
 
445
  — *end example*]
446
 
447
  #### Placeholder type specifiers <a id="dcl.spec.auto">[[dcl.spec.auto]]</a>
448
 
 
 
449
  ``` bnf
450
  placeholder-type-specifier:
451
  type-constraintₒₚₜ auto
452
  type-constraintₒₚₜ decltype '(' auto ')'
453
  ```
@@ -464,11 +498,11 @@ placeholder* of the function declaration or *lambda-expression*.
464
 
465
  [*Note 1*: Having a generic parameter type placeholder signifies that
466
  the function is an abbreviated function template [[dcl.fct]] or the
467
  lambda is a generic lambda [[expr.prim.lambda]]. — *end note*]
468
 
469
- The placeholder type can appear with a function declarator in the
470
  *decl-specifier-seq*, *type-specifier-seq*, *conversion-function-id*, or
471
  *trailing-return-type*, in any context where such a declarator is valid.
472
  If the function declarator includes a *trailing-return-type*
473
  [[dcl.fct]], that *trailing-return-type* specifies the declared return
474
  type of the function. Otherwise, the function declarator shall declare a
@@ -480,54 +514,49 @@ non-discarded `return` statements, if any, in the body of the function
480
  The type of a variable declared using a placeholder type is deduced from
481
  its initializer. This use is allowed in an initializing declaration
482
  [[dcl.init]] of a variable. The placeholder type shall appear as one of
483
  the *decl-specifier*s in the *decl-specifier-seq* and the
484
  *decl-specifier-seq* shall be followed by one or more *declarator*s,
485
- each of which shall be followed by a non-empty *initializer*. In an
486
- *initializer* of the form
487
-
488
- ``` cpp
489
- ( expression-list )
490
- ```
491
-
492
- the *expression-list* shall be a single *assignment-expression*.
493
 
494
  [*Example 1*:
495
 
496
  ``` cpp
497
- auto x = 5; // OK: x has type int
498
- const auto *v = &x, u = 6; // OK: v has type const int*, u has type const int
499
- static auto y = 0.0; // OK: y has type double
500
  auto int r; // error: auto is not a storage-class-specifier
501
- auto f() -> int; // OK: f returns int
502
- auto g() { return 0.0; } // OK: g returns double
503
- auto h(); // OK: h's return type will be deduced when it is defined
504
  ```
505
 
506
  — *end example*]
507
 
508
  The `auto` *type-specifier* can also be used to introduce a structured
509
  binding declaration [[dcl.struct.bind]].
510
 
511
  A placeholder type can also be used in the *type-specifier-seq* in the
512
  *new-type-id* or *type-id* of a *new-expression* [[expr.new]] and as a
513
  *decl-specifier* of the *parameter-declaration*'s *decl-specifier-seq*
514
- in a *template-parameter* [[temp.param]].
 
 
515
 
516
  A program that uses a placeholder type in a context not explicitly
517
- allowed in this subclause is ill-formed.
518
 
519
  If the *init-declarator-list* contains more than one *init-declarator*,
520
  they shall all form declarations of variables. The type of each declared
521
  variable is determined by placeholder type deduction
522
  [[dcl.type.auto.deduct]], and if the type that replaces the placeholder
523
  type is not the same in each deduction, the program is ill-formed.
524
 
525
  [*Example 2*:
526
 
527
  ``` cpp
528
- auto x = 5, *y = &x; // OK: auto is int
529
  auto a = 5, b = { 1, 2 }; // error: different types for auto
530
  ```
531
 
532
  — *end example*]
533
 
@@ -555,15 +584,15 @@ type shall be defined in the translation unit containing its exported
555
  declaration, outside the *private-module-fragment* (if any).
556
 
557
  [*Note 2*: The deduced return type cannot have a name with internal
558
  linkage [[basic.link]]. — *end note*]
559
 
560
- If the name of an entity with an undeduced placeholder type appears in
561
- an expression, the program is ill-formed. Once a non-discarded `return`
562
- statement has been seen in a function, however, the return type deduced
563
- from that statement can be used in the rest of the function, including
564
- in other `return` statements.
565
 
566
  [*Example 4*:
567
 
568
  ``` cpp
569
  auto n = n; // error: n's initializer refers to n
@@ -577,14 +606,14 @@ auto sum(int i) {
577
  }
578
  ```
579
 
580
  — *end example*]
581
 
582
- Return type deduction for a templated entity that is a function or
583
- function template with a placeholder in its declared type occurs when
584
- the definition is instantiated even if the function body contains a
585
- `return` statement with a non-type-dependent operand.
586
 
587
  [*Note 3*: Therefore, any use of a specialization of the function
588
  template will cause an implicit instantiation. Any errors that arise
589
  from this instantiation are not in the immediate context of the function
590
  type and can result in the program being ill-formed
@@ -600,24 +629,22 @@ void g() { int (*p)(int*) = &f; } // instantiates both fs to deter
600
  // chooses second
601
  ```
602
 
603
  — *end example*]
604
 
605
- Redeclarations or specializations of a function or function template
606
- with a declared return type that uses a placeholder type shall also use
607
- that placeholder, not a deduced type. Similarly, redeclarations or
608
- specializations of a function or function template with a declared
609
- return type that does not use a placeholder type shall not use a
610
- placeholder.
611
 
612
  [*Example 6*:
613
 
614
  ``` cpp
615
  auto f();
616
  auto f() { return 42; } // return type is int
617
  auto f(); // OK
618
- int f(); // error: cannot be overloaded with auto f()
619
  decltype(auto) f(); // error: auto and decltype(auto) don't match
620
 
621
  template <typename T> auto g(T t) { return t; } // #1
622
  template auto g(int); // OK, return type is int
623
  template char g(char); // error: no matching template
@@ -669,44 +696,63 @@ int (*p)(int) = f; // instantiates f<int> to determine its return t
669
 
670
  *Placeholder type deduction* is the process by which a type containing a
671
  placeholder type is replaced by a deduced type.
672
 
673
  A type `T` containing a placeholder type, and a corresponding
674
- initializer E, are determined as follows:
675
 
676
- - for a non-discarded `return` statement that occurs in a function
677
  declared with a return type that contains a placeholder type, `T` is
678
- the declared return type and E is the operand of the `return`
679
- statement. If the `return` statement has no operand, then E is
680
- `void()`;
681
- - for a variable declared with a type that contains a placeholder type,
682
- `T` is the declared type of the variable and E is the initializer. If
683
- the initialization is direct-list-initialization, the initializer
684
- shall be a *braced-init-list* containing only a single
685
- *assignment-expression* and E is the *assignment-expression*;
686
- - for a non-type template parameter declared with a type that contains a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
687
  placeholder type, `T` is the declared type of the non-type template
688
  parameter and E is the corresponding template argument.
689
 
690
- In the case of a `return` statement with no operand or with an operand
691
- of type `void`, `T` shall be either *type-constraint*ₒₚₜ
692
- `decltype(auto)` or cv *type-constraint*ₒₚₜ `auto`.
693
-
694
- If the deduction is for a `return` statement and E is a
695
- *braced-init-list* [[dcl.init.list]], the program is ill-formed.
696
 
697
  If the *placeholder-type-specifier* is of the form *type-constraint*ₒₚₜ
698
  `auto`, the deduced type T' replacing `T` is determined using the rules
699
- for template argument deduction. Obtain `P` from `T` by replacing the
700
- occurrences of *type-constraint*ₒₚₜ `auto` either with a new invented
701
- type template parameter `U` or, if the initialization is
702
- copy-list-initialization, with `std::initializer_list<U>`. Deduce a
703
- value for `U` using the rules of template argument deduction from a
704
- function call [[temp.deduct.call]], where `P` is a function template
705
- parameter type and the corresponding argument is E. If the deduction
706
- fails, the declaration is ill-formed. Otherwise, T' is obtained by
707
- substituting the deduced `U` into `P`.
 
 
 
708
 
709
  [*Example 8*:
710
 
711
  ``` cpp
712
  auto x1 = { 1, 2 }; // decltype(x1) is std::initializer_list<int>
@@ -733,12 +779,12 @@ template <class U> void f(const U& u);
733
 
734
  — *end example*]
735
 
736
  If the *placeholder-type-specifier* is of the form *type-constraint*ₒₚₜ
737
  `decltype(auto)`, `T` shall be the placeholder alone. The type deduced
738
- for `T` is determined as described in  [[dcl.type.simple]], as though E
739
- had been the operand of the `decltype`.
740
 
741
  [*Example 10*:
742
 
743
  ``` cpp
744
  int i;
@@ -753,10 +799,12 @@ auto x5a = f(); // decltype(x5a) is int
753
  decltype(auto) x5d = f(); // decltype(x5d) is int&&
754
  auto x6a = { 1, 2 }; // decltype(x6a) is std::initializer_list<int>
755
  decltype(auto) x6d = { 1, 2 }; // error: { 1, 2 } is not an expression
756
  auto *x7a = &i; // decltype(x7a) is int*
757
  decltype(auto)*x7d = &i; // error: declared type is not plain decltype(auto)
 
 
758
  ```
759
 
760
  — *end example*]
761
 
762
  For a *placeholder-type-specifier* with a *type-constraint*, the
 
1
  ### Type specifiers <a id="dcl.type">[[dcl.type]]</a>
2
 
3
+ #### General <a id="dcl.type.general">[[dcl.type.general]]</a>
4
+
5
  The type-specifiers are
6
 
7
  ``` bnf
8
  type-specifier:
9
  simple-type-specifier
 
58
  complete *decl-specifier-seq*.[^1]
59
 
60
  [*Note 1*: *enum-specifier*s, *class-specifier*s, and
61
  *typename-specifier*s are discussed in [[dcl.enum]], [[class]], and
62
  [[temp.res]], respectively. The remaining *type-specifier*s are
63
+ discussed in the rest of [[dcl.type]]. — *end note*]
64
 
65
  #### The *cv-qualifier*s <a id="dcl.type.cv">[[dcl.type.cv]]</a>
66
 
67
  There are two *cv-qualifier*s, `const` and `volatile`. Each
68
  *cv-qualifier* shall appear at most once in a *cv-qualifier-seq*. If a
 
91
  some other access path.
92
 
93
  [*Note 4*: Cv-qualifiers are supported by the type system so that they
94
  cannot be subverted without casting [[expr.const.cast]]. — *end note*]
95
 
96
+ Any attempt to modify
97
+ [[expr.ass]], [[expr.post.incr]], [[expr.pre.incr]] a const object
98
+ [[basic.type.qualifier]] during its lifetime [[basic.life]] results in
99
+ undefined behavior.
100
 
101
  [*Example 1*:
102
 
103
  ``` cpp
104
  const int ci = 3; // cv-qualified (initialized as required)
105
  ci = 4; // error: attempt to modify const
106
 
107
  int i = 2; // not cv-qualified
108
  const int* cip; // pointer to const int
109
+ cip = &i; // OK, cv-qualified access path to unqualified
110
  *cip = 4; // error: attempt to modify through ptr to const
111
 
112
  int* ip;
113
  ip = const_cast<int*>(cip); // cast needed to convert const int* to int*
114
  *ip = 4; // defined: *ip points to i, a non-const object
 
186
  class-name
187
  enum-name
188
  typedef-name
189
  ```
190
 
191
+ The component names of a *simple-type-specifier* are those of its
192
+ *nested-name-specifier*, *type-name*, *simple-template-id*,
193
+ *template-name*, and/or *type-constraint* (if it is a
194
+ *placeholder-type-specifier*). The component name of a *type-name* is
195
+ the first name in it.
196
+
197
  A *placeholder-type-specifier* is a placeholder for a type to be deduced
198
  [[dcl.spec.auto]]. A *type-specifier* of the form `typename`ₒₚₜ
199
  *nested-name-specifier*ₒₚₜ *template-name* is a placeholder for a
200
  deduced class type [[dcl.type.class.deduct]]. The
201
  *nested-name-specifier*, if any, shall be non-dependent and the
 
278
  ``` bnf
279
  elaborated-type-specifier:
280
  class-key attribute-specifier-seqₒₚₜ nested-name-specifierₒₚₜ identifier
281
  class-key simple-template-id
282
  class-key nested-name-specifier templateₒₚₜ simple-template-id
 
 
 
 
 
283
  enum nested-name-specifierₒₚₜ identifier
284
  ```
285
 
286
+ The component names of an *elaborated-type-specifier* are its
287
+ *identifier* (if any) and those of its *nested-name-specifier* and
288
+ *simple-template-id* (if any).
289
+
290
+ If an *elaborated-type-specifier* is the sole constituent of a
291
+ declaration, the declaration is ill-formed unless it is an explicit
292
  specialization [[temp.expl.spec]], an explicit instantiation
293
  [[temp.explicit]] or it has one of the following forms:
294
 
295
  ``` bnf
296
  class-key attribute-specifier-seqₒₚₜ identifier ';'
297
+ class-key attribute-specifier-seqₒₚₜ simple-template-id ';'
298
+ ```
299
+
300
+ In the first case, the *elaborated-type-specifier* declares the
301
+ *identifier* as a *class-name*. The second case shall appear only in an
302
+ *explicit-specialization* [[temp.expl.spec]] or in a
303
+ *template-declaration* (where it declares a partial specialization
304
+ [[temp.decls]]). The *attribute-specifier-seq*, if any, appertains to
305
+ the class or template being declared.
306
+
307
+ Otherwise, an *elaborated-type-specifier* E shall not have an
308
+ *attribute-specifier-seq*. If E contains an *identifier* but no
309
+ *nested-name-specifier* and (unqualified) lookup for the *identifier*
310
+ finds nothing, E shall not be introduced by the `enum` keyword and
311
+ declares the *identifier* as a *class-name*. The target scope of E is
312
+ the nearest enclosing namespace or block scope.
313
+
314
+ If an *elaborated-type-specifier* appears with the `friend` specifier as
315
+ an entire *member-declaration*, the *member-declaration* shall have one
316
+ of the following forms:
317
+
318
+ ``` bnf
319
+ friend class-key nested-name-specifierₒₚₜ identifier ';'
320
+ friend class-key simple-template-id ';'
321
  friend class-key nested-name-specifier templateₒₚₜ simple-template-id ';'
322
  ```
323
 
324
+ Any unqualified lookup for the *identifier* (in the first case) does not
325
+ consider scopes that contain the target scope; no name is bound.
 
 
326
 
327
+ [*Note 1*: A *using-directive* in the target scope is ignored if it
328
+ refers to a namespace not contained by that scope. [[basic.lookup.elab]]
329
+ describes how name lookup proceeds in an
330
+ *elaborated-type-specifier*. — *end note*]
331
+
332
+ [*Note 2*: An *elaborated-type-specifier* can be used to refer to a
333
+ previously declared *class-name* or *enum-name* even if the name has
334
+ been hidden by a non-type declaration. — *end note*]
335
 
336
  If the *identifier* or *simple-template-id* resolves to a *class-name*
337
  or *enum-name*, the *elaborated-type-specifier* introduces it into the
338
  declaration the same way a *simple-type-specifier* introduces its
339
  *type-name* [[dcl.type.simple]]. If the *identifier* or
340
+ *simple-template-id* resolves to a *typedef-name*
341
+ [[dcl.typedef]], [[temp.names]], the *elaborated-type-specifier* is
342
+ ill-formed.
343
 
344
+ [*Note 3*:
345
 
346
  This implies that, within a class template with a template
347
  *type-parameter* `T`, the declaration
348
 
349
  ``` cpp
 
391
  [[dcl.struct.bind]], `decltype(E)` is the referenced type as given in
392
  the specification of the structured binding declaration;
393
  - otherwise, if E is an unparenthesized *id-expression* naming a
394
  non-type *template-parameter* [[temp.param]], `decltype(E)` is the
395
  type of the *template-parameter* after performing any necessary type
396
+ deduction [[dcl.spec.auto]], [[dcl.type.class.deduct]];
397
  - otherwise, if E is an unparenthesized *id-expression* or an
398
  unparenthesized class member access [[expr.ref]], `decltype(E)` is the
399
+ type of the entity named by E. If there is no such entity, the program
400
+ is ill-formed;
401
  - otherwise, if E is an xvalue, `decltype(E)` is `T&&`, where `T` is the
402
  type of E;
403
  - otherwise, if E is an lvalue, `decltype(E)` is `T&`, where `T` is the
404
  type of E;
405
  - otherwise, `decltype(E)` is the type of E.
406
 
407
  The operand of the `decltype` specifier is an unevaluated operand
408
+ [[term.unevaluated.operand]].
409
 
410
  [*Example 1*:
411
 
412
  ``` cpp
413
  const int&& foo();
 
457
  // for the temporary introduced by the use of h().
458
  // (A temporary is not introduced as a result of the use of i().)
459
  template<class T> auto f(T) // #2
460
  -> void;
461
  auto g() -> void {
462
+ f(42); // OK, calls #2. (#1 is not a viable candidate: type deduction
463
  // fails[temp.deduct] because A<int>::~A() is implicitly used in its
464
  // decltype-specifier)
465
  }
466
  template<class T> auto q(T)
467
  -> decltype((h<T>())); // does not force completion of A<T>; A<T>::~A() is not implicitly
 
476
 
477
  — *end example*]
478
 
479
  #### Placeholder type specifiers <a id="dcl.spec.auto">[[dcl.spec.auto]]</a>
480
 
481
+ ##### General <a id="dcl.spec.auto.general">[[dcl.spec.auto.general]]</a>
482
+
483
  ``` bnf
484
  placeholder-type-specifier:
485
  type-constraintₒₚₜ auto
486
  type-constraintₒₚₜ decltype '(' auto ')'
487
  ```
 
498
 
499
  [*Note 1*: Having a generic parameter type placeholder signifies that
500
  the function is an abbreviated function template [[dcl.fct]] or the
501
  lambda is a generic lambda [[expr.prim.lambda]]. — *end note*]
502
 
503
+ A placeholder type can appear with a function declarator in the
504
  *decl-specifier-seq*, *type-specifier-seq*, *conversion-function-id*, or
505
  *trailing-return-type*, in any context where such a declarator is valid.
506
  If the function declarator includes a *trailing-return-type*
507
  [[dcl.fct]], that *trailing-return-type* specifies the declared return
508
  type of the function. Otherwise, the function declarator shall declare a
 
514
  The type of a variable declared using a placeholder type is deduced from
515
  its initializer. This use is allowed in an initializing declaration
516
  [[dcl.init]] of a variable. The placeholder type shall appear as one of
517
  the *decl-specifier*s in the *decl-specifier-seq* and the
518
  *decl-specifier-seq* shall be followed by one or more *declarator*s,
519
+ each of which shall be followed by a non-empty *initializer*.
 
 
 
 
 
 
 
520
 
521
  [*Example 1*:
522
 
523
  ``` cpp
524
+ auto x = 5; // OK, x has type int
525
+ const auto *v = &x, u = 6; // OK, v has type const int*, u has type const int
526
+ static auto y = 0.0; // OK, y has type double
527
  auto int r; // error: auto is not a storage-class-specifier
528
+ auto f() -> int; // OK, f returns int
529
+ auto g() { return 0.0; } // OK, g returns double
530
+ auto h(); // OK, h's return type will be deduced when it is defined
531
  ```
532
 
533
  — *end example*]
534
 
535
  The `auto` *type-specifier* can also be used to introduce a structured
536
  binding declaration [[dcl.struct.bind]].
537
 
538
  A placeholder type can also be used in the *type-specifier-seq* in the
539
  *new-type-id* or *type-id* of a *new-expression* [[expr.new]] and as a
540
  *decl-specifier* of the *parameter-declaration*'s *decl-specifier-seq*
541
+ in a *template-parameter* [[temp.param]]. The `auto` *type-specifier*
542
+ can also be used as the *simple-type-specifier* in an explicit type
543
+ conversion (functional notation) [[expr.type.conv]].
544
 
545
  A program that uses a placeholder type in a context not explicitly
546
+ allowed in [[dcl.spec.auto]] is ill-formed.
547
 
548
  If the *init-declarator-list* contains more than one *init-declarator*,
549
  they shall all form declarations of variables. The type of each declared
550
  variable is determined by placeholder type deduction
551
  [[dcl.type.auto.deduct]], and if the type that replaces the placeholder
552
  type is not the same in each deduction, the program is ill-formed.
553
 
554
  [*Example 2*:
555
 
556
  ``` cpp
557
+ auto x = 5, *y = &x; // OK, auto is int
558
  auto a = 5, b = { 1, 2 }; // error: different types for auto
559
  ```
560
 
561
  — *end example*]
562
 
 
584
  declaration, outside the *private-module-fragment* (if any).
585
 
586
  [*Note 2*: The deduced return type cannot have a name with internal
587
  linkage [[basic.link]]. — *end note*]
588
 
589
+ If a variable or function with an undeduced placeholder type is named by
590
+ an expression [[basic.def.odr]], the program is ill-formed. Once a
591
+ non-discarded `return` statement has been seen in a function, however,
592
+ the return type deduced from that statement can be used in the rest of
593
+ the function, including in other `return` statements.
594
 
595
  [*Example 4*:
596
 
597
  ``` cpp
598
  auto n = n; // error: n's initializer refers to n
 
606
  }
607
  ```
608
 
609
  — *end example*]
610
 
611
+ Return type deduction for a templated function with a placeholder in its
612
+ declared type occurs when the definition is instantiated even if the
613
+ function body contains a `return` statement with a non-type-dependent
614
+ operand.
615
 
616
  [*Note 3*: Therefore, any use of a specialization of the function
617
  template will cause an implicit instantiation. Any errors that arise
618
  from this instantiation are not in the immediate context of the function
619
  type and can result in the program being ill-formed
 
629
  // chooses second
630
  ```
631
 
632
  — *end example*]
633
 
634
+ If a function or function template F has a declared return type that
635
+ uses a placeholder type, redeclarations or specializations of F shall
636
+ use that placeholder type, not a deduced type; otherwise, they shall not
637
+ use a placeholder type.
 
 
638
 
639
  [*Example 6*:
640
 
641
  ``` cpp
642
  auto f();
643
  auto f() { return 42; } // return type is int
644
  auto f(); // OK
645
+ int f(); // error: auto and int don't match
646
  decltype(auto) f(); // error: auto and decltype(auto) don't match
647
 
648
  template <typename T> auto g(T t) { return t; } // #1
649
  template auto g(int); // OK, return type is int
650
  template char g(char); // error: no matching template
 
696
 
697
  *Placeholder type deduction* is the process by which a type containing a
698
  placeholder type is replaced by a deduced type.
699
 
700
  A type `T` containing a placeholder type, and a corresponding
701
+ *initializer-clause* E, are determined as follows:
702
 
703
+ - For a non-discarded `return` statement that occurs in a function
704
  declared with a return type that contains a placeholder type, `T` is
705
+ the declared return type.
706
+ - If the `return` statement has no operand, then E is `void()`.
707
+ - If the operand is a *braced-init-list* [[dcl.init.list]], the
708
+ program is ill-formed.
709
+ - If the operand is an *expression* X that is not an
710
+ *assignment-expression*, E is `(X)`. \[*Note 4*: A comma expression
711
+ [[expr.comma]] is not an *assignment-expression*. *end note*]
712
+ - Otherwise, E is the operand of the `return` statement.
713
+
714
+ If E has type `void`, `T` shall be either *type-constraint*ₒₚₜ
715
+ `decltype(auto)` or cv *type-constraint*ₒₚₜ `auto`.
716
+ - For a variable declared with a type that contains a placeholder type,
717
+ `T` is the declared type of the variable.
718
+ - If the initializer of the variable is a *brace-or-equal-initializer*
719
+ of the form `= initializer-clause`, E is the *initializer-clause*.
720
+ - If the initializer is a *braced-init-list*, it shall consist of a
721
+ single brace-enclosed *assignment-expression* and E is the
722
+ *assignment-expression*.
723
+ - If the initializer is a parenthesized *expression-list*, the
724
+ *expression-list* shall be a single *assignment-expression* and E is
725
+ the *assignment-expression*.
726
+ - For an explicit type conversion [[expr.type.conv]], `T` is the
727
+ specified type, which shall be `auto`.
728
+ - If the initializer is a *braced-init-list*, it shall consist of a
729
+ single brace-enclosed *assignment-expression* and E is the
730
+ *assignment-expression*.
731
+ - If the initializer is a parenthesized *expression-list*, the
732
+ *expression-list* shall be a single *assignment-expression* and E is
733
+ the *assignment-expression*.
734
+ - For a non-type template parameter declared with a type that contains a
735
  placeholder type, `T` is the declared type of the non-type template
736
  parameter and E is the corresponding template argument.
737
 
738
+ `T` shall not be an array type.
 
 
 
 
 
739
 
740
  If the *placeholder-type-specifier* is of the form *type-constraint*ₒₚₜ
741
  `auto`, the deduced type T' replacing `T` is determined using the rules
742
+ for template argument deduction. If the initialization is
743
+ copy-list-initialization, a declaration of `std::initializer_list` shall
744
+ precede [[basic.lookup.general]] the *placeholder-type-specifier*.
745
+ Obtain `P` from `T` by replacing the occurrences of
746
+ *type-constraint*ₒₚₜ `auto` either with a new invented type template
747
+ parameter `U` or, if the initialization is copy-list-initialization,
748
+ with `std::initializer_list<U>`. Deduce a value for `U` using the rules
749
+ of template argument deduction from a function call
750
+ [[temp.deduct.call]], where `P` is a function template parameter type
751
+ and the corresponding argument is E. If the deduction fails, the
752
+ declaration is ill-formed. Otherwise, T' is obtained by substituting the
753
+ deduced `U` into `P`.
754
 
755
  [*Example 8*:
756
 
757
  ``` cpp
758
  auto x1 = { 1, 2 }; // decltype(x1) is std::initializer_list<int>
 
779
 
780
  — *end example*]
781
 
782
  If the *placeholder-type-specifier* is of the form *type-constraint*ₒₚₜ
783
  `decltype(auto)`, `T` shall be the placeholder alone. The type deduced
784
+ for `T` is determined as described in  [[dcl.type.decltype]], as though
785
+ E had been the operand of the `decltype`.
786
 
787
  [*Example 10*:
788
 
789
  ``` cpp
790
  int i;
 
799
  decltype(auto) x5d = f(); // decltype(x5d) is int&&
800
  auto x6a = { 1, 2 }; // decltype(x6a) is std::initializer_list<int>
801
  decltype(auto) x6d = { 1, 2 }; // error: { 1, 2 } is not an expression
802
  auto *x7a = &i; // decltype(x7a) is int*
803
  decltype(auto)*x7d = &i; // error: declared type is not plain decltype(auto)
804
+ auto f1(int x) -> decltype((x)) { return (x); } // return type is int&
805
+ auto f2(int x) -> decltype(auto) { return (x); } // return type is int&&
806
  ```
807
 
808
  — *end example*]
809
 
810
  For a *placeholder-type-specifier* with a *type-constraint*, the