File: 03b.mss

package info (click to toggle)
ada-reference-manual 1%3A2012.3-2
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 12,872 kB
  • sloc: ada: 29,393; makefile: 193; python: 92
file content (2409 lines) | stat: -rwxr-xr-x 103,406 bytes parent folder | download | duplicates (6)
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
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
@Part(03, Root="ada.mss")

@Comment{$Date: 2006/10/17 05:29:42 $}

@Comment{$Source: e:\\cvsroot/ARM/Source/03b.mss,v $}
@Comment{$Revision: 1.66 $}

@LabeledClause{Array Types}

@begin{Intro}
@Defn{array}
@Defn{array type}
An @i(array) object is a composite object consisting of components
which all have the same subtype.
The name for a component of an array uses one or more
index values belonging to specified discrete types.
The value of an array object is a composite
value consisting of the values of the components.
@end{Intro}

@begin{Syntax}
@Syn{lhs=<array_type_definition>,rhs="
   @Syn2{unconstrained_array_definition} | @Syn2{constrained_array_definition}"}


@Syn{lhs=<unconstrained_array_definition>,rhs="
   @key{array}(@Syn2{index_subtype_definition} {, @Syn2{index_subtype_definition}}) @key{of} @Syn2{component_definition}"}

@Syn{lhs=<index_subtype_definition>,rhs="@Syn2{subtype_mark} @key{range} <>"}

@Syn{lhs=<constrained_array_definition>,rhs="
   @key{array} (@Syn2{discrete_subtype_definition} {, @Syn2{discrete_subtype_definition}}) @key{of} @Syn2{component_definition}"}

@Syn{lhs=<discrete_subtype_definition>,rhs="@SynI{discrete_}@Syn2{subtype_indication} | @Syn2{range}"}

@ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00230-01],ARef=[AI95-00406-01]}
@Syn{lhs=<component_definition>,rhs="@Chg{Version=[2],New=<
   >,Old=<>}[@key{aliased}] @Syn2{subtype_indication}@Chg{Version=[2],New=<
 | [@key{aliased}] @Syn2{access_definition}>,Old=<>}"}
@end{Syntax}

@begin{Resolution}
@PDefn2{Term=[expected type], Sec=(discrete_subtype_definition range)}
For a @nt<discrete_subtype_definition> that is a @nt<range>, the
@nt<range> shall resolve to be of some specific discrete
type@Redundant[; which
  discrete type shall be determined without using any context other than
  the bounds of the @nt<range> itself (plus the preference
  for @i(root_integer) @em
  see @RefSecNum(The Context of Overload Resolution)).]
@end{Resolution}

@begin{Legality}
@Defn{index subtype}
Each @nt{index_subtype_definition}
or @nt{discrete_subtype_definition} in an @nt{array_type_definition}
defines an @i(index subtype);
@Defn{index type}
its type (the @i(index type)) shall be discrete.
@begin{Discussion}
@Defn2{Term=[index], Sec=(of an array)}
An @i(index) is a discrete quantity used to select along a given
dimension of an array. A component is selected by specifying corresponding
values for each of the indices.
@end{Discussion}

@Defn{component subtype}
The subtype defined by the @nt<subtype_indication> of a
@nt<component_definition> (the @i(component subtype)) shall be
a definite subtype.
@begin{Ramification}

  This applies to all uses of @nt<component_definition>,
  including in @nt<record_type_definition>s and @nt<protected_definition>s.@end{ramification}

@ChgRef{Version=[2],Kind=[Deleted],ARef=[AI95-00363-01]}
@ChgDeleted{Version=[2],Text=[Within the definition of a
nonlimited composite type
(or a limited composite type that later in its immediate
scope becomes nonlimited @em see @RefSecNum{Private Operations}
and @RefSecNum{Limited Types}),
if a @nt{component_definition} contains the reserved word
@key[aliased] and the type of the component is discriminated,
then the nominal subtype of the component shall be constrained.]}
@begin{Reason}
@ChgRef{Version=[2],Kind=[DeletedNoDelMsg]}
@ChgNote{The rule's gone, we might as well clobber all the notes.}
@ChgDeleted{Version=[2],Text=[If we allowed the subtype to be unconstrained,
then the discriminants might change because of
an assignment to the containing (nonlimited) object,
thus causing a potential violation of an access subtype constraint
of an access value designating the aliased component.]}

@ChgRef{Version=[2],Kind=[DeletedNoDelMsg]}
@ChgDeleted{Version=[2],Text=[Note that the rule elsewhere defining all aliased
discriminated objects to be constrained does not help @em that rule prevents
assignments to the component itself from doing any harm, but not assignments to
the containing object.]}

@ChgRef{Version=[2],Kind=[DeletedNoDelMsg]}
@ChgDeleted{Version=[2],Type=[Leading],Text=[We allow this
for components within limited types since assignment to
the enclosing object is not a problem. Furthermore, it is
important to be able to use a default expression for a discriminant
in arrays of limited components, since that is the only way
to give the components different values for their discriminants.
For example:]}
@begin{Example}
@ChgRef{Version=[2],Kind=[DeletedNoDelMsg]}
@ChgDeleted{Version=[2],Text=[@key[protected] @key[type] Counter_Type(Initial_Value : Integer := 1) @key[is]
   @key[procedure] Get_Next(Next_Value : @key[out] Integer);
     --@RI{ Returns the next value on each call, bumping Count}
     --@RI{ before returning.}
@key[private]
   Count : Integer := Initial_Value;
@key[end] Counter_Type;
@key[protected] @key[body] Counter_Type @key[is] ...]}

@ChgRef{Version=[2],Kind=[DeletedNoDelMsg]}
@ChgDeleted{Version=[2],Text=[@key[function] Next_Id(Counter : @key[access] Counter_Type) @key[return] Integer @key[is]
    Result : Integer;
@key[begin]
    Counter.Get_Next(Result);
    @key[return] Result;
@key[end] Next_Id;]}

@ChgRef{Version=[2],Kind=[DeletedNoDelMsg]}
@ChgDeleted{Version=[2],Text=[C : @key[aliased] Counter_Type;
@key[task] @key[type] T(Who_Am_I : Integer := Next_Id(C'Access));
@key[task] @key[body] T @key[is] ...]}

@ChgRef{Version=[2],Kind=[DeletedNoDelMsg]}
@ChgDeleted{Version=[2],Text=[Task_Array : @key[array](1..100) @key[of] @key[aliased] T;
  --@RI{ Array of task elements, each with its own unique ID.}
  --@RI{ We specify "aliased" so we can use Task_Array(I)'Access.}
  --@RI{ This is safe because Task_Array is of a limited type,}
  --@RI{ so there is no way an assignment to it could change}
  --@RI{ the discriminants of one of its components.}]}
@end{Example}
@end{Reason}
@begin{Ramification}
@ChgRef{Version=[2],Kind=[DeletedNoDelMsg]}
@ChgDeleted{Version=[2],Text=[Note that this rule applies to array components
and record components, but not to protected type components (since
they are always limited).]}
@end{Ramification}
@end{Legality}

@begin{StaticSem}
@Defn2{Term=[dimensionality], Sec=(of an array)}
@Defn{one-dimensional array}
@Defn{multi-dimensional array}
An array is characterized by the number of indices
(the @i(dimensionality) of the array), the type and position
of each index, the lower and upper bounds for each index, and
the subtype of the components.
The order of the indices is significant.

A one-dimensional array has a distinct component for each possible index
value. A multidimensional array has a distinct component for each possible
sequence of index values that can be formed by selecting one value for
each index position (in the given order).
The possible values for a given index are all the values between the
lower and upper bounds, inclusive;
@Defn{index range}
this range of values is called the @i(index range).
@Defn2{Term=[bounds], Sec=(of an array)}
The @i(bounds) of an array are the bounds of its index ranges.
@Defn2{Term=[length], Sec=(of a dimension of an array)}
The @i(length) of a dimension of an array is
the number of values of the index range of the dimension (zero for
a null range).
@Defn2{Term=[length], Sec=(of a one-dimensional array)}
The @i(length) of a one-dimensional array is
the length of its only dimension.

An @nt<array_type_definition> defines an array type and its first subtype.
For each object of this array type, the number of indices, the type
and position of each index, and the subtype of the components
are as in the type definition@Redundant[; the values of the lower
and upper bounds for each index belong to
the corresponding index subtype of its type, except for null arrays
(see @RefSecNum(Index Constraints and Discrete Ranges))].

@Defn2{Term=[constrained], Sec=(subtype)}
@Defn2{Term=[unconstrained], Sec=(subtype)}
An @nt{unconstrained_array_definition} defines an array type with
an unconstrained first subtype.
Each @nt{index_@!subtype_@!definition} defines the
corresponding index subtype to be the subtype denoted
by the @nt{subtype_@!mark}.
@redundant[@PDefn2{Term=[box], Sec=(compound delimiter)}
The compound delimiter <> (called a @i(box)) of an
@nt<index_subtype_definition> stands for an undefined range
(different objects of the type need not have the same bounds).]

@Defn2{Term=[constrained], Sec=(subtype)}
@Defn2{Term=[unconstrained], Sec=(subtype)}
A @nt{constrained_array_definition} defines an array type with
a constrained first subtype.
Each @nt{discrete_@!subtype_@!definition}
defines the corresponding index subtype,
as well as the corresponding index range for the
constrained first subtype.
@PDefn2{Term=[constraint], Sec=(of a first array subtype)}
The @i(constraint) of the first subtype consists of the bounds
of the index ranges.
@begin{Discussion}
  Although there is no namable
  unconstrained array subtype in this case, the predefined slicing
  and concatenation operations can operate on and yield
  values that do not necessarily belong to the first array subtype.
  This is also true for Ada 83.
@end{Discussion}

@Leading@;The discrete subtype defined by a @nt{discrete_@!subtype_@!definition} is
either that defined by the @nt{subtype_@!indication}, or a subtype
determined by the @nt{range} as follows:
@begin(itemize)
  If the type of the @nt{range} resolves to @i(root_integer), then
  the @nt{discrete_subtype_definition} defines a subtype of the
  predefined type Integer with bounds given by a conversion to Integer
  of the bounds of the @nt<range>;
  @PDefn2{Term=[implicit subtype conversion],Sec=(bounds of a range)}
  @begin{Reason}
    This ensures that
    indexing over the discrete subtype can be performed with
    regular Integers, rather than only @i(universal_integer)s.
  @end{Reason}
  @begin{Discussion}
    We considered doing this by simply creating
    a @lquotes@;preference@rquotes@; for Integer when resolving the @nt<range>.
    @PDefn{Beaujolais effect}
    However, this can introduce @i(Beaujolais) effects when the
    @nt<simple_expression>s involve calls on functions visible
    due to @key(use) clauses.
  @end{Discussion}

  Otherwise, the @nt{discrete_subtype_definition} defines
  a subtype of the type of the @nt{range}, with the bounds given
  by the @nt<range>.
@end(itemize)

@PDefn2{Term=[nominal subtype], Sec=(of a component)}
The @nt{component_definition} of an @nt<array_type_definition>
defines the nominal subtype of the components.
If the reserved word @key(aliased) appears in the @nt{component_definition},
then each component of the array is aliased
(see @RefSecNum{Access Types}).
@begin(Ramification)
  @ChgRef{Version=[2],Kind=[DeletedNoDelMsg],ARef=[AI95-00363-01]}
  @ChgDeleted{Version=[2],Text=[In this case, the nominal subtype cannot be an
  unconstrained discriminated subtype. See @RefSecNum{Record Types}.]}
@end(Ramification)

@end{StaticSem}

@begin{RunTime}
@PDefn2{Term=[elaboration], Sec=(array_type_definition)}
The elaboration of an @nt{array_type_definition}
creates the array type and its first subtype,
and consists of the elaboration of any @nt{discrete_@!subtype_@!definition}s
and the @nt{component_@!definition}.

@ChgRef{Version=[1],Kind=[Revised],Ref=[8652/0002],ARef=[AI95-00171-01]}
@ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00230-01]}
@PDefn2{Term=[elaboration], Sec=(discrete_subtype_definition)}
The elaboration of a @nt{discrete_subtype_definition}
@Chg{New=[that does not contain any per-object expressions],Old=[]}
creates the discrete subtype, and consists
of the elaboration of the @nt{subtype_@!indication} or the
evaluation of the @nt{range}.
@Chg{New=[The elaboration of a @nt{discrete_subtype_definition} that contains
one or more per-object expressions is defined in @RefSecNum{Record Types}.],Old=[]}
@PDefn2{Term=[elaboration], Sec=(component_definition)}
The elaboration of a @nt{component_@!definition} in an
@nt{array_@!type_@!definition} consists of the elaboration
of the @nt{subtype_@!indication}@Chg{Version=[2],New=[ or @nt{access_definition}],Old=[]}.
The elaboration of any @nt{discrete_@!subtype_@!definition}s
and the elaboration of the
@nt{component_@!definition} are performed in an arbitrary order.
@end{RunTime}

@begin{Notes}
All components of an array have the same subtype. In particular, for an array
of components that are one-dimensional arrays, this means that all components
have the same bounds and hence the same length.

Each elaboration of an @nt<array_type_definition> creates
a distinct array type. A consequence of this is that each
object whose @nt<object_declaration> contains an @nt<array_type_definition>
is of its own unique type.
@end{Notes}

@begin{Examples}
@Leading@keepnext@i(Examples of type declarations with unconstrained array definitions: )
@begin(Example)
@key(type) Vector     @key(is) @key(array)(Integer  @key(range) <>) @key(of) Real;
@key(type) Matrix     @key(is) @key(array)(Integer  @key(range) <>, Integer @key(range) <>) @key(of) Real;
@key(type) Bit_Vector @key(is) @key(array)(Integer  @key(range) <>) @key(of) Boolean;
@key(type) Roman      @key(is) @key(array)(Positive @key(range) <>) @key(of) Roman_Digit; --@RI[ see @RefSecNum(Character Types)]
@end(Example)

@begin{Wide}
@leading@keepnext@i(Examples of type declarations with constrained array definitions: )
@end{Wide}
@begin(Example)
@key(type) Table    @key(is) @key(array)(1 .. 10) @key(of) Integer;
@key(type) Schedule @key(is) @key(array)(Day) @key(of) Boolean;
@key(type) Line     @key(is) @key(array)(1 .. Max_Line_Size) @key(of) Character;
@end(Example)

@begin{Wide}
@leading@keepnext@i(Examples of object declarations with array type definitions: )
@end{Wide}
@begin(Example)
@ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00433-01]}
Grid @Chg{Version=[2],New=[     ],Old=[]}: @key(array)(1 .. 80, 1 .. 100) @key(of) Boolean;
Mix  @Chg{Version=[2],New=[     ],Old=[]}: @key(array)(Color @key(range) Red .. Green) @key(of) Boolean;@Chg{Version=[2],New=[
Msg_Table : @key(constant array)(Error_Code) @key(of access constant) String :=
      (Too_Big => @key(new) String'("Result too big"), Too_Small => ...);],Old=[]}
Page @Chg{Version=[2],New=[     ],Old=[]}: @key(array)(Positive @key(range) <>) @key(of) Line :=  --@RI[  an array of arrays]
  (1 | 50  => Line'(1 | Line'Last => '+', @key(others) => '-'),  --@RI[ see @RefSecNum(Array Aggregates)]
   2 .. 49 => Line'(1 | Line'Last => '|', @key(others) => ' '));
    --@RI[ Page is constrained by its initial value to (1..50)]
@end(Example)
@end{Examples}

@begin{Extend83}
@Defn{extensions to Ada 83}
The syntax rule for @nt{component_definition} is modified to allow
the reserved word @key{aliased}.

The syntax rules for @nt{unconstrained_array_definition} and
@nt{constrained_array_definition} are modified to use
@nt{component_definition} (instead of
@i(component_)@nt{subtype_indication}). The effect of this change is to allow
the reserved word @key{aliased} before the
component @nt{subtype_indication}.

A @nt{range} in a @nt{discrete_subtype_definition}
may use arbitrary
universal expressions for each bound (e.g. @en@;1 .. 3+5), rather
than strictly "implicitly convertible" operands. The subtype
defined will still be a subtype of Integer.
@end{Extend83}

@begin{DiffWord83}
We introduce a new syntactic category, @nt{discrete_subtype_definition},
as distinct from @nt{discrete_range}. These two constructs have
the same syntax, but their semantics
are quite different (one defines a subtype, with
a preference for Integer subtypes, while the
other just selects a subrange of an existing subtype).
We use this new syntactic category in @key(for) loops
and entry families.

The syntax for @nt{index_constraint} and @nt{discrete_range}
have been moved to their own subclause, since they are no
longer used here.

The syntax rule for @nt{component_definition} (formerly
@ntf<component_subtype_definition>) is moved here from
RM83-3.7.
@end{DiffWord83}

@begin{Extend95}
  @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00230-01],ARef=[AI95-00406-01]}
  @ChgAdded{Version=[2],Text=[@Defn{extensions to Ada 95}
  Array components can have an anonymous access type.]}

  @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00363-01]}
  @ChgAdded{Version=[2],Text=[The prohibition against unconstrained
  discriminated aliased components has been lifted. It has been replaced
  by a prohibition against the actual troublemakers: general access
  discriminant constraints (see @RefSecNum{Discriminant Constraints}).]}
@end{Extend95}

@begin{DiffWord95}
  @ChgRef{Version=[2],Kind=[AddedNormal],Ref=[8652/0002],ARef=[AI95-00171-01]}
  @ChgAdded{Version=[2],Text=[@b<Corrigendum:> Added wording to allow
  the elaboration of per-object constraints for constrained arrays.]}
@end{DiffWord95}


@LabeledSubClause{Index Constraints and Discrete Ranges}

@begin{Intro}
An @nt<index_constraint> determines the range of possible values for every
index of an array subtype, and thereby the corresponding array bounds.
@end{Intro}

@begin{Syntax}
@Syn{lhs=<index_constraint>,rhs=" (@Syn2{discrete_range} {, @Syn2{discrete_range}})"}

@Syn{lhs=<discrete_range>,rhs="@SynI{discrete_}@Syn2{subtype_indication} | @Syn2{range}"}
@end{Syntax}

@begin{Resolution}
@Defn{type of a @nt{discrete_range}}
The type of a @nt<discrete_range> is the
type of the subtype defined by the @nt<subtype_indication>,
or the type of the @nt<range>.
@PDefn2{Term=[expected type], Sec=(index_constraint discrete_range)}
For an @nt{index_constraint},
each @nt{discrete_range} shall resolve to be of the type of the
corresponding index.
@begin(Discussion)
  In Ada 95, @nt{index_constraint}s only appear in
  a @nt{subtype_indication}; they no longer appear in
  @nt<constrained_array_definition>s.
@end(Discussion)

@end{Resolution}

@begin{Legality}
An @nt{index_constraint} shall appear only in a
@nt{subtype_indication} whose @nt{subtype_mark} denotes
either an unconstrained array subtype, or an
unconstrained access subtype whose designated subtype is
an unconstrained array subtype; in either case,
the @nt{index_constraint} shall provide a @nt{discrete_range}
for each index of the array type.
@end{Legality}

@begin{StaticSem}
@Defn2{Term=[bounds], Sec=(of a @nt<discrete_range>)}
A @nt{discrete_range} defines a range whose bounds are given
by the @nt{range}, or by the range of the subtype defined by the
@nt{subtype_indication}.
@end{StaticSem}

@begin{RunTime}
@PDefn2{Term=[compatibility], Sec=(index constraint with a subtype)}
An @nt{index_constraint} is @i(compatible) with an unconstrained array subtype
if and only if the index range defined by each @nt{discrete_range}
is compatible (see @RefSecNum(Scalar Types)) with the corresponding index subtype.
@Defn{null array}
If any of the @nt<discrete_range>s defines a null range, any array thus
constrained is a @i(null array), having no components.
@PDefn2{Term=[satisfies], Sec=(an index constraint)}
An array value @i(satisfies) an @nt{index_constraint} if at each index position
the array value and the @nt{index_constraint} have the same index
bounds.
@begin{Ramification}

  There is no need to define compatibility with a constrained
  array subtype, because one is not allowed to constrain it again.@end{ramification}

@PDefn2{Term=[elaboration], Sec=(index_constraint)}
The elaboration of an @nt{index_constraint} consists
of the evaluation of the @nt{discrete_range}(s), in an arbitrary order.
@PDefn2{Term=[evaluation], Sec=(discrete_range)}
The evaluation of a @nt{discrete_range}
consists of the elaboration of the @nt{subtype_indication}
or the evaluation of the @nt{range}.
@end{RunTime}

@begin{Notes}
The elaboration of a @nt<subtype_indication> consisting
of a @nt<subtype_mark> followed
by an @nt<index_constraint> checks the compatibility of the
@nt<index_constraint> with the @nt<subtype_mark>
(see @RefSecNum(Subtype Declarations)).

Even if an array value does not satisfy the index constraint
of an array subtype, Constraint_Error is not
raised on conversion to the array subtype, so long as
the length of each dimension of the array value and the
array subtype match. See @RefSecNum(Type Conversions).
@end{Notes}

@begin{Examples}
@leading@keepnext@i(Examples of array declarations including an index constraint: )
@begin(Example)
Board     : Matrix(1 .. 8,  1 .. 8);  --@RI[  see @RefSecNum(Array Types)]
Rectangle : Matrix(1 .. 20, 1 .. 30);
Inverse   : Matrix(1 .. N,  1 .. N);  --@RI[  N need not be static ]

Filter    : Bit_Vector(0 .. 31);
@end(Example)

@begin{Wide}
@leading@keepnext@i(Example of array declaration with a constrained array subtype: )
@end{Wide}
@begin(Example)
My_Schedule : Schedule;  --@RI[  all arrays of type Schedule have the same bounds]
@end(Example)

@begin{Wide}
@leading@keepnext@i(Example of record type with a component that is an array: )
@end{Wide}
@begin(Example)
@key(type) Var_Line(Length : Natural) @key(is)
   @key(record)
      Image : String(1 .. Length);
   @key(end) @key(record);

Null_Line : Var_Line(0);  --@RI[  Null_Line.Image is a null array]
@end(Example)
@end{Examples}

@begin{Extend83}
@Defn{extensions to Ada 83}
We allow the declaration of a variable with
a nominally unconstrained array subtype, so long as
it has an initialization expression to determine
its bounds.
@end{Extend83}

@begin{DiffWord83}
We have moved the syntax for @nt{index_constraint} and
@nt{discrete_range} here since they are no longer
used in @nt{constrained_array_definition}s.
We therefore also no longer have to describe the
(special) semantics of @nt{index_constraint}s and @nt{discrete_range}s
that appear in @nt{constrained_array_definition}s.

The rules given in RM83-3.6.1(5,7-10),
which define the bounds of an array object, are redundant
with rules given elsewhere, and so are not repeated here.
RM83-3.6.1(6), which requires that the (nominal) subtype of
an array variable be constrained, no longer applies,
so long as the variable is explicitly initialized.
@end{DiffWord83}

@LabeledSubClause{Operations of Array Types}

@begin{Legality}
@Redundant[The argument N used in the @nt<attribute_designator>s for
the N-th dimension of an array shall be a static @nt<expression> of
some integer type.] The value of N shall be positive (nonzero)
and no greater than the dimensionality of the array.
@end{Legality}

@begin{StaticSem}
@ChgRef{Version=[1],Kind=[Revised],Ref=[8652/0006],ARef=[AI95-00030-01]}
The following attributes are defined for
@ChgPrefixType{Version=[1],Kind=[Revised],Text=[a @Chg{New=[@nt{prefix}],
Old=[prefix]} A that is of an array type
@Redundant[(after any implicit dereference)], or denotes
a constrained array subtype]}:
@begin{Ramification}
These attributes are not defined if A is a subtype-mark
  for an access-to-array subtype. They are defined (by implicit
  dereference) for access-to-array values.@end{ramification}
@begin(description)
@Attribute{Prefix=<A>, AttrName=<First>,
  Text=[A'First denotes the lower bound of the first index range; its
  type is the corresponding index type.]}

@Attribute{Prefix=<A>, AttrName=<First(N)>,
  Text=[A'First(N) denotes the lower bound of the N-th index range; its
  type is the corresponding index type.]}

@Attribute{Prefix=<A>, AttrName=<Last>,
  Text=[A'Last denotes the upper bound of the first index range; its
  type is the corresponding index type.]}

@Attribute{Prefix=<A>, AttrName=<Last(N)>,
  Text=[A'Last(N) denotes the upper bound of the N-th index range; its
  type is the corresponding index type.]}

@Attribute{Prefix=<A>, AttrName=<Range>,
  Text=[A'Range is equivalent to the range A'First .. A'Last,
  except that the @nt<prefix> A is only evaluated once.]}

@Attribute{Prefix=<A>, AttrName=<Range(N)>,
  Text=[A'Range(N) is equivalent to the range A'First(N) .. A'Last(N),
  except that the @nt<prefix> A is only evaluated once.]}

@Attribute{Prefix=<A>, AttrName=<Length>,
  Text=[A'Length denotes the number of values of the first index
  range (zero for a null range); its type is @i(universal_integer).]}

@Attribute{Prefix=<A>, AttrName=<Length(N)>,
  Text=[A'Length(N) denotes the number of values of the N-th index
  range (zero for a null range); its type is @i(universal_integer).]}
@end(description)
@EndPrefixType{}
@end{StaticSem}

@begin{ImplAdvice}
An implementation should normally represent
multidimensional arrays in row-major order, consistent with the notation used
for multidimensional array aggregates (see @RefSecNum(Array Aggregates)).
However, if a @key<pragma> Convention(Fortran, ...) applies to a
multidimensional array type, then column-major order should be used
instead (see @RefSec{Interfacing with Fortran}).
@ChgImplAdvice{Version=[2],Kind=[AddedNormal],Text=[@ChgAdded{Version=[2],
Text=[Multidimensional arrays should be represented in row-major order,
unless the array has convention Fortran.]}]}
@end{ImplAdvice}

@begin{Notes}
@Leading@;The @nt<attribute_reference>s A'First and A'First(1) denote the same value.
A similar relation exists for the @nt<attribute_reference>s A'Last,
A'Range, and A'Length. The following relation is satisfied (except
for a null array) by the above attributes if the index type is an
integer type:
@begin(example)
   A'Length(N) = A'Last(N) - A'First(N) + 1
@end(example)

An array type is limited if its component type is limited
(see @RefSecNum(Limited Types)).

@PDefn2{Term=[predefined operations],Sec=(of an array type)}
The predefined operations of an array type include the
membership tests, qualification, and explicit conversion.
If the array type is not limited, they also include assignment
and the predefined
equality operators. For a one-dimensional array type,
they include the predefined concatenation operators (if nonlimited) and,
if the component type is discrete, the predefined relational operators;
if the component type is boolean, the predefined
logical operators are also included.

@ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00287-01]}
A component of an array can be named with an @nt<indexed_component>.
A value of an array type can be specified with an
@nt<array_aggregate>@Chg{Version=[2],New=[],Old=[, unless the array type
is limited]}.
For a one-dimensional array type, a slice of the array can be named;
also, string literals are defined if the component type is
a character type.
@end{Notes}

@begin{Examples}
@Leading@keepnext@i{Examples (using arrays declared in the examples of subclause @RefSecNum(Index Constraints and Discrete Ranges)):}
@begin(Example)
--  Filter'First      =   0   Filter'Last       =  31   Filter'Length =  32
--  Rectangle'Last(1) =  20   Rectangle'Last(2) =  30
@end(Example)

@end{Examples}

@LabeledSubClause{String Types}

@begin{StaticSem}
@Defn{string type}
A one-dimensional array type whose component type is a character type
is called a @i(string) type.

@ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00285-01]}
@Leading@redundant[There are @Chg{Version=[2],New=[three],Old=[two]} predefined
string types, String@Chg{Version=[2],New=[,],Old=[ and]}
Wide_String@Chg{Version=[2],New=[, and Wide_Wide_String],Old=[]},
each indexed by values of the predefined subtype Positive;
these are declared in the visible part of package Standard:]
@begin(example)
@redundant[@key(subtype) Positive @key(is) Integer @key(range) 1 .. Integer'Last;

@ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00285-01]}
@key(type) String @key(is) @key(array)(Positive @key(range) <>) @key(of) Character;
@key(type) Wide_String @key(is) @key(array)(Positive @key(range) <>) @key(of) Wide_Character;
@Chg{Version=[2],New=[@key(type) Wide_Wide_String @key(is) @key(array)(Positive @key(range) <>) @key(of) Wide_Wide_Character;],Old=[]}
]@end(example)
@end{StaticSem}

@begin{Notes}
String literals (see @RefSecNum(String Literals) and
@RefSecNum(Literals)) are defined for all string types.
The concatenation operator & is predefined
for string types, as for all nonlimited
one-dimensional array types.
The ordering operators <, <=, >, and >= are predefined
for string types, as for all one-dimensional discrete array types;
these ordering operators correspond to lexicographic order
(see @RefSecNum(Relational Operators and Membership Tests)).

@end{Notes}

@begin{Examples}
@Leading@keepnext@i(Examples of string objects:)
@begin(Example)
@TabClear()@TabSet(P50)
Stars      : String(1 .. 120) := (1 .. 120 => '*' );
Question   : @key(constant) String  := "How many characters?";
@\--@RI[ Question'First = 1, Question'Last = 20]
@\--@RI[ Question'Length = 20 (the number of characters)]

Ask_Twice  : String  := Question & Question;@\--@RI[ constrained to (1..40)]
Ninety_Six : @key(constant) Roman   := "XCVI";@\--@RI[ see @RefSecNum(Character Types) and @RefSecNum(Array Types)]
@end(Example)
@end{Examples}

@begin{Inconsistent83}
@Defn{inconsistencies with Ada 83}
The declaration of Wide_String in Standard hides a use-visible
declaration with the same @nt<defining_identifier>.
In rare cases, this might result in an inconsistency between
Ada 83 and Ada 95.
@end{Inconsistent83}

@begin{Incompatible83}
@Defn{incompatibilities with Ada 83}
Because both String and Wide_String are always directly visible,
an expression like
@begin(Example)
"a" < "bc"
@end(Example)

is now ambiguous, whereas in Ada 83 both string literals could
be resolved to type String.
@end{Incompatible83}

@begin{Extend83}
@Defn{extensions to Ada 83}
The type Wide_String is new (though it was approved by
ARG for Ada 83 compilers as well).
@end{Extend83}

@begin{DiffWord83}
We define the term @i(string type) as a natural analogy
to the term @i(character type).
@end{DiffWord83}

@begin{Inconsistent95}
@ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00285-01]}
@ChgAdded{Version=[2],Text=[@Defn{inconsistencies with Ada 95}
The declaration of Wide_Wide_String in Standard hides a use-visible
declaration with the same @nt<defining_identifier>.
In the (very) unlikely event that an Ada 95 program had
depended on such a use-visible declaration, and the program remains
legal after the substitution of Standard.Wide_Wide_String,
the meaning of the program will be different.]}
@end{Inconsistent95}

@begin{Extend95}
  @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00285-01]}
  @ChgAdded{Version=[2],Text=[@Defn{extensions to Ada 95}
  The type Wide_Wide_String is new.]}
@end{Extend95}


@LabeledClause{Discriminants}

@begin{Intro}
@ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00251-01],ARef=[AI95-00326-01]}
@redundant[@Defn{discriminant}
@IndexSee{Term=[type parameter],See=(discriminant)}
@IndexSeeAlso{Term=[parameter],See=(discriminant)}
A composite type (other than an array@Chg{Version=[2],New=[ or
interface],Old=[]} type) can have discriminants,
which parameterize the type.
A @nt<known_discriminant_part> specifies the discriminants
of a composite type.
A discriminant of an object is a component of the object,
and is either of a discrete type or an access type.
An @nt<unknown_discriminant_part> in the declaration of
a@Chg{Version=[2],New=[],Old=[ partial]} view of a type
specifies that the discriminants of the type are unknown
for the given view;
all subtypes of such a@Chg{Version=[2],New=[],Old=[ partial]} view
are indefinite subtypes.]
@ChgRef{Version=[2],Kind=[Revised]}
@ChgToGlossary{Version=[2],Kind=[Revised],Term=<Discriminant>,
  Text=<A discriminant is a parameter @Chg{Version=[2],New=[for],Old=[of]} a composite type.
  It can control, for example, the bounds of a component
  of the type if @Chg{Version=[2],New=[the component is],Old=[that type is]}
  an array@Chg{Version=[2],New=[],Old=[ type]}.
  A discriminant @Chg{Version=[2],New=[for],Old=[of]} a task type can be
  used to pass data to a task of the type upon creation.>}
@begin{Discussion}
  @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00114-01]}
  @PDefn{unknown discriminants}
  @PDefn2{Term=[discriminants], Sec=(unknown)}
  A @Chg{Version=[2],New=[view of a ],Old=[]}type, and all @Chg{Version=[2],New=[],
  Old=[of its ]}subtypes@Chg{Version=[2],New=[ of the view],Old=[]}, have
  @i(unknown discriminants)
  when the number or names of the discriminants, if any, are unknown at
  the point of the type declaration@Chg{Version=[2],New=[ for the view],Old=[]}.
  A @nt<discriminant_part> of (<>) is used to indicate unknown discriminants.
@end{Discussion}
@end{Intro}

@begin{Metarules}
  @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00402-01]}
  @ChgAdded{Version=[2],Text=[When an access discriminant
  is initialized at the time of object creation with an allocator
  of an anonymous type, the allocated object and the object
  with the discriminant are tied together for their lifetime.
  They should be allocated out of the same storage pool,
  and then at the end of the lifetime of the enclosing object, finalized
  and reclaimed together. In this case, the allocated object is called
  a coextension (see @RefSecNum{Operations of Access Types}).]}
@begin{Discussion}
  @ChgRef{Version=[2],Kind=[AddedNormal]}
  @ChgAdded{Version=[2],Text=[The above principle when applied to a
  nonlimited type implies that such an object may be copied only to a
  shorter-lived object, because attempting to assign it to a longer-lived
  object would fail because the access discriminants would not match.
  In a copy, the lifetime connection between the enclosing object
  and the allocated object does not exist. The allocated object is
  tied in the above sense only to the original object. Other copies
  have only secondary references to it.]}

  @ChgRef{Version=[2],Kind=[AddedNormal]}
  @ChgAdded{Version=[2],Text=[Note that when an @nt{allocator} appears as a
  constraint on an access discriminant in a @nt{subtype_indication}
  that is elaborated independently from object creation,
  no such connection exists. For example, if a named constrained
  subtype is declared via
  "@key{subtype} Constr @key{is} Rec(Acc_Discrim => @key{new} T);"
  or if such an @nt{allocator} appears in the @nt{subtype_indication} for
  a component, the allocator is evaluated when the @nt{subtype_indication}
  is elaborated, and hence its lifetime is typically longer than
  the objects or components that will later be subject to the
  constraint. In these cases, the allocated object should not
  be reclaimed until the @nt{subtype_indication} goes out of scope.]}
@end{Discussion}
@end{Metarules}

@begin{Syntax}
@Syn{lhs=<discriminant_part>,rhs="@Syn2{unknown_discriminant_part} | @Syn2{known_discriminant_part}"}

@Syn{lhs=<unknown_discriminant_part>,rhs="(<>)"}

@Syn{lhs=<known_discriminant_part>,rhs="
   (@Syn2{discriminant_specification} {; @Syn2{discriminant_specification}})"}

@ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00231-01]}
@Syn{lhs=<discriminant_specification>,rhs="
   @Syn2{defining_identifier_list} : @Chg{Version=[2],New=<[@Syn2{null_exclusion}] >,Old=<>}@Syn2{subtype_mark} [:= @Syn2{default_expression}]
 | @Syn2{defining_identifier_list} : @Syn2{access_definition} [:= @Syn2{default_expression}]"}

@Syn{lhs=<default_expression>,rhs="@Syn2{expression}"}
@end{Syntax}

@begin{Resolution}
@PDefn2{Term=[expected type], Sec=(discriminant default_expression)}
The expected type for the @nt{default_expression}
of a @nt{discriminant_specification} is that of the corresponding
discriminant.
@end{Resolution}

@begin{Legality}
@ChgRef{Version=[1],Kind=[Revised],Ref=[8652/0007],ARef=[AI95-00098-01]}
@ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00251-01]}
A @Chg{New=[@nt{discriminant_part}],Old=[@nt{known_discriminant_part}]} is only
permitted in a declaration for a composite type that is not an
array@Chg{Version=[2],New=[ or interface],Old=[]} type
@Redundant[(this includes generic formal types)]@Chg{New=[. A],Old=[; a]}
type declared with a @nt<known_discriminant_part> is called
a @i(discriminated) type,@Defn{discriminated type} as is a type that inherits
(known) discriminants.
@begin{ImplNote}
  Discriminants on array types were considered,
  but were omitted to ease (existing) implementations.
@end{implnote}
@begin(Discussion)
  Note that the above definition for @lquotes@;discriminated type@rquotes@; does
  not include types declared with an @nt<unknown_discriminant_part>.
  This seems consistent with Ada 83, where such types (in a generic
  formal part) would not be considered discriminated types.
  Furthermore, the full type for a type with unknown discriminants
  need not even be composite, much less have any discriminants.

  @ChgRef{Version=[1],Kind=[Added],Ref=[8652/0007],ARef=[AI95-00098-01]}
  @Chg{New=[On the other hand, @nt<unknown_discriminant_part>s cannot be
  applied to type declarations that cannot have a @nt<known_discriminant_part>.
  There is no point in having unknown discriminants on a type that can never
  have discriminants (for instance, a formal modular type), even when these
  are allowed syntactically.],Old=[]}
@end(Discussion)

@ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00231-01],ARef=[AI95-00254-01]}
The subtype of a discriminant may be defined
by@Chg{Version=[2],New=[ an optional @nt{null_exclusion} and],Old=[]} a
@nt<subtype_mark>, in which case the @nt<subtype_mark> shall denote
a discrete or access subtype, or it may be defined by an
@nt<access_definition>@Chg{Version=[2],New=[],Old=[ @Redundant[(in which case
the @nt<subtype_mark> of the @nt<access_definition> may denote
any kind of subtype)]]}.
@Defn{access discriminant}
A discriminant that is defined by an @nt<access_definition>
is called an @i(access discriminant)
and is of an anonymous @Chg{Version=[2],New=[access],
Old=[general access-to-variable]} type@Chg{Version=[2],New=[],Old=[ whose
designated subtype is
denoted by the @nt<subtype_mark> of the @nt<access_definition>]}.
@begin(Reason)
  @ChgRef{Version=[2],Kind=[Deleted],ARef=[AI95-00230-01]}
  @ChgNote{It still does cause complexities. :-)}@ChgNote{We don't
  want to delete "Reason:" here, thus we use @Chg and not @ChgDeleted}
  @Chg{Version=[2],New=[],Old=[In an early version of Ada 9X,
  we allowed access discriminants on nonlimited types,
  but this created unpleasant complexities.
  It turned out to be simpler and more uniform to allow discriminants
  of a named access type on any discriminated type, and keep access
  discriminants just for limited types.]}

  Note that discriminants of a named access type are not
  considered @lquotes@;access discriminants.@rquotes@;
  Similarly, @lquotes@;access parameter@rquotes@;
  only refers to a formal parameter defined by an @nt<access_definition>.
@end(Reason)

@ChgNote{This paragraph is just moved up}
@ChgRef{Version=[2],Kind=[Added],ARef=[AI95-00402-01]}
@ChgAdded{Version=[2],Text=[@nt{Default_expression}s shall be provided either
for all or for none
of the discriminants of a @nt{known_@!discriminant_@!part}.
No @nt<default_@!expression>s are permitted in a
@nt<known_@!discriminant_@!part> in a declaration of a tagged
type @Redundant[or a generic formal type].]}

@begin(Reason)
  @ChgRef{Version=[2],Kind=[AddedNormal]}
  @ChgAdded{Version=[2],Text=[The all-or-none rule
  is related to the rule that a discriminant constraint shall specify
  values for all discriminants. One could imagine a different rule
  that allowed a constraint to specify only some of the discriminants,
  with the others provided by default. Having defaults for discriminants
  has a special significance @em it allows objects of the type to
  be unconstrained, with the discriminants alterable as part of
  assigning to the object.]}

  @ChgRef{Version=[2],Kind=[AddedNormal]}
  @ChgAdded{Version=[2],Text=[Defaults for discriminants of tagged types
  are disallowed so that every object of a
  tagged type is constrained,
  either by an explicit constraint,
  or by its initial discriminant values.
  This substantially simplifies the semantic rules
  and the implementation of inherited
  dispatching operations. For generic formal types,
  the restriction simplifies the type matching rules.
  If one simply wants a "default" value for the discriminants,
  a constrained subtype can be declared for future use.]}
@end(Reason)

@ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00230-01],ARef=[AI95-00402-01],ARef=[AI95-00419-01]}
A @nt<discriminant_specification> for
an access discriminant
@Chg{Version=[2],New=[may have a @nt{default_expression}],Old=[shall appear]}
only in the declaration for a task or protected type,
or for a type @Chg{Version=[2],New=[that is a descendant of an explicitly
limited record type],Old=[with the reserved word @key[limited] in its
@Redundant[(full)] definition
or in that of one of its ancestors]}.
In addition to the places where @LegalityTitle normally apply
(see @RefSecNum{Generic Instantiation}),
this rule applies also in the private part of an
instance of a generic unit.@PDefn{generic contract issue}
@begin{Discussion}
  @ChgRef{Version=[2],Kind=[Revised]}
  This rule implies that a type can have @Chg{Version=[2],
  New=[a default for ],Old=[]}an access discriminant
  if the type is limited,
  but not if the only reason it's limited is because of a limited component.
  Compare with the definition of limited type in
  @RefSecNum{Limited Types}.@Chg{Version=[2],New=[ Also, recall that a
  @lquotes@;descendant@rquote includes the type itself, so an explicitly
  limited record type can have defaults.],Old=[]}
@end{Discussion}
@begin{Ramification}
  @ChgRef{Version=[2],Kind=[Deleted]}
  @ChgDeleted{Version=[2],Text=[
  It is a consequence of this rule that only a return-by-reference
  type can have an access discriminant (see @RefSecNum{Return Statements}).
  This is important to avoid dangling references to local variables.]}
@end{Ramification}
@begin{Reason}
  @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00230-01]}
  @Leading@Keepnext@;We @Chg{Version=[2],New=[],Old=[also ]}considered the
  following rules@Chg{Version=[2],New=[ for access discriminants],Old=[]}:
  @begin{Itemize}
    If a type has an access discriminant,
    this automatically makes it limited,
    just like having a limited component automatically
    makes a type limited.
    This was rejected because it decreases program readability,
    and because it seemed error prone (two bugs in a previous
    version of the RM9X were attributable to this rule).

    @ChgRef{Version=[2],Kind=[Revised]}
    A type with an access discriminant shall be limited.
    This is equivalent to the rule we actually chose@Chg{Version=[2],New=[ for Ada 95],Old=[]},
    except that it allows a type to have an access discriminant
    if it is limited just because of a limited component.
    For example, any record containing a task would be allowed to have
    an access discriminant, whereas the actual rule requires
    @lquotes@key[limited] @key[record]@rquotes@;.
    This rule was also rejected due to readability concerns,
    and because would interact badly with the rules for
    limited types that @lquotes@;become nonlimited@rquotes@;.

    @ChgRef{Version=[2],Kind=[AddedNormal]}
    @ChgAdded{Version=[2],Text=[A type may have an access discriminant if
    it is a limited partial view, or a task, protected, or
    explicitly limited record type. This was the rule chosen for Ada 95.]}

    @ChgRef{Version=[2],Kind=[AddedNormal]}
    @ChgAdded{Version=[2],Text=[Any type may have an access discriminant.
    For nonlimited type, there is no special accessibility for access
    discriminants; they're the same as any other anonymous access component.
    For a limited type, they have the special accessibility of Ada 95. However,
    this doesn't work because a limited partial view can have a nonlimited
    full view -- giving the two views different accessibility.]}

    @ChgRef{Version=[2],Kind=[AddedNormal]}
    @ChgAdded{Version=[2],Text=[Any type may have an access discriminant,
    as above. However, special accessibility rules only apply to types
    that are @lquotes@;really@rquotes@; limited (task, protected, and
    explicitly limited records). However, this breaks privacy; worse,
    @LegalityTitle depend on the definition of accessibility.]}

    @ChgRef{Version=[2],Kind=[AddedNormal]}
    @ChgAdded{Version=[2],Text=[Any type may have an access discriminant,
    as above. Limited types have special accessibility, while nonlimited
    types have normal accessibility. However, a limited partial view with an
    access discriminant can only be completed by a task, protected, or
    explicitly limited record type. That prevents accessibility from changing.
    A runtime accessibility check is required on generic formal types with
    access discriminants. However, changing between limited and nonlimited
    types would have far-reaching consequences for access discriminants @em
    which is uncomfortable.]}

    @ChgRef{Version=[2],Kind=[AddedNormal]}
    @ChgAdded{Version=[2],Text=[Any type may have an access discriminant.
    All types have special accessibility. This was considered early during
    the Ada 9X process, but was dropped for @lquotes@;unpleasant
    complexities@rquotes@;, which unfortunately aren't recorded. It does
    seem that an accessibility check would be needed on assignment of such
    a type, to avoid copying an object with a discriminant pointing to a
    local object into a more global object (and thus creating a dangling
    pointer).]}

    @ChgRef{Version=[2],Kind=[AddedNormal]}
    @ChgAdded{Version=[2],Text=[Any type may have an access discriminant,
    but access discriminants cannot have defaults. All types have special
    accessibility. This gets rid of the problems on assignment (you couldn't
    change such a discriminant), but it would be horribly incompatible with
    Ada 95.]}

    @ChgRef{Version=[2],Kind=[AddedNormal]}
    @ChgAdded{Version=[2],Text=[Any type may have an access discriminant,
    but access discriminants may have defaults only if they are a
    @lquotes@;really@rquotes@; limited type. This is the rule chosen for
    Ada 2005, as it is not incompatible, and it doesn't require weird
    accessibility checks.]}
  @end{Itemize}
@end{Reason}

@ChgRef{Version=[2],Kind=[Deleted],ARef=[AI95-00402-01]}
@ChgDeleted{Version=[2],Text=[@nt{Default_expression}s shall be provided either for all or for none
of the discriminants of a @nt{known_@!discriminant_@!part}.
No @nt<default_@!expression>s are permitted in a
@nt<known_@!discriminant_@!part> in a declaration of a tagged
type @Redundant[or a generic formal type].]}
@begin(Reason)
  @ChgRef{Version=[2],Kind=[DeletedNoDelMsg]}
  @ChgDeleted{Version=[2],Text=[The all-or-none rule
  is related to the rule that a discriminant constraint shall specify
  values for all discriminants. One could imagine a different rule
  that allowed a constraint to specify only some of the discriminants,
  with the others provided by default. Having defaults for discriminants
  has a special significance @em it allows objects of the type to
  be unconstrained, with the discriminants alterable as part of
  assigning to the object.]}

  @ChgRef{Version=[2],Kind=[DeletedNoDelMsg]}
  @ChgDeleted{Version=[2],Text=[Defaults for discriminants of tagged types
  are disallowed so that every object of a
  tagged type is constrained,
  either by an explicit constraint,
  or by its initial discriminant values.
  This substantially simplifies the semantic rules
  and the implementation of inherited
  dispatching operations. For generic formal types,
  the restriction simplifies the type matching rules.
  If one simply wants a "default" value for the discriminants,
  a constrained subtype can be declared for future use.]}
@end(Reason)

@Leading@;For a type defined by a @nt<derived_type_definition>,
if a @nt<known_discriminant_part> is provided in its declaration, then:
@begin{Itemize}
The parent subtype shall be constrained;

If the parent type is not a tagged type, then each discriminant
of the derived type shall be used in the constraint defining
the parent subtype;@begin{ImplNote}

  This ensures that the new discriminant can share storage with
  an existing discriminant.@end{implnote}

If a discriminant is used in the constraint defining the parent subtype,
the subtype of the discriminant shall be statically compatible
(see @RefSecNum{Statically Matching Constraints and Subtypes}) with the
subtype of the corresponding parent discriminant.
@begin(Reason)
  This ensures that on conversion
  (or extension via an extension aggregate) to a distantly related type,
  if the discriminants satisfy the target type's requirements they satisfy
  all the intermediate types' requirements as well.
@end(Reason)
@begin(Ramification)
  There is no requirement that the new discriminant have the
  same (or any) @nt<default_expression> as the parent's discriminant.
@end(Ramification)
@end{Itemize}

The type of the @nt<default_expression>, if any, for an access discriminant
shall be convertible to the anonymous access type of the discriminant
(see @RefSecNum{Type Conversions}).
@PDefn2{Term=[convertible],Sec=(required)}
@begin{Ramification}
This requires convertibility
of the designated subtypes.
@end{ramification}
@end{Legality}

@begin{StaticSem}
A @nt{discriminant_specification} declares a discriminant;
the @nt{subtype_mark}
denotes its subtype unless it is an access discriminant, in which case
the discriminant's subtype is the anonymous access-to-variable subtype
defined by the @nt{access_definition}.

@Redundant[For a type defined by a @nt<derived_type_definition>,
each discriminant of the parent type
is either inherited,
constrained to equal some new discriminant of the derived type,
or constrained to the value of an expression.]
@Defn{corresponding discriminants}
When inherited or constrained to equal some new discriminant,
the parent discriminant and the discriminant of the derived type are said
to @i(correspond).
Two discriminants also correspond
if there is some common discriminant to which they
both correspond. A discriminant corresponds to itself
as well.
@Defn{specified discriminant}
If a discriminant of a parent type is constrained to a specific value
by a @nt<derived_type_definition>,
then that discriminant is said to be @i(specified)
by that @nt<derived_type_definition>.
@begin{Ramification}

  The correspondence relationship is transitive, symmetric,
  and reflexive. That is,
  if A corresponds to B, and B corresponds to C, then
  A, B, and C each corresponds to A, B, and C in all combinations.@end{ramification}

@Defn2{Term=[depend on a discriminant],
  Sec=(for a @nt<constraint> or @nt<component_definition>)}
A @nt{constraint} that appears
within the definition of a discriminated
type @i(depends on a discriminant) of the type if it names the
discriminant as a bound or discriminant value.
A @nt{component_definition} depends on a discriminant if its
@nt{constraint} depends on the discriminant, or on a discriminant
that corresponds to it.
@begin(Ramification)
  A @nt{constraint} in a @nt{task_body} is not considered to
  @i(depend) on a discriminant of the task type, even if it
  names it. It is only the @nt<constraint>s in the type definition
  itself that are considered dependents. Similarly for protected types.
@end(Ramification)

@Leading@keepnext@Defn2{Term=[depend on a discriminant], Sec=(for a component)}
A component @i(depends on a discriminant) if:
@begin(itemize)
  Its @nt{component_definition} depends on the discriminant; or
  @begin{Ramification}
A component does @i(not) depend on a discriminant just because
  its @nt<default_expression> refers to the discriminant.@end{ramification}

  It is declared in a @nt{variant_part} that is governed by the
  discriminant; or

  It is a component inherited as part of a @nt<derived_type_definition>,
  and the @nt<constraint> of the @i(parent_)@nt<subtype_indication>
  depends on the discriminant; or
  @begin{Reason}
    When the parent subtype depends on a discriminant, the parent
    part of the derived type is treated like a discriminant-dependent
    component.
  @end{Reason}
  @begin{Ramification}
    Because of this rule, we don't really need to worry about @lquotes@;corresponding@rquotes@;
    discriminants, since all the inherited components will be
    discriminant-dependent if there is a new @nt<known_discriminant_part>
    whose discriminants are used to constrain the old discriminants.
  @end{Ramification}

  It is a subcomponent of a component that depends on the discriminant.
@end(itemize)
@begin{Reason}
  The concept of discriminant-dependent (sub)components is primarily used
  in various rules that disallow renaming or 'Access, or specify that
  certain discriminant-changing assignments are erroneous.
  The goal is to allow implementations to move around or change the size
  of discriminant-dependent subcomponents upon a discriminant-changing
  assignment to an enclosing object. The above definition specifies that
  all subcomponents of a discriminant-dependent component or parent part
  are themselves discriminant-dependent, even though their presence
  or size does not in fact depend on a discriminant. This is because
  it is likely that they will move in a discriminant-changing assignment
  if they are a component of one of several discriminant-dependent
  parts of the same record.
@end{Reason}

Each value of a discriminated type includes a value for
each component
of the type that does not depend
on a discriminant@Redundant[; this includes the discriminants
themselves]. The values
of discriminants determine which other component values are present
in the value of the discriminated type.
@begin{Honest}
Which values are present might depend on discriminants of
  some ancestor type that are constrained in an intervening
  @nt<derived_type_definition>. That's why we say "values of discriminants"
  instead of "values of @i(the) discriminants" @em a subtle point.@end{honest}

@Defn{known discriminants}
@Defn2{Term=[discriminants], Sec=(known)}
@Defn2{Term=[constrained], Sec=(subtype)}
@Defn2{Term=[unconstrained], Sec=(subtype)}
A type declared with a @nt<known_discriminant_part> is said to have
@i(known discriminants); its first subtype is unconstrained.
@Defn{unknown discriminants}
@Defn2{Term=[discriminants], Sec=(unknown)}
A type declared with an
@nt<unknown_discriminant_part> is said to have @i(unknown discriminants).
A type declared without a @nt<discriminant_part> has
no discriminants, unless it is a derived type; if derived,
such a type has the same sort of discriminants (known, unknown, or none)
as its parent (or ancestor) type.
A tagged class-wide type also has unknown discriminants.
@Defn{class-wide type}
@Defn{indefinite subtype}
@Redundant[Any subtype of a type with unknown discriminants
is an unconstrained and indefinite
subtype (see @RefSecNum{Types and Subtypes}
and @RefSecNum{Objects and Named Numbers}).]
@begin(Discussion)
  @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00114-01]}
  An @nt<unknown_discriminant_part> @lquotes@;(<>)@rquotes@; is only permitted in
  the declaration of a (generic or nongeneric) private type,
  private extension, @Chg{Version=[2],New=[incomplete type, ],Old=[]}or
  formal derived type.@Comment{That was always intended,
  but 8652/0007 was needed to make it true.}
  Hence, only such types, descendants thereof, and class-wide
  types can have unknown discriminants.
  An @nt<unknown_discriminant_part> is used to indicate that the corresponding
  actual or full type might have discriminants without defaults,
  or be an unconstrained array subtype. Tagged class-wide types
  are also considered to have unknown discriminants because discriminants
  can be added by type extensions, so the total number of
  discriminants of any given value of a tagged class-wide type
  is not known at compile time.

  @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00287-01]}
  A subtype with unknown discriminants
  is indefinite, and hence an object of such a subtype needs
  explicit initialization.@Chg{Version=[2],New=[],Old=[ If the subtype is
  limited, no (stand-alone) objects
  can be declared since initialization is not permitted (though
  formal parameters are permitted, and objects of the actual/full type
  will generally be declarable).]} A limited private type with
  unknown discriminants is @lquotes@;extremely@rquotes@;
  limited;@Chg{Version=[2],New=[ objects of],Old=[]} such a type
  @Chg{Version=[2],New=[ can be initialized only by subprograms (either
  procedures with a parameter of the type, or a function returning the
  type) declared in the package. Subprograms declared elsewhere can operate on
  and even return the type, but they can only initialize the object by calling
  (ultimately) a subprogram in the package declaring the type. Such a type],Old=[]} is useful for
  keeping complete control over object creation within the package declaring
  the type.

  A partial view of a type might have unknown discriminants, while
  the full view of the same type might have known, unknown, or no
  discriminants@Chg{New=[.],Old=[,]}
@end(Discussion)
@end{StaticSem}

@begin{RunTime}
@ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00230-01],ARef=[AI95-00416-01]}
@Chg{Version=[2],New=[For an access discriminant, its],
Old=[An]} @nt<access_definition> is
elaborated when the value of @Chg{Version=[2],New=[the],Old=[a corresponding]}
access discriminant is defined@Chg{Version=[2],New=[:],Old=[, either]}
by evaluation of its @nt<default_expression>@Chg{Version=[2],New=[,],Old=[ or]}
by elaboration of a @nt<discriminant_constraint>@Chg{Version=[2],New=[, or
by an assignment that initializes the enclosing object.],Old=[.
@Redundant[The elaboration of an @nt<access_definition> creates the
anonymous access type. When the expression defining the
access discriminant is evaluated, it is converted to this
anonymous access type (see @RefSecNum{Type Conversions}).]]}
@PDefn2{Term=[implicit subtype conversion],Sec=(access discriminant)}
@begin(Ramification)
  @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00231-01],ARef=[AI95-00416-01]}
  @Chg{Version=[2],New=[The],Old=[This]} conversion@Chg{Version=[2],New=[
  of the @nt{expression} defining the access discriminant to the anonymous
  access type],Old=[]} raises @Chg{Version=[2],New=[Program_Error],
  Old=[Constraint_Error if the initial value is @key(null), or,]} for an
  object created by an allocator of an access type T, if the
  initial value is an access parameter that designates a view whose
  accessibility level is deeper than that of T.
@end(Ramification)
@end{RunTime}

@begin{Notes}
If a discriminated type has @nt<default_expression>s for its
discriminants, then unconstrained variables of the type are permitted,
and the values of the discriminants can be changed by an assignment
to such a variable.
If defaults are not provided for the discriminants, then all
variables of the type are constrained, either by explicit
constraint or by their initial value; the values of the discriminants
of such a variable cannot be changed after initialization.
@begin(Discussion)
  This connection between discriminant defaults and unconstrained variables
  can be a source of confusion. For Ada 95, we considered various
  ways to break the connection between defaults and unconstrainedness,
  but ultimately gave up for lack of a sufficiently simple and intuitive
  alternative.


  @Defn{mutable}
  An unconstrained discriminated subtype with defaults is called
  a @i{mutable} subtype, and a variable of such a subtype is called
  a mutable variable,
  because the discriminants of such a variable can change.
  There are no mutable arrays (that is, the bounds of an array
  object can never change), because there is no way in the language
  to define default values for the bounds.
  Similarly, there are no mutable class-wide subtypes,
  because there is no way to define the default tag,
  and defaults for discriminants are not allowed in the
  tagged case.
  Mutable tags would also require a way for the
  maximum possible size of such a class-wide subtype to be known.
  (In some implementations, all mutable variables are allocated
  with the maximum possible size. This approach is appropriate
  for real-time applications where implicit use of the heap
  is inappropriate.)

@end(Discussion)

The @nt{default_expression} for a discriminant of a type is evaluated
when an object of an unconstrained subtype of the type is created.

Assignment to a discriminant of an object (after its
initialization) is not allowed,
since the name of a discriminant is a constant; neither
@nt{assignment_statement}s
nor assignments inherent in passing as an @key(in out)
or @key(out) parameter
are allowed.
Note however that the value of a discriminant
can be changed by assigning to the enclosing object, presuming it
is an unconstrained variable.
@begin(Discussion)
@ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00114-01]}
An @nt{unknown_discriminant_part} is permitted only in the
declaration of a private type (including generic formal private),
private extension, @Chg{Version=[2],New=[incomplete type, ],Old=[]}or
generic formal derived type.
These are the things that will have a corresponding completion or
generic actual, which will either define the discriminants,
or say there are none.
The (<>) indicates that the actual/full subtype might be an indefinite subtype.
An @nt{unknown_discriminant_part} is not permitted in a normal
untagged derived type declaration, because there is no separate
full type declaration for such a type.
Note that (<>) allows unconstrained array bounds;
those are somewhat like undefaulted discriminants.

For a derived type, either the discriminants are inherited as is,
or completely respecified in a new @nt<discriminant_part>. In this
latter case, each discriminant of the parent type shall be constrained,
either to a specific value, or to equal one of the new discriminants.
Constraining a parent type's discriminant to equal one of the new
discriminants is like a renaming of the discriminant, except that
the subtype of the new discriminant can be more restrictive than
that of the parent's one.
In any case, the new discriminant can share storage with the
parent's discriminant.
@end(Discussion)

A discriminant that is of a named access type is not called
an access discriminant; that term is
used only for discriminants defined by an @nt<access_definition>.
@end{Notes}

@begin{Examples}
@Leading@keepnext@i(Examples of discriminated types:)
@begin(Example)
@key(type) Buffer(Size : Buffer_Size := 100)  @key(is)        --@RI[ see @RefSecNum(Integer Types)]
   @key(record)
      Pos   : Buffer_Size := 0;
      Value : String(1 .. Size);
   @key(end) @key(record);

@key(type) Matrix_Rec(Rows, Columns : Integer) @key(is)
   @key(record)
      Mat : Matrix(1 .. Rows, 1 .. Columns);       --@RI[ see @RefSecNum(Array Types)]
   @key(end) @key(record);

@key(type) Square(Side : Integer) @key(is) @key(new)
   Matrix_Rec(Rows => Side, Columns => Side);

@key(type) Double_Square(Number : Integer) @key(is)
   @key(record)
      Left  : Square(Number);
      Right : Square(Number);
   @key(end) @key(record);

@ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00433-01]}
@Chg{Version=[2],New=[@key(task type) Worker(Prio : System.Priority; Buf : @key(access) Buffer) @key(is)
   --@RI[ discriminants used to parameterize the task type (see @RefSecNum{Task Units and Task Objects})]
   @key(pragma) Priority(Prio);  --@RI[ see @RefSecNum{Task Priorities}]
   @key(entry) Fill;
   @key(entry) Drain;
@key(end) Worker;],Old=[@key(type) Item(Number : Positive) @key(is)
   @key(record)
      Content : Integer;
      --@RI[  no component depends on the discriminant]
   @key(end) @key(record);]}
@end(Example)
@end{Examples}

@begin{Extend83}
@Defn{extensions to Ada 83}
The syntax for a @nt{discriminant_specification}
is modified to allow an @i{access discriminant},
with a type specified by an @nt{access_definition}
(see @RefSecNum{Access Types}).

@ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00251-01]}
Discriminants are allowed on all composite types other than array@Chg{Version=[2],New=[ and
interface],Old=[]} types.

Discriminants may be of an access type.
@end{Extend83}

@begin{DiffWord83}
@nt{Discriminant_part}s are not elaborated,
though an @nt<access_definition> is elaborated
when the discriminant is initialized.

@end{DiffWord83}

@begin{Extend95}
  @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00230-01],ARef=[AI95-00402-01],ARef=[AI95-00416-01]}
  @ChgAdded{Version=[2],Text=[Access discriminants (anonymous access types
  used as a discriminant) can be used on any type allowing discriminants.
  Defaults aren't allowed on discriminants of non-limited types, however, so
  that accessibility problems don't happen on assignment.]}

  @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00231-01]}
  @ChgAdded{Version=[2],Text=[
  @nt{null_exclusion} can be used in the declaration of a discriminant.]}
@end{Extend95}

@begin{DiffWord95}
  @ChgRef{Version=[2],Kind=[AddedNormal],Ref=[8652/0007],ARef=[AI95-00098-01]}
  @ChgAdded{Version=[2],Text=[@b<Corrigendum:> The wording was clarified so
  that types that cannot have discriminants cannot have an
  @nt{unknown_discriminant_part}.]}

  @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00251-01]}
  @ChgAdded{Version=[2],Text=[Added wording to prevent interfaces from
  having discriminants. We don't want interfaces to have any components.]}

  @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00254-01]}
  @ChgAdded{Version=[2],Text=[Removed wording which implied or required an
  access discriminant to have an access-to-object type (anonymous access
  types can now be access-to-subprogram types as well).]}

  @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00326-01]}
  @ChgAdded{Version=[2],Text=[Fixed the wording of the introduction to this
  clause to reflect that both incomplete and partial views can have
  unknown discriminants. That was always true, but for some reason this
  wording specified partial views.]}

  @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00419-01]}
  @ChgAdded{Version=[2],Text=[Changed the wording to use the new term
  @lquotes@;explicitly limited record@rquotes, which makes the intent
  much clearer (and eliminates confusion with derived types that happen to
  contain the reserved word @key(limited).]}
@end{DiffWord95}


@LabeledSubClause{Discriminant Constraints}

@begin{Intro}
A @nt<discriminant_constraint> specifies the values of the discriminants
for a given discriminated type.
@end{Intro}

@begin{MetaRules}
The rules in this clause are intentionally parallel
to those given in Record Aggregates.
@end{MetaRules}

@begin{Syntax}
@Syn{lhs=<discriminant_constraint>,rhs="
   (@Syn2{discriminant_association} {, @Syn2{discriminant_association}})"}


@Syn{lhs=<discriminant_association>,rhs="
   [@SynI{discriminant_}@Syn2{selector_name} {| @SynI{discriminant_}@Syn2{selector_name}} =>] @Syn2{expression}"}

@begin{SyntaxText}
@Defn{named discriminant association}
A @nt<discriminant_association>
is said to be @i(named) if it has one or more
@i(discriminant_)@nt<selector_name>s;
@Defn{positional discriminant association}
it is otherwise said to be @i(positional).
In a @nt<discriminant_constraint>,
any positional associations shall precede any named
associations.
@end{SyntaxText}

@end{Syntax}

@begin{Resolution}
Each @nt<selector_name> of a named @nt<discriminant_@!association> shall
resolve to denote a discriminant of the subtype being constrained;
@Defn2{Term=[associated discriminants],
  Sec=(of a named @nt<discriminant_association>)}
the discriminants so named are the @i(associated discriminants) of
the named association.
@Defn2{Term=[associated discriminants],
  Sec=(of a positional @nt<discriminant_association>)}
For a positional association, the @i(associated discriminant)
is the one whose @nt<discriminant_@!specification> occurred in
the corresponding position in the @nt<known_@!discriminant_@!part>
that defined the discriminants of the subtype being constrained.

@PDefn2{Term=[expected type], Sec=(discriminant_association expression)}
The expected type for the @nt{expression} in
a @nt{discriminant_association}
is that of the associated discriminant(s).
@end{Resolution}

@begin{Legality}
@ChgRef{Version=[1],Kind=[Revised],Ref=[8652/0008],ARef=[AI95-00168-01]}
@ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00363-01]}
A @nt{discriminant_constraint} is only allowed in a
@nt{subtype_indication} whose @nt{subtype_mark} denotes
either an unconstrained discriminated subtype, or an
unconstrained access subtype whose designated subtype is
an unconstrained discriminated subtype.
@Chg{New=[However, in the case of @Chg{Version=[2],New=[an],Old=[a general]}
access subtype, a @nt{discriminant_@!constraint} is illegal
if @Chg{Version=[2],New=[the
designated type has a partial view that is constrained or, for a general
access subtype, has @nt{default_expression}s for its discriminants.
In addition to the places where @LegalityTitle@; normally apply
(see @RefSecNum{Generic Instantiation}),
these rules apply also in the private part of an instance
of a generic unit. In a generic body, this rule is checked presuming all
formal access types of the generic might be general access types, and all
untagged discriminated formal types of the generic might have
@nt{default_expression}s for their discriminants.
@PDefn{generic contract issue}],
Old=[there is a place within the
immediate scope of the designated subtype where the designated subtype's view
is constrained.]}],Old=[]}

@begin{Reason}
@ChgRef{Version=[1],Kind=[Added],Ref=[8652/0008],ARef=[AI95-00168-01]}
@ChgRef{Version=[2],Kind=[DeletedAdded],ARef=[AI95-00363-01]}
@ChgDeleted{Version=[2],Text=[@Chg{New=[The second rule is necessary to
prevent assignments that change the discriminant of a constrained object.
See the defect report for examples.],Old=[]}]}
@end{Reason}

@begin{Reason}
@ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00363-01]}
@ChgAdded{Version=[2],Text=[The second rule is necessary to prevent objects
from changing so that they no longer match their constraint. In Ada 95, we
attempted to prevent this by banning every case where an aliased object
could be unconstrained or be changed by an enclosing assignment. New ways
to cause this problem were being discovered frequently, meaning that new rules
had to be dreamed up to cover them. Meanwhile, aliased objects and components
were getting more and more limited. In Ada 2005, we sweep away all of that
cruft and replace it by a simple rule @lquotes@;thou shalt not create an
access subtype that can point to an item whose discriminants can be changed by
assignment@rquotes@;.]}
@end{Reason}

A named @nt<discriminant_association> with more than one
@nt<selector_name> is allowed only if the named discriminants
are all of the same type.
A @nt<discriminant_constraint> shall provide exactly one value for each
discriminant of the subtype being constrained.

The @nt<expression> associated with an access discriminant
shall be of a type convertible to the anonymous access type.
@PDefn2{Term=[convertible],Sec=(required)}
@begin(Ramification)

  This implies both convertibility of designated types, and
  static accessibility.
  This implies that if an object of type T with an
  access discriminant is created
  by an allocator for an access type A, then it requires that the
  type of the @nt<expression> associated
  with the access discriminant have an accessibility level
  that is not statically deeper than that of A.
  This is to avoid dangling references.

@end(Ramification)
@end{Legality}

@begin{RunTime}
@PDefn2{Term=[compatibility], Sec=(discriminant constraint with a
subtype)}
A @nt{discriminant_constraint} is @i(compatible) with an unconstrained
discriminated subtype if each discriminant value belongs to the
subtype of the corresponding discriminant.
@begin{Ramification}
The "dependent
  compatibility check" has been eliminated in Ada 95. Any checking
  on subcomponents is performed when (and if) an object is created.@end{ramification}
@begin{Discussion}
  There is no need to define compatibility with a constrained
  discriminated subtype, because one is not allowed to constrain it again.@end{discussion}

@PDefn2{Term=[satisfies], Sec=(a discriminant constraint)}
A composite value @i(satisfies) a discriminant constraint if and only
if each discriminant of the composite value has the value imposed
by the discriminant constraint.

@PDefn2{Term=[elaboration], Sec=(discriminant_constraint)}
For the elaboration of a @nt{discriminant_constraint}, the @nt{expression}s
in the @nt{discriminant_association}s are evaluated in an arbitrary
order and converted to the type of the associated
discriminant (which might raise Constraint_Error @em
see @RefSecNum{Type Conversions});
the @nt{expression} of a named association is evaluated
(and converted) once for each associated discriminant.
@PDefn2{Term=[implicit subtype conversion],Sec=(discriminant values)}
The result of each evaluation and conversion is the
value imposed by the constraint for the associated discriminant.
@begin{Reason}

  We convert to the type, not the subtype, so that the definition
  of compatibility of discriminant constraints is not vacuous.@end{reason}

@end{RunTime}

@begin{Notes}
The rules of the language ensure that
a discriminant of an object always has a value, either
from explicit or implicit initialization.
@begin(Discussion)
Although it is illegal to constrain a class-wide tagged subtype, it
is possible to have a partially constrained class-wide
subtype: If the subtype S is defined by T(A => B),
then S'Class is partially constrained in the sense that objects of
subtype S'Class have to have discriminants corresponding
to A equal to B,
but there can be other discriminants defined
in extensions that are not constrained to any particular value.
@end(Discussion)
@end{Notes}

@begin{Examples}
@Leading@keepnext@i{Examples (using types declared above in clause @RefSecNum(Discriminants)):}
@begin(Example)
Large   : Buffer(200);  --@RI[  constrained, always 200 characters]
                        --@RI[   (explicit discriminant value)]
Message : Buffer;       --@RI[  unconstrained, initially 100 characters]
                        --@RI[   (default discriminant value)]
Basis   : Square(5);    --@RI[  constrained, always 5 by 5]
Illegal : Square;       --@RI[  illegal, a Square has to be constrained]
@end(Example)
@end{Examples}

@begin{Inconsistent83}
@Defn{inconsistencies with Ada 83}
Dependent compatibility checks are no longer performed on
subtype declaration. Instead they are deferred until
object creation (see @RefSecNum(Object Declarations)).
This is upward compatible for a program
that does not raise Constraint_Error.
@end{Inconsistent83}

@begin{DiffWord83}
Everything in RM83-3.7.2(7-12), which specifies the
initial values for discriminants, is now redundant
with 3.3.1, 6.4.1, 8.5.1, and 12.4. Therefore, we don't
repeat it here. Since the material is largely intuitive,
but nevertheless complicated to state formally, it doesn't
seem worth putting it in a "NOTE."
@end{DiffWord83}

@begin{Incompatible95}
@ChgRef{Version=[2],Kind=[AddedNormal],Ref=[8652/0008],ARef=[AI95-00168-01],ARef=[AI95-00363-01]}
@ChgAdded{Version=[2],Text=[@Defn{incompatibilities with Ada 95}
The Corrigendum added a restriction on @nt{discriminant_constraint}s for
general access subtypes. Such constraints are prohibited
if the designated type can be treated as constrained somewhere in the program.
Ada 2005 goes further and prohibits such @nt{discriminant_constraint}s if
the designated type has (or might have, in the case of a formal type)
defaults for its discriminants. The use of general access subtypes is rare,
and this eliminates a boatload of problems that required many restrictions
on the use of aliased objects and components (now lifted). Similarly,
Ada 2005 prohibits @nt{discriminant_constraint}s on any access type whose
designated type has a partial view that is constrained. Such a type will
not be constrained in the heap to avoid privacy problems. Again, the use
of such subtypes is rare (they can only happen within the package and its
child units).]}
@end{Incompatible95}


@LabeledSubClause{Operations of Discriminated Types}

@begin{Intro}
@Redundant[If a discriminated type has @nt<default_expression>s for its
discriminants, then unconstrained variables of the type are permitted,
and the discriminants of such a variable can be changed by assignment to
the variable. For a formal parameter of such a type, an attribute
is provided to determine whether the corresponding actual parameter
is constrained or unconstrained.]
@end{Intro}

@begin{StaticSem}
For @PrefixType{a @nt<prefix> A that is of a
discriminated type @Redundant[(after any implicit dereference)]},
the following attribute is defined:
@begin(description)
@Attribute{Prefix=<A>, AttrName=<Constrained>,
  Text=[Yields the value True if A denotes a constant, a value,
  or a constrained variable,
  and False otherwise.]}
@begin(ImplNote)
 This attribute is primarily used on parameters, to determine whether
 the discriminants can be changed as part of an assignment.
 The Constrained attribute is statically True for @key(in) parameters.
 For @key(in out) and @key(out) parameters of a discriminated type,
 the value of this attribute needs to be passed as an implicit
 parameter, in general. However, if the type does not have
 defaults for its discriminants, the attribute is statically True,
 so no implicit parameter is needed.
 Parameters of a limited type
 with defaulted discriminants need this implicit parameter,
 unless there are no nonlimited views,
 because they might be passed to a subprogram whose body has
 visibility on a nonlimited view of the type, and hence might be
 able to assign to the object and change its discriminants.
@end(ImplNote)
@end(description)
@EndPrefixType{}
@end{StaticSem}

@begin{Erron}
@PDefn2{Term=(erroneous execution),Sec=(cause)}
The execution of a construct is erroneous if the construct
has a constituent that is a @nt<name> denoting
a subcomponent that depends on discriminants, and the
value of any of these discriminants is changed by this execution
between evaluating the @nt<name> and the last use (within this
execution) of the subcomponent denoted by the @nt<name>.
@begin{Ramification}
  This rule applies to @nt<assignment_statement>s,
  calls (except when the discriminant-dependent subcomponent is
  an @key(in) parameter passed by copy),
  @nt<indexed_component>s, and @nt<slice>s.
  Ada 83 only covered the first two cases. AI83-00585 pointed out
  the situation with the last two cases.
  The cases of @nt<object_renaming_declaration>s and
  generic formal @key(in out) objects are handled differently,
  by disallowing the situation at compile time.
@end{Ramification}
@end{Erron}

@begin{Extend83}
@ChgRef{Version=[1],Kind=[Revised]}@ChgNote{To be consistent with 8652/0006}
@Defn{extensions to Ada 83}
For consistency with other attributes, we are allowing
the @Chg{New=[@nt{prefix}],Old=[prefix]} of Constrained to be a value as well
as an object of a discriminated type, and also an implicit
dereference. These extensions are
not important capabilities, but there seems no
reason to make this attribute different from
other similar attributes. We are curious what most
Ada 83 compilers do with F(1).X'Constrained.

We now handle in a general way
the cases of erroneousness identified by AI83-00585, where
the @nt<prefix> of an @nt<indexed_component> or @nt<slice>
is discriminant-dependent, and the evaluation of the index or
discrete range changes the value of a discriminant.
@end{Extend83}

@begin{DiffWord83}
We have moved all discussion of erroneous use of @nt<name>s
that denote discriminant-dependent
subcomponents to this subclause. In Ada 83, it used to
appear separately under @nt{assignment_statement}s and
subprogram calls.
@end{DiffWord83}


@LabeledClause{Record Types}

@begin{Intro}
@Defn{record}
@Defn{record type}
A record object is a composite object consisting of named components.
The value of a record object is a composite value consisting of the
values of the components.
@IndexSee{Term=[structure],See=(record type)}
@end{Intro}

@begin{Syntax}
@Syn{lhs=<record_type_definition>,rhs="[[@key{abstract}] @key{tagged}] [@key{limited}] @Syn2{record_definition}"}
@Syn{lhs=<record_definition>,rhs="
    @key{record}
       @Syn2{component_list}
    @key{end} @key{record}
  | @key{null record}"}


@Syn{lhs=<component_list>,rhs="
      @Syn2{component_item} {@Syn2{component_item}}
   | {@Syn2{component_item}} @Syn2{variant_part}
   |  @key{null};"}

@ChgRef{Version=[1],Kind=[Revised],Ref=[8652/0009],ARef=[AI95-00137-01]}
@Syn{lhs=<component_item>,rhs="@Syn2{component_declaration} | @Chg{New=[@Syn2{aspect_clause}],Old=[@Syn2{representation_clause}]}"}

@Syn{lhs=<component_declaration>,rhs="
   @Syn2{defining_identifier_list} : @Syn2{component_definition} [:= @Syn2{default_expression}];"}
@end{Syntax}

@begin{Resolution}
@PDefn2{Term=[expected type], Sec=(component_declaration default_expression)}
The expected type for the @nt<default_expression>, if any, in
a @nt<component_declaration> is the type of the
component.
@end{Resolution}

@begin{Legality}
@ChgRef{Version=[2],Kind=[Deleted],ARef=[AI95-00287-01]}
@ChgDeleted{Version=[2],Text=[A @nt<default_expression> is not permitted if
the component is of a limited type.]}

@ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00366-01]}@ChgNote{This is not THE definition of component}
@PDefn2{Term=[components], Sec=(of a record type)}
Each @nt<component_declaration> declares a
@Chg{Version=[2],New=[component],Old=[@i(component)]} of the record type.
Besides components declared by @nt<component_declaration>s, the components of a
record type include any components declared by @nt<discriminant_specification>s
of the record type declaration. @Redundant[The identifiers of all components of
a record type shall be distinct.]
@begin{TheProof}
  The identifiers of all
  components of a record type have to
  be distinct because they are all declared immediately
  within the same declarative region. See Section 8.
@end{theproof}


Within a @nt{type_declaration},
a @nt{name} that denotes a component, protected subprogram,
or entry of the type is allowed only in the following cases:

@begin{Itemize}
A @nt{name} that denotes any component, protected subprogram,
or entry is allowed within a
representation item that occurs within the declaration of the composite type.

A @nt{name} that denotes a noninherited discriminant
is allowed within the declaration of the type,
but not within the @nt{discriminant_part}.
If the discriminant is used to define the constraint of
a component, the bounds of an entry family, or
the constraint of the parent subtype in a
@nt<derived_type_definition>
then its name shall appear alone as a @nt<direct_name> (not as
part of a larger expression or expanded name).
A discriminant shall not be used to define the constraint of
a scalar component.@Defn2{Term=[discriminant],Sec=[use in a record definition]}@ChgNote{New index entry}
@begin{Reason}
The penultimate restriction simplifies implementation,
  and allows the outer discriminant and the inner discriminant
  or bound to possibly share storage.
@end{reason}
@begin{Ramification}
  Other rules prevent such a discriminant from being an inherited one.
@end{ramification}
@begin{Reason}
The last restriction is inherited from Ada 83.
The restriction is not really necessary from a language design point of
view, but we did not remove it,
in order to avoid unnecessary changes to existing compilers.
@end{Reason}
@begin{Discussion}
  Note that a discriminant can be used to define the constraint
  for a component that is of an access-to-composite type.
@end{Discussion}
@begin{Reason}
  @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00373-01]}
  The above rules, and a similar one in @RefSecNum{Subprogram Declarations}
  for formal parameters, are intended to allow initializations of
  components or parameters to occur in @Chg{Version=[2],
  New=[a (nearly)],Old=[an]} arbitrary order @em whatever
  order is most efficient@Chg{Version=[2],New=[ (subject to the restrictions
  of @RefSecNum{Object Declarations})],Old=[]},
  since one @nt{default_expression} cannot depend on the value of
  another one.
  @Chg{Version=[2],New=[They],Old=[It]} also prevent circularities.
@end{Reason}
@begin{Ramification}
  Inherited discriminants are not allowed to be denoted,
  except within representation items.
  However, the @SynI{discriminant_}@nt{selector_name} of
  the parent @nt{subtype_indication} is allowed to denote
  a discriminant of the parent.
@end{Ramification}
@end{Itemize}

If the name of the current instance of a type
(see @RefSecNum{The Context of Overload Resolution})
is used to define the constraint of a component,
then it shall appear as a @nt{direct_name}
that is the @nt<prefix> of an @nt{attribute_reference}
whose result is of an access type,
and the @nt{attribute_reference} shall appear alone.
@begin{Reason}
  This rule allows T'Access
  or T'Unchecked_Access, but disallows, for example,
  a range constraint (1..T'Size).
  Allowing things like (1..T'Size) would mean that a per-object
  constraint could affect the size of the object,
  which would be bad.
@end{Reason}

@end{Legality}

@begin{StaticSem}
@ChgRef{Version=[2],Kind=[Added],ARef=[AI95-00318-02]}
@ChgAdded{Version=[2],Text=[@Defn{explicitly limited record}
@Defn2{Term=[record],Sec=(explicitly limited)}
If a @nt{record_type_definition} includes the
reserved word @key{limited}, the type is called an
@i<explicitly limited record> type.]}

@PDefn2{Term=[nominal subtype], Sec=(of a record component)}
The @nt{component_definition} of a @nt<component_declaration>
defines the (nominal) subtype of the component.
If the reserved word @key(aliased) appears in the @nt{component_definition},
then the component is aliased (see @RefSecNum{Access Types}).
@begin(Ramification)
  @ChgRef{Version=[2],Kind=[DeletedNoDelMsg],ARef=[AI95-00363-01]}
  @ChgDeleted{Version=[2],Text=[In this case, the nominal subtype cannot be
  an unconstrained discriminated subtype.
  See @RefSecNum{Array Types}.]}
@end(Ramification)

@Defn{null record}
If the @nt<component_list> of a record type is defined by the reserved
word @key(null) and there are no discriminants, then the record type has
no components and all records of the type are @i(null records).
A @nt<record_definition> of @key{null record} is equivalent to
@key{record null; end record}.
@begin{Ramification}

  This short-hand is available both for declaring a record type
  and a record extension @em see @RefSecNum(Type Extensions).
@end{ramification}

@end{StaticSem}

@begin{RunTime}
@PDefn2{Term=[elaboration], Sec=(record_type_definition)}
The elaboration of a @nt{record_type_definition} creates
the record type and its first subtype,
and consists of the elaboration of the @nt<record_definition>.
@PDefn2{Term=[elaboration], Sec=(record_definition)}
The elaboration of a @nt<record_definition> consists of the
elaboration of its @nt{component_list}, if any.

@PDefn2{Term=[elaboration], Sec=(component_list)}
The elaboration of a @nt{component_list} consists of the elaboration
of the @nt{component_item}s and
@nt{variant_part}, if any, in the order in which they appear.
@PDefn2{Term=[elaboration], Sec=(component_declaration)}
The elaboration of a @nt{component_declaration} consists of the
elaboration of the @nt{component_definition}.
@begin(Discussion)
  If the @nt<defining_identifier_list> has more than one
  @nt<defining_identifier>, we presume here that the transformation
  explained in @RefSecNum(Object Declarations) has already
  taken place. Alternatively, we could say that
  the @nt<component_definition> is elaborated once for
  each @nt<defining_identifier> in the list.
@end(Discussion)

@ChgRef{Version=[1],Kind=[Revised],Ref=[8652/0002],ARef=[AI95-00171-01]}
@ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00230-01]}
@Defn{per-object expression}
@Defn{per-object constraint}
@Defn{entry index subtype}
Within the definition of a composite type,
if a @nt<component_definition> or @nt<discrete_subtype_definition>
(see @RefSecNum{Entries and Accept Statements})
includes a @nt<name> that denotes a discriminant of the type, or
that is an @nt<attribute_reference> whose @nt<prefix> denotes the current
instance of the type,
the expression containing the @nt<name> is called a @i(per-object expression),
and the @Chg{New=[@nt{constraint} or @nt{range}],Old=[constraint]} being defined
is called a @i(per-object constraint).
@PDefn2{Term=[elaboration], Sec=(component_definition)}
For the elaboration of a @nt{component_definition} of
a @nt<component_declaration>@Chg{New=[ or the @nt{discrete_@!subtype_@!definition}
of an @nt{entry_@!declaration} for an entry family (see
@RefSecNum{Entries and Accept Statements})],Old=[]},@Chg{Version=[2],
New=[ if the component subtype is defined by an @nt{access_definition} or],
Old=[]} if the @nt{constraint}
@Chg{New=[or @nt{range}],Old=[]} of the @nt{subtype_indication}
@Chg{New=[or @nt{discrete_@!subtype_@!definition}],Old=[]} is not a per-object
constraint, then the@Chg{Version=[2],New=[ @nt{access_definition},],Old=[]}
@nt{subtype_indication}@Chg{Version=[2],New=[,],Old=[]}
@Chg{New=[or @nt{discrete_@!subtype_@!definition}],Old=[]}
is elaborated. On the other hand, if the @nt{constraint}
@Chg{New=[or @nt{range}],Old=[]} is a per-object constraint,
then the elaboration consists of the evaluation of any included
expression that is not part of a per-object expression.
@Chg{New=[Each such expression is evaluated once unless it is part of a named
association in a discriminant constraint, in which case it is evaluated once
for each associated discriminant.],Old=[]}

@ChgRef{Version=[1],Kind=[Added],Ref=[8652/0002],ARef=[AI95-00171-01]}
@Chg{New=[@PDefn2{Term=[Elaboration],Sec=(per-object constraint)}When a
per-object constraint is elaborated @Redundant[(as part of creating an
object)], each per-object expression of the constraint is evaluated. For other
expressions, the values determined during the elaboration of the
@nt{component_@!definition} or @nt{entry_@!declaration} are used. Any checks
associated with the enclosing @nt{subtype_indication} or
@nt{discrete_subtype_definition} are performed@Redundant[, including the subtype
compatibility check (see @RefSecNum{Subtype Declarations}),] and the associated
subtype is created.],
Old=[]}
@begin(Discussion)
  The evaluation of other expressions that appear in
  @nt<component_definition>s and @nt<discrete_subtype_definition>s
  is performed when the type definition is elaborated.
  The evaluation of expressions that appear as
  @nt<default_expression>s is postponed until an object is created.
  Expressions in representation items
  that appear within a composite type definition are evaluated
  according to the rules of the particular representation item.
@end(Discussion)
@end{RunTime}

@begin{Notes}
A @nt<component_declaration> with several identifiers is equivalent
to a sequence of single @nt<component_declaration>s, as explained
in @RefSecNum{Object Declarations}.

The @nt<default_expression> of a record component is only
evaluated upon the creation of
a default-initialized object of the record type (presuming
the object has the component, if it is in a @nt<variant_part> @em
see @RefSecNum{Object Declarations}).

The subtype defined by a @nt<component_definition> (see @RefSecNum(Array Types))
has to be a definite subtype.

If a record type does not have a @nt<variant_part>, then the same components
are present in all values of the type.

A record type is limited if it has the reserved word @key[limited]
in its definition, or if any of its components are
limited (see @RefSecNum{Limited Types}).

@PDefn2{Term=[predefined operations],Sec=(of a record type)}
The predefined operations of a record type include membership
tests, qualification, and explicit conversion. If the
record type is nonlimited, they also include
assignment and the predefined equality operators.

@ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00287-01]}
A component of a record can be named with a @nt<selected_component>.
A value of a record can be specified with a @nt<record_aggregate>@Chg{Version=[2],
New=[],Old=[, unless the record type is limited]}.

@end{Notes}

@begin{Examples}
@Leading@keepnext@i(Examples of record type declarations: )
@begin(Example)
@key(type) Date @key(is)
   @key(record)
      Day   : Integer @key(range) 1 .. 31;
      Month : Month_Name;
      Year  : Integer @key(range) 0 .. 4000;
   @key(end) @key(record);

@key(type) Complex @key(is)
   @key(record)
      Re : Real := 0.0;
      Im : Real := 0.0;
   @key(end) @key(record);
@end(Example)

@begin{Wide}
@leading@keepnext@i(Examples of record variables: )
@end{Wide}
@begin(Example)
Tomorrow, Yesterday : Date;
A, B, C : Complex;

--@RI[ both components of A, B, and C are implicitly initialized to zero ]
@end(Example)
@end{Examples}

@begin{Extend83}
@Defn{extensions to Ada 83}
The syntax rule for @nt<component_declaration> is modified
to use @nt<component_definition> (instead of
@ntf<component_subtype_definition>). The effect of this change
is to allow the reserved word @key(aliased) before the
@ntf<component_subtype_definition>.

A short-hand is provided for defining a null record type
(and a null record extension), as these will be more common
for abstract root types (and derived types without additional components).

The syntax rule for @nt{record_type_definition} is modified to allow
the reserved words @key{tagged} and @key{limited}.
Tagging is new.
Limitedness is now orthogonal to privateness.
In Ada 83 the syntax implied that limited private was sort of more
private than private.
However, limitedness really has nothing to do with privateness;
limitedness simply indicates the lack of assignment capabilities,
and makes perfect sense for nonprivate types such as record types.
@end{Extend83}

@begin{DiffWord83}
@ChgRef{Version=[1],Kind=[Revised],Ref=[8652/0009],ARef=[AI95-00137-01]}
The syntax rules now allow @Chg{New=[@nt{aspect_clause}s],
Old=[@nt{representation_clause}s]} to appear in a @nt{record_definition}.
This is not a language extension, because @LegalityName@;s prevent all
language-defined representation clauses from appearing there.
However, an implementation-defined @nt{attribute_definition_clause}
could appear there.
The reason for this change is to allow the rules for
@Chg{New=[@nt{aspect_clause}s],Old=[@nt{representation_clause}s]} and
representation pragmas to be as similar as possible.
@end{DiffWord83}

@begin{Extend95}
  @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00287-01]}
  @ChgAdded{Version=[2],Text=[@Defn{extensions to Ada 95}
  Record components can have an anonymous access type.]}

  @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00287-01]}
  @ChgAdded{Version=[2],Text=[@Defn{extensions to Ada 95}
  Limited components can be initialized, so long as the expression is
  one that allows building the object in place (such as an @nt{aggregate} or
  @nt{function_call}).]}
@end{Extend95}

@begin{DiffWord95}
  @ChgRef{Version=[2],Kind=[AddedNormal],Ref=[8652/0002],ARef=[AI95-00171-01]}
  @ChgAdded{Version=[2],Text=[@b<Corrigendum:> Improved the description of the
  elaboration of per-object constraints.]}

  @ChgRef{Version=[2],Kind=[AddedNormal],Ref=[8652/0009],ARef=[AI95-00137-01]}
  @ChgAdded{Version=[2],Text=[@b<Corrigendum:> Changed representation clauses to
  aspect clauses to reflect that they are used for more than just
  representation.]}

  @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00318-02]}
  @ChgAdded{Version=[2],Text=[Defined @i{explicitly limited record} type to
  use in other rules.]}
@end{DiffWord95}


@LabeledSubClause{Variant Parts and Discrete Choices}

@begin{Intro}
A record type with a @nt<variant_part> specifies alternative
lists of components. Each @nt<variant> defines the components
for the value or values of the discriminant
covered by its @nt<discrete_choice_list>.
@begin{Discussion}
@RootDefn{cover a value}
@nt{Discrete_choice_list}s and @nt{discrete_choice}s are
said to @i(cover) values as defined below; which
@nt{discrete_choice_list} covers a value determines
which of various alternatives is chosen. These are used
in @nt{variant_part}s, @nt{array_aggregate}s, and
@nt{case_statement}s.
@end{Discussion}
@end{Intro}

@begin{MetaRules}
The definition of @lquotes@;cover@rquotes@; in this subclause
and the rules about discrete choices
are designed so that they
are also appropriate for array aggregates and case statements.

The rules of this subclause intentionally
parallel those for case statements.
@end{MetaRules}

@begin{Syntax}
@Syn{lhs=<variant_part>,rhs="
   @key{case} @SynI{discriminant_}@Syn2{direct_name} @key{is}
       @Syn2{variant}
      {@Syn2{variant}}
   @key{end} @key{case};"}


@Syn{lhs=<variant>,rhs="
   @key{when} @Syn2{discrete_choice_list} =>
      @Syn2{component_list}"}


@Syn{lhs=<discrete_choice_list>,rhs="@Syn2{discrete_choice} {| @Syn2{discrete_choice}}"}

@Syn{lhs=<discrete_choice>,rhs="@Syn2{expression} | @Syn2{discrete_range} | @key{others}"}
@end{Syntax}

@begin{Resolution}
@Defn2{Term=[discriminant], Sec=(of a @nt<variant_part>)}
The @i(discriminant_)@nt{direct_name} shall resolve to denote
a discriminant (called
the @i(discriminant of the @nt<variant_part>)) specified in
the @nt{known_discriminant_part} of the @nt{full_type_declaration}
that contains the @nt{variant_part}.
@PDefn2{Term=[expected type], Sec=(variant_part discrete_choice)}
The expected type for each @nt{discrete_choice} in a @nt<variant> is the type
of the discriminant of the @nt{variant_part}.
@begin{Ramification}
  A @nt<full_type_declaration> with a @nt<variant_part>
  has to have a (new) @nt<known_discriminant_part>;
  the discriminant of the @nt<variant_part> cannot be an
  inherited discriminant.
@end{Ramification}
@end{Resolution}

@begin{Legality}
The discriminant of the @nt{variant_part} shall
be of a discrete type.
  @begin{Ramification}
It shall not be of an access type,
  named or anonymous.@end{ramification}

The @nt{expression}s and @nt{discrete_range}s given as
@nt{discrete_choice}s in a @nt{variant_part} shall be static.
The @nt{discrete_choice} @key(others) shall appear alone
in a @nt{discrete_choice_list}, and such a @nt{discrete_choice_list},
if it appears, shall be the last one in the enclosing construct.

@Leading@PDefn2{Term=[cover a value], Sec=(by a @nt{discrete_choice})}
A @nt<discrete_choice> is defined to @i(cover a value) in the
following cases:
@begin(itemize)
  A @nt{discrete_choice} that is an @nt{expression} covers a value if
  the value equals the value of the @nt{expression}
  converted to the expected type.

  A @nt{discrete_choice} that is a @nt{discrete_range} covers all values
  (possibly none) that belong to the range.

  The @nt{discrete_choice} @key{others} covers all values of its
  expected type that are not covered by
  previous @nt{discrete_choice_list}s of the same construct.
  @begin(Ramification)
    For @nt{case_statement}s,
    this includes values outside the range of the static subtype (if any)
    to be covered by the choices.
    It even includes values outside the base
    range of the case expression's type,
    since values of numeric types (and undefined values of any scalar type?)
    can be outside their base range.
  @end(Ramification)
@end(itemize)

@PDefn2{Term=[cover a value], Sec=(by a @nt{discrete_choice_list})}
A @nt{discrete_choice_list} covers a value if one of
its @nt{discrete_choice}s covers the value.

@Leading@keepnext@;The possible values of the discriminant of a @nt{variant_part}
shall be covered as follows:
@begin{itemize}
  If the discriminant is of a static constrained scalar subtype,
  then each non-@key{others} @nt{discrete_@!choice} shall cover only values in
  that subtype, and each value of that subtype shall be covered
  by some @nt{discrete_@!choice} @Redundant[(either explicitly or
  by @key<others>)];

  If the type of the discriminant is a
  descendant of a generic formal scalar type
  then the @nt{variant_part} shall have an @key{others}
  @nt{discrete_choice};@begin{Reason}
The base range is not known statically in this
  case.@end{reason}

  Otherwise,
  each value of the base range of the type of the discriminant shall
  be covered @Redundant[(either explicitly or by @key<others>)].
@end{itemize}

Two distinct @nt{discrete_choice}s of a @nt{variant_part} shall not cover
the same value.

@end{Legality}

@begin{StaticSem}
If the @nt{component_list} of a @nt{variant} is specified by @key(null),
the variant has no components.

@Defn{govern a @nt{variant_part}}
@Defn{govern a @nt{variant}}
The discriminant of a @nt<variant_part> is said to @i(govern) the
@nt<variant_part> and its @nt<variant>s. In addition,
the discriminant of a derived
type governs a @nt<variant_part> and its @nt<variant>s if it
corresponds (see @RefSecNum(Discriminants)) to the
discriminant of the @nt<variant_part>.

@end{StaticSem}

@begin{RunTime}
A record value contains the values of the components of a particular
@nt{variant} only if the
value of the discriminant governing the @nt<variant> is covered
by the @nt{discrete_choice_list} of the @nt{variant}.
This rule applies in turn to any further @nt{variant} that is, itself,
included in the @nt{component_list} of the given @nt{variant}.

@PDefn2{Term=[elaboration], Sec=(variant_part)}
The elaboration of a @nt{variant_part} consists
of the elaboration of the @nt{component_list} of each
@nt{variant} in the order in which they appear.
@end{RunTime}

@begin{Examples}
@Leading@keepnext@i(Example of record type with a variant part: )
@begin(Example)
@key(type) Device @key(is) (Printer, Disk, Drum);
@key(type) State  @key(is) (Open, Closed);

@key(type) Peripheral(Unit : Device := Disk) @key(is)
   @key(record)
      Status : State;
      @key(case) Unit @key(is)
         @key(when) Printer =>
            Line_Count : Integer @key(range) 1 .. Page_Size;
         @key(when) @key(others) =>
            Cylinder   : Cylinder_Index;
            Track      : Track_Number;
         @key(end) @key(case);
      @key(end) @key(record);
@end(Example)

@begin{Wide}
@leading@keepnext@i(Examples of record subtypes:)
@end{Wide}
@begin(Example)
@key(subtype) Drum_Unit @key(is) Peripheral(Drum);
@key(subtype) Disk_Unit @key(is) Peripheral(Disk);
@end(Example)

@begin{Wide}
@leading@keepnext@i(Examples of constrained record variables:)
@end{Wide}
@begin(Example)
Writer   : Peripheral(Unit  => Printer);
Archive  : Disk_Unit;
@end(Example)
@end{Examples}

@begin{Extend83}
@Defn{extensions to Ada 83}
In Ada 83, the discriminant of a @nt{variant_part} is not allowed to
be of a generic formal type.
This restriction is removed in Ada 95; an @key{others} @nt{discrete_choice}
is required in this case.
@end{Extend83}

@begin{DiffWord83}
The syntactic category @ntf{choice} is removed.
The syntax rules for @nt{variant}, @nt{array_aggregate}, and
@nt{case_statement} now use @nt{discrete_choice_list}
or @nt{discrete_choice} instead.
The syntax rule for @nt{record_aggregate} now defines its own syntax
for named associations.

We have added the term Discrete Choice to the title
since this is where they are talked about.
This is analogous to the name of the subclause
"Index Constraints and Discrete Ranges" in
the clause on Array Types.

The rule requiring that the discriminant denote
a discriminant of the type being defined seems to have been
left implicit in RM83.
@end{DiffWord83}