-
Notifications
You must be signed in to change notification settings - Fork 0
/
p0696r1.html
1362 lines (1263 loc) · 54.7 KB
/
p0696r1.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<!doctype html public "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
<head>
<title>Remove abbreviated functions and template-introduction syntax from the Concepts TS</title>
<style type="text/css">
table#header th,
table#header td
{
text-align: left;
}
table#references th,
table#references td
{
vertical-align: top;
}
blockquote.code
{
background-color: #F1F1F1;
border: 1px solid #D1D1D1;
}
ins, ins * { text-decoration:none; font-weight:bold; background-color:#A0FFA0 }
del, del * { text-decoration:line-through; background-color:#FFA0A0 }
#hidedel:checked ~ * del, #hidedel:checked ~ * del * { display:none; visibility:hidden }
blockquote
{
color: #000000;
background-color: #F1F1F1;
border: 1px solid #D1D1D1;
padding-left: 0.5em;
padding-right: 0.5em;
}
blockquote.stdins
{
text-decoration: underline;
color: #000000;
background-color: #C8FFC8;
border: 1px solid #B3EBB3;
padding: 0.5em;
}
blockquote.stddel
{
text-decoration: line-through;
color: #000000;
background-color: #FFEBFF;
border: 1px solid #ECD7EC;
padding-left: 0.5empadding-right: 0.5em;
}
blockquote.code
{
background-color: #F1F1F1;
border: 1px solid #D1D1D1;
}
</style>
</head>
<body>
<table id="header">
<tr>
<th>Document Number:</th>
<td>P0696R1</td>
</tr>
<tr>
<th>Date:</th>
<td>2017-07-13</td>
</tr>
<tr>
<th>Audience:</th>
<td>Evolution Working Group</td>
</tr>
<tr>
<th>Reply-to:</th>
<td>Tom Honermann <[email protected]></td>
</tr>
</table>
<h1>Remove abbreviated functions and template-introduction syntax from the
Concepts TS</h1>
<ul>
<li><a href="#changes_since_p0696r0">
Changes Since P0696R0</a></li>
<li><a href="#introduction">
Introduction</a></li>
<li><a href="#motivation">
Motivation</a></li>
<li><a href="#wording">
Wording</a></li>
<li><a href="#acknowledgements">
Acknowledgements</a></li>
<li><a href="#references">
References</a></li>
</ul>
<h1 id="changes_since_p0696r0">Changes Since P0696R0</h1>
<p>This is the P0696 revision presented in Toronto on Tuesday July 11th, 2017.
<ul>
<li>Added references to the current Concepts TS working paper (N4674)</li>
<li>Corrected example <tt>f5</tt> to reflect that changes in C++11 now permit
<tt>typename</tt> to be used outside of a template. Thanks to Barry
Revzin for pointing out the error.</li>
<li>Removed the examples previously named <tt>f6</tt> and <tt>f7</tt> that
illustrated a semantic difference in behavior based on whether the return
type for an abbreviated function was specified in a
<em>trailing-return-type</em> or not. Further discussion clarified that
the described behavior is a gcc issue now tracked by
<a title="[concepts] Same type constraints not enforced for constrained-type specifiers specified in trailing return types of abbreviated functions"
href="https://gcc.gnu.org/bugzilla/show_bug.cgi?id=81198">
gcc bug 81198</a>
<sup>
<a title="[concepts] Same type constraints not enforced for constrained-type specifiers specified in trailing return types of abbreviated functions"
href="#ref_gcc_bug_81198">
[GccBug81198]</a></sup>.
</li>
<li>Updated the <tt>f6</tt> and <tt>f7</tt> examples (previously named
<tt>f8</tt> and <tt>f9</tt>) to reference a gcc bug filed to track the
noted issue.
</li>
</ul>
<h1 id="introduction">Introduction</h1>
<p>The abbreviated function and template introducer syntax features defined
in the Concepts TS <sup><a href="#ref_concepts">[Concepts]</a></sup>
have proven to be controversial as evidenced by discussion within the
committee reflectors
<sup><a href="#ref_exp_concepts">[ExploringConcepts]</a></sup>
and the
<a title="P0587R0: Concepts TS revisited"
href="http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2017/p0587r0.pdf">
P0587R0</a>
<sup><a title="P0587R0: Concepts TS revisited"
href="#ref_p0587r0">
[P0587R0]</a></sup>
and <a title="P0464R2: Revisiting the meaning of <tt>foo(ConceptName,ConceptName)</tt>"
href="http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2017/p0464r2.html">
P0464R2</a>
<sup><a title="P0587R0: Revisiting the meaning of <tt>foo(ConceptName,ConceptName)</tt>"
href="#ref_p0464r2">
[P0464R2]</a></sup>
paper submissions. This paper proposes removing these features from the
Concepts TS with the goal of increasing consensus on adopting the remaining
Concepts TS functionality into the current working paper.
</p>
<p>Removal of support for abbreviated functions means that the following
example that is currently well-defined by the Concepts TS will no longer be
valid:
<blockquote class="code">
<tt><pre>
template<typename> concept bool C = true;
void af1(auto); <em>// Previously ok; declares an abbreviated function (template)</em>
<em>// with a single function parameter with an unconstrained type.</em>
<em>// Now ill-formed.</em>
void af2(C); <em>// Previously ok; declares an abbreviated function (template)</em>
<em>// with a single function parameter with a constrained type.</em>
<em>// Now ill-formed.</em>
</pre></tt>
</blockquote>
This paper does <strong>not</strong> propose removing support for declaring
functions and function templates with return types containing placeholders.
The following examples retain their current behavior under the Concepts TS:
<blockquote class="code">
<tt><pre>
template<typename, typename> class ct {};
ct<auto,auto> f1(); <em>// Ok; declares a function with a return type</em>
<em>// that requires the template arguments of <tt>ct</tt></em>
<em>// to be deduced from a return statement.</em>
ct<C,C> f2(); <em>// Ok; declares a function with a return type</em>
<em>// that requires the template arguments of <tt>ct</tt></em>
<em>// to be deduced from a return statement, to be deduced</em>
<em>// to the same type, and to satisfy <tt>C</tt>.</em>
</pre></tt>
</blockquote>
Removal of support for template introducers means that the following examples
that are currently well-defined by the Conepts TS will no longer be valid:
<blockquote class="code">
<tt><pre>
C{T} void ft1(T); <em>// Previously ok; declares a function template</em>
<em>// with a single constrained type template parameter.</em>
<em>// Now ill-formed.</em>
C{T} class ct1; <em>// Previously ok; declares a class template</em>
<em>// with a single constrained type template parameter.</em>
<em>// Now ill-formed.</em>
</pre></tt>
</blockquote>
</p>
<p>This paper does <strong>not</strong> propose removing support for declaring
parameters of generic lambdas with <em>constrained-type-specifier</em>s, nor
does it alter the current requirement that the same types be deduced for
equivalently constrained parameters. The following examples retain their
current behavior under the Concepts TS:
<blockquote class="code">
<tt><pre>
auto gl1 = [](C,C) { return 1; };
auto v1 = gl1(0,0); <em>// Ok</em>
auto v2 = gl1(0,'c'); <em>// Ill-formed; different types deduced for <tt>C</tt></em>
</pre></tt>
</blockquote>
</p>
<h1 id="motivation">Motivation</h1>
<p>The abbreviated function and template introducer syntax defined by the
Concepts TS is intended to reduce boilerplate, improve readability, and
ultimately, make generic programming more accessible as elaborated in
<a title="P0557R0: Concepts: The Future of Generic Programming"
href="http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2017/p0557r0.pdf">
P0557R0</a>
<sup><a title="P0557R0: Concepts: The Future of Generic Programming"
href="#ref_p0557r0">
[P0557R0]</a></sup>.
These are laudible goals and ones the author is in favor of continued pursuit.
However, the features currently defined in the Concepts TS raise concerns
regarding mutation of code undergoing maintenance and difficulties programmers
may face in navigating the differences in requirements and behaviors exhibited
by functions and function templates that are made more subtle by the current
design.
</p>
<p>
Consider the following function declaration. Does it declare a function or
a function template?
<blockquote class="code">
<tt><pre>
void f(X x) {}
</pre></tt>
</blockquote>
Prior to the Concepts TS, this unambiguously declares a non-template function.
However, if <tt>X</tt> names a concept, then <tt>f</tt> is an abbreviated
function equivalent to the following function template:
<blockquote class="code">
<tt><pre>
template<X T> void f(T x) {}
</pre></tt>
</blockquote>
This is exactly the intent as described in
<a title="P0557R0: Concepts: The Future of Generic Programming"
href="http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2017/p0557r0.pdf">
P0557R0</a>
<sup><a title="P0557R0: Concepts: The Future of Generic Programming"
href="#ref_p0557r0">
[P0557R0]</a></sup>; one may now write generic functions as familiar to any
<tt>C</tt> programmer without the boilerplate currently required to author a
function template!
</p>
<p>The problem is, this simplicity is an illusion that dissolves under further
inspection as illustrated in the following examples.
</p>
<blockquote class="code">
<tt><pre>
void f1(X&& x) {}
</pre></tt>
</blockquote>
If <tt>X</tt> names a concept, then parameter <tt>x</tt> is a forwarding
reference; otherwise, it is an rvalue reference and <tt>f1</tt> may only be
called with an rvalue argument.
<blockquote class="code">
<tt><pre>
int f2(X x) {
static int invocation_count;
return ++invocation_count;
}
</pre></tt>
</blockquote>
<tt>f2</tt> maintains a count of either every invocation of <tt>f2</tt>, or
every invocation of an instantiated specialization of <tt>f2</tt> depending
on whether <tt>X</tt> names a concept or a type.
<blockquote class="code">
<tt><pre>
void f3(X x) {}
</pre></tt>
</blockquote>
<tt>f3</tt> may be moved from a primary source file to a header if <tt>X</tt>
names a concept, but doing so risks introducing multiple definition errors if
<tt>X</tt> names a type.
<blockquote class="code">
<tt><pre>
void f4(int i) {}
</pre></tt>
</blockquote>
If <tt>f4</tt> were modified to:
<blockquote class="code">
<tt><pre>
void f4(int i, X x) {}
</pre></tt>
</blockquote>
then its definition will change from a non-template function to a template
function if <tt>X</tt> names a concept, but will remain a function if <tt>X</tt>
names a type.
<blockquote class="code">
<tt><pre>
void f5(Ziggle z, Piddle p) {
Ziggle::type x1; <em>// Ok if Ziggle is a type, ill-formed if it's a concept.</em>
decltype(p)::type x2; <em>// Ok if Piddle is a type, needs typename if it is a concept.</em>
typename decltype(z)::type x3; <em>// typename required if Ziggle is a concept, optional if it is a type.</em>
}
</pre></tt>
</blockquote>
<tt>f5</tt> illustrates the increased subtlety in determining when
<tt>typename</tt> disambiguation is required. The presence of a
<em>template-parameter-list</em> enables such determination without having
to be familiar with the particular identifiers:
<blockquote class="code">
<tt><pre>
template<Ziggle Z>
void f5(Z z, Piddle p) {
Ziggle::type x1; <em>// Ill-formed; Ziggle is a concept.</em>
decltype(p)::type x2; <em>// Ok; <tt>decltype(p)</tt> is not dependent.</em>
typename decltype(z)::type x3; <em>// typename required; <tt>decltype(z)</tt> is dependent.</em>
}
</pre></tt>
</blockquote>
Abbreviated functions have the behavior that placeholders specified within
the declared return type of the function that match a
<em>constrained-type-specifier</em> used in a parameter type are not deduced,
but are rather replaced by the deduced type for the matching parameter(s).
This behavior introduces the possibility that a change to the declaration of
a function parameter may alter the meaning of the return type:
[ <em>Note:</em> gcc 6.2-7.1 erroneously rejects both of the following cases
due to an issue tracked by
<a title="Non-deduced return type in abbreviated function template"
href="https://gcc.gnu.org/bugzilla/show_bug.cgi?id=81139">
gcc bug 81139</a>
<sup>
<a title="Non-deduced return type in abbreviated function template"
href="#ref_gcc_bug_81139">
[GccBug81139]</a></sup>.
— <em>end note</em> ]
<blockquote class="code">
<tt><pre>
template<typename> concept bool C = true;
template<typename> class ct {};
ct<C> f6(auto) { return ct<int>{}; }
ct<C> f7(C) { return ct<int>{}; }
f6('c'); <em>// Ok; <tt>C</tt> deduced as <tt>int</tt> from the return statement.</em>
f7('c'); <em>// Ill-formed; <tt>C</tt> deduced as <tt>char</tt> from the function</em>
<em>// argument and <tt>ct<int></tt> is not convertible to ct<char>.</em>
</pre></tt>
</blockquote>
</p>
<p>The template introduction syntax does not suffer concerns like those above.
The primary concern with it is aesthetic; that it lacks cohesiveness with the
rest of the language as described in
<a title="P0587R0: Concepts TS revisited"
href="http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2017/p0587r0.pdf">
P0587R0</a>
<sup><a title="P0587R0: Concepts TS revisited"
href="#ref_p0587r0">
[P0587R0]</a></sup>. The choice to remove it as proposed in this paper is
based on a perception that an alternate syntax to replace abbreviated function
syntax might also encompass the goals of template introductions.
</p>
<p>Few of the concerns raised above are applicable to every template
declaration and it has not been claimed that either of the terse syntaxes
is the best fit for all template declarations. Is it not therefore
reasonable for the use of these syntaxes to be a matter of code style? Do
tools such as IDEs that provide semantic markup not help to counteract these
concerns?
</p>
<p>The examples above suggest that guidelines for the usage of abbreviated
function syntax can be crafted. A simple guideline might look like:
<blockquote>
Write a function template instead of an abbreviated function when:
<ul>
<li>parameters declared with <tt>&&</tt> are present.</li>
<li>the parameter list consists of non-dependent user declared types
and constrained types.</li>
<li>dependent member type access is needed.</li>
<li>static local variables are present.</li>
<li>constrained types are present in the return type and in at least one
parameter type.</li>
</ul>
</blockquote>
Whether the concerns presented in this paper rise above a level adequately
addressed by guidelines and coding standards is a matter of judgement and
no arguments are presented here to attempt to establish a litmus test.
</p>
<p>IDEs and other tools that provide semantic markup are certainly helpful.
However, not all programmers use IDEs and most of us use tools that lack
semantic awareness; particularly for tools used for code review, diffing,
and merging. Relying on semantic awareness to help elucidate code is likely
to result in disappointment in various parts of our collective work flows
for the forseeable future.
</p>
<h1 id="wording">Wording</h1>
<input type="checkbox" id="hidedel">Hide deleted text</input>
<p>These changes are relative to
<a title="Working Draft, C++ extensions for Concepts"
href="http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2017/n4674.pdf">
N4674</a>
<sup><a title="Working Draft, C++ extensions for Concepts"
href="#ref_n4674">
[N4674]</a></sup></p>
<p>Change the added paragraph 6 inserted in 8.1.4.2 [expr.prim.id.qual]:
<!-- TODO: gcc does not yet implement this functionality -->
<blockquote>
In a <em>nested-name-specifier</em> of the form <tt>auto::</tt> or <tt>C::</tt>,
where <tt>C</tt> is a <em>constrained-type-name</em>, that
<em>nested-name-specifier</em> designates a placeholder that will be replaced
later according to the rules for placeholder deduction in 10.1.7.4. If a
placeholder designated by a <em>constrained-type-specifier</em> is not a
placeholder type, the program is ill-formed. [ <em>Note:</em> A
<em>constrained-type-specifier</em> can designate a placeholder for a non-type
or template (10.1.7.4.2). — <em>end note</em> ] The replacement type
deduced for a placeholder shall be a class or enumeration type. [
<em>Example:</em>
<blockquote class="code">
<tt><pre>
template<typename T> concept bool C = sizeof(T) == sizeof(int);
template<int N> concept bool D = true;
struct S1 { int n; };
struct S2 { char c; };
struct S3 { struct X { using Y = int; }; };
int auto::* p1 = &S1::n; <em>// <tt>auto</tt> deduced as <tt>S1</tt></em>
int D::* p2 = &S1::n; <em>// error: <tt>D</tt> does not designate a placeholder type</em>
int C::* p3 = &S1::n; <em>// OK: <tt>C</tt> deduced as <tt>S1</tt></em>
char C::* p4 = &S2::c; <em>// error: deduction fails because constraints are not satisfied</em>
<del>void f(typename auto::X::Y);
f(S1()); <em>// error: <tt>auto</tt> cannot be deduced from <tt>S1()</tt></em>
f<S3>(0); <em>// OK</em></del>
</pre></tt>
</blockquote>
<del>In the declaration of <tt>f</tt>, the placeholder appears in a non-deduced
context (17.8.2.5). It may be replaced later through the explicit specification
of template arguments.</del>
— <em>end example</em> ]
</blockquote>
</p>
<p>Change in 8.1.5.1 [expr.prim.lambda.closure]:
<blockquote>
Modify paragraph 3 so that the meaning of a generic lambda is defined in terms
of its <del>abbreviated</del> member function template call operator.
<blockquote>
[…] The closure type for a generic lambda has a public inline function
call operator member template that is <del>an abbreviated</del><ins>a</ins>
function template whose parameters and return type are derived from the
<em>lambda-expression</em>'s <em>parameter-declaration-clause</em> and
<em>trailing-return-type</em> according to the rules in
<del>(11.3.5)</del><ins>(10.1.7.4.1)</ins>.
</blockquote>
Add the following example after those in paragraph 3 in the C++ Standard.
<blockquote>
<em>[ Example:</em>
<blockquote class="code">
<!-- TODO: If it is decided that each parameter declared with the same
constrained-type-specifier is to be deduced independently, than this
member function template will have to be updated to declare multiple
constrained template type parameters. -->
<tt><pre>
template<typename T> concept bool C = true;
auto gl = [](C& a, C* b) { a = *b; }; <em>// OK: denotes a generic lambda</em>
struct Fun {
<ins>template<C T></ins> auto operator()(<del>C</del><ins>T</ins>& a, <del>C</del><ins>T</ins>* b) const { a = *b; }
} fun;
</pre></tt>
</blockquote>
<tt>C</tt> is a <em>constrained-type-specifier</em>, signifying that the
lambda is generic. The generic lambda <tt>gl</tt> and the function object
<tt>fun</tt> have equivalent behavior when called with the same arguments.<br/>
<em>— end example ]</em>
</blockquote>
</blockquote>
</p>
<p>Change in 8.1.7.3 [expr.prim.req.compound] paragraph 1 near the end of the
example:
<blockquote>
[…]<br/>
<blockquote class="code">
<tt><pre>
template<typename T> concept bool C() { return true; }
template<typename T> concept bool C5 =
requires(T x) {
{f(x)} -> const C&;
};
</pre></tt>
</blockquote>
The <em>compound-requirement</em> in <tt>C5</tt> introduces two constraints:
an expression constraint for <tt>f(x)</tt>, and a deduction constraint
requiring that overload resolution succeeds for the call <tt>g(f(x))</tt>
where <tt>g</tt> is the following invented <del>abbreviated</del> function
template.
<blockquote class="code">
<tt><pre>
<ins>template<C T> </ins>void g(const <del>C</del><ins>T</ins>&);
</pre></tt>
</blockquote>
— <em>end example</em> ]
</blockquote>
</p>
<p>Change within the replacement text in 10.1.7.4 [dcl.spec.auto] paragraph 1:
<blockquote>
Replace paragraph 1 with the text below.
<blockquote>
[…] The <em>type-specifier</em>s <tt>auto</tt> and
<tt>decltype(auto)</tt> and <em>constrained-type-specifier</em>s designate a
placeholder (type, non-type, or template) that will be replaced later, either
through deduction or an explicit specification. The <tt>auto</tt> and
<tt>decltype(auto)</tt> <em>type-specifier</em>s designate placeholder types;
a <em>constrained-type-specifier</em> can also designate placeholders for
values and templates. [ <em>Note:</em> The deduction of placeholders is done
through the invention of template parameters as described in 10.1.7.4.1
<del>and 11.3.5</del>. — <em>end note</em> ] Placeholders are also used
to signify that a lambda is a generic lambda (8.1.5)<del>, that a function
declaration is an abbreviated function template (11.3.5)</del>, or that a
<em>trailing-return-type</em> in a <em>compound-requirement</em> (8.1.7.3)
introduces an argument deduction constraint (17.10.1.6). The <tt>auto</tt>
<em>type-specifier</em> is also <ins>used to</ins> introduce a function
type having a <em>trailing-return-type</em> or to introduce a structured
binding declaration 11.5. [ <em>Note:</em> A <em>nested-name-specifier</em>
can also include placeholders (8.1). Replacements for those placeholders
are determined according to the rules in this section.
— <em>end note</em> ]
</blockquote>
</blockquote>
</p>
<p>Remove the allowance for placeholders appearing in the parameter type of
a function declaration in the added text in 10.1.7.4 [dcl.spec.auto]
paragraph 3:
<blockquote>
[…]<br/>
— <em>end example</em> ] <del>Similarly, if a placeholder appears in
a parameter type of a function declaration, the function declaration declares
an abbreviated function template (11.3.5). [ <em>Example:</em></del>
<blockquote class="code">
<tt><pre>
<del>void f(const auto&, int); <em>// OK: an abbreviated function template</em></del>
</pre></tt>
</blockquote>
<del>— <em>end example</em> ]</del>
</blockquote>
</p>
<p>Remove the added paragraph 4 inserted in 10.1.7.4 [dcl.spec.auto]:
<blockquote>
<del>Add the following after paragraph 3 to describe when
<em>constrained-type-specifier</em>s in the return type refer to template
parameters.</del>
<blockquote>
<del>A <em>constrained-type-specifier</em> <tt>C1</tt> within the declared
return type of an abbreviated function template declaration does not designate
a placeholder if its introduced <em>constraint-expression</em> (10.1.7.4.2)
is determined to be equivalent, using the rules in 17.6.5.1 for comparing
expressions, to the introduced <em>constraint-expression</em> for a
<em>constrained-type-specifier</em> <tt>C2</tt> in the
<em>parameter-declaration-clause</em> of that function declaration. Instead,
<tt>C1</tt> is replaced by the template parameter invented for <tt>C2</tt>
(11.3.5). [ <em>Example:</em></del>
<blockquote class="code">
<tt><pre><del>
template<typename T> concept bool C = true;
template<typename... T> struct Tuple;
C const& f1(C); <em>// has one template parameter and no deduced return type</em>
Tuple<C...> f2(C); <em>// has one template parameter and a deduced return type</em>
</del></pre></tt>
</blockquote>
<del>In the declaration <tt>f1</tt>, the <em>constraint-expression</em>
introduced by the <em>constrained-type-specifier</em>s in the
<em>parameter-declaration-clause</em> and return type are equivalent<del> </del>;
they would both introduce the expression <tt>C<T></tt>, for some invented
template parameter <tt>T</tt>. In <tt>f2</tt>, the use of <tt>C</tt> in the
return type would introduce the <em>constraint-expression</em>
<tt>(C<T> &l&l ...)</tt>, which is distinct from the
<em>constraint-expression</em> <tt>C<T></tt> introduced by the invented
<em>constrained-parameter</em> (17.1) for the
<em>constrained-type-specifier</em> in the
<em>parameter-declaration-clause</em> according to the rules in 11.3.5.
— <em>end example</em></del>
</blockquote>
</blockquote>
</p>
<p>Renumber the added paragraphs 5 and 6 added to 10.1.7.4 [dcl.spec.auto] to
4 and 5 respectively.
</p>
<p>Replace the changes to 10.1.7.4.1 [dcl.spec.auto.deduct] paragraph 2
with the following:
<blockquote>
A type <tt>T</tt> containing <del>a placeholder type</del><ins>placeholders</ins>,
and a corresponding initializer <tt>e</tt>, are determined as follows:
<blockquote>
(2.1) — for a non-discarded <tt>return</tt> statement that occurs in a
function declared with a return type that contains <del>a placeholder type</del>
<ins>placeholders</ins>, <tt>T</tt> is the declared return type and <tt>e</tt>
is the operand of the <tt>return</tt> statement. If the <tt>return</tt>
statement has no operand, then <tt>e</tt> is <tt>void()</tt>;
</blockquote>
<blockquote>
(2.2) — for a variable declared with a type that contains
<del>a placeholder type</del><ins>placeholders</ins>, <tt>T</tt> is the
declared type of the variable and <tt>e</tt> is the initializer. If the
initialization is <em>direct-list-initialization</em>, the initializer shall
be a <em>braced-init-list</em> containing only a single
<em>assignment-expression</em> and <tt>e</tt> is the
<em>assignment-expression</em>;
</blockquote>
<blockquote>
(2.3) — for a non-type template parameter declared with a type that
contains <del>a placeholder type</del><ins>placeholders</ins>, <tt>T</tt>
is the declared type of the non-type template parameter and <tt>e</tt>
is the corresponding template argument<del>.</del><ins>;</ins>
</blockquote>
<blockquote>
<ins>(2.4) — for a parameter of a generic <em>lambda-expression</em>
declared with a type that contains placeholders, <tt>T</tt> is the declared
type of the parameter and <tt>e</tt> is the corresponding argument in an
invocation of the generic lambda's function call operator template;</ins>
</blockquote>
<blockquote>
<ins>(2.5) — for an <em>argument deduction constraint</em> (17.10.1.6),
<tt>T</tt> is the <em>trailing-return-type</em>, and <tt>e</tt> is the
<em>expression</em> of the corresponding <em>compound-requirement</em>.</ins>
</blockquote>
In the case of a <tt>return</tt> statement with no operand or with an operand
of type <tt>void</tt>, <tt>T</tt> shall be either <tt>decltype(auto)</tt>
<del>or</del><ins>,</ins> <em>cv</em> <tt>auto</tt><ins>, or a
<em>constrained-type-specifier</em></ins>.
</blockquote>
</p>
<p>Correct the changes to 10.1.7.4.1 [dcl.spec.auto.deduct] paragraph 3 to
reference paragraph 4 from the <tt>C++</tt> standard.
</p>
<p>Replace the changes to 10.1.7.4.1 [dcl.spec.auto.deduct] paragraph 4
with the following:
<blockquote>
If the <del>placeholder is</del><ins>placeholders include</ins> the
<tt>auto</tt> <em>type-specifier</em> <ins>or a
<em>constrained-type-specifier</em>, </ins>the deduced type <tt>T'</tt>
replacing <tt>T</tt> is determined using the rules for template argument
deduction. <ins>If <tt>T</tt> corresponds to the type of a parameter of a
generic <em>lambda-expression</em>, then template argument deduction is
performed for all parameter types containing placeholders together.</ins>
<del>Obtain <tt>P</tt> from <tt>T</tt> by replacing the
occurrences of <tt>auto</tt> with either a new invented type template
parameter <tt>U</tt> or, if the initialization is
<em>copy-list-initialization,</em> with
<tt>std::initializer_list<U></tt>.</del> <ins>Obtain a type
<tt>P</tt> from <tt>T</tt> by replacing each placeholder as follows:</ins>
<blockquote>
<ins>(4.1) — if the initialization is a <em>copy-list-initialization</em>
and a placeholder is a <em>decl-specifier</em> of the
<em>decl-specifier-seq</em> of the variable declaration, replace that
occurrence of the placeholder with <tt>std::initializer_list<U></tt>
where <tt>U</tt> is an invented type template parameter;</ins>
</blockquote>
<blockquote>
<ins>(4.2) — otherwise, if the placeholder is designated by the
<tt>auto</tt> <em>type-specifier</em>, replace the occurrence with a new
invented type <em>template-parameter</em> or, if <tt>T</tt> corresponds to
a <em>function parameter pack</em>, with a new invented type
<em>template parameter pack</em>;</ins>
</blockquote>
<blockquote>
<ins>(4.3) — otherwise, the placeholder is designated by a
<em>constrained-type-specifier</em>. If a placeholder in <tt>T</tt> or,
for parameters of generic <em>lambda-expression</em>s, any preceding
parameter, has already been replaced by an invented
<em>constrained-parameter</em> (17.1) with <em>constraint-expression</em>s
(17.1) equivalent according to the rules for comparing <em>expression</em>s
in 17.6.5.1 to a <em>constrained-parameter</em> whose
<em>qualified-concept-name</em> is that of the
<em>constrained-type-specifier</em>, then replace the occurrence with the
existing invented <tt>constrained-parameter</tt>. Otherwise, replace the
occurrence with a new invented <em>constrained-parameter</em> whose
<em>qualified-concept-name</em> is that of the
<em>constrained-type-specifier</em>.
</blockquote>
Deduce a value for <del><tt>U</tt></del><ins>each invented template
parameter</ins> using the rules of template argument deduction from a
function call (17.8.2.1), where <tt>P</tt> is a function template parameter
type and the corresponding argument is <tt>e</tt>. <ins>[ <em>Note:</em>
multiple function template parameters will be present when deducing types
for generic <em>lambda-expression</em>s with multiple parameters with
types containing placeholders. — <em>end note</em> ]</ins> If the
deduction fails, the declaration is ill-formed. <ins>If any placeholders
in the declared type were introduced by a <em>constrained-type-specifier</em>,
then define <tt>C</tt> to be a <em>constraint-expression</em> as follows:</ins>
</blockquote>
<blockquote>
<blockquote>
<ins>(4.4) — if there is a single <em>constrained-type-specifier</em>,
then <tt>C</tt> is the <em>constraint-expression</em> introduced by the
invented template <em>constrained-parameter</em> (17.1) corresponding to that
<em>constrained-type-specifier</em>;</ins>
</blockquote>
<blockquote>
<ins>(4.5) — otherwise, <tt>C</tt> is the <em>logical-and-expression</em>
(8.14) whose operands are the <em>constraint-expression</em>s introduced by the
invented template <em>constrained-parameter</em>s corresponding to each
<em>constrained-type-specifier</em>, in order of appearance.</ins>
</blockquote>
<ins>If the normalized constraint for <tt>C</tt> (17.10.2) is not satisfied
by the deduced values, the declaration is ill-formed.</ins> Otherwise,
<tt>T'</tt> is obtained by substituting the deduced <del><tt>U</tt></del>
<ins>values for the invented type template parameters</ins> into <tt>P</tt>.
<br/>
[ <em>Example:</em>
<blockquote class="code">
<tt><pre>
auto x1 = { 1, 2 }; <em>// <tt>decltype(x1)</tt> is <tt>std::initializer_list<int></tt></em>
auto x2 = { 1, 2.0 }; <em>// error: cannot deduce element type</em>
auto x3{ 1, 2 }; <em>// error: not a single element</em>
auto x4 = { 3 }; <em>// <tt>decltype(x4)</tt> is <tt>std::initializer_list<int></tt></em>
auto x5{ 3 }; <em>// <tt>decltype(x5)</tt> is int</em>
<ins>template<typename T> struct Vec { };
template<typename T> Vec<T> make_vec(std::initializer_list<T>) { return Vec<T>{}; }
template<typename... Ts> struct Tuple { };
template<typename... Ts> auto make_tup(Ts... args) { return Tuple<Ts...>{}; }
auto& x3 = *x1.begin(); <em>// OK: <tt>decltype(x3)</tt> is <tt>int&</tt></em>
const auto* p = &x3; <em>// OK: <tt>decltype(p)</tt> is <tt>const int*</tt></em>
Vec<auto> v1 = make_vec({1, 2, 3}); <em>// OK: <tt>decltype(v1)</tt> is <tt>Vec<int></tt></em>
Vec<auto> v2 = {1, 2, 3}; <em>// error: type deduction fails</em>
Tuple<auto...> v3 = make_tup(0, ’a’); <em>// OK: <tt>decltype(v3)</tt> is <tt>Tuple<int, char></tt></em></ins>
</pre></tt>
</blockquote>
— <em>end example</em> ]<br/>
[ <em>Example:</em>
<blockquote class="code">
<tt><pre>
const auto &i = expr;
</pre></tt>
</blockquote>
The type of <tt>i</tt> is the deduced type of the parameter <tt>u</tt>
in the call <tt>f(expr)</tt> of the following invented function template:
<blockquote class="code">
<tt><pre>
template <class U> void f(const U& u);
</pre></tt>
</blockquote>
— <em>end example</em> ]<br/>
<ins>[ <em>Example:</em>
<blockquote class="code">
<tt><pre>
template<typename F, typename S> struct Pair;
template<typename T, typename U> Pair<T, U> make_pair(T, U);
struct S { void mfn(bool); } s;
int fn(char, double);
Pair<auto (*)(auto, auto), auto (auto::*)(auto)> p = make_pair(fn, &S::mfn);
</pre></tt>
</blockquote>
The declared type of <tt>p</tt> is the deduced type of the parameter
<tt>x</tt> in the call of <tt>g(make_pair(fn, &S::mfn))</tt> of the
following invented function template:
<blockquote class="code">
<tt><pre>
template<class T1, class T2, class T3, class T4, class T5, class T6>
void g(Pair< T1(*)(T2, T3), T4 (T5::*)(T6)> x);
</pre></tt>
</blockquote>
— <em>end example</em> ]<br/>
<ins>[ <em>Example:</em>
<blockquote class="code">
<tt><pre>
template<typename T> concept bool C = true;
const C* cv = expr;
</pre></tt>
</blockquote>
The type of <tt>cv</tt> is deduced from the parameter <tt>p1</tt> in the call
<tt>f1(expr)</tt> of the following invented function:
<blockquote class="code">
<tt><pre>
template<C T> void f1(const T* p1);
</pre></tt>
</blockquote>
— <em>end example</em> ]<br/>
<ins>[ <em>Example:</em>
<blockquote class="code">
<tt><pre>
auto cf(int) -> Pair<C, C> { return expr; }
</pre></tt>
</blockquote>
The return type of <tt>cf</tt> is deduced from the parameter <tt>p2</tt>
in the call <tt>f2(expr)</tt> of the following invented function:
<blockquote class="code">
<tt><pre>
template<C T> void f2(Pair<T, T> p2);
</pre></tt>
</blockquote>
Both <em>constrained-type-specifier</em>s in the return type of <tt>cf</tt>
correspond to the same invented template parameter.
<br/>— <em>end example</em> ]<br/>
<ins>[ <em>Example:</em>
<blockquote class="code">
<tt><pre>
namespace N {
template<typename T> concept bool C = true;
}
template<typename T> concept bool C = true;
template<typename T, int> concept bool D = true;
template<typename, int = 0> concept bool E = true;
auto gl1 = [](C, D<0>) {};
</pre></tt>
</blockquote>
The <em>constrained-type-specifier</em>s <tt>C</tt> and <tt>D<0></tt>
correspond to distinct invented template parameters in the declaration of the
function call operator template of the closure type.
<blockquote class="code">
<tt><pre>
auto gl2 = [](C a, C b) {};
</pre></tt>
</blockquote>
The types of <tt>a</tt> and <tt>b</tt> are the same invented template type
parameter.
<blockquote class="code">
<tt><pre>
auto gl3 = [](C& a, C* b) {};
</pre></tt>
</blockquote>
The type of <tt>a</tt> is a reference to an invented template type parameter
<tt>T</tt>, and the type of <tt>b</tt> is a <em>pointer</em> to <tt>T</tt>.
<blockquote class="code">
<tt><pre>
auto gl4 = [](N::C a, C b) {};
auto gl5 = [](D<0> a, D<1> b) {};
</pre></tt>
</blockquote>
In both <em>lambda-expression</em>s, the parameters <tt>a</tt> and <tt>b</tt>
have different invented template type parameters.
<blockquote class="code">
<tt><pre>
auto gl6 = [](E a, E<> b, E<0> c) {};
</pre></tt>
</blockquote>
The types of <tt>a</tt>, <tt>b</tt>, and <tt>c</tt> are the same because the
<em>constrained-type-specifier</em>s <tt>E</tt>, <tt>E<></tt>, and
<tt>E<0></tt> all associate the <em>constraint-expression</em>
<tt>E<T, 0></tt>, where <tt>T</tt> is an invented template type parameter.
<blockquote class="code">
<tt><pre>
auto gl7 = [](C head, C... tail) {};
</pre></tt>
</blockquote>
The types of <tt>head</tt> and <tt>tail</tt> are different. Their respective
introduced <em>constraint-expression</em>s are <tt>C<T></tt> and
<tt>(C<U> && ...)</tt>, where <tt>T</tt> is the template
parameter invented for <tt>head</tt> and <tt>U</tt> is the template parameter
invented for <tt>tail</tt> (17.1).
<br/>— <em>end example</em> ]<br/>
</ins></blockquote>
</p>
<p>Change the example in 10.1.7.4.2 [dcl.spec.auto.constr] paragraph 1:
<blockquote>
[…]<br/>
[ <em>Example:</em>
<blockquote class="code">
<tt><pre>
template<typename T> concept bool C1 = false;
template<int N> concept bool C2 = false;
template<template<typename> class X> concept bool C3 = false;
template<typename T, int N> class Array { };
template<typename T, template<typename> class A> class Stack { };
template<typename T> class Alloc { };
<del>void f1(C1); <em>// <tt>C1</tt> designates a placeholder type</em>
void f2(Array<auto, C2>); <em>// <tt>C2</tt> designates a placeholder for an integer value</em>
void f3(Stack<auto, C3>); <em>// <tt>C3</tt> designates a placeholder for a class template</em></del>
<ins>C1 f1(); <em>// <tt>C1</tt> designates a placeholder type</em>
Array<auto, C2> f2(); <em>// <tt>C2</tt> designates a placeholder for an integer value</em>
Stack<auto, C3> f3(); <em>// <tt>C3</tt> designates a placeholder for a class template</em></ins>
</pre></tt>
</blockquote>
— <em>end example</em>
</blockquote>
</p>
<p>Change in 10.1.7.4.2 [dcl.spec.auto.constr] paragraph 2:
<blockquote>
An identifier is a <em>concept-name</em> if it refers to a set of concept
definitions (10.1.8). [ <em>Note:</em> The set of concepts has multiple members
only when referring to a set of overloaded function concepts. There is at most
one member of this set when a <em>concept-name</em> refers to a variable
concept. <em>— end note</em> ] [ <em>Example:</em>
<blockquote class="code">
<tt><pre>
template<typename T> concept bool C() { return true; } <em>// #1</em>
template<typename T, typename U> concept bool C() { return true; } <em>// #2</em>
template<typename T> concept bool D = true; <em>// #3</em>
<ins>template<C T> </ins>void f(<del>C</del><ins>T</ins>); <em>// OK: the set of concepts referred to by C includes both #1 and #2;</em>
<em>// concept resolution (17.10.4) selects #1.</em>
<ins>template<D T> </ins>void g(<del>D</del><ins>T</ins>); <em>// OK: the concept-name <tt>D</tt> refers only to #3</em>
</pre></tt>
</blockquote>
<em>— end example</em> ]
</blockquote>
</p>
<p>Change in 10.1.7.4.2 [dcl.spec.auto.constr] paragraph 3:
<blockquote>
A <em>partial-concept-id</em> is a <em>concept-name</em> followed by a sequence
of <em>template-argument</em>s. [ <em>Example:</em>
<blockquote class="code">
<tt><pre>
template<typename T, int N = 0> concept bool Seq = true;
<ins>template<Seq<3> T> </ins>void f1(<del>Seq<3></del><ins>T</ins>); <em>// OK</em>
<ins>template<Seq<> T> </ins>void f2(<del>Seq<></del><ins>T</ins>); <em>// OK</em>
</pre></tt>
</blockquote>
<em>— end example</em> ]
</blockquote>
</p>
<p>Change in 10.1.7.4.2 [dcl.spec.auto.constr] paragraph 5:
<blockquote>
[…] The rules for inventing template parameters corresponding to
placeholders in the <em>parameter-declaration-clause</em> of a
<em>lambda-expression</em> (8.1.2)<del> or function declaration (11.3.5)</del>
are described in <del>11.3.5</del><ins>10.1.7.4.1</ins> […]
</blockquote>
</p>
<p>Remove the added paragraphs 18-21 inserted in 11.3.5 [dcl.fct]:
<blockquote>
<del>Add the following paragraphs after paragraph 17.</del>
<blockquote>
<del>18 An <em>abbreviated function template</em> is a function declaration</del>
[…]
<del>— <em>end note</em> ]</del>
</blockquote>
<blockquote>
<del>19 Each template parameter is invented as follows.</del><br/>
[…]<br/>
<del>where <tt>T</tt> is the template parameter invented for <tt>head</tt> and
<tt>U</tt> is the <em>template parameter</em> invented for <tt>tail</tt> (14.1).</del>
</blockquote>
<blockquote>
<del>20 The adjusted function parameters of an abbreviated function template
are derived</del> […]<br/>
[…]<br/>
<del>— <em>end example</em> ]</del>
</blockquote>
<blockquote>
<del>19 A function template can be an abbreviated function template.</del> […]</br>
[…]<br/>
<del>— <em>end example</em> ]</del>
</blockquote>
</blockquote>
</p>
<p>Change in 17 [temp]:
<blockquote>
Modify the <em>template-declaration</em> grammar in paragraph 1 to allow a
template declaration <del>introduced by a concept</del><ins> to specify a
<em>requires-clause</em></ins>.