Debian Codegraph @

source_2020/04b.mss

raw
1 @Part(04, Root="ada.mss")
2
3 @Comment{$Date: 2020/06/03 00:09:00 $}
4
5 @Comment{$Source: e:\\cvsroot/ARM/Source/04b.mss,v $}
6 @Comment{$Revision: 1.82 $}
7
8 @LabeledClause{Type Conversions}
9
10 @begin{Intro}
11 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0299-1]}
12 @Redundant[Explicit type conversions, both
13 value conversions and view conversions, are
14 allowed between closely related
15 types as defined below. This @Chg{Version=[3],New=[subclause],Old=[clause]}
16 also defines rules for value and view
17 conversions to a particular subtype of a type,
18 both explicit ones and those implicit in other constructs.
19 @IndexSee{Term=[subtype conversion],See=(type conversion)}
20 @Defn{type conversion}
21 @Defn{conversion}
22 @IndexSee{Term=[cast],See=(type conversion)}]
23 @IndexSeeAlso{Term=[subtype conversion],See=(implicit subtype conversion)}
24 @IndexSee{Term=[type conversion, implicit],See=(implicit subtype conversion)}
25 @end{Intro}
26
27 @begin{Syntax}
28 @Syn{lhs=<type_conversion>,rhs="
29 @Syn2{subtype_mark}(@Syn2{expression})
30 | @Syn2{subtype_mark}(@Syn2{name})"}
31
32 @end{Syntax}
33
34 @begin{Intro}
35 @Defn2{Term=[target subtype], Sec=(of a @nt<type_conversion>)}
36 The @i(target subtype) of a @nt<type_conversion> is the subtype
37 denoted by the @nt{subtype_mark}.
38 @Defn2{Term=[operand], Sec=(of a @nt<type_conversion>)}
39 The @i(operand) of a @nt<type_conversion> is the
40 @nt{expression} or @nt{name} within the parentheses;
41 @Defn2{Term=[operand type], Sec=(of a @nt<type_conversion>)}
42 its type is the @i(operand type).
43
44 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0299-1]}
45 @Defn{convertible}
46 One type is @i(convertible) to a second type if a @nt<type_conversion>
47 with the first type as operand type and the second type as target type
48 is legal according to the rules of this @Chg{Version=[3],New=[subclause],Old=[clause]}.
49 Two types are convertible if each is convertible to the other.
50 @begin{Ramification}
51 Note that @lquotes@;convertible@rquotes@; is defined in terms of legality
52 of the conversion. Whether the conversion would raise an exception
53 at run time is irrelevant to this definition.
54 @end{Ramification}
55
56 @ChgRef{Version=[1],Kind=[Revised],Ref=[8652/0017],ARef=[AI95-00184-01]}
57 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00330-01]}
58 @Defn{view conversion}
59 @Defn2{Term=[conversion],Sec=(view)}
60 A @nt{type_conversion} whose operand is the
61 @nt<name> of an object is called a @i(view conversion) if
62 @Chg{New=[both ],Old=[]}its target type
63 @Chg{New=[and operand type are],Old=[is]} tagged, or if it
64 appears@Chg{Version=[2],New=[ in a call],Old=[]} as an actual parameter of mode
65 @key[out] or @key[in out];
66 @Defn{value conversion}
67 @Defn2{Term=[conversion],Sec=(value)}
68 other @nt<type_conversion>s are called @i(value conversions).
69 @IndexSee{Term=[super],See=(view conversion)}
70 @begin{Ramification}
71 A view conversion to a tagged type can appear in
72 any context that requires an object @nt<name>, including in
73 an object renaming, the @nt<prefix> of a @nt<selected_component>,
74 and if the operand is a variable, on the left side of an
75 @nt<assignment_statement>. View conversions to other types only
76 occur as actual parameters. Allowing view conversions of untagged
77 types in all contexts seemed to incur an undue implementation burden.
78
79 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00330-01]}
80 @ChgAdded{Version=[2],Text=[A type conversion appearing as an @key{in out}
81 parameter in a generic instantiation is not a view conversion; the second
82 part of the rule only applies to subprogram calls, not instantiations.]}
83 @end{Ramification}
84 @end{Intro}
85
86 @begin{Resolution}
87 @PDefn2{Term=[expected type],
88 Sec=(type_conversion operand)}
89 The operand of a @nt<type_conversion> is expected to be of any type.
90 @begin{Discussion}
91 This replaces the "must be determinable" wording of Ada 83.
92 This is equivalent to (but hopefully more intuitive than) saying
93 that the operand of a @nt<type_conversion>
94 is a @lquotes@;complete context.@rquotes@;
95 @end{Discussion}
96
97 The operand of a view conversion
98 is interpreted only as a @nt<name>;
99 the operand of a value conversion
100 is interpreted as an @nt<expression>.
101 @begin{Reason}
102 @ChgRef{Version=[4],Kind=[Revised],ARef=[AI12-0005-1]}
103 @ChgRef{Version=[5],Kind=[Revised]}@ChgNote{This is also in AI12-0005-1, don't want a duplicate reference}
104 This formally resolves the syntactic ambiguity between
105 the two forms of @nt<type_conversion>@Chg{Version=[4],New=[.
106 This matters @Chg{Version=[5],New=[because],Old=[as]} an @nt{expression} that
107 is a @nt{name} is evaluated and represents a value while a @nt{name} by
108 itself can be an object; we want
109 a view conversion to be an object],Old=[, not that it really matters]}.
110 @end{Reason}
111 @begin{Ramification}
112 @ChgRef{Version=[4],Kind=[AddedNormal],ARef=[AI12-0005-1]}
113 @ChgAdded{Version=[4],Text=[This wording uses "interpreted as" rather than
114 "shall be" so that this rule is not used to resolve overloading; it is
115 solely about evaluation as described above.]}
116 @end{Ramification}
117
118 @end{Resolution}
119
120 @begin{Legality}
121 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00251-01]}
122 @Chg{Version=[2],New=[In a view conversion for an untagged type,
123 the target type shall be convertible (back) to the operand type.],
124 Old=[@Defn2{Term=[type conversion],sec=(numeric)}
125 @Defn2{Term=[conversion],sec=(numeric)}
126 If the target type is a numeric type, then the operand type
127 shall be a numeric type.]}
128 @begin{Reason}
129 @ChgRef{Version=[2],Kind=[AddedNormal]}
130 @ChgAdded{Version=[2],Text=<Untagged view conversions appear only as [@key{in}]
131 @key{out}
132 parameters. Hence, the reverse conversion must be legal as well.
133 The forward conversion must be legal even for an @key{out} parameter,
134 because (for example) actual parameters of an access type are always
135 copied in anyway.>}
136 @end{Reason}
137 @begin{NotIso}
138 @ChgAdded{Version=[2],Noprefix=[T],Noparanum=[T],Text=[@Shrink{@i<Paragraphs 9
139 through 20 were reorganized and moved below.>}]}@Comment{This message should be
140 deleted if the paragraphs are ever renumbered.}
141 @end{NotIso}
142 @begin{Discussion}
143 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00251-01]}
144 @ChgAdded{Version=[2],Text=[The entire @LegalityTitle section has been
145 reorganized to eliminate an
146 unintentional incompatibility with Ada 83. In rare cases, a type conversion
147 between two types related by derivation is not allowed by Ada 95, while it is
148 allowed in Ada 83. The reorganization fixes this.
149 Much of the wording of the legality section is unchanged, but it is reordered
150 and reformatted. Because of the limitations of our tools, we had to delete and
151 replace nearly the entire section. The text of Ada 95 paragraphs 8 through 12,
152 14, 15, 17, 19, 20, and 24 are unchanged (just moved); these are now
153 24.1 through 24.5, 24.12, 24.13, 24.17, 24.19, 24.20, and 8.]}
154 @end{Discussion}
155
156 @ChgRef{Version=[2],Kind=[DeletedNoDelMsg],ARef=[AI95-00251-01]}
157 @ChgDeleted{Version=[2],Type=[Leading],Text=[@Defn2{Term=[type conversion],sec=(array)}
158 @Defn2{Term=[conversion],sec=(array)}
159 If the target type is an array type, then the operand type shall
160 be an array type. Further:]}
161 @begin(itemize)
162 @ChgRef{Version=[2],Kind=[DeletedNoDelMsg],ARef=[AI95-00251-01]}
163 @ChgDeleted{Version=[2],Text=[The types shall have the same dimensionality;]}
164
165 @ChgRef{Version=[1],Kind=[Revised],Ref=[8652/0008],ARef=[AI95-00168-01]}
166 @ChgRef{Version=[2],Kind=[DeletedNoDelMsg],ARef=[AI95-00251-01]}
167 @ChgDeleted{Version=[2],Text=[Corresponding index types shall be convertible;@Chg{New=[],Old=[ and]}
168 @PDefn2{Term=[convertible],Sec=(required)}]}
169
170 @ChgRef{Version=[1],Kind=[Revised],Ref=[8652/0008],ARef=[AI95-00168-01]}
171 @ChgRef{Version=[2],Kind=[DeletedNoDelMsg],ARef=[AI95-00251-01]}
172 @ChgDeleted{Version=[2],Text=[The component subtypes shall statically match@Chg{New=[; and],Old=[.]}
173 @PDefn2{Term=[statically matching],Sec=(required)}]}
174
175 @ChgRef{Version=[1],Kind=[Added],Ref=[8652/0008],ARef=[AI95-00168-01]}
176 @ChgRef{Version=[2],Kind=[DeletedAddedNoDelMsg],ARef=[AI95-00251-01]}
177 @ChgDeleted{Version=[2],Text=[@Chg{New=[In a view conversion, the target type and the operand type shall
178 both or neither have aliased components.],Old=[]}]}
179 @begin{Reason}
180 @ChgRef{Version=[1],Kind=[Added]}
181 @ChgRef{Version=[2],Kind=[DeletedAddedNoDelMsg]}
182 @ChgDeleted{Version=[2],Text=[@Chg{New=[Without this rule, it is possible to violate the constrained status
183 of aliased array components. Consider:],Old=[]}]}
184 @begin{Example}
185 @ChgRef{Version=[1],Kind=[Added]}
186 @ChgRef{Version=[2],Kind=[DeletedAddedNoDelMsg]}
187 @ChgDeleted{Version=[2],Text=[@Chg{New=[@key[package] P @key[is]
188 @key[type] T @key[is private];
189 A : @key[constant] T;
190 @key[type] A1 @key[is array] (1 .. 10) @key[of aliased] T;
191 @key[type] A2 @key[is array] (1 .. 10) @key[of] T;
192 @key[private]
193 @key[type] T (D : Integer := 0) @key[is null record];
194 A : @key[constant] T := (D => 1);
195 @key[end] P;],Old=[]}]}
196
197 @ChgRef{Version=[1],Kind=[Added]}
198 @ChgRef{Version=[2],Kind=[DeletedAddedNoDelMsg]}
199 @ChgDeleted{Version=[2],Text=[@Chg{New=[@key[with] P;
200 @key[procedure] Exam @key[is]
201 X : P.A1;
202 @key[procedure] S (Y : @key[in out] P.A2) @key[is]
203 @key[begin]
204 Y (1) := P.A;
205 @key[end];
206 @key[begin]
207 S (P.A2 (X)); -- This call will change the discriminant of X (1),
208 -- so we cannot allow the conversion.
209 @key[end];],Old=[]}]}
210 @end{Example}
211 @end{Reason}
212 @end(itemize)
213
214 @ChgRef{Version=[2],Kind=[DeletedNoDelMsg],ARef=[AI95-00251-01]}
215 @ChgDeleted{Version=[2],Type=[Leading],Text=[@Defn2{Term=[type conversion],sec=(access)}
216 @Defn2{Term=[conversion],sec=(access)}
217 If the target type is a general access type, then the operand type
218 shall be an access-to-object type. Further:]}
219 @begin{Discussion}
220 @ChgRef{Version=[2],Kind=[DeletedNoDelMsg]}
221 @ChgDeleted{Version=[2],Text=[The @LegalityTitle and @RunTimeTitle are worded
222 so that a @nt{type_conversion} T(X) (where T is an access type) is (almost)
223 equivalent to the @nt{attribute_reference} X.@key[all]'Access, where the
224 result is of type T. The @nt{type_conversion} accepts a null value, whereas
225 the @nt{attribute_reference} would raise Constraint_Error.]}
226 @end{Discussion}
227 @begin(itemize)
228 @ChgRef{Version=[2],Kind=[DeletedNoDelMsg],ARef=[AI95-00251-01]}
229 @ChgDeleted{Version=[2],Text=[If the target type is an access-to-variable
230 type, then the operand type shall be an access-to-variable type;]}
231 @begin{Ramification}
232 @ChgRef{Version=[2],Kind=[DeletedNoDelMsg]}
233 @ChgDeleted{Version=[2],Text=[If the target type is an access-to-constant
234 type, then the operand type
235 can be access-to-constant or access-to-variable.]}
236 @end{Ramification}
237
238 @ChgRef{Version=[2],Kind=[DeletedNoDelMsg],ARef=[AI95-00251-01]}
239 @ChgDeleted{Version=[2],Text=[If the target designated type is tagged,
240 then the operand designated type
241 shall be convertible to the target designated type;
242 @PDefn2{Term=[convertible],Sec=(required)}]}
243
244 @ChgRef{Version=[2],Kind=[DeletedNoDelMsg],ARef=[AI95-00251-01]}
245 @ChgDeleted{Version=[2],Text=[If the target designated type is not tagged,
246 then the designated types shall be the same,
247 and either the designated subtypes shall statically match or
248 the target designated subtype shall be discriminated and unconstrained; and
249 @PDefn2{Term=[statically matching],Sec=(required)}]}
250 @begin{Reason}
251 @ChgRef{Version=[2],Kind=[DeletedNoDelMsg]}
252 @ChgDeleted{Version=[2],Text=[These rules are designed to ensure that
253 aliased array objects only @i(need) "dope" if their nominal subtype is unconstrained,
254 but they can always @i(have) dope if required by the run-time model
255 (since no sliding is permitted as part of access type conversion).
256 By contrast, aliased discriminated objects will always @i(need) their
257 discriminants stored with them, even if nominally constrained.
258 (Here, we are assuming an implementation that represents
259 an access value as a single pointer.)]}
260 @end{Reason}
261
262 @ChgRef{Version=[2],Kind=[DeletedNoDelMsg],ARef=[AI95-00251-01]}
263 @ChgDeleted{Version=[2],Text=[@PDefn2{Term=[accessibility rule],Sec=(type conversion)}
264 The accessibility level of the operand type shall not be statically
265 deeper than that of the target type.
266 @PDefn{generic contract issue}
267 In addition to the places where @LegalityTitle normally apply
268 (see @RefSecNum{Generic Instantiation}),
269 this rule applies also in the private part of an
270 instance of a generic unit.]}
271 @begin{Ramification}
272 @ChgRef{Version=[2],Kind=[DeletedNoDelMsg]}
273 @ChgDeleted{Version=[2],Text=[The access parameter case is handled by a runtime check.
274 Runtime checks are also done in instance bodies.]}
275 @end{Ramification}
276 @end(itemize)
277
278 @ChgRef{Version=[2],Kind=[DeletedNoDelMsg],ARef=[AI95-00251-01]}
279 @ChgDeleted{Version=[2],Type=[Leading],Text=[@Defn2{Term=[type conversion],sec=(access)}
280 @Defn2{Term=[conversion],sec=(access)}
281 If the target type is an access-to-subprogram type, then the operand
282 type shall be an access-to-subprogram type. Further:]}
283 @begin(itemize)
284 @ChgRef{Version=[2],Kind=[DeletedNoDelMsg],ARef=[AI95-00251-01]}
285 @ChgDeleted{Version=[2],Text=[The designated profiles shall be
286 subtype-conformant.@Defn2{Term=[subtype conformance],Sec=(required)}]}
287
288 @ChgRef{Version=[2],Kind=[DeletedNoDelMsg],ARef=[AI95-00251-01]}
289 @ChgDeleted{Version=[2],Text=[@PDefn2{Term=[accessibility rule],Sec=(type conversion)}
290 The accessibility level of the operand type shall not be statically
291 deeper than that of the target type.
292 @PDefn{generic contract issue}
293 In addition to the places where @LegalityTitle normally apply
294 (see @RefSecNum{Generic Instantiation}),
295 this rule applies also in the private part of an
296 instance of a generic unit.
297 If the operand type is declared within a generic body,
298 the target type shall be declared within the generic body.]}
299
300 @begin{Reason}
301 @ChgRef{Version=[2],Kind=[DeletedNoDelMsg]}
302 @ChgDeleted{Version=[2],Text=[The reason it is illegal to convert from
303 an access-to-subprogram type
304 declared in a generic body to one declared outside that body
305 is that in an implementation that shares generic bodies,
306 procedures declared inside the generic need to have a different
307 calling convention @em they need an extra parameter pointing to the
308 data declared in the current instance.
309 For procedures declared in the spec,
310 that's OK, because the compiler can know about them at compile time of
311 the instantiation.]}
312 @end{Reason}
313 @end(itemize)
314
315 @Comment{We start the new text here, so we can modify the handful of rules
316 that are not reformatted. (Except the first rule is at the top.)}
317
318 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00251-01]}
319 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0115-1]}
320 @Leading@Defn2{Term=[type conversion],sec=[composite (non-array)]}
321 @Defn2{Term=[conversion],sec=[composite (non-array)]}
322 @Chg{Version=[2],New=[If there is a type@Chg{Version=[3],New=[ (other than a
323 root numeric type)],Old=[]} that is an ancestor of both the target
324 type and the operand type, or both types are class-wide types, then at least
325 one of the following rules shall apply:],Old=[@Defn2{Term=[type conversion],sec=(enumeration)}
326 @Defn2{Term=[conversion],sec=(enumeration)}
327 If the target type is not included in any of the above four
328 cases, there shall be a type that is an ancestor of both
329 the target type and the operand type.
330 Further, if the target type is tagged, then either:]}
331 @begin(itemize)
332 @ChgRef{Version=[2],Kind=[Added],ARef=[AI95-00251-01]}
333 @ChgAdded{Version=[2],Text=[@Defn2{Term=[type conversion],sec=(enumeration)}
334 @Defn2{Term=[conversion],sec=(enumeration)}The target type shall be
335 untagged; or]}
336
337 The operand type shall be covered by or
338 descended from the target type; or
339 @begin{Ramification}
340 This is a conversion
341 toward the root, which is always safe.
342 @end{Ramification}
343
344 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00251-01]}
345 The operand type shall be a class-wide type that covers the target
346 type@Chg{Version=[2],New=[; or],Old=[.]}
347 @begin{Ramification}
348 This is a conversion of a class-wide type toward the leaves,
349 which requires a tag check. See @RunTimeTitle.
350
351 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00251-01]}
352 These two rules imply that a conversion from @Chg{Version=[2],New=[an
353 ancestor],Old=[a parent]} type
354 to a type extension is not permitted, as this would require
355 specifying the values for additional components, in general,
356 and changing the tag. An @nt<extension_aggregate> has to be used
357 instead, constructing a new value, rather than converting an
358 existing value. However, a conversion
359 from the class-wide type rooted at @Chg{Version=[2],New=[an
360 ancestor],Old=[the parent]} type is permitted;
361 such a conversion just verifies that the operand's tag is
362 a descendant of the target.
363 @end{Ramification}
364
365 @ChgRef{Version=[2],Kind=[Added],ARef=[AI95-00251-01]}
366 @ChgAdded{Version=[2],Text=[The operand and target types shall both be class-wide
367 types and the specific type associated with at least one of them shall be an
368 interface type.]}
369 @begin{Ramification}
370 @ChgRef{Version=[2],Kind=[AddedNormal]}
371 @ChgAdded{Version=[2],Text=[We allow converting any class-wide type T'Class to
372 or from a class-wide interface type even if the specific type T does not
373 have an appropriate
374 interface ancestor, because some extension of T might have the needed
375 ancestor. This is similar to a conversion of a class-wide type toward the
376 leaves of the tree, and we need to be consistent. Of course, there is
377 a runtime check that the actual object has the needed interface.]}
378 @end{Ramification}
379 @end(itemize)
380
381 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00251-01]}
382 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0115-1]}
383 @Chg{Version=[2],New=[If there is no type@Chg{Version=[3],New=[ (other than a
384 root numeric type)],Old=[]} that is the ancestor of both the
385 target type and the operand type, and they are not both class-wide types, one
386 of the following rules shall apply:], Old=[In a view conversion for
387 an untagged type, the target type shall be convertible (back) to the operand type.]}
388 @begin{Reason}
389 @ChgRef{Version=[2],Kind=[DeletedNoDelMsg]}
390 @ChgDeleted{Version=[2],Text=<Untagged view conversions appear only as [in] out
391 parameters. Hence, the reverse conversion must be legal as well.
392 The forward conversion must be legal even if an out parameter,
393 because actual parameters of an access type are always
394 copied in anyway.>}
395 @end{Reason}
396
397 @begin(itemize)
398 @ChgRef{Version=[2],Kind=[Added],ARef=[AI95-00251-01]}
399 @ChgAdded{Version=[2],Text=[@Defn2{Term=[type conversion],sec=(numeric)}
400 @Defn2{Term=[conversion],sec=(numeric)}
401 If the target type is a numeric type, then the operand type
402 shall be a numeric type.]}
403
404 @ChgRef{Version=[2],Kind=[Added],ARef=[AI95-00251-01]}
405 @ChgAdded{Version=[2],Type=[Leading],Text=[@Defn2{Term=[type conversion],sec=(array)}
406 @Defn2{Term=[conversion],sec=(array)}
407 If the target type is an array type, then the operand type shall
408 be an array type. Further:]}
409
410 @begin(inneritemize)
411
412 @ChgRef{Version=[2],Kind=[Added],ARef=[AI95-00251-01]}
413 @Chg{Version=[2],New=[The types shall have the same dimensionality;],Old=[]}
414
415 @ChgRef{Version=[2],Kind=[Added],ARef=[AI95-00251-01]}
416 @Chg{Version=[2],New=[Corresponding index types shall be convertible;
417 @PDefn2{Term=[convertible],Sec=(required)}],Old=[]}
418
419 @ChgRef{Version=[2],Kind=[Added],ARef=[AI95-00251-01]}
420 @Chg{Version=[2],New=[The component subtypes shall statically match;
421 @PDefn2{Term=[statically matching],Sec=(required)}],Old=[]}
422
423 @ChgRef{Version=[2],Kind=[Added],ARef=[AI95-00392-01]}
424 @Chg{Version=[2],New=[If the component types are anonymous access types, then the
425 accessibility level of the operand type shall not be statically deeper
426 than that of the target type;
427 @PDefn2{Term=[accessibility rule],Sec=(type conversion, array components)}],Old=[]}
428 @begin{Reason}
429 @ChgRef{Version=[2],Kind=[AddedNormal]}
430 @ChgAdded{Version=[2],Text=[For unrelated array types, the component types
431 could have different accessibility, and we had better not allow a
432 conversion of a local type into a global type, in case the local type
433 points at local objects. We don't need a check for other types of
434 components; such components necessarily are for related types, and
435 either have the same accessibility or (for access discriminants) cannot
436 be changed so the discriminant check will prevent problems.]}
437 @end{Reason}
438
439 @ChgRef{Version=[2],Kind=[Added],ARef=[AI95-00246-01]}
440 @ChgAdded{Version=[2],Text=[Neither the target type nor the operand type shall be
441 limited;]}
442 @begin{Reason}
443 @ChgRef{Version=[2],Kind=[AddedNormal]}
444 @ChgAdded{Version=[2],Text=[We cannot allow conversions between unrelated limited
445 types, as they may have different representations, and (since the types
446 are limited), a copy cannot be made to reconcile the representations.]}
447 @end{Reason}
448
449 @ChgRef{Version=[2],Kind=[Added],ARef=[AI95-00251-01],ARef=[AI95-00363-01]}
450 @ChgAdded{Version=[2],Text=[If the target type of a view conversion has
451 aliased components, then so shall the operand type; and]}
452 @begin{Reason}
453 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00363-01]}
454 @ChgAdded{Version=[2],Text=[We cannot allow a view conversion from an object
455 with unaliased components to an object with aliased components, because
456 that would effectively allow pointers to unaliased components. This rule
457 was missing from Ada 95.]}
458 @end{Reason}
459
460 @ChgRef{Version=[2],Kind=[Added],ARef=[AI95-00246-01],ARef=[AI95-00251-01]}
461 @ChgAdded{Version=[2],Text=[The operand type of a view conversion shall not
462 have a tagged, private, or volatile subcomponent.]}
463 @begin{Reason}
464 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00246-01]}
465 @ChgAdded{Version=[2],Text=[We cannot allow view conversions between unrelated
466 might-be-by-reference types, as they may have different representations,
467 and a copy cannot be made to reconcile the representations.]}
468 @end{Reason}
469 @begin{Ramification}
470 @ChgRef{Version=[2],Kind=[AddedNormal]}
471 @ChgAdded{Version=[2],Text=[These rules only apply to unrelated array
472 conversions; different (weaker) rules apply to conversions between related
473 types.]}
474 @end{Ramification}
475 @end(inneritemize)
476
477 @ChgRef{Version=[2],Kind=[Added],ARef=[AI95-00230-01]}
478 @Chg{Version=[2],New=[If the target type is @i<universal_access>, then the
479 operand type shall be an access type.],Old=[]}
480
481 @begin{Discussion}
482 @ChgRef{Version=[2],Kind=[AddedNormal]}
483 @ChgAdded{Version=[2],Text=[Such a conversion cannot be written explicitly,
484 of course, but it can be implicit (see below).]}
485 @end{Discussion}
486
487 @ChgRef{Version=[2],Kind=[Added],ARef=[AI95-00230-01],ARef=[AI95-00251-01]}
488 @ChgAdded{Version=[2],Type=[Leading],Text=[@Defn2{Term=[type conversion],sec=(access)}
489 @Defn2{Term=[conversion],sec=(access)}If the target type is a general access-to-object type, then
490 the operand type shall be @i<universal_@!access> or an access-to-object type.
491 Further, if the operand type is not @i<universal_@!access>:]}
492
493 @begin{Discussion}
494 @ChgRef{Version=[2],Kind=[AddedNormal]}
495 @ChgAdded{Version=[2],Text=[The @LegalityTitle and @RunTimeTitle are worded
496 so that a @nt{type_conversion} T(X) (where T is an access type) is
497 (almost) equivalent to the @nt{attribute_reference}
498 X.@key[all]'Access, where the result is of type T.
499 The only difference is that the @nt{type_conversion} accepts a null value,
500 whereas the @nt{attribute_reference} would raise Constraint_Error.]}
501 @end{Discussion}
502
503 @begin(inneritemize)
504
505 @ChgRef{Version=[2],Kind=[Added],ARef=[AI95-00251-01]}
506 @Chg{Version=[2],New=[If the target type is an access-to-variable
507 type, then the operand type shall be an access-to-variable type;],Old=[]}
508 @begin{Ramification}
509 @ChgRef{Version=[2],Kind=[AddedNormal]}
510 @ChgAdded{Version=[2],Text=[If the target type is an access-to-constant type,
511 then the operand type can be access-to-constant or access-to-variable.]}
512 @end{Ramification}
513
514 @ChgRef{Version=[2],Kind=[Added],ARef=[AI95-00251-01]}
515 @ChgAdded{Version=[2],Text=[If the target designated type is tagged, then the
516 operand designated type shall be convertible to the target designated type;
517 @PDefn2{Term=[convertible],Sec=(required)}]}
518
519 @ChgRef{Version=[2],Kind=[Added],ARef=[AI95-00251-01],ARef=[AI95-00363-01]}
520 @ChgAdded{Version=[2],Type=[Leading],Text=[If the target designated type is
521 not tagged, then the designated types shall be the same, and either:]}
522
523 @begin(innerinneritemize)
524 @ChgRef{Version=[2],Kind=[Added],ARef=[AI95-00363-01]}
525 @Chg{Version=[2],New=[the designated subtypes shall statically match;
526 or@PDefn2{Term=[statically matching],Sec=(required)}],Old=[]}
527
528 @ChgRef{Version=[2],Kind=[Added],ARef=[AI95-00363-01],ARef=[AI95-00384-01]}
529 @Chg{Version=[2],New=[the designated type shall be discriminated in its
530 full view and unconstrained in any partial view, and one of the designated
531 subtypes shall be unconstrained;],Old=[]}
532
533 @begin{Ramification}
534 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00363-01]}
535 @ChgAdded{Version=[2],Text=[This does not require that types have a partial view
536 in order to allow the conversion, simply that any partial view that does
537 exist is unconstrained.]}
538
539 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00384-01]}
540 @ChgAdded{Version=[2],Text=[This allows conversions both ways (either subtype
541 can be unconstrained); while Ada 95 only allowed the conversion if the
542 target subtype is unconstrained. We generally want type conversions to be
543 symmetric; which type is the target shouldn't matter for legality.]}
544 @end{Ramification}
545
546 @begin{Reason}
547 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00363-01]}
548 @ChgAdded{Version=[2],Text=[If the visible partial view is constrained, we
549 do not allow conversion between unconstrained and constrained subtypes.
550 This means that whether the full type had discriminants is not visible
551 to clients of the partial view.]}
552 @end{Reason}
553
554 @begin{Discussion}
555 @ChgRef{Version=[4],Kind=[Added],ARef=[AI12-0095-1]}
556 @ChgAdded{Version=[4],Text=[We assume the worst in a generic body whether
557 or not a formal subtype has a constrained partial view; specifically, in a
558 generic body a discriminated subtype is considered to have a constrained
559 partial view if it is a descendant of an untagged generic formal private
560 or derived type (see @RefSecNum{Formal Private and Derived Types} for the
561 formal definition of this rule).]}
562 @end{Discussion}
563
564 @end(innerinneritemize)
565 @begin{Reason}
566 @ChgRef{Version=[2],Kind=[AddedNormal]}
567 @ChgAdded{Version=[2],Text=[These rules are designed to ensure that aliased array objects
568 only @i(need) "dope" if their nominal subtype is unconstrained,
569 but they can always @i(have) dope if required by the run-time model
570 (since no sliding is permitted as part of access type conversion).
571 By contrast, aliased discriminated objects will always @i(need) their
572 discriminants stored with them, even if nominally constrained.
573 (Here, we are assuming an implementation that represents
574 an access value as a single pointer.)]}
575 @end{Reason}
576
577 @ChgRef{Version=[2],Kind=[Added],ARef=[AI95-00251-01]}
578 @ChgRef{Version=[3],Kind=[RevisedAdded],ARef=[AI05-0148-1],ARef=[AI05-0248-1]}
579 @ChgRef{Version=[4],Kind=[RevisedAdded],ARef=[AI12-0027-1]}
580 @Chg{Version=[2],New=[@PDefn2{Term=[accessibility rule],Sec=(type conversion)}
581 The accessibility level of the operand type shall not be statically
582 deeper than that of the target type@Chg{Version=[3],New=[, unless the target
583 type is an anonymous access type of a stand-alone object. If the target type
584 is that of such a stand-alone object, the accessibility level of the operand
585 type shall not be statically deeper than that of the declaration of the
586 stand-alone object],Old=[]}.@Chg{Version=[4],New=[],Old=[
587 @PDefn{generic contract issue}
588 In addition to the places where @LegalityTitle normally apply
589 (see @RefSecNum{Generic Instantiation}),
590 this rule applies also in the private part of an
591 instance of a generic unit.]}],Old=[]}
592 @begin{Ramification}
593 @ChgRef{Version=[2],Kind=[AddedNormal]}
594 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0148-1]}
595 @ChgAdded{Version=[2],Text=[The access parameter case is handled by a run-time
596 check. runtime checks are also done in instance bodies@Chg{Version=[3],
597 New=[, and for stand-alone objects of anonymous access types],Old=[]}.]}
598 @end{Ramification}
599 @begin{Reason}
600 @ChgRef{Version=[3],Kind=[Added]}
601 @ChgAdded{Version=[3],Text=[We prohibit storing accesses to objects deeper
602 than a stand-alone object of an anonymous access-to-object (even while we
603 allow storing all other accesses) in order to prevent dangling accesses.]}
604 @end{Reason}
605
606 @end(inneritemize)
607
608 @ChgRef{Version=[2],Kind=[Added],ARef=[AI95-00230-01]}
609 @ChgAdded{Version=[2],Text=[@Defn2{Term=[type conversion],sec=(access)}
610 @Defn2{Term=[conversion],sec=(access)}If the target type is a pool-specific
611 access-to-object type, then
612 the operand type shall be @i<universal_access>.]}
613 @begin{Reason}
614 @ChgRef{Version=[2],Kind=[AddedNormal]}
615 @ChgAdded{Version=[2],Text=[This allows @b<null> to be converted to pool-specific
616 types. Without it, @b<null> could be converted to general access types but
617 not pool-specific ones, which would be too inconsistent. Remember that these
618 rules only apply to unrelated types, so we don't have to talk about
619 conversions to derived or other related types.]}
620 @end{Reason}
621
622 @ChgRef{Version=[2],Kind=[Added],ARef=[AI95-00230-01],ARef=[AI95-00251-01]}
623 @ChgAdded{Version=[2],Type=[Leading],Text=[@Defn2{Term=[type conversion],sec=(access)}
624 @Defn2{Term=[conversion],sec=(access)}
625 If the target type is an access-to-subprogram type, then the operand type
626 shall be @i<universal_@!access> or an access-to-subprogram type. Further, if
627 the operand type is not @i<universal_@!access>:]}
628
629 @begin(inneritemize)
630
631 @ChgRef{Version=[2],Kind=[Added],ARef=[AI95-00251-01]}
632 @ChgRef{Version=[3],Kind=[RevisedAdded],ARef=[AI05-0239-1]}
633 @Chg{Version=[2],New=[The designated profiles shall be
634 @Chg{Version=[3],New=[subtype conformant],Old=[subtype-conformant]}.
635 @Defn2{Term=[subtype conformance],Sec=(required)}],Old=[]}
636
637 @ChgRef{Version=[2],Kind=[Added],ARef=[AI95-00251-01]}
638 @ChgRef{Version=[4],Kind=[RevisedAdded],ARef=[AI12-0027-1]}
639 @Chg{Version=[2],New=[@PDefn2{Term=[accessibility rule],Sec=(type conversion)}
640 The accessibility level of the operand type shall not be statically
641 deeper than that of the target type.@Chg{Version=[4],New=[],Old=[
642 @PDefn{generic contract issue}
643 In addition to the places where @LegalityTitle normally apply
644 (see @RefSecNum{Generic Instantiation}),
645 this rule applies also in the private part of an
646 instance of a generic unit.]}
647 If the operand type is declared within a generic body,
648 the target type shall be declared within the generic body.],Old=[]}
649
650 @begin{Reason}
651 @ChgRef{Version=[2],Kind=[AddedNormal]}
652 @ChgAdded{Version=[2],Text=[The reason it is illegal to convert from an
653 access-to-subprogram type declared in a generic body to one declared outside
654 that body is that in an implementation that shares generic bodies,
655 subprograms declared inside the generic need to have a different
656 calling convention @em they need an extra parameter pointing to the
657 data declared in the current instance. For subprograms declared in the spec,
658 that's OK, because the compiler can know about them at compile time of
659 the instantiation.]}
660 @end{Reason}
661
662 @ChgRef{Version=[5],Kind=[Added],ARef=[AI12-0064-2]}
663 @ChgAdded{Version=[5],Text=[If the target type is nonblocking, the operand
664 type shall be nonblocking.]}
665 @end(inneritemize)
666
667 @end(itemize)
668
669 @ChgRef{Version=[4],Kind=[Added],ARef=[AI12-0027-1]}
670 @ChgRef{Version=[5],Kind=[RevisedAdded]}@Comment{Just for a paragraph number change}
671 @ChgAdded{Version=[4],Text=[@PDefn{generic contract issue}
672 In addition to the places where @LegalityTitle normally apply
673 (see @RefSecNum{Generic Instantiation}),
674 these rules apply also in the private part of an
675 instance of a generic unit.]}
676 @begin{Discussion}
677 @ChgRef{Version=[4],Kind=[AddedNormal]}
678 @ChgRef{Version=[5],Kind=[Revised],ARef=[AI12-0005-1]}
679 @ChgAdded{Version=[4],Text=[This applies to @i<all> of the @LegalityTitle
680 in this section. It won't matter for the majority of these rules, but
681 in any case that it does, we want to apply the same
682 @Chg{Version=[5],New=[rules],Old=[recheck]} in the private
683 part. (Ada got the default wrong for these, as there is only one known case
684 where we don't want to recheck in the private part,
685 see derivations without record extensions in
686 @RefSecNum{Derived Types and Classes}.)]}
687 @end{Discussion}
688
689 @end{Legality}
690
691 @begin{StaticSem}
692 A @nt{type_conversion} that is a value conversion denotes the value
693 that is
694 the result of converting the value of the operand to the target subtype.
695
696 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0264-1]}
697 A @nt{type_conversion} that is a view conversion
698 denotes a view of the object denoted by the operand. This
699 view is a variable of the target type if the operand denotes
700 a variable; otherwise@Chg{Version=[3],New=[,],Old=[]}
701 it is a constant of the target type.
702
703 @PDefn2{Term=[nominal subtype], Sec=(associated with a @nt<type_conversion>)}
704 The nominal subtype of a @nt<type_conversion> is its target subtype.
705 @end{StaticSem}
706
707 @begin{RunTime}
708 @Leading@PDefn2{Term=[evaluation], Sec=(value conversion)}
709 @Defn2{Term=[corresponding value],
710 Sec=(of the target type of a conversion)}
711 @Defn{conversion}
712 For the evaluation of a @nt<type_conversion> that is a value conversion,
713 the operand is evaluated, and then
714 the value of the operand is @i(converted) to a @i(corresponding)
715 value of the target type, if any.
716 @IndexCheck{Range_Check}
717 @Defn2{Term=[Constraint_Error],Sec=(raised by failure of runtime check)}
718 If there is no value
719 of the target type that corresponds to the operand value,
720 Constraint_Error is raised@Redundant[; this can only
721 happen on conversion to a modular type,
722 and only when the operand value is outside the base range of
723 the modular type.]
724 Additional rules follow:
725 @begin(itemize)
726 @Defn2{Term=[type conversion],sec=(numeric)}
727 @Defn2{Term=[conversion],sec=(numeric)}
728 Numeric Type Conversion
729 @begin(inneritemize)
730 If the target and the operand types are both integer types, then
731 the result is the value of the target type that corresponds
732 to the same mathematical integer as the operand.
733
734 If the target type is a decimal fixed point type, then the result is
735 truncated (toward 0) if the
736 value of the operand is not a multiple of the @i{small} of the target
737 type.
738
739 @Defn{accuracy}
740 If the target type is some other real type,
741 then the result is within the accuracy of the target type
742 (see @RefSec{Numeric Performance Requirements},
743 for implementations that support the Numerics Annex).
744 @begin(Discussion)
745 An integer type might have more bits of precision than a real type,
746 so on conversion (of a large integer), some precision might be lost.
747 @end(Discussion)
748
749 If the target type is an integer type and the operand type is real,
750 the result is rounded to the nearest integer (away from zero
751 if exactly halfway between two integers).
752 @begin{Discussion}
753 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00267-01]}
754 This was implementation defined in Ada 83.
755 There seems no reason to preserve the nonportability
756 in Ada 95. Round-away-from-zero is the conventional
757 definition of rounding, and standard Fortran and COBOL both specify
758 rounding away from zero, so for interoperability, it seems important
759 to pick this. This is also the most easily @lquotes@;undone@rquotes@; by hand.
760 Round-to-nearest-even is an alternative, but that is quite complicated
761 if not supported by the hardware. In any case, this operation is not
762 @Chg{Version=[2],New=[usually],Old=[expected to be]} part of an inner loop,
763 so predictability and portability are judged most important.
764 @Chg{Version=[2],New=[A],Old=[We anticipate that
765 a]} floating point attribute function Unbiased_Rounding @Chg{Version=[2],
766 New=[is],Old=[will be]} provided@Chg{Version=[2],
767 New=[ (see @RefSecNum{Attributes of Floating Point Types})],Old=[]}
768 for those applications that require round-to-nearest-even@Chg{Version=[2],
769 New=[, and a floating point attribute function Machine_Rounding (also see
770 @RefSecNum{Attributes of Floating Point Types}) is provided for those
771 applications that require the highest possible performance], Old=[]}.
772 @lquotes@;Deterministic@rquotes@; rounding is required for static
773 conversions to integer as well.
774 See @RefSecNum{Static Expressions and Static Subtypes}.
775 @end{Discussion}
776 @end(inneritemize)
777
778 @Defn2{Term=[type conversion],sec=(enumeration)}
779 @Defn2{Term=[conversion],sec=(enumeration)}
780 Enumeration Type Conversion
781 @begin(inneritemize)
782 The result is the value of the target type with the same
783 position number as that of the operand value.
784 @end(inneritemize)
785
786 @Defn2{Term=[type conversion],sec=(array)}
787 @Defn2{Term=[conversion],sec=(array)}
788 Array Type Conversion
789 @begin(inneritemize)
790 @IndexCheck{Length_Check}
791 If the target subtype is a constrained array subtype, then
792 a check is made that the length of each dimension of the value of
793 the operand equals the length of the corresponding dimension of the
794 target subtype.
795 The bounds of the result are those of the target subtype.
796
797 @IndexCheck{Range_Check}
798 If the target subtype is an unconstrained array subtype, then the
799 bounds of the result are obtained by converting each bound of the value
800 of the operand to the corresponding index type of the target type.
801 @PDefn2{Term=[implicit subtype conversion],Sec=(array bounds)}
802 For each nonnull index range, a check is made that the
803 bounds of the range belong to the corresponding index subtype.
804 @begin(Discussion)
805 Only nonnull index ranges are checked, per AI83-00313.
806 @end(Discussion)
807
808 In either array case, the value of each component of the result is that
809 of the matching component of the operand value
810 (see @RefSecNum{Relational Operators and Membership Tests}).
811 @begin{Ramification}
812 This applies whether or not the component is initialized.
813 @end{Ramification}
814
815 @ChgRef{Version=[2],Kind=[Added],ARef=[AI95-00392-01]}
816 @ChgAdded{Version=[2],Text=[If the component types of the array types are
817 anonymous access types, then a check is made that the accessibility level
818 of the operand type is not deeper than that of the target type.
819 @IndexCheck{Accessibility_Check}]}
820 @begin{Reason}
821 @ChgRef{Version=[2],Kind=[AddedNormal]}
822 @ChgRef{Version=[5],Kind=[Revised],ARef=[AI12-0005-1]}
823 @ChgAdded{Version=[2],Text=[This check is needed for operands that are
824 @Chg{Version=[5],New=[],Old=[access
825 parameters and ]}in instance bodies. Other cases are handled by the
826 legality rule given previously.]}
827 @end{Reason}
828
829 @end(inneritemize)
830
831 @Defn2{Term=[type conversion],sec=[composite (non-array)]}
832 @Defn2{Term=[conversion],sec=[composite (non-array)]}
833 Composite (Non-Array) Type Conversion
834 @begin(inneritemize)
835 The value of each nondiscriminant component of the result
836 is that of the matching component of the operand value.
837 @begin{Ramification}
838 This applies whether or not the component is initialized.
839 @end{Ramification}
840
841 @Redundant[The tag of the result is that of the operand.]
842 @IndexCheck{Tag_Check}
843 If the operand type is class-wide,
844 a check is made that the tag of the operand identifies
845 a (specific) type that is covered by or descended from
846 the target type.
847 @begin{Ramification}
848 This check is certain to succeed
849 if the operand type is itself covered by or descended from
850 the target type.
851 @end{Ramification}
852 @begin{TheProof}
853 The fact that a @nt{type_conversion} preserves the tag
854 is stated officially in @RefSec{Tagged Types and Type Extensions}
855 @end{TheProof}
856
857 For each discriminant of the target type that corresponds to
858 a discriminant of the operand type, its value is that of
859 the corresponding discriminant of the operand value;
860 @IndexCheck{Discriminant_Check}
861 if it corresponds
862 to more than one discriminant of the operand type, a check is made
863 that all these discriminants are equal in the operand value.
864
865 For each discriminant of the target type that corresponds to
866 a discriminant that is specified by the @nt<derived_type_definition>
867 for some ancestor of the operand type (or if class-wide,
868 some ancestor of the specific type identified by the tag
869 of the operand), its
870 value in the result is that specified by the @nt<derived_type_definition>.
871 @begin{Ramification}
872 It is a ramification of the rules for the discriminants of derived types
873 that each discriminant of the result is covered either by this
874 paragraph or the previous one. See @RefSecNum(Discriminants).
875 @end{Ramification}
876
877 @IndexCheck{Discriminant_Check}
878 For each discriminant of the operand type that corresponds
879 to a discriminant that is specified by the @nt<derived_type_definition>
880 for some ancestor of the target type,
881 a check is made that in the operand value it equals the value
882 specified for it.
883
884 @IndexCheck{Range_Check}
885 For each discriminant of the result, a check is made that its
886 value belongs to its subtype.
887 @end(inneritemize)
888
889 @Defn2{Term=[type conversion],sec=(access)}
890 @Defn2{Term=[conversion],sec=(access)}
891 Access Type Conversion
892 @begin(inneritemize)
893 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0148-1],ARef=[AI05-0248-1]}
894 For an access-to-object type,
895 a check is made that the accessibility level of the operand
896 type is not deeper than that of the target type@Chg{Version=[3],New=[,
897 unless the target type is an anonymous access type of a stand-alone
898 object. If the target type is that of such a stand-alone object, a check is
899 made that the accessibility level of the operand type is not deeper than that
900 of the declaration of the stand-alone object@Redundant[; then if the check
901 succeeds, the accessibility level of the target type becomes that of the
902 operand type]],Old=[]}.
903 @IndexCheck{Accessibility_Check}
904
905 @begin{Ramification}
906 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0148-1]}
907 This check is needed for operands that are access
908 parameters@Chg{Version=[3],New=[, for stand-alone anonymous access objects,],Old=[]}
909 and in instance bodies.
910
911 Note that this check can never fail for the implicit conversion
912 to the anonymous type of an access parameter that is done when
913 calling a subprogram with an access parameter.
914 @end{Ramification}
915
916 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00230-01],ARef=[AI95-00231-01]}
917 If the @Chg{Version=[2],New=[],Old=[target type is an anonymous access type,
918 a check is made that the value of the operand is not null;
919 if the target is not an anonymous access type, then the
920 result is null if the ]}operand value is null@Chg{Version=[2],New=[, the
921 result of the conversion is the null value of the target type.],Old=[.
922 @IndexCheck{Access_Check}]}
923 @begin{Ramification}
924 @ChgRef{Version=[2],Kind=[Revised]}
925 A conversion to an anonymous access type
926 happens implicitly as part of initializing
927 @Chg{Version=[2],New=[or assigning to an anonymous access object],
928 Old=[an access discriminant or access parameter]}.
929 @end{Ramification}
930 @begin{Reason}
931 @ChgRef{Version=[2],Kind=[DeletedNoDelMsg],ARef=[AI95-00231-01]}
932 @ChgDeleted{Version=[2],Text=[As explained in @RefSec{Access Types},
933 it is important that a value of an anonymous access type
934 can never be null.]}
935 @end{Reason}
936
937 If the operand value is not null, then
938 the result designates the same
939 object (or subprogram) as is designated by the operand value,
940 but viewed as being of the target designated subtype (or profile);
941 any checks associated with evaluating a conversion to
942 the target designated subtype are performed.
943 @begin{Ramification}
944 The checks are certain to succeed if
945 the target and operand designated subtypes statically match.
946 @end{Ramification}
947 @end(inneritemize)
948 @end(itemize)
949
950 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00231-01]}
951 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0153-3],ARef=[AI05-0290-1]}
952 @ChgRef{Version=[4],Kind=[Revised],ARef=[AI12-0071-1]}
953 @ChgRef{Version=[5],Kind=[Revised],ARef=[AI12-0333-1]}
954 @ChgAdded{Version=[5],Type=[Leading],Text=[]}@Comment{Conditional "leading"}
955 @IndexCheck{Range_Check}
956 @IndexCheck{Discriminant_Check}
957 @IndexCheck{Index_Check}
958 @Chg{Version=[2],New=[@IndexCheck{Access_Check}],Old=[]}
959 After conversion of the value to the target type,
960 if the target subtype is constrained,
961 a check is performed that the value satisfies this constraint.@Chg{Version=[2],
962 New=[ If the target subtype excludes null,
963 then a check is made that the value is not null.],Old=[]}@Chg{Version=[3],
964 New=[ If predicate checks are enabled
965 for the target subtype (see @RefSecNum{Subtype Predicates}), a check
966 is performed that the @Chg{Version=[4],New=[value satisfies the
967 predicates],Old=[predicate]} of the target
968 subtype@Chg{Version=[4],New=[],Old=[ is satisfied for the
969 value]}@Chg{Version=[5],New=[, unless the conversion
970 is:],Old=[]}.@Defn2{Term=[predicate check],
971 Sec=[subtype conversion]}@Defn2{Term=[check, language-defined],
972 Sec=[controlled by assertion policy]}],Old=[]}
973 @begin{Ramification}
974 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00231-01]}
975 The @Chg{Version=[2],New=[first],Old=[above]} check
976 @Chg{Version=[2],New=[above ],Old=[]}is a Range_Check for scalar subtypes, a
977 Discriminant_Check or Index_Check for access subtypes, and a Discriminant_Check
978 for discriminated subtypes. The Length_Check for an array conversion is
979 performed as part of the conversion to the target type.@Chg{Version=[2],
980 New=[ The check for exclusion of null is an Access_Check.],Old=[]}
981 @end{Ramification}
982 @begin{Itemize}
983 @ChgRef{Version=[5],Kind=[Added],ARef=[AI12-0333-1]}
984 @ChgAdded{Version=[5],Text=[a view conversion that is an actual
985 parameter of mode @key<out>; or]}
986
987 @ChgRef{Version=[5],Kind=[Added],ARef=[AI12-0333-1]}
988 @ChgAdded{Version=[5],Text=[an implicit subtype conversion of an actual
989 parameter of mode @key<out> to the nominal subtype of its formal
990 parameter.]}
991 @end{Itemize}
992
993 @begin{Ramification}
994 @ChgRef{Version=[5],Kind=[AddedNormal],ARef=[AI12-0333-1]}
995 @ChgAdded{Version=[5],Text=[The reverse conversion applied to by-copy @key{out}
996 parameters is @i<not> a view conversion and it is to the nominal subtype
997 of the @i<actual> parameter, therefore any enabled predicate
998 checks @i<are> performed.]}
999 @end{Ramification}
1000
1001 @PDefn2{Term=[evaluation], Sec=(view conversion)}
1002 For the evaluation of a view conversion, the operand @nt<name> is
1003 evaluated, and a new view of the
1004 object denoted by the operand is created, whose type is the
1005 target type;
1006 @IndexCheck{Length_Check}
1007 @IndexCheck{Tag_Check}
1008 @IndexCheck{Discriminant_Check}
1009 if the target type is composite, checks are
1010 performed as above for a value conversion.
1011
1012 @Leading@;The properties of this new view are as follows:
1013 @begin(itemize)
1014 @ChgRef{Version=[1],Kind=[Revised],Ref=[8652/0017],ARef=[AI95-00184-01]}
1015 If the target type is composite, the bounds or discriminants (if any)
1016 of the view are as defined above for a value conversion;
1017 each nondiscriminant component of the view denotes the matching
1018 component of the operand object; the
1019 subtype of the view is constrained if either the target subtype
1020 or the operand object is constrained,
1021 @Chg{New=[or if the target subtype is indefinite,],Old=[]}
1022 or if the operand type is a descendant of the target type@Chg{New=[],Old=[,]}
1023 and has discriminants that were not inherited from
1024 the target type;
1025
1026 If the target type is tagged, then an assignment to the
1027 view assigns to the corresponding part of the object denoted
1028 by the operand; otherwise, an assignment to the view
1029 assigns to the object, after converting
1030 the assigned value to the subtype of the object (which
1031 might raise Constraint_Error);
1032 @PDefn2{Term=[implicit subtype conversion],Sec=(assignment to view conversion)}
1033
1034 @ChgRef{Version=[4],Kind=[Revised],ARef=[AI12-0074-1]}
1035 Reading the value of the view yields the result of converting
1036 the value of the operand object to the target subtype
1037 (which might raise Constraint_Error), except if the object
1038 is of an @Chg{Version=[4],New=[elementary],Old=[access]} type and the
1039 view conversion is passed as an @key(out) parameter;
1040 in this latter case, the value of the operand object
1041 @Chg{Version=[4],New=[may be],Old=[is]} used to initialize the
1042 formal parameter without checking against any constraint of the
1043 target subtype
1044 (@Chg{Version=[4],New=[as described more precisely in],Old=[see]}
1045 @RefSecNum(Parameter Associations)).
1046 @PDefn2{Term=[implicit subtype conversion],Sec=(reading a view conversion)}
1047 @begin(Reason)
1048 @ChgRef{Version=[4],Kind=[Revised],ARef=[AI12-0074-1]}
1049 This ensures that even an @key(out) parameter of
1050 an @Chg{Version=[4],New=[elementary],Old=[access]} type is
1051 initialized reasonably.
1052 @end(Reason)
1053 @end(itemize)
1054
1055 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0290-1]}
1056 @ChgRef{Version=[4],Kind=[Revised],ARef=[AI12-0096-1]}
1057 @Defn2{Term=[Program_Error],Sec=(raised by failure of runtime check)}
1058 @Defn2{Term=[Constraint_Error],Sec=(raised by failure of runtime check)}@Chg{Version=[3],New=[
1059 @Defn2{Term=(Assertion_Error),Sec=(raised by failure of runtime check)}],Old=[]}
1060 If an Accessibility_Check fails, Program_Error is raised.
1061 @Chg{Version=[3],New=[If a predicate check fails, @Chg{Version=[4],New=[the
1062 effect is as defined in subclause @RefSec{Subtype Predicates}],
1063 Old=[Assertions.Assertion_Error is
1064 raised]}. ],Old=[]}Any other check associated with a conversion raises
1065 Constraint_Error if it fails.
1066
1067 Conversion to a type is the same as conversion to an unconstrained
1068 subtype of the type.
1069 @begin{Reason}
1070 This definition is needed because the semantics of various
1071 constructs involves converting to a type,
1072 whereas an explicit @nt{type_conversion} actually converts to a subtype.
1073 For example, the evaluation of a @nt{range} is defined to convert the
1074 values of the expressions to the type of the range.
1075 @end{Reason}
1076 @begin{Ramification}
1077 A conversion to a scalar type, or, equivalently,
1078 to an unconstrained scalar subtype,
1079 can raise Constraint_Error if the value is outside the base range of the
1080 type.
1081 @end{Ramification}
1082
1083 @ChgRef{Version=[4],Kind=[Added],ARef=[AI12-0027-1]}
1084 @ChgRef{Version=[5],Kind=[RevisedAdded],ARef=[AI12-0226-1]}
1085 @ChgAdded{Version=[4],Type=[Leading],Text=[Evaluation of a value conversion of
1086 @Chg{Version=[5],New=[an object],Old=[a composite type]} either creates a new
1087 anonymous object@Redundant[ (similar to the
1088 object created by the evaluation of an @nt{aggregate} or a function call)] or
1089 yields a new view of the operand object without creating a new object:]}
1090
1091 @begin{Itemize}
1092 @ChgRef{Version=[4],Kind=[Added]}
1093 @ChgAdded{Version=[4],Text=[If the target type is a by-reference type and
1094 there is a type that is an ancestor of both the target type and the operand
1095 type then no new object is created;]}
1096
1097 @ChgRef{Version=[4],Kind=[Added]}
1098 @ChgAdded{Version=[4],Text=[If the target type is an array type having
1099 aliased components and the operand type is an array type having unaliased
1100 components, then a new object is created;]}
1101
1102 @ChgRef{Version=[5],Kind=[Added],ARef=[AI12-0226-1]}
1103 @ChgAdded{Version=[5],Text=[If the target type is an elementary type,
1104 then a new object is created;]}
1105
1106 @ChgRef{Version=[4],Kind=[Added]}
1107 @ChgRef{Version=[5],Kind=[RevisedAdded]}@Comment{To mark a paragraph number change}
1108 @ChgAdded{Version=[4],Text=[Otherwise, it is unspecified whether a new object
1109 is created.@PDefn{unspecified}]}
1110 @end{Itemize}
1111
1112 @ChgRef{Version=[4],Kind=[Added],ARef=[AI12-0027-1]}
1113 @ChgRef{Version=[5],Kind=[RevisedAdded]}@Comment{To mark a paragraph number change}
1114 @ChgAdded{Version=[4],Text=[If a new object is created, then the initialization
1115 of that object is an assignment operation.]}
1116
1117 @begin{Reason}
1118 @ChgRef{Version=[4],Kind=[AddedNormal]}
1119 @ChgAdded{Version=[4],Text=[This makes a difference in the case of converting
1120 from an array type with unaliased components to one with aliased components
1121 if the element type has a controlled part.]}
1122
1123 @ChgRef{Version=[5],Kind=[AddedNormal],ARef=[AI12-0226-1]}
1124 @ChgAdded{Version=[5],Text=[For an elementary type, the representation might
1125 change so we require a new object to avoid problems.]}
1126 @end{Reason}
1127
1128 @begin{ImplNote}
1129 @ChgRef{Version=[5],Kind=[AddedNormal],ARef=[AI12-0226-1]}
1130 @ChgAdded{Version=[5],Text=[The temporary object need not be materialized
1131 in most cases; it should be handled like the return object of a predefined
1132 operator. Generally, whether the object exists can only be detected if it
1133 is renamed (unless a part of the type is controlled).]}
1134 @end{ImplNote}
1135
1136 @begin{Discussion}
1137 @ChgRef{Version=[5],Kind=[AddedNormal],ARef=[AI12-0226-1]}
1138 @ChgAdded{Version=[5],Text=[This set of rules does not apply in those cases
1139 where the operand is not an object (such as a value conversion of a named
1140 number); in such cases, the result isn't an object, so it isn't necessary to
1141 describe what that means. The rules cover all value conversions of composite
1142 types (since there aren't any values of composite types separate from
1143 objects).]}
1144 @end{Discussion}
1145 @end{RunTime}
1146
1147 @begin{Notes}
1148 @RootDefn{implicit subtype conversion}
1149 In addition to explicit @nt<type_conversion>s,
1150 type conversions are performed implicitly in situations where the
1151 expected type and the actual type of a construct differ,
1152 as is permitted by the type resolution rules
1153 (see @RefSecNum(The Context of Overload Resolution)).
1154 For example, an integer literal is
1155 of the type @i(universal_integer), and is implicitly converted
1156 when assigned to a target of some specific integer type.
1157 Similarly, an actual parameter of a specific
1158 tagged type is implicitly converted when the corresponding
1159 formal parameter is of a class-wide type.
1160
1161 @NoPrefix@;@RootDefn{implicit subtype conversion}
1162 @Defn2{Term=[Constraint_Error],Sec=(raised by failure of runtime check)}
1163 Even when the expected and actual types are the same,
1164 implicit subtype conversions are performed to adjust the array bounds (if any)
1165 of an operand to match the desired target subtype, or to
1166 raise Constraint_Error if the (possibly adjusted) value does not satisfy
1167 the constraints of the target subtype.
1168
1169 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00230-01]}
1170 A ramification of the
1171 overload resolution rules is that the operand of
1172 an (explicit) @nt<type_conversion> cannot be
1173 @Chg{Version=[2],New=[],Old=[the literal @key(null), ]}an @nt<allocator>,
1174 an @nt<aggregate>, a @nt<string_literal>,
1175 a @nt<character_literal>, or an @nt<attribute_reference>
1176 for an Access or Unchecked_Access attribute.
1177 Similarly, such an @nt{expression} enclosed by parentheses is not
1178 allowed. A @nt<qualified_expression> (see @RefSecNum(Qualified Expressions))
1179 can be used instead of such a @nt<type_conversion>.
1180
1181 The constraint of the target subtype has no effect
1182 for a @nt<type_conversion> of an elementary type passed
1183 as an @key(out) parameter. Hence, it is recommended
1184 that the first subtype be specified
1185 as the target to minimize confusion
1186 (a similar recommendation applies to renaming and
1187 generic formal @key(in out) objects).
1188 @end{Notes}
1189
1190 @begin{Examples}
1191 @Leading@keepnext@i(Examples of numeric type conversion:)
1192 @begin{Example}
1193 Real(2*J) @RI[-- value is converted to floating point]
1194 Integer(1.6) @RI[-- value is 2]
1195 Integer(-0.4) @RI[-- value is 0]
1196 @end{Example}
1197
1198 @begin{WideAbove}
1199 @leading@keepnext@i(Example of conversion between derived types:)
1200 @end{WideAbove}
1201 @begin{Example}
1202 @key(type) A_Form @key(is) @key(new) B_Form;
1203
1204 X : A_Form;
1205 Y : B_Form;
1206
1207 X := A_Form(Y);
1208 Y := B_Form(X); @RI[-- the reverse conversion ]
1209 @end{Example}
1210
1211 @begin{WideAbove}
1212 @leading@keepnext@i(Examples of conversions between array types:)
1213 @end{WideAbove}
1214
1215 @begin{Example}
1216 @key(type) Sequence @key(is) @key(array) (Integer @key(range) <>) @key(of) Integer;
1217 @key(subtype) Dozen @key(is) Sequence(1 .. 12);
1218 Ledger : @key(array)(1 .. 100) @key(of) Integer;
1219
1220 Sequence(Ledger) @RI[-- bounds are those of Ledger]
1221 Sequence(Ledger(31 .. 42)) @RI[-- bounds are 31 and 42]
1222 Dozen(Ledger(31 .. 42)) @RI[-- bounds are those of Dozen ]
1223 @end{Example}
1224 @end{Examples}
1225
1226 @begin{Incompatible83}
1227 @Defn{incompatibilities with Ada 83}
1228 A @nt<character_literal> is not allowed as the
1229 operand of a @nt<type_conversion>,
1230 since there are now two character types in package Standard.
1231
1232 The component subtypes have to statically match in an array conversion,
1233 rather than being checked for matching constraints at run time.
1234
1235 Because sliding of array bounds is now provided for operations where it
1236 was not in Ada 83,
1237 programs that used to raise Constraint_Error might now
1238 continue executing and produce a reasonable result.
1239 This is likely to fix more bugs than it creates.
1240 @end{Incompatible83}
1241
1242 @begin{Extend83}
1243 @Defn{extensions to Ada 83}
1244 A @nt<type_conversion> is considered the name of an object
1245 in certain circumstances (such a @nt<type_conversion>
1246 is called a view conversion).
1247 In particular, as in Ada 83,
1248 a @nt<type_conversion> can appear as an @key(in out) or @key(out)
1249 actual parameter. In addition, if the target type is tagged
1250 and the operand is the @nt<name> of an object, then so
1251 is the @nt<type_conversion>, and it can be used as the @nt<prefix>
1252 to a @nt<selected_component>, in an @nt<object_renaming_declaration>, etc.
1253
1254 We no longer require type-mark conformance between
1255 a parameter of the form of a type conversion, and the corresponding
1256 formal parameter. This had caused some problems for
1257 inherited subprograms (since there isn't really a type-mark
1258 for converted formals), as well as for renamings, formal subprograms,
1259 etc. See AI83-00245, AI83-00318, AI83-00547.
1260
1261 We now specify @lquotes@;deterministic@rquotes@; rounding from real to integer types
1262 when the value of the operand is exactly between two integers
1263 (rounding is away from zero in this case).
1264
1265 @lquotes@;Sliding@rquotes@; of array bounds
1266 (which is part of conversion to an array subtype)
1267 is performed in more cases in Ada 95 than in Ada 83.
1268 Sliding is not performed on
1269 the operand of a membership test,
1270 nor on the operand of a @nt{qualified_expression}.
1271 It wouldn't make sense on a membership test,
1272 and we wish to retain a connection between subtype membership
1273 and subtype qualification. In general, a subtype membership test returns
1274 True if and only if a corresponding subtype qualification
1275 succeeds without raising an exception.
1276 Other operations that take arrays perform sliding.
1277 @end{Extend83}
1278
1279 @begin{DiffWord83}
1280 We no longer explicitly list the kinds of things that are not allowed
1281 as the operand of a @nt<type_conversion>, except in a NOTE.
1282
1283 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0299-1]}
1284 The rules in this @Chg{Version=[3],New=[subclause],Old=[clause]} subsume the rules
1285 for "parameters of the form of a type conversion,"
1286 and have been generalized to cover the use of a type conversion
1287 as a @nt<name>.
1288 @end{DiffWord83}
1289
1290 @begin{Incompatible95}
1291 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00246-01]}
1292 @ChgAdded{Version=[2],Text=[@Defn{incompatibilities with Ada 95}
1293 @b[Amendment Correction:] Conversions
1294 between unrelated array types that are limited or (for view conversions)
1295 might be by-reference types are now illegal. The representations of two such
1296 arrays may differ, making the conversions impossible. We make the check here,
1297 because legality should not be based on representation properties.
1298 Such conversions are likely to be rare, anyway. There is a potential that
1299 this change would make a working program illegal (if the types have the same
1300 representation).]}
1301
1302 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00363-01]}
1303 @ChgAdded{Version=[2],Text=[If a discriminated full type has a partial view
1304 (private type) that is constrained, we do not allow conversion between
1305 access-to-unconstrained and access-to-constrained subtypes designating the
1306 type. Ada 95 allowed this conversion and the declaration of various access
1307 subtypes, requiring that the designated object be constrained and thus making
1308 details of the implementation of the private type visible to the client of
1309 the private type. See @RefSecNum{Allocators} for more on this topic.]}
1310 @end{Incompatible95}
1311
1312 @begin{Extend95}
1313 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00230-01]}
1314 @ChgAdded{Version=[2],Text=[@Defn{extensions to Ada 95}Conversion rules for
1315 @i<universal_access> were defined. These allow the use of anonymous access
1316 values in equality tests (see
1317 @RefSecNum{Relational Operators and Membership Tests}), and also allow the
1318 use of @b<null> in type conversions and other
1319 contexts that do not provide a single expected type.]}
1320
1321 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00384-01]}
1322 @ChgAdded{Version=[2],Text=[A type conversion from
1323 an access-to-discriminated and unconstrained object to an
1324 access-to-discriminated and constrained one is allowed. Ada 95 only allowed
1325 the reverse conversion, which was weird and asymmetric. Of course, a
1326 constraint check will be performed for this conversion.]}
1327 @end{Extend95}
1328
1329 @begin{DiffWord95}
1330 @ChgRef{Version=[2],Kind=[AddedNormal],Ref=[8652/0017],ARef=[AI95-00184-01]}
1331 @ChgAdded{Version=[2],Text=[@b<Corrigendum:> Wording was added to ensure that
1332 view conversions are constrained, and that a tagged view conversion has a
1333 tagged object. Both rules are needed to avoid having a way to change the
1334 discriminants of a constrained object.]}
1335
1336 @ChgRef{Version=[2],Kind=[AddedNormal],Ref=[8652/0008],ARef=[AI95-00168-01]}
1337 @ChgAdded{Version=[2],Text=[@b<Corrigendum:> Wording was added to ensure
1338 that the aliased status of array components cannot change in a view
1339 conversion. This rule was needed to avoid having a way to change the
1340 discriminants of an aliased object. This rule was repealed later, as
1341 Ada 2005 allows changing the discriminants of an aliased object.]}
1342
1343 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00231-01]}
1344 @ChgAdded{Version=[2],Text=[Wording was added to check subtypes that exclude
1345 null (see @RefSecNum{Access Types}).]}
1346
1347 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00251-01]}
1348 @ChgAdded{Version=[2],Text=[The organization of the legality rules was
1349 changed, both to make it clearer, and to eliminate an unintentional
1350 incompatibility with Ada 83. The old organization prevented type conversions
1351 between some types that were related by derivation (which Ada 83 always
1352 allowed).]}
1353
1354 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00330-01]}
1355 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0005-1]}
1356 @ChgAdded{Version=[2],Text=[Clarified that an untagged type conversion
1357 appearing as a generic actual parameter for a generic @key{in out} formal
1358 parameter is not a view conversion (and thus is illegal). This confirms
1359 the ACATS tests, so all implementations already follow this
1360 @Chg{Version=[3],New=[interpretation],Old=[intepretation]}.]}
1361
1362 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00363-01]}
1363 @ChgAdded{Version=[2],Text=[Rules added by the Corrigendum to eliminate
1364 problems with discriminants of aliased components changing were removed, as
1365 we now generally allow discriminants of aliased components to be changed.]}
1366
1367 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00392-01]}
1368 @ChgAdded{Version=[2],Text=[Accessibility checks on conversions involving
1369 types with anonymous access components were added. These components have
1370 the level of the type, and conversions can be between types at different
1371 levels, which could cause dangling access values in the absence of such
1372 checks.]}
1373 @end{DiffWord95}
1374
1375 @begin{Inconsistent2005}
1376 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0148-1]}
1377 @ChgAdded{Version=[3],Text=[@Defn{inconsistencies with Ada 2005}A
1378 stand-alone object of an anonymous access-to-object type now has dynamic
1379 accessibility. Normally, this will make programs legal that were illegal
1380 in Ada 2005. However, it is possible that a program that previously raised
1381 Program_Error now will not. It is very unlikely that an existing program
1382 intentionally depends on the exception being raised; the change is more likely
1383 to fix bugs than introduce them.]}
1384 @end{Inconsistent2005}
1385
1386 @begin{Diffword2005}
1387 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0115-1]}
1388 @ChgAdded{Version=[3],Text=[@b<Correction:> Clarified that a root numeric
1389 type is not considered a common ancestor for a conversion.]}
1390
1391 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0153-3],ARef=[AI05-0290-1]}
1392 @ChgAdded{Version=[3],Text=[Added rules so that predicate aspects (see
1393 @RefSecNum{Subtype Predicates}) are enforced on subtype conversion.]}
1394 @end{Diffword2005}
1395
1396 @begin{Inconsistent2012}
1397 @ChgRef{Version=[5],Kind=[AddedNormal],ARef=[AI12-0333-1]}
1398 @ChgAdded{Version=[5],Text=[@b<Correction:> Predicate checks are no longer
1399 made on any @key{out} parameters before a call (they're still made when the
1400 call returns). This was already true for elementary @key{out} parameters. If
1401 a program depends on a predicate check failing on an inbound @key{out}
1402 composite parameter, it will get an incorrect result. This seems
1403 quite unlikely, as programs (outside of ACATS tests) that depend on the
1404 failure of checks are very rare, and the predicate might be checking
1405 uninitialized components (making check failure unreliable).]}
1406 @end{Inconsistent2012}
1407
1408 @begin{Incompatible2012}
1409 @ChgRef{Version=[4],Kind=[AddedNormal],ARef=[AI12-0095-1]}
1410 @ChgRef{Version=[5],Kind=[Revised],ARef=[AI12-0005-1]}
1411 @ChgAdded{Version=[4],Text=[@b<Corrigendum:> Because of a rule added in
1412 @RefSecNum{Formal Private and Derived Types}, the checks for the
1413 legality of an access type conversion in a generic body were strengthened
1414 to use an @Chg{Version=[5],New=[assume-the-worst],Old=[assume the worst]}
1415 rule. This case is rather unlikely @Chg{Version=[5],New=[because],Old=[as]}
1416 a formal private or derived type with discriminants is required along with a
1417 conversion between two access types whose designated types don't statically
1418 match, and any such programs were at risk having objects disappear while
1419 valid access values still pointed at them.]}
1420 @end{Incompatible2012}
1421
1422 @begin{Diffword2012}
1423 @ChgRef{Version=[4],Kind=[AddedNormal],ARef=[AI12-0027-1]}
1424 @ChgAdded{Version=[4],Text=[@b<Corrigendum:> Moved the generic boilerplate
1425 so that it covers all @LegalityTitle in this subclause. This was always
1426 intended, but it is not expected to change anything other than conversions
1427 between unrelated arrays.]}
1428
1429 @ChgRef{Version=[4],Kind=[AddedNormal],ARef=[AI12-0027-1]}
1430 @ChgAdded{Version=[4],Text=[@b<Corrigendum:> Added a formal definition of
1431 the copy potentially created by a value conversion of a composite type,
1432 so properties like finalization and accessibility are properly defined.
1433 This model was always intended and expected (else
1434 @RefSecNum{Change of Representation} would not work), but it was not
1435 previously formally defined.]}
1436
1437 @ChgRef{Version=[4],Kind=[AddedNormal],ARef=[AI12-0071-1]}
1438 @ChgAdded{Version=[4],Text=[@b<Corrigendum:> Updated wording of
1439 type conversions to use the new term "satisfies the predicates"
1440 (see @RefSecNum{Subtype Predicates}).]}
1441
1442 @ChgRef{Version=[4],Kind=[AddedNormal],ARef=[AI12-0074-1]}
1443 @ChgAdded{Version=[4],Text=[@b<Corrigendum:> Clarified the wording
1444 describing the effect of view conversions of @key[out] parameters
1445 such that it is clear that the detailed effect is defined in
1446 @RefSecNum(Parameter Associations), not here.]}
1447
1448 @ChgRef{Version=[4],Kind=[AddedNormal],ARef=[AI12-0096-1]}
1449 @ChgAdded{Version=[4],Text=[@b<Corrigendum:> Updated wording of
1450 type conversions so that the exception raise or other effect of a failed
1451 predicate check is as defined in @RefSecNum{Subtype Predicates}; we don't
1452 want to repeat those rules here. This doesn't change the behavior for
1453 predicate checks possible in original Ada 2012, only ones using the new
1454 aspect Predicate_Failure.]}
1455
1456 @ChgRef{Version=[5],Kind=[AddedNormal],ARef=[AI12-0064-2]}
1457 @ChgAdded{Version=[5],Text=[Required Nonblocking
1458 (see @RefSecNum{Intertask Communication}) matching for
1459 access-to-subprogram conversions.]}
1460
1461 @ChgRef{Version=[5],Kind=[AddedNormal],ARef=[AI12-0226-1]}
1462 @ChgAdded{Version=[5],Text=[Described the objects associated with
1463 value conversions of elementary types. This is necessary to support
1464 an extension documented in @RefSecNum{Objects and Named Numbers}.]}
1465 @end{Diffword2012}
1466
1467
1468 @LabeledClause{Qualified Expressions}
1469
1470 @begin{Intro}
1471 @Redundant[A @nt<qualified_expression> is used to state explicitly the type,
1472 and to verify the subtype, of an operand that is either an @nt<expression>
1473 or an @nt<aggregate>.
1474 @IndexSeeAlso{Term=[type conversion],See=(qualified_expression)}]
1475 @end{Intro}
1476
1477 @begin{Syntax}
1478 @Syn{lhs=<qualified_expression>,rhs="
1479 @Syn2{subtype_mark}@SingleQuote@;(@Syn2{expression}) | @Syn2{subtype_mark}@SingleQuote@Syn2{aggregate}"}
1480 @end{Syntax}
1481
1482 @begin{Resolution}
1483 @ChgRef{Version=[5],Kind=[Revised],ARef=[AI12-0325-1]}
1484 @PDefn2{Term=[operand], Sec=(of a @nt{qualified_expression})}
1485 The @Chg{Version=[5],New=[expected type for the ],Old=[]}@i(operand) (the
1486 @nt{expression} or @nt{aggregate})
1487 @Chg{Version=[5],New=[is],Old=[shall resolve to be of the type]} determined
1488 by the @nt{subtype_@!mark}@Chg{Version=[5],New=[],Old=[,
1489 or a universal type that covers it]}.@Chg{Version=[5],New=[ Furthermore, the
1490 operand shall resolve to be either the specified expected type or a universal
1491 type that covers it.],Old=[]}
1492 @begin{Reason}
1493 @ChgRef{Version=[5],Kind=[AddedNormal],ARef=[AI12-0325-1]}
1494 @ChgAdded{Version=[5],Text=[The first sentence defines the expected type for
1495 rules that assume one is defined. The second sentence prevents the use of the
1496 various implicit conversions that are usually allowed for expected
1497 types (except the one for numeric literals). The intent is that a qualified
1498 expression is similar to an assertion about the subtype of the operand, and
1499 thus implicit conversions would interfere with that intent.]}
1500 @end{Reason}
1501 @end{Resolution}
1502
1503 @begin{StaticSem}
1504 @ChgRef{Version=[3],Kind=[Added],ARef=[AI05-0003-1]}
1505 @ChgAdded{Version=[3],Text=[@Redundant[If the operand of a @nt{qualified_expression}
1506 denotes an object, the @nt{qualified_expression} denotes a constant view
1507 of that object.] The nominal subtype of a @nt{qualified_expression}
1508 is the subtype denoted by the @nt{subtype_mark}.]}
1509 @begin{TheProof}
1510 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0003-1]}
1511 @ChgAdded{Version=[3],Text=[This is stated in @RefSecNum{Objects and Named Numbers}.]}
1512 @end{TheProof}
1513 @end{StaticSem}
1514
1515 @begin{RunTime}
1516 @ChgRef{Version=[4],Kind=[Revised],ARef=[AI12-0100-1]}
1517 @PDefn2{Term=[evaluation], Sec=(qualified_expression)}
1518 @IndexCheck{Range_Check}
1519 @IndexCheck{Discriminant_Check}
1520 @IndexCheck{Index_Check}
1521 The evaluation of a @nt{qualified_expression} evaluates the
1522 operand (and if of a universal type, converts it
1523 to the type determined by the @nt{subtype_mark})
1524 and checks that its value belongs to the subtype denoted by
1525 the @nt{subtype_mark}.
1526 @PDefn2{Term=[implicit subtype conversion],Sec=(qualified_expression)}
1527 @Defn2{Term=[Constraint_Error],Sec=(raised by failure of runtime check)}
1528 The exception Constraint_Error is raised if this check fails.@Chg{Version=[4],
1529 New=[ Furthermore, if predicate checks are enabled for the subtype
1530 denoted by the @nt{subtype_mark}, a check is performed as defined in
1531 subclause @RefSec{Subtype Predicates} that the value satifies the predicates
1532 of the subtype.],Old=[]}
1533 @begin{Ramification}
1534 This is one of the few contexts in Ada 95 where implicit subtype conversion
1535 is not performed prior to a constraint check, and hence no
1536 @lquotes@;sliding@rquotes@; of array bounds is provided.
1537
1538 @ChgRef{Version=[4],Kind=[Added],ARef=[AI12-0100-1]}
1539 @ChgAdded{Version=[4],Text=[The effect of a failed predicate check
1540 is as defined in @RefSecNum{Subtype Predicates}; such a check could raise
1541 any exception, not just Constraint_Error or Assertion_Error.]}
1542 @end{Ramification}
1543 @begin{Reason}
1544 Implicit subtype conversion is not provided because a
1545 @nt<qualified_expression> with a constrained target subtype is
1546 essentially an assertion about the subtype of the operand, rather
1547 than a request for conversion. An explicit @nt<type_conversion> can
1548 be used rather than a @nt<qualified_expression> if subtype
1549 conversion is desired.
1550
1551 @ChgRef{Version=[4],Kind=[AddedNormal],ARef=[AI12-0100-1]}
1552 @ChgAdded{Version=[4],Text=[We do a predicate check here so that
1553 a @nt{qualified_expression} never allows something that the equivalent
1554 @nt{type_conversion} would not allow.]}
1555 @end{Reason}
1556 @end{RunTime}
1557
1558 @begin{Notes}
1559 When a given context does not uniquely identify an expected type,
1560 a @nt<qualified_expression> can be used to do so.
1561 In particular, if an overloaded @nt<name> or
1562 @nt<aggregate> is passed to an overloaded subprogram, it
1563 might be necessary to qualify the operand to resolve its type.
1564 @end{Notes}
1565
1566 @begin{Examples}
1567 @Leading@keepnext@i(Examples of disambiguating expressions using qualification:)
1568 @begin{Example}
1569 @key(type) Mask @key(is) (Fix, Dec, Exp, Signif);
1570 @key(type) Code @key(is) (Fix, Cla, Dec, Tnz, Sub);
1571
1572 Print (Mask'(Dec)); @RI[-- Dec is of type Mask]
1573 Print (Code'(Dec)); @RI[-- Dec is of type Code ]
1574
1575 @key(for) J @key(in) Code'(Fix) .. Code'(Dec) @key(loop) ... @RI[-- qualification needed for either Fix or Dec]
1576 @key(for) J @key(in) Code @key(range) Fix .. Dec @key(loop) ... @RI[-- qualification unnecessary]
1577 @key(for) J @key(in) Code'(Fix) .. Dec @key(loop) ... @RI[-- qualification unnecessary for Dec]
1578
1579 Dozen'(1 | 3 | 5 | 7 => 2, @key(others) => 0) @RI[-- see @RefSecNum{Type Conversions} ]
1580 @end{Example}
1581 @end{Examples}
1582
1583 @begin{DiffWord2005}
1584 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0003-1]}
1585 @ChgAdded{Version=[3],Text=[Added a definition of
1586 the nominal subtype of a @nt{qualified_expression}.]}
1587 @end{DiffWord2005}
1588
1589 @begin{Inconsistent2012}
1590 @ChgRef{Version=[4],Kind=[AddedNormal],ARef=[AI12-0100-1]}
1591 @ChgAdded{Version=[4],Text=[@Defn{inconsistencies with Ada 2012}@b<Corrigendum:>
1592 A @nt{qualified_expression} now performs a predicate check for the named
1593 subtype (if it is enabled). Original Ada 2012 did not include that check
1594 (an omission). While this is formally inconsistent (an exception could
1595 be raised when none would be raised by original Ada 2012), cases when this
1596 could be the case are likely to be rare (the qualified expression would have
1597 to have a stricter subtype than the following usage) and the check is more
1598 likely to detect bugs than be unexpected.]}
1599 @end{Inconsistent2012}
1600
1601 @begin{DiffWord2012}
1602 @ChgRef{Version=[5],Kind=[AddedNormal],ARef=[AI12-0325-1]}
1603 @ChgAdded{Version=[5],Text=[Reworded the resolution rule so that the
1604 operand of a @nt{qualified_expression} has an expected type. This eliminates
1605 an annoying inconsistency in the language definition.]}
1606 @end{DiffWord2012}
1607
1608
1609 @LabeledClause{Allocators}
1610
1611 @begin{Intro}
1612 @Redundant[The evaluation of an @nt<allocator> creates an object and yields
1613 an access value that designates the object.
1614 @IndexSee{Term=[new],See=(allocator)}
1615 @IndexSee{Term=[malloc],See=(allocator)}
1616 @IndexSeeAlso{Term=[heap management],See=(allocator)}]
1617 @end{Intro}
1618
1619 @begin{Syntax}
1620 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0111-3]}
1621 @Syn{lhs=<allocator>,rhs="
1622 @key{new} @Chg{Version=[3],New=<[@Syn2{subpool_specification}] >,Old=<>}@Syn2{subtype_indication}@Chg{Version=[3],New=<
1623 >,Old=<>} | @key{new} @Chg{Version=[3],New=<[@Syn2{subpool_specification}] >,Old=<>}@Syn2{qualified_expression}"}
1624
1625 @ChgRef{Version=[3],Kind=[Added],ARef=[AI05-0111-3]}
1626 @AddedSyn{Version=[3],lhs=<@Chg{Version=[3],New=<subpool_specification>,Old=<>}>,
1627 rhs="@Chg{Version=[3],New=<(@SynI{subpool_handle_}@Syn2{name})>,Old=<>}"}
1628
1629 @begin{SyntaxText}
1630 @ChgRef{Version=[3],Kind=[Added],ARef=[AI05-0104-1]}
1631 @ChgAdded{Version=[3],Text=[For an @nt{allocator} with a @nt{subtype_indication},
1632 the @nt{subtype_indication} shall not specify a @nt{null_exclusion}.]}
1633
1634 @begin{Reason}
1635 @ChgRef{Version=[3],Kind=[AddedNormal]}
1636 @ChgAdded{Version=[3],Text=[Such an uninitialized @nt{allocator} would
1637 necessarily raise Constraint_Error, as the default value is @key[null].
1638 Also note that the syntax does not allow a @nt{null_exclusion} in
1639 an initialized @nt{allocator}, so it makes sense to make the
1640 uninitialized case illegal as well.]}
1641 @end{Reason}
1642 @end{SyntaxText}
1643 @end{Syntax}
1644
1645 @begin{Resolution}
1646 @ChgRef{Version=[1],Kind=[Revised],Ref=[8652/0010],ARef=[AI95-00127-01]}
1647 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0111-3],ARef=[AI05-0269-1]}
1648 @PDefn2{Term=[expected type],Sec=(allocator)}
1649 The expected type for an @nt<allocator> shall be a single access-to-object
1650 type @Chg{New=[with],Old=[whose]} designated type
1651 @Chg{New=[@i<D> such that either @i<D>],Old=[]} covers the type determined
1652 by the @nt<subtype_mark> of the @nt<subtype_@!indication> or
1653 @nt<qualified_@!expression>@Chg{New=[, or the expected type is anonymous and
1654 the determined type is @i<D>'Class],Old=[]}.@Chg{Version=[3],New=[
1655 A @SynI{subpool_handle_}@nt{name} is expected to be of any type descended from
1656 Subpool_Handle, which is the type used to identify a subpool, declared
1657 in package System.Storage_Pools.Subpools
1658 (see @RefSecNum{Storage Subpools}).@PDefn2{Term=[expected type],Sec=(subpool_handle_name)}],Old=[]}
1659 @begin{Discussion}
1660 See @RefSec(The Context of Overload Resolution) for the meaning
1661 of @lquotes@;shall be a single ... type whose ...@rquotes@;
1662 @end{Discussion}
1663 @begin{Ramification}
1664 @ChgRef{Version=[1],Kind=[Added],Ref=[8652/0010],ARef=[AI95-00127-01]}
1665 @Chg{New=[An @nt{allocator} is allowed as a controlling parameter of a dispatching
1666 call (see @RefSecNum{Dispatching Operations of Tagged Types}).],Old=[]}
1667 @end{Ramification}
1668 @end{Resolution}
1669
1670 @begin{Legality}
1671 @Defn{initialized allocator}
1672 An @i(initialized) allocator is an @nt{allocator}
1673 with a @nt{qualified_expression}.
1674 @Defn{uninitialized allocator}
1675 An @i(uninitialized) allocator is one with
1676 a @nt{subtype_indication}.
1677 In the @nt<subtype_indication> of an uninitialized allocator, a
1678 @nt<constraint> is permitted only if the @nt<subtype_mark> denotes an
1679 @Redundant[unconstrained] composite subtype;
1680 if there is no @nt<constraint>, then the @nt<subtype_mark>
1681 shall denote a definite subtype.
1682 @IndexSee{Term=[constructor],See=[initialized allocator]}
1683 @begin{Ramification}
1684 For example, ... @key[new] S'Class ... (with no initialization
1685 expression) is illegal,
1686 but ... @key[new] S'Class'(X) ... is legal,
1687 and takes its tag and constraints from the initial value X.
1688 (Note that the former case cannot have a constraint.)
1689 @end{Ramification}
1690
1691 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00287-01]}
1692 If the type of the @nt<allocator> is an access-to-constant type,
1693 the @nt<allocator> shall be an initialized allocator.
1694 @Chg{Version=[2],New=[],Old=[If the designated type is limited,
1695 the @nt<allocator> shall be an uninitialized allocator.]}
1696 @begin{Ramification}
1697 @ChgRef{Version=[2],Kind=[Deleted],ARef=[AI95-00287-01]}
1698 @ChgDeleted{Version=[2],Text=[For an access-to-constant type whose designated
1699 type is limited, @nt{allocator}s are illegal.
1700 The Access attribute is legal for such a type, however.]}
1701 @end{Ramification}
1702
1703 @ChgRef{Version=[3],Kind=[Added],ARef=[AI05-0111-3]}
1704 @ChgAdded{Version=[3],Text=[If a @nt{subpool_specification} is given,
1705 the type of the storage pool of the access type shall be a descendant
1706 of Root_Storage_Pool_With_Subpools.]}
1707
1708 @ChgRef{Version=[2],Kind=[Added],ARef=[AI95-00344-01]}
1709 @ChgRef{Version=[3],Kind=[RevisedAdded]}@ChgNote{Because the paragraph numbers changed}
1710 @ChgAdded{Version=[2],Text=[If the designated type of the type of the
1711 @nt{allocator} is class-wide, the accessibility level of the type determined by the
1712 @nt{subtype_indication} or @nt{qualified_expression} shall not be statically
1713 deeper than that of the type of the @nt{allocator}.]}
1714 @begin{Reason}
1715 @ChgRef{Version=[2],Kind=[AddedNormal]}
1716 @ChgAdded{Version=[2],Text=[This prevents the allocated object from outliving
1717 its type.]}
1718 @end{Reason}
1719
1720 @ChgRef{Version=[2],Kind=[Added],ARef=[AI95-00416-01]}
1721 @ChgRef{Version=[3],Kind=[RevisedAdded],ARef=[AI05-0051-1]}
1722 @ChgAdded{Version=[2],Text=[If the @Chg{Version=[3],New=[subtype determined
1723 by the @nt{subtype_indication} or @nt{qualified_expression}],Old=[designated
1724 subtype of the type]} of the @nt{allocator} has one or more
1725 @Chg{Version=[3],New=[],Old=[unconstrained ]}access discriminants, then the
1726 accessibility level of the anonymous access type of each access
1727 discriminant@Chg{Version=[3],New=[],Old=[,
1728 as determined by the @nt{subtype_indication} or @nt{qualified_expression} of
1729 the @nt{allocator},]} shall not be statically deeper than that of the type
1730 of the @nt{allocator} (see @RefSecNum{Operations of Access Types}).]}
1731 @begin{Reason}
1732 @ChgRef{Version=[2],Kind=[AddedNormal]}
1733 @ChgAdded{Version=[2],Text=[This prevents the allocated object from outliving
1734 its discriminants.]}
1735 @end{Reason}
1736
1737 @ChgRef{Version=[2],Kind=[Added],ARef=[AI95-00366-01]}
1738 @ChgRef{Version=[3],Kind=[RevisedAdded],ARef=[AI05-0052-1],ARef=[AI05-0157-1]}
1739 @ChgAdded{Version=[2],Text=[An @nt{allocator} shall not be of an access type
1740 for which the Storage_Size has been specified by a static expression with value
1741 zero or is defined by the language to be zero. @Chg{Version=[3],New=[],
1742 Old=[@PDefn{generic contract issue}In addition to the places
1743 where @LegalityTitle normally apply
1744 (see @RefSecNum{Generic Instantiation}), this rule applies also in the private
1745 part of an instance of a generic unit. This rule does not apply in the body of
1746 a generic unit or within a body declared within the declarative region of a
1747 generic unit, if the type of the allocator is a descendant of a formal access
1748 type declared within the formal part of the generic unit.]}]}
1749
1750 @begin{Reason}
1751 @ChgRef{Version=[2],Kind=[AddedNormal]}
1752 @ChgAdded{Version=[2],Text=[An @nt{allocator} for an access type that has
1753 Storage_Size specified to be zero is required to raise Storage_Error anyway.
1754 It's better to detect the error at compile-time, as the @nt{allocator}
1755 might be executed infrequently. This also simplifies the rules for Pure
1756 units, where we do not want to allow any allocators for library-level access
1757 types, as they would represent state.]}
1758
1759 @ChgRef{Version=[2],Kind=[AddedNormal]}
1760 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0157-1]}
1761 @ChgAdded{Version=[2],Text=[@Chg{Version=[3],New=[We don't need a special
1762 rule to cover generic formals (unlike many other similar @LegalityTitle).
1763 There are only two cases of interest. For formal access types, the
1764 Storage_Size property is not known in the generic, and surely isn't
1765 static, so this @LegalityName can never apply. For a formal derived type,
1766 this @LegalityName can only be triggered by a parent type having one of
1767 the appropriate properties. But Storage_Size can never be specified for
1768 a derived access type, so it always has the same value for all child types;
1769 additionally, a type derived from a remote access type (which has Storage_Size
1770 defined to be zero) is also a remote access type. That means that any actual
1771 that would match the formal derived type necessarily has the same
1772 Storage_Size properties, so it is harmless (and preferable) to check them
1773 in the body - they are always known in that case.
1774 For other formal types,@nt{allocator}s are not allowed, so we don't need
1775 to consider them. So we don't need an assume-the-best rule
1776 here.],Old=[The last sentence covers the case of children of
1777 generics, and formal access types of formal packages of the generic unit.]}]}
1778 @end{Reason}
1779
1780 @ChgRef{Version=[3],Kind=[Added],ARef=[AI05-0052-1]}
1781 @ChgAdded{Version=[3],Text=[If the designated type of the type of the
1782 @nt{allocator} is limited, then
1783 the @nt{allocator} shall not be used to define the value of an access
1784 discriminant, unless the discriminated type is immutably limited
1785 (see @RefSecNum{Limited Types}).]}
1786
1787 @begin{Reason}
1788 @ChgRef{Version=[3],Kind=[AddedNormal]}
1789 @ChgAdded{Version=[3],Text=[Because coextensions work very much like parts,
1790 we don't want users creating limited coextensions for nonlimited types. This
1791 would be similar to extending a nonlimited type with a limited component. We
1792 check this on the @nt{allocator}. Note that there is an asymmetry in what
1793 types are considered limited; this is required to preserve privacy. We have
1794 to assume that the designated type might be limited as soon as we see a
1795 limited partial view, but we want to ensure that the containing object is of
1796 a type that is always limited.]}
1797 @end{Reason}
1798
1799 @ChgRef{Version=[3],Kind=[Added],ARef=[AI05-0052-1]}
1800 @ChgAdded{Version=[3],Text=[@PDefn{generic contract issue}In addition to
1801 the places where @LegalityTitle normally apply
1802 (see @RefSecNum{Generic Instantiation}), these rules apply also in the private
1803 part of an instance of a generic unit.]}
1804 @begin{Discussion}
1805 @ChgRef{Version=[3],Kind=[AddedNormal]}
1806 @ChgAdded{Version=[3],Text=[This applies to all of the @LegalityTitle
1807 of this subclause.]}
1808 @end{Discussion}
1809 @end{Legality}
1810
1811 @begin{StaticSem}
1812 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00363-01]}
1813 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0041-1]}
1814 If the designated type of the type of the @nt<allocator> is elementary,
1815 then the subtype of the created object is the designated
1816 subtype.
1817 If the designated type is composite, then the
1818 @Chg{Version=[2],New=[subtype of the ],Old=[]}created object is
1819 @Chg{Version=[2],New=[the designated
1820 subtype when the designated subtype is constrained or there is
1821 @Chg{Version=[3],New=[an ancestor of the designated type that
1822 has a constrained],Old=[a]} partial
1823 view@Chg{Version=[3],New=[],Old=[ of the designated type that is constrained]};
1824 otherwise, the created],Old=[always constrained;
1825 if the designated subtype is constrained,
1826 then it provides the constraint of the created object;
1827 otherwise, the]} object is constrained by its initial value
1828 @Redundant[(even if the designated subtype is unconstrained with defaults)].
1829 @PDefn{constrained by its initial value}
1830 @begin{Discussion}
1831 See AI83-00331.
1832 @end{Discussion}
1833 @begin{Reason}
1834 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00363-01]}
1835 All objects created by an @Chg{Version=[2],New=[@nt{allocator}],Old=[allocator]}
1836 are aliased,
1837 and @Chg{Version=[2],New=[most],Old=[all]} aliased composite objects
1838 need to be constrained so that access subtypes work reasonably.
1839 @Chg{Version=[2],New=[Problematic access subtypes are prohibited for
1840 types with a constrained partial view.],Old=[]}
1841 @end{Reason}
1842 @begin{Discussion}
1843 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00363-01]}
1844 @ChgAdded{Version=[2],Text=[If there is a constrained partial view of the type, this
1845 allows the objects to be unconstrained. This eliminates privacy breaking
1846 (we don't want the objects to act differently simply because they're
1847 allocated). Such a created object is effectively constrained by its initial
1848 value if the access type is an access-to-constant type, or the designated
1849 type is limited (in all views), but we don't need to state that here. It is
1850 implicit in other rules. Note, however, that a value of an
1851 access-to-constant type can designate a variable object via 'Access or
1852 conversion, and the variable object might be assigned by some other access
1853 path, and that assignment might alter the discriminants.]}
1854 @end{Discussion}
1855 @end{StaticSem}
1856
1857 @begin{RunTime}
1858 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00373-01]}
1859 @PDefn2{Term=[evaluation], Sec=(allocator)}
1860 For the evaluation of an @Chg{Version=[2],New=[initialized allocator],
1861 Old=[@nt<allocator>]}, the @Chg{Version=[2],New=[],Old=[elaboration of
1862 the @nt<subtype_indication> or the ]}evaluation of the
1863 @nt<qualified_expression> is performed first.
1864 @PDefn2{Term=[evaluation], Sec=(initialized allocator)}
1865 @Defn2{Term=[assignment operation], Sec=(during evaluation of an
1866 initialized allocator)}
1867 @Chg{Version=[2],New=[An],Old=[For the evaluation of an initialized allocator,
1868 an]} object of the designated type is created and the value of the
1869 @nt<qualified_expression> is converted to the designated subtype
1870 and assigned to the object.
1871 @PDefn2{Term=[implicit subtype conversion],Sec=(initialization expression of allocator)}
1872 @begin{Ramification}
1873 The conversion might raise Constraint_Error.
1874 @end{Ramification}
1875
1876 @PDefn2{Term=[evaluation], Sec=(uninitialized allocator)}
1877 @Leading@keepnext@;@ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00373-01]}
1878 For the evaluation of an uninitialized allocator@Chg{Version=[2],New=[, the
1879 elaboration of the @nt{subtype_indication} is performed first. Then],Old=[]}:
1880 @begin(itemize)
1881 @Defn2{Term=[assignment operation], Sec=(during evaluation of an
1882 uninitialized allocator)}
1883 If the designated type is elementary, an object of the
1884 designated subtype is created and any implicit initial value is assigned;
1885
1886 @ChgRef{Version=[1],Kind=[Revised],Ref=[8652/0002],ARef=[AI95-00171-01]}
1887 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00373-01]}
1888 @Chg{Version=[2],New=[],Old=[@Defn2{Term=[assignment operation],
1889 Sec=(during evaluation of an uninitialized allocator)}]}
1890 If the designated type is composite, an object of the
1891 designated type is created with tag, if any, determined
1892 by the @nt<subtype_mark> of the @nt<subtype_indication>@Chg{Version=[2],New=[.
1893 This object is then initialized by default (see
1894 @RefSecNum{Object Declarations}) using],Old=[;
1895 any per-object constraints on subcomponents are elaborated
1896 @Chg{New=[(see @RefSecNum{Record Types}) ],Old=[]}and any implicit initial
1897 values for the subcomponents of the object are obtained as determined by]}
1898 the @nt<subtype_indication>
1899 @Chg{Version=[2],New=[to determine its nominal subtype],
1900 Old=[and assigned to the corresponding subcomponents]}.
1901 @IndexCheck{Index_Check}
1902 @IndexCheck{Discriminant_Check}
1903 A check is made that the value of the object belongs to the designated
1904 subtype.
1905 @Defn2{Term=[Constraint_Error],Sec=(raised by failure of runtime check)}
1906 Constraint_Error is raised if this check fails.
1907 This check and the initialization of the object are performed in
1908 an arbitrary order.@PDefn2{Term=[arbitrary order],Sec=[allowed]}
1909
1910 @begin{Discussion}
1911 AI83-00150.
1912 @end{Discussion}
1913 @end(itemize)
1914
1915 @ChgRef{Version=[2],Kind=[Added],ARef=[AI95-00344-01],ARef=[AI95-00416-01]}
1916 @ChgRef{Version=[3],Kind=[RevisedAdded],ARef=[AI05-0024-1],ARef=[AI05-0051-1],ARef=[AI05-0234-1]}
1917 @ChgAdded{Version=[2],Text=[For any @nt{allocator}, if the designated type of
1918 the type of the @nt{allocator}
1919 is class-wide, then a check is made that the @Chg{Version=[3],New=[master],
1920 Old=[accessibility level]} of the type
1921 determined by the @nt{subtype_indication}, or by the tag of the value of the
1922 @nt{qualified_expression}, @Chg{Version=[3],New=[includes the elaboration],
1923 Old=[is not deeper than that]} of the type of the @nt{allocator}. If
1924 @Chg{Version=[3],New=[any part of ],Old=[]}the
1925 @Chg{Version=[3],New=[subtype determined by the @nt{subtype_indication} or
1926 @nt{qualified_expression}],Old=[designated subtype]} of the @nt{allocator}
1927 @Chg{Version=[3],New=[(or by the tag of the value if the type of the
1928 @nt{qualified_expression} is class-wide) ],Old=[]}has
1929 one or more @Chg{Version=[3],New=[],Old=[unconstrained ]}access
1930 discriminants, then a check is made that the accessibility
1931 level of the anonymous access type of each access discriminant is
1932 not deeper than that of the type of the @nt{allocator}.
1933 Program_Error is raised
1934 if either such check fails.@IndexCheck{Accessibility_Check}
1935 @Defn2{Term=[Program_Error],Sec=(raised by failure of runtime check)}]}
1936 @begin{Reason}
1937 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00344-01]}
1938 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0024-1]}
1939 @ChgAdded{Version=[2],Text=[The
1940 @Chg{Version=[3],New=[master],Old=[accessibility]} check on class-wide types
1941 prevents the allocated object from outliving its type. We need the run-time
1942 check in instance bodies, or when the type of the @nt{qualified_expression}
1943 is class-wide (other cases are statically detected).]}
1944
1945 @ChgRef{Version=[3],Kind=[Added],ARef=[AI05-0024-1]}
1946 @ChgAdded{Version=[3],Type=[Leading],Text=[We can't use the normal
1947 accessibility level @lquotes@;deeper than@rquotes@; check
1948 here because we may have @lquotes@;incomparable@rquotes@; levels if
1949 the appropriate master and the type declaration belong to two different
1950 tasks. This can happen when
1951 checking the master of the tag for an allocator initialized by
1952 a parameter passed in to an accept statement, if the type of the allocator
1953 is an access type declared in the enclosing task body. For example:]}
1954
1955 @begin{Example}
1956 @ChgRef{Version=[3],Kind=[Added]}
1957 @ChgAdded{Version=[3],Text=[@key[task body] TT @key[is]
1958 @key[type] Acc_TC @key[is access] T'Class;
1959 P : Acc_TC;
1960 @key[begin]
1961 @key[accept] E(X : T'Class) @key[do]
1962 P := @key[new] T'Class'(X);
1963 @RI[-- Master check on tag of X.]
1964 @RI[-- Can't use "accessibility levels" since they might be incomparable.]
1965 @RI[-- Must revert to checking that the master of the type identified by]
1966 @RI[-- X'tag includes the elaboration of Acc_TC, so it is sure to outlive it.]
1967 @key[end] E;]}
1968 @end{Example}
1969
1970 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00416-01]}
1971 @ChgAdded{Version=[2],Text=[The accessibility check on access discriminants
1972 prevents the allocated object from outliving its discriminants.]}
1973
1974 @end{Reason}
1975
1976 @ChgRef{Version=[2],Kind=[Added],ARef=[AI95-00280-01]}
1977 @Chg{Version=[2],New=[If the object to be created by an @nt<allocator> has a
1978 controlled or protected part, and the finalization of the collection of the
1979 type of the @nt{allocator} (see @RefSecNum{Completion and Finalization}) has
1980 started, Program_Error is raised.@IndexCheck{Allocation_Check}
1981 @Defn2{Term=[Program_Error],Sec=(raised by failure of runtime check)}],Old=[]}
1982 @begin{Reason}
1983 @ChgRef{Version=[2],Kind=[AddedNormal]}
1984 @ChgAdded{Version=[2],Text=[If the object has a controlled or protected part, its
1985 finalization is likely to be nontrivial. If the allocation was allowed,
1986 we could not know whether the finalization would actually be performed.
1987 That would be dangerous to otherwise safe abstractions, so we mandate
1988 a check here. On the other hand, if the finalization of the object will
1989 be trivial, we do not require (but allow) the check, as no real harm
1990 could come from late allocation.]}
1991 @end{Reason}
1992 @begin{Discussion}
1993 @ChgRef{Version=[2],Kind=[AddedNormal]}
1994 @ChgAdded{Version=[2],Text=[This check can only fail if an @nt{allocator}
1995 is evaluated in code reached from a Finalize routine for a type declared
1996 in the same master. That's highly unlikely; Finalize routines are much
1997 more likely to be deallocating objects than allocating them.]}
1998 @end{Discussion}
1999
2000 @ChgRef{Version=[2],Kind=[Added],ARef=[AI95-00280-01]}
2001 @Chg{Version=[2],New=[If the object to be created by an @nt<allocator>
2002 contains any tasks, and the master of the type of the @nt<allocator> is
2003 completed, and all of the dependent tasks of the master are terminated
2004 (see @RefSecNum{Task Dependence - Termination of Tasks}), then
2005 Program_Error is raised.@IndexCheck{Allocation_Check}
2006 @Defn2{Term=[Program_Error],Sec=(raised by failure of runtime check)}],Old=[]}
2007 @begin{Reason}
2008 @ChgRef{Version=[2],Kind=[AddedNormal]}
2009 @ChgAdded{Version=[2],Text=[A task created after waiting for tasks has
2010 finished could depend on freed data structures, and certainly would never
2011 be awaited.]}
2012 @end{Reason}
2013
2014 @ChgRef{Version=[3],Kind=[Added],ARef=[AI05-0111-3]}
2015 @ChgAdded{Version=[3],Text=[If the @nt{allocator} includes a
2016 @SynI{subpool_handle_}@nt{name}, Constraint_Error is raised if the subpool
2017 handle is @key[null]. Program_Error is raised if the subpool does not @i<belong>
2018 (see @RefSecNum{Storage Subpools}) to the storage pool of the access type of the
2019 @nt{allocator}.@IndexCheck{Access_Check}@IndexCheck{Allocation_Check}
2020 @Defn2{Term=[Constraint_Error],Sec=(raised by failure of runtime check)}
2021 @Defn2{Term=[Program_Error],Sec=(raised by failure of runtime check)}]}
2022
2023 @begin{ImplNote}
2024 @ChgRef{Version=[3],Kind=[AddedNormal]}
2025 @ChgAdded{Version=[3],Text=[This can be implemented by comparing the result of
2026 Pool_of_Subpool to a reference to the storage pool object. Pool_of_Subpool's
2027 parameter is @key[not null], so the check for null falls out naturally.]}
2028 @end{ImplNote}
2029
2030 @begin{Reason}
2031 @ChgRef{Version=[3],Kind=[AddedNormal]}
2032 @ChgAdded{Version=[3],Text=[This detects cases where the subpool belongs to
2033 another pool, or to no pool at all. This includes detecting dangling subpool
2034 handles so long as the subpool object (the object designated by the handle)
2035 still exists. (If the subpool object has been deallocated, execution is
2036 erroneous; it is likely that this check will still detect the problem, but
2037 there cannot be a guarantee.)]}
2038 @end{Reason}
2039
2040 @Redundant[If the created object contains any tasks,
2041 they are activated
2042 (see @RefSecNum(Task Execution - Task Activation)).]
2043 Finally, an access value that designates the created object is returned.
2044 @end{RunTime}
2045
2046 @begin{Bounded}
2047 @ChgRef{Version=[2],Kind=[Added],ARef=[AI95-00280-01]}
2048 @ChgAdded{Version=[2],Text=[@PDefn2{Term=(bounded error),Sec=(cause)} It is a
2049 bounded error if the finalization of the collection of the type (see
2050 @RefSecNum{Completion and Finalization}) of the @nt<allocator> has started. If
2051 the error is detected, Program_Error is raised. Otherwise, the allocation
2052 proceeds normally.@Defn2{Term=[Program_Error],Sec=(raised by detection of a bounded error)}]}
2053 @begin{Discussion}
2054 @ChgRef{Version=[2],Kind=[AddedNormal]}
2055 @ChgAdded{Version=[2],Text=[This check is required in some cases; see above.]}
2056 @end{Discussion}
2057 @end{Bounded}
2058
2059 @begin{Notes}
2060 Allocators cannot create objects of an abstract type.
2061 See @RefSecNum{Abstract Types and Subprograms}.
2062
2063 If any part of the created object is controlled, the initialization
2064 includes calls on corresponding Initialize or Adjust procedures.
2065 See @RefSecNum{Assignment and Finalization}.
2066
2067 As explained in @RefSec{Storage Management},
2068 the storage for an object allocated by an @nt{allocator} comes from a
2069 storage pool (possibly user defined).
2070 The exception Storage_Error is raised by an @nt<allocator> if there
2071 is not enough storage.
2072 Instances of Unchecked_Deallocation may be used to explicitly reclaim
2073 storage.
2074
2075 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0229-1]}
2076 Implementations are permitted, but not required,
2077 to provide garbage collection@Chg{Version=[3],New=[],Old=[
2078 (see @RefSecNum{Default Storage Pools})]}.
2079 @begin{Ramification}
2080 Note that in an @nt<allocator>,
2081 the exception Constraint_Error can be
2082 raised by the evaluation of the @nt<qualified_expression>,
2083 by the elaboration of the @nt<subtype_indication>, or by the
2084 initialization.
2085 @end{Ramification}
2086 @begin{Discussion}
2087 By default, the implementation provides the storage pool.
2088 The user may exercise more control over storage management by
2089 associating a user-defined pool with an access type.
2090 @end{Discussion}
2091 @end{Notes}
2092
2093 @begin{Examples}
2094 @Leading@keepnext@i{Examples of allocators:}
2095 @begin{Example}
2096 @key(new) Cell'(0, @key(null), @key(null)) @RI[-- initialized explicitly, see @RefSecNum{Incomplete Type Declarations}]
2097 @key(new) Cell'(Value => 0, Succ => @key(null), Pred => @key(null)) @RI[-- initialized explicitly]
2098 @key(new) Cell @RI[-- not initialized]
2099
2100 @key(new) Matrix(1 .. 10, 1 .. 20) @RI[-- the bounds only are given]
2101 @key(new) Matrix'(1 .. 10 => (1 .. 20 => 0.0)) @RI[-- initialized explicitly]
2102
2103 @key(new) Buffer(100) @RI[-- the discriminant only is given]
2104 @key(new) Buffer'(Size => 80, Pos => 0, Value => (1 .. 80 => 'A')) @RI[-- initialized explicitly]
2105
2106 Expr_Ptr'(@key(new) Literal) @RI[-- allocator for access-to-class-wide type, see @RefSecNum{Type Extensions}]
2107 Expr_Ptr'(@key(new) Literal'(Expression @key[with] 3.5)) @RI[-- initialized explicitly]
2108
2109 @end{Example}
2110 @end{Examples}
2111
2112 @begin{Incompatible83}
2113 @ChgRef{Version=[1],Kind=[Revised]}@ChgNote{Presentation AI-00019}
2114 @Defn{incompatibilities with Ada 83}
2115 The @nt<subtype_indication> of an uninitialized allocator may
2116 not have an explicit @nt<constraint> if the designated type is an access type.
2117 In Ada 83, this was permitted even though the @nt<constraint> had
2118 no @Chg{New=[e],Old=[a]}ffect on the subtype of the created object.
2119 @end{Incompatible83}
2120
2121 @begin{Extend83}
2122 @Defn{extensions to Ada 83}
2123 Allocators creating objects of type @i(T)
2124 are now overloaded on access types designating
2125 @i(T')Class and all class-wide types that cover @i(T).
2126
2127 Implicit array subtype conversion (sliding) is now performed
2128 as part of an initialized allocator.
2129 @end{Extend83}
2130
2131 @begin{DiffWord83}
2132 We have used a new organization, inspired by the ACID
2133 document, that makes it clearer what is the subtype of
2134 the created object, and what subtype conversions take place.
2135
2136 Discussion of storage management issues,
2137 such as garbage collection and the raising of Storage_Error,
2138 has been moved to @RefSec{Storage Management}.
2139 @end{DiffWord83}
2140
2141 @begin{Inconsistent95}
2142 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00363-01]}
2143 @ChgAdded{Version=[2],Text=[@Defn{inconsistencies with Ada 95}If the
2144 designated type has a constrained partial view,
2145 the allocated object can be unconstrained. This might cause the object to
2146 take up a different amount of memory, and might cause the operations to work
2147 where they previously would have raised Constraint_Error. It's unlikely that
2148 the latter would actually matter in a real program (Constraint_Error usually
2149 indicates a bug that would be fixed, not left in a program.) The former
2150 might cause Storage_Error to be raised at a different time than in an Ada 95
2151 program.]}
2152 @end{Inconsistent95}
2153
2154 @begin{Incompatible95}
2155 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00366-01]}
2156 @ChgAdded{Version=[2],Text=[@Defn{incompatibilities with Ada 95}An
2157 @nt{allocator} for an access type that has Storage_Size specified to be
2158 zero is now illegal. Ada 95 allowed the @nt{allocator}, but it had to
2159 raise Storage_Error if executed. The primary impact of this change should
2160 be to detect bugs.]}
2161 @end{Incompatible95}
2162
2163 @begin{Extend95}
2164 @ChgRef{Version=[2],Kind=[AddedNormal],Ref=[8652/0010],ARef=[AI95-00127-01]}
2165 @ChgAdded{Version=[2],Text=[@Defn{extensions to Ada 95}@b<Corrigendum:> An
2166 @nt{allocator} can be a controlling parameter of a dispatching call. This
2167 was an oversight in Ada 95.]}
2168
2169 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00287-01]}
2170 @ChgAdded{Version=[2],Text=[Initialized @nt{allocator}s are allowed when
2171 the designated type is limited.]}
2172 @end{Extend95}
2173
2174 @begin{DiffWord95}
2175 @ChgRef{Version=[2],Kind=[AddedNormal],Ref=[8652/0002],ARef=[AI95-00171-01]}
2176 @ChgAdded{Version=[2],Text=[@b<Corrigendum:> Clarified the elaboration of
2177 per-object constraints for an uninitialized allocator.]}
2178
2179 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00280-01]}
2180 @ChgAdded{Version=[2],Text=[Program_Error is now raised if the @nt{allocator}
2181 occurs after the finalization of the collection or the waiting for tasks.
2182 This is not listed as an incompatibility as the Ada 95 behavior was
2183 unspecified, and Ada 95 implementations tend to generate programs that crash
2184 in this case.]}
2185
2186 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00344-01]}
2187 @ChgAdded{Version=[2],Text=[Added accessibility checks to class-wide
2188 @nt{allocator}s. These checks could not fail in Ada 95 (as all of the
2189 designated types had to be declared at the same level, so the access type
2190 would necessarily have been at the same level or more nested than the type
2191 of allocated object).]}
2192
2193 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00373-01]}
2194 @ChgAdded{Version=[2],Text=[Revised the description of evaluation of
2195 uninitialized allocators to use @lquotes@;initialized by default@rquotes
2196 so that the ordering requirements are the same for all kinds of objects
2197 that are default-initialized.]}
2198
2199 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00416-01]}
2200 @ChgAdded{Version=[2],Text=[Added accessibility checks to access
2201 discriminants of @nt{allocator}s. These checks could not fail in Ada 95
2202 as the discriminants always have the accessibility of the object.]}
2203 @end{DiffWord95}
2204
2205 @begin{Incompatible2005}
2206 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0052-1]}
2207 @ChgAdded{Version=[3],Text=[@Defn{incompatibilities with Ada 2005}@b<Correction:>
2208 Added a rule to prevent limited coextensions of nonlimited types. Allowing
2209 this would have far-reaching implementation costs. Because of those costs, it
2210 seems unlikely that any implementation ever supported it properly and thus it
2211 is unlikely that any existing code depends on this capability.]}
2212
2213 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0104-1]}
2214 @ChgAdded{Version=[3],Text=[@b<Correction:> Added a rule to
2215 make @nt{null_exclusion}s illegal for uninitialized @nt{allocator}s,
2216 as such an @nt{allocator} would always raise Constraint_Error.
2217 Programs that depend on the unconditional raising of a predefined
2218 exception should be very rare.]}
2219 @end{Incompatible2005}
2220
2221 @begin{Extend2005}
2222 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0111-3]}
2223 @ChgAdded{Version=[3],Text=[@Defn{extensions to Ada 2005}Subpool handles
2224 (see @RefSecNum{Storage Subpools}) can be specified in an @nt{allocator}.]}
2225 @end{Extend2005}
2226
2227 @begin{DiffWord2005}
2228 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0024-1]}
2229 @ChgAdded{Version=[3],Text=[@b<Correction:> Corrected the master check
2230 for tags since the masters may be for different tasks and thus incomparable.]}
2231
2232 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0041-1]}
2233 @ChgAdded{Version=[3],Text=[@b<Correction:> Corrected the rules for
2234 when a designated object is constrained by its initial value so that
2235 types derived from a partial view are handled properly.]}
2236
2237 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0051-1],ARef=[AI05-0234-1]}
2238 @ChgAdded{Version=[3],Text=[@b<Correction:> Corrected the accessibility
2239 check for access discriminants so that it does not depend on the
2240 designated type (which might not have discriminants when the allocated
2241 type does).]}
2242 @end{DiffWord2005}
2243
2244
2245
2246 @LabeledClause{Static Expressions and Static Subtypes}
2247
2248 @begin{Intro}
2249 Certain expressions of a scalar or string type are defined to be static.
2250 Similarly, certain discrete ranges are defined to be static, and
2251 certain scalar and string subtypes are defined to be static subtypes.
2252 @Redundant[@Defn{static}
2253 @i(Static) means determinable at compile time,
2254 using the declared properties or values of the program entities.]
2255 @IndexSeeAlso{Term=[constant],See=(static)}
2256 @begin{Discussion}
2257 As opposed to more elaborate data flow analysis, etc.
2258 @end{Discussion}
2259 @end{Intro}
2260
2261 @begin{MetaRules}
2262 For an expression to be static,
2263 it has to be calculable at compile time.
2264
2265 Only scalar and string expressions are static.
2266
2267 To be static, an expression cannot have any nonscalar, nonstring
2268 subexpressions (though it can have nonscalar constituent @nt<name>s).
2269 A static scalar expression cannot have any nonscalar subexpressions.
2270 There is one exception @em a membership test for a string subtype
2271 can be static, and the result is scalar, even though a subexpression
2272 is nonscalar.
2273
2274 The rules for evaluating static expressions are designed
2275 to maximize portability of static calculations.
2276
2277 @begin{Reason}
2278 @ChgRef{Version=[5],Kind=[AddedNormal],ARef=[AI12-0201-1]}
2279 @ChgAdded{Version=[5],Text=[We support static string expressions so that, for
2280 example, the @nt{aspect_definition} for a Link_Name aspect can contain a
2281 concatenation. We don't support static aggregates (even for string types) or
2282 non-string static nonscalar types; we're trying to keep it cheap and simple
2283 (from the implementer's viewpoint).]}
2284 @end{Reason}
2285 @end{MetaRules}
2286
2287 @begin{StaticSem}@Comment{Was "Intro" by mistake until version 5}
2288 @Leading@Defn2{Term=[static], Sec=(expression)}
2289 A static expression is
2290 @Redundant[a scalar or string expression that is]
2291 one of the following:
2292
2293 @begin{Itemize}
2294 @ChgRef{Version=[5],Kind=[Revised],ARef=[AI12-0249-1]}
2295 a @nt{numeric_literal}@Chg{Version=[5],New=[ of a numeric type],Old=[]};
2296 @begin{Ramification}
2297 @ChgRef{Version=[5],Kind=[Revised],ARef=[AI12-0249-1]}
2298 A @nt<numeric_literal>@Chg{Version=[5],New=[ of a numeric type],Old=[]}
2299 is always a static expression, even if
2300 its expected type is not that of a static subtype. However, if its value
2301 is explicitly converted to, or qualified by, a nonstatic subtype,
2302 the resulting expression is nonstatic.@Chg{Version=[5],New=[ Non-numeric
2303 types can have numeric literals if aspect Integer_Literal or Real_Literal
2304 is used; these are never static.],Old=[]}
2305 @end{Ramification}
2306
2307 a @nt{string_literal} of a static string subtype;
2308 @begin(Ramification)
2309 That is, the constrained subtype defined by the index range
2310 of the string is static. Note that elementary values don't
2311 generally have subtypes, while composite values do (since
2312 the bounds or discriminants are inherent in the value).
2313 @end(Ramification)
2314
2315 a @nt{name}
2316 that denotes the declaration
2317 of a named number or a static constant;
2318 @begin{Ramification}
2319 Note that enumeration
2320 literals are covered by the @nt{function_call} case.
2321 @end{Ramification}
2322
2323 a @nt{function_call}
2324 whose @SynI{function_}@nt{name} or
2325 @SynI{function_}@nt{prefix} statically denotes a static function,
2326 and whose actual parameters, if any (whether given explicitly or by default),
2327 are all static expressions;
2328 @begin{Ramification}
2329 This includes uses of operators that are equivalent to
2330 @nt{function_call}s.
2331 @end{Ramification}
2332
2333
2334 an @nt{attribute_reference} that denotes a scalar value,
2335 and whose @nt{prefix} denotes a static scalar subtype;
2336
2337 @begin{Ramification}
2338 Note that this does not include the case of an attribute
2339 that is a function;
2340 a reference to
2341 such an attribute is not even an expression.
2342 See above for function @i{calls}.
2343
2344 An implementation may define the staticness and other
2345 properties of implementation-defined attributes.
2346 @end{Ramification}
2347
2348 @ChgRef{Version=[5],Kind=[Revised],ARef=[AI12-0368-1]}
2349 an @nt{attribute_reference} whose
2350 @nt{prefix} statically @Chg{Version=[5],New=[names],Old=[denotes]} a
2351 statically constrained array object or array subtype,
2352 and whose @nt<attribute_designator>
2353 is First, Last, or Length,
2354 with an optional dimension;
2355
2356 @ChgRef{Version=[5],Kind=[Added],ARef=[AI12-0064-2]}
2357 @ChgAdded{Version=[5],Text=[an @nt{attribute_reference} whose
2358 @nt{prefix} denotes a non-generic
2359 entity that is not declared in a generic unit, and whose
2360 @nt{attribute_designator} is Nonblocking;]}
2361
2362 @ChgRef{Version=[5],Kind=[Revised],ARef=[AI12-0201-1]}
2363 a @nt{type_conversion}
2364 whose @nt{subtype_mark} denotes a static
2365 @Chg{Version=[5],New=<@Redundant[(scalar or string)]>,Old=[scalar]}
2366 subtype, and whose operand is a static expression;
2367
2368 a @nt{qualified_expression}
2369 whose @nt{subtype_mark} denotes a
2370 static @Redundant[(scalar or string)] subtype,
2371 and whose operand is a static expression;
2372 @begin{Ramification}
2373 This rules out the @nt{subtype_mark}'@nt{aggregate} case.
2374 @end{Ramification}
2375 @begin{Reason}
2376 Adding qualification to an expression shouldn't make it nonstatic, even
2377 for strings.
2378 @end{Reason}
2379
2380 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0158-1],ARef=[AI05-0269-1]}
2381 @ChgRef{Version=[4],Kind=[Revised],ARef=[AI12-0039-1]}
2382 a membership test whose
2383 @Chg{Version=[4],New=[@SynI{tested_}@nt{simple_expression}],Old=[@nt{simple_expression}]}
2384 is a static expression,
2385 and whose @Chg{Version=[3],New=[@nt{membership_choice_list} consists only of
2386 @nt{membership_choice}s that are either static
2387 @Chg{Version=[4],New=[@SynI{choice_}@nt{simple_expression}s],Old=[@nt{choice_expression}s]},
2388 static @nt{range}s, or @nt{subtype_mark}s that denote],Old=[@nt{range}
2389 is a static range or whose @nt{subtype_mark} denotes]} a
2390 static @Redundant[(scalar or string)] subtype;
2391 @begin{Reason}
2392 Clearly, we should allow membership tests in exactly the same cases
2393 where we allow @nt{qualified_expression}s.
2394 @end{Reason}
2395
2396 a short-circuit control form
2397 both of whose @nt{relation}s are static expressions;
2398
2399 @ChgRef{Version=[3],Kind=[Added],ARef=[AI05-0147-1],ARef=[AI05-0188-1]}
2400 @ChgAdded{Version=[3],Text=[a @nt{conditional_expression} all of whose
2401 @nt{condition}s, @SynI{selecting_}@nt{expression}s,
2402 and @SynI{dependent_}@nt{expression}s are static expressions;]}
2403
2404 @ChgRef{Version=[5],Kind=[Added],ARef=[AI12-0368-1]}
2405 @ChgAdded{Version=[5],Text=[a @nt{declare_expression} whose
2406 @Syni{body_}@nt{expression} is static and each of whose
2407 declarations, if any, is either the declaration of a static constant or is
2408 an @nt{object_renaming_declaration} with an @Syni{object_}@nt{name} that
2409 statically names the renamed object;]}
2410
2411 a static expression enclosed in parentheses.
2412 @end{Itemize}
2413 @begin(Discussion)
2414 @Defn2{Term=[static], Sec=(value)}
2415 Informally, we talk about a @i(static value). When we do,
2416 we mean a value specified by a static expression.
2417 @end(Discussion)
2418 @begin{Ramification}
2419 The language requires a static
2420 expression in a @nt<number_declaration>,
2421 a numeric type definition, a @nt<discrete_choice> (sometimes),
2422 certain representation items, an @nt<attribute_designator>,
2423 and when specifying the value of a discriminant
2424 governing a @nt{variant_part}
2425 in a @nt<record_aggregate> or @nt<extension_aggregate>.
2426 @end{Ramification}
2427
2428 @Leading@Defn{statically denote}
2429 A @nt{name} @i(statically denotes) an entity if it
2430 denotes the entity and:
2431 @begin(itemize)
2432 It is a @nt<direct_name>, expanded name, or
2433 @nt{character_literal},
2434 and it denotes a declaration other than a @nt<renaming_declaration>;
2435 or
2436
2437 It is an @nt{attribute_reference} whose @nt{prefix} statically denotes
2438 some entity; or
2439
2440 @ChgRef{Version=[5],Kind=[Added],ARef=[AI12-0322-1]}
2441 @ChgAdded{Version=[5],Text=[It is a @nt{target_name} (see
2442 @RefSecNum{Target Name Symbols}) in an @nt{assignment_statement} whose
2443 @SynI{variable_}@nt{name} statically denotes some entity; or]}
2444
2445 It denotes a @nt<renaming_declaration> with a @nt<name> that
2446 statically denotes the renamed entity.
2447 @end(itemize)
2448 @begin{Ramification}
2449 @nt{Selected_component}s that are not expanded names
2450 and @nt{indexed_component}s do not statically denote things.
2451 @end{Ramification}
2452
2453 @ChgRef{Version=[5],Kind=[Added],ARef=[AI12-0368-1]}
2454 @ChgAdded{Version=[5],Type=[Leading],Text=[A @nt{name} @i<statically names>
2455 an object if it:@Defn{Statically names}]}
2456 @begin{Itemize}
2457 @ChgRef{Version=[5],Kind=[Added],ARef=[AI12-0368-1]}
2458 @ChgAdded{Version=[5],Text=[statically denotes the declaration of an object
2459 @Redundant[(possibly through one or more renames)];]}
2460 @begin{TheProof}
2461 @ChgRef{Version=[5],Kind=[AddedNormal]}
2462 @ChgAdded{Version=[5],Text=[Follows from the definition of statically
2463 denotes.]}
2464 @end{TheProof}
2465 @ChgRef{Version=[5],Kind=[Added],ARef=[AI12-0368-1],ARef=[AI12-0373-1]}
2466 @ChgAdded{Version=[5],Text=[is a @nt{selected_component} whose prefix
2467 statically names an object, there is no implicit dereference of the prefix,
2468 and the @nt{selector_name} does not denote a
2469 @nt{component_declaration} occurring within a @nt{variant_part}; or]}
2470 @begin{Reason}
2471 @ChgRef{Version=[5],Kind=[AddedNormal]}
2472 @ChgAdded{Version=[5],Text=[We disallow components in a @nt{variant_part}
2473 so that no discriminant checks are needed to evaluate the
2474 @nt{selected_component}. Note that other kinds of discriminant-dependent
2475 components do not need any checks on access (only when they are
2476 changed).]}
2477 @end{Reason}
2478 @ChgRef{Version=[5],Kind=[Added],ARef=[AI12-0368-1]}
2479 @ChgAdded{Version=[5],Text=[is an @nt{indexed_component} whose prefix
2480 statically names an object, there is no implicit dereference of the prefix,
2481 the object is statically constrained, and the index expressions of the
2482 object are static and have values that are within
2483 the range of the index constraint.]}
2484 @end{Itemize}
2485
2486 @ChgRef{Version=[5],Kind=[Added],ARef=[AI12-0368-1]}
2487 @ChgAdded{Version=[5],Text=[For an entity other than an object, a @nt{name}
2488 statically names an entity if the @nt{name} statically denotes the entity.]}
2489
2490
2491 @Leading@Defn2{Term=[static], Sec=(function)}
2492 A @i{static function} is one of the following:
2493 @begin{Ramification}
2494 These are the functions whose calls can be static expressions.
2495 @end{Ramification}
2496 @begin{Itemize}
2497 a predefined operator whose parameter and result
2498 types are all scalar types none of which are descendants of
2499 formal scalar types;
2500
2501 @ChgRef{Version=[5],Kind=[Added],ARef=[AI12-0201-1]}
2502 @ChgAdded{Version=[5],Text=[a predefined relational operator whose parameters
2503 are of a string type that is not a descendant of a formal array type;]}
2504
2505 @ChgRef{Version=[5],Kind=[Revised],ARef=[AI12-0201-1]}
2506 a predefined concatenation operator whose result type is a string
2507 type@Chg{Version=[5],New=[ that is not a descendant of a formal array
2508 type],Old=[]};
2509
2510 an enumeration literal;
2511
2512 @ChgRef{Version=[5],Kind=[Added],ARef=[AI12-0075-1]}
2513 @ChgAdded{Version=[5],Text=[a static expression function
2514 (see @RefSecNum{Expression Functions});]}
2515
2516 a language-defined attribute that is a function,
2517 if the @nt{prefix} denotes a static scalar subtype,
2518 and if the parameter and result types are scalar.
2519 @end{Itemize}
2520
2521 In any case, a generic formal subprogram is not a static function.
2522
2523 @ChgRef{Version=[5],Kind=[Revised],ARef=[AI12-0201-1]}
2524 @Defn2{Term=[static], Sec=(constant)}
2525 A @i(static constant) is
2526 a constant view declared by a full constant declaration
2527 or an @nt<object_@!renaming_@!declaration> with a static nominal subtype,
2528 having a value defined by a static scalar expression or by
2529 a static string expression@Chg{Version=[5],New=[],Old=[ whose value has a
2530 length not exceeding the maximum length of a @nt{string_@!literal} in the
2531 implementation]}.
2532 @begin{Ramification}
2533 A deferred constant is not static;
2534 the view introduced by the corresponding full constant declaration
2535 can be static.
2536 @end{Ramification}
2537 @begin{Reason}
2538 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0229-1]}
2539 @ChgRef{Version=[5],Kind=[Deleted],ARef=[AI12-0201-1]}
2540 @ChgDeleted{Version=[5],Text=[The reason for restricting the length of static
2541 string constants is so
2542 that compilers don't have to store giant strings in their symbol tables.
2543 Since most string constants will be initialized
2544 from @nt{string_literal}s, the length limit seems pretty natural.
2545 The reason for avoiding nonstring types is also to save symbol table
2546 space.
2547 We're trying to keep it cheap and simple
2548 (from the implementer's viewpoint),
2549 while still allowing, for example,
2550 the @Chg{Version=[3],New=[@nt{aspect_definition} for a Link_Name aspect],
2551 Old=[link name of a pragma Import]} to contain a concatenation.]}
2552
2553 @ChgRef{Version=[5],Kind=[Deleted],ARef=[AI12-0201-1]}
2554 @ChgDeleted{Version=[5],Text=[The length we're talking about is the maximum
2555 number of characters in the value represented by a @nt{string_literal},
2556 not the number of characters in the source representation;
2557 the quotes don't count.]}
2558 @end{Reason}
2559
2560 @Defn2{Term=[static], Sec=(range)}
2561 A @i(static range) is a @nt{range} whose bounds are
2562 static expressions,
2563 @Redundant[or a @nt<range_@!attribute_@!reference> that is equivalent to
2564 such a @nt<range>.]
2565 @Defn2{Term=[static], Sec=(discrete_range)}
2566 A @i(static @nt<discrete_@!range>) is one that is a static range
2567 or is a @nt<subtype_@!indication> that defines a static scalar subtype.
2568 The base range of a scalar type is a static range, unless the
2569 type is a descendant of a formal scalar type.
2570
2571 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00263-01]}
2572 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0153-3]}
2573 @Defn2{Term=[static], Sec=(subtype)}
2574 A @i(static subtype) is either a @i(static scalar subtype) or a
2575 @i(static string subtype).
2576 @Defn2{Term=[static], Sec=(scalar subtype)}
2577 A static scalar subtype is an unconstrained scalar subtype whose
2578 type is not a descendant of a
2579 formal @Chg{Version=[2],New=[],Old=[scalar ]}type, or
2580 a constrained scalar subtype formed by imposing a compatible
2581 static constraint on a static scalar subtype.
2582 @Defn2{Term=[static], Sec=(string subtype)}
2583 A static string subtype is an unconstrained string subtype
2584 whose index subtype and component subtype are
2585 static@Chg{Version=[2],New=[],Old=[ (and whose type is not a descendant
2586 of a formal array type)]},
2587 or a constrained string subtype formed by imposing a compatible static
2588 constraint on a static string subtype.
2589 In any case, the subtype of a generic formal object of mode @key[in out],
2590 and the result subtype of a generic formal function, are not static.@Chg{Version=[3],
2591 New=[ Also, a subtype is not static if any Dynamic_Predicate specifications
2592 apply to it.],Old=[]}
2593 @begin{Ramification}
2594 String subtypes are the only composite subtypes that can be static.
2595 @end{Ramification}
2596 @begin{Reason}
2597 @Leading@;The part about generic formal objects of mode @key[in out]
2598 is necessary because the subtype of the formal is not required
2599 to have anything to do with the subtype of the actual.
2600 For example:
2601 @begin{Example}
2602 @key[subtype] Int10 @key[is] Integer @key[range] 1..10;
2603
2604 @key[generic]
2605 F : @key[in] @key[out] Int10;
2606 @key[procedure] G;
2607
2608 @key[procedure] G @key[is]
2609 @key[begin]
2610 @key[case] F @key[is]
2611 @key[when] 1..10 => @key[null];
2612 --@RI{ Illegal!}
2613 @key[end] @key[case];
2614 @key[end] G;
2615
2616 X : Integer @key[range] 1..20;
2617 @key[procedure] I @key[is] @key[new] G(F => X); --@RI{ OK.}
2618 @end{Example}
2619
2620 The @nt{case_statement} is illegal, because the subtype of F is not
2621 static, so the choices have to cover all values of Integer,
2622 not just those in the range 1..10.
2623 A similar issue arises for generic formal functions,
2624 now that function calls are object names.
2625 @end{Reason}
2626
2627 @Leading@Defn2{Term=[static], Sec=(constraint)}
2628 The different kinds of @i(static constraint) are defined as follows:
2629 @begin(itemize)
2630 A null constraint is always static;
2631
2632 @Defn2{Term=[static], Sec=(range constraint)}
2633 @Defn2{Term=[static], Sec=(digits constraint)}
2634 @Defn2{Term=[static], Sec=(delta constraint)}
2635 A scalar constraint is static if it has no
2636 @nt<range_constraint>,
2637 or one with a static range;
2638
2639 @Defn2{Term=[static], Sec=(index constraint)}
2640 An index constraint is static if each
2641 @nt<discrete_range> is static, and each index subtype of the
2642 corresponding array type is static;
2643
2644 @Defn2{Term=[static], Sec=(discriminant constraint)}
2645 A discriminant constraint is static if
2646 each @nt<expression> of the constraint is static,
2647 and the subtype of each discriminant is static.
2648 @end(itemize)
2649
2650 @ChgRef{Version=[2],Kind=[Added],ARef=[AI95-00311-01]}
2651 @Chg{Version=[2],New=[In any case, the constraint of the first subtype of a
2652 scalar formal type is neither static nor null.],Old=[]}
2653
2654 @Defn{statically constrained}
2655 A subtype is @i(statically constrained) if it is constrained,
2656 and its constraint is static.
2657 An object is @i(statically constrained) if its nominal subtype is
2658 statically constrained,
2659 or if it is a static string constant.
2660 @end{StaticSem}
2661
2662 @begin{Legality}
2663 @ChgRef{Version=[3],Kind=[Added],ARef=[AI05-0147-1]}
2664 @ChgAdded{Version=[3],Type=[Leading],Text=[An expression is @i<statically
2665 unevaluated> if it is part of:@Defn{statically unevaluated}]}
2666
2667 @begin{Itemize}
2668 @ChgRef{Version=[3],Kind=[Added],ARef=[AI05-0147-1]}
2669 @ChgAdded{Version=[3],Text=[the right operand of a static short-circuit control
2670 form whose value is determined by its left operand; or]}
2671
2672 @ChgRef{Version=[3],Kind=[Added],ARef=[AI05-0147-1],ARef=[AI05-0188-1]}
2673 @ChgAdded{Version=[3],Text=[a @SynI{dependent_}@nt{expression} of an
2674 @nt{if_expression} whose
2675 associated @nt{condition} is static and equals False; or]}
2676
2677 @ChgRef{Version=[3],Kind=[Added],ARef=[AI05-0147-1],ARef=[AI05-0188-1]}
2678 @ChgAdded{Version=[3],Text=[a @nt{condition} or @SynI{dependent_}@nt{expression}
2679 of an @nt{if_expression} where the @nt{condition} corresponding to at least one
2680 preceding @SynI{dependent_}@nt{expression} of the @nt{if_expression} is static
2681 and equals True; or]}
2682
2683 @begin{Reason}
2684 @ChgRef{Version=[3],Kind=[AddedNormal]}
2685 @ChgAdded{Version=[3],Type=[Leading],Text=[We need this bullet so that only a
2686 single @SynI{dependent_}@nt{expression} is evaluated in a static
2687 @nt{if_expression} if there is more than one @nt{condition} that evaluates to
2688 True. The part about @nt{condition}s makes]}
2689 @begin{Example}
2690 @ChgRef{Version=[3],Kind=[AddedNormal]}
2691 @ChgAdded{Version=[3],Text=[(@key[if] N = 0 @key[then] Min @key[elsif] 10_000/N > Min @key[then] 10_000/N @key[else] Min)]}
2692 @end{Example}
2693 @ChgRef{Version=[3],Kind=[AddedNormal]}
2694 @ChgAdded{Version=[3],Text=[legal if N and Min are static and N = 0.]}
2695 @end{Reason}
2696
2697 @begin{Discussion}
2698 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0147-1],ARef=[AI05-0188-1]}
2699 @ChgAdded{Version=[3],Text=[We need the "of the @nt{if_expression}" here so
2700 there is no confusion for nested @nt{if_expression}s; this rule only applies to
2701 the @nt{condition}s and @Syni{dependent_}@nt{expression}s of a single
2702 @nt{if_expression}. Similar
2703 reasoning applies to the "of a @nt{case_expression}" of the last bullet.]}
2704 @end{Discussion}
2705
2706 @ChgRef{Version=[3],Kind=[Added],ARef=[AI05-0188-1],ARef=[AI05-0269-1]}
2707 @ChgAdded{Version=[3],Text=[a @SynI{dependent_}@nt{expression} of a
2708 @nt{case_expression} whose @SynI{selecting_}@nt{expression} is static and
2709 whose value is not covered by the corresponding @nt{discrete_choice_list}; or]}
2710
2711 @ChgRef{Version=[3],Kind=[Added],ARef=[AI05-0158-1]}
2712 @ChgRef{Version=[4],Kind=[RevisedAdded],ARef=[AI12-0039-1]}
2713 @ChgAdded{Version=[3],Text=[a
2714 @Chg{Version=[4],New=[@SynI{choice_}@nt{simple_expression}],Old=[@nt{choice_expression}]}
2715 (or a @nt{simple_expression}
2716 of a @nt{range} that occurs as a @nt{membership_choice} of a
2717 @nt{membership_choice_list}) of a static membership test that is preceded in
2718 the enclosing @nt{membership_choice_list} by another item whose individual
2719 membership test (see @RefSecNum{Relational Operators and Membership Tests})
2720 statically yields True.]}
2721 @end{Itemize}
2722
2723 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0147-1]}
2724 @Leading@;A static expression is evaluated at compile time except when it is
2725 @Chg{Version=[3],New=[statically unevaluated],Old=[part
2726 of the right operand of a static short-circuit control form whose value
2727 is determined by its left operand]}.
2728 @Chg{Version=[3],New=[The compile-time],Old=[This]} evaluation
2729 @Chg{Version=[3],New=[of a static expression ],Old=[]}is performed exactly,
2730 without performing Overflow_Checks.
2731 For a static expression that is evaluated:
2732 @begin{Itemize}
2733 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0262-1]}
2734 The expression is illegal if its evaluation fails a language-defined
2735 check other than Overflow_@!Check.@Chg{Version=[3],New=[ For the purposes of
2736 this evaluation, the assertion policy is assumed to be Check.],Old=[]}
2737
2738 @begin{Reason}
2739 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0262-1]}
2740 @ChgAdded{Version=[3],Text=[Assertion policies can control whether checks are
2741 made, but we don't want assertion policies to affect legality. For Ada 2012,
2742 subtype predicates are the only checks controlled by the assertion policy that
2743 can appear in static expressions.]}
2744 @end{Reason}
2745
2746 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00269-01]}
2747 If the expression is not part of a larger static
2748 expression@Chg{Version=[2],New=[ and the expression is expected to be of a
2749 single specific type],Old=[]},
2750 then its value shall be within the base range of its expected type.
2751 Otherwise, the value may be arbitrarily large or small.
2752 @begin{Ramification}
2753 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00269-01]}
2754 @ChgAdded{Version=[2],Text=[If the expression is expected to be of a universal
2755 type, or of @lquotes@;any integer type@rquotes, there are no limits on the
2756 value of the expression.]}
2757 @end{Ramification}
2758
2759 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00269-01]}
2760 If the expression is of type @i<universal_real> and its expected type is
2761 a decimal fixed point type,
2762 then its value shall be a multiple of the @i<small> of the decimal
2763 type.@Chg{Version=[2],New=[ This restriction
2764 does not apply if the expected type is a
2765 descendant of a formal scalar type
2766 (or a corresponding actual type in an instance).],Old=[]}
2767 @begin{Ramification}
2768 This means that a @nt{numeric_literal} for a decimal type cannot have
2769 @lquotes@;extra@rquotes@; significant digits.
2770 @end{Ramification}
2771 @begin{Reason}
2772 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00269-01]}
2773 @ChgAdded{Version=[2],Text=[The small is not known for a generic formal
2774 type, so we have to exclude formal types from this check.]}
2775 @end{Reason}
2776 @end{Itemize}
2777
2778 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00269-01]}
2779 @Chg{Version=[2],New=[@PDefn{generic contract issue}
2780 In addition to the places where @LegalityTitle normally apply
2781 (see @RefSecNum{Generic Instantiation}),
2782 the above restrictions also apply in the private part of an
2783 instance of a generic unit.],Old=[The last two restrictions above
2784 do not apply if the expected type is a descendant of a formal scalar type
2785 (or a corresponding actual type in an instance).]}
2786
2787 @begin{Discussion}
2788 Values outside the base range are not permitted
2789 when crossing from the @lquotes@;static@rquotes@; domain to the @lquotes@;dynamic@rquotes@; domain.
2790 This rule is designed to enhance portability of programs
2791 containing static expressions.
2792 Note that this rule applies to the exact value,
2793 not the value after any rounding or truncation.
2794 (See below for the rounding and truncation requirements.)
2795
2796 @Leading@;Short-circuit control forms are a special case:
2797 @begin{Example}
2798 N: @key[constant] := 0.0;
2799 X: @key[constant] Boolean := (N = 0.0) @key[or] @key[else] (1.0/N > 0.5); --@RI{ Static.}
2800 @end{Example}
2801
2802 The declaration of X is legal, since the divide-by-zero part of the
2803 expression is not evaluated.
2804 X is a static constant equal to True.
2805
2806 @ChgRef{Version=[5],Kind=[AddedNormal],ARef=[AI12-0075-1]}
2807 @ChgAdded{Version=[5],Type=[Leading],Text=[The preceding
2808 @ldquote@;statically unevaluated@rdquote rule allows]}
2809
2810 @begin{Example}
2811 @ChgRef{Version=[5],Kind=[AddedNormal]}
2812 @ChgAdded{Version=[5],Text=[X : @key[constant] := (@key[if] True @key[then] 37 @key[else] (1 / 0));]}
2813 @end{Example}
2814
2815 @ChgRef{Version=[5],Kind=[AddedNormal]}
2816 @ChgAdded{Version=[5],Type=[Leading],Text=[but does not allow]}
2817
2818 @begin{Example}
2819 @ChgRef{Version=[5],Kind=[AddedNormal]}
2820 @ChgAdded{Version=[5],Text=[@key[function] If_Then_Else (Flag : Boolean; X, Y : Integer) @key[return] Integer @key[is]
2821 (@key[if] Flag @key[then] X @key[else] Y) @key[with] Static; -- @Examcom{see @RefSecNum{Expression Functions}}
2822 X : @key[constant] := If_Then_Else (True, 37, 1 / 0);]}
2823 @end{Example}
2824
2825 @ChgRef{Version=[5],Kind=[AddedNormal]}
2826 @ChgAdded{Version=[5],Type=[Trailing],Text=[because evaluation of a function
2827 call includes evaluation of all of its actual parameters.]}
2828 @end{Discussion}
2829 @begin{Ramification}
2830 @ChgRef{Version=[2],Kind=[DeletedNoDelMsg],ARef=[AI95-00269-01]}
2831 @ChgDeleted{Version=[2],Text=[There is no requirement to recheck these rules
2832 in an instance; the base range check will generally be performed at run time
2833 anyway.]}
2834 @end{Ramification}
2835 @end{Legality}
2836
2837 @begin{ImplReq}
2838 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00268-01],ARef=[AI95-00269-01]}
2839 For a real static expression that is not part of a larger static
2840 expression,
2841 and whose expected type is not a descendant of a formal
2842 @Chg{Version=[2],New=[],Old=[scalar ]}type,
2843 the implementation shall round or truncate
2844 the value (according to the Machine_Rounds
2845 attribute of the expected type) to the nearest machine
2846 number of the expected type;
2847 if the value is exactly half-way between two machine
2848 numbers, @Chg{Version=[2],New=[the],Old=[any]} rounding
2849 @Chg{Version=[2],New=[],Old=[shall be ]}performed
2850 @Chg{Version=[2],New=[is implementation-defined],Old=[away from zero]}.
2851 If the expected type is a descendant of a formal
2852 @Chg{Version=[2],New=[],Old=[scalar ]}type,
2853 @Chg{Version=[2],New=[or if the static expression appears in
2854 the body of an instance of a generic unit and the corresponding expression is
2855 nonstatic in the corresponding generic body, then],Old=[]}
2856 no special rounding or truncating is required @em normal
2857 accuracy rules apply (see @RefSecNum(Numerics)).
2858 @ChgImplDef{Version=[2],Kind=[Added],Text=[@Chg{Version=[2],New=[Rounding of
2859 real static expressions which are exactly half-way between two machine numbers.],Old=[]}]}
2860 @begin{Reason}
2861 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00268-01]}
2862 Discarding extended precision enhances portability
2863 by ensuring that the value of a
2864 static constant of a real type is always a machine number of the type.
2865 @Chg{Version=[2],New=[],Old=[Deterministic rounding of exact halves also enhances portability.]}
2866
2867 When the expected type is a descendant of a formal floating point type,
2868 extended precision (beyond that of the machine numbers)
2869 can be retained when evaluating
2870 a static expression, to ease code sharing for generic
2871 instantiations. For similar reasons,
2872 normal (nondeterministic) rounding or truncating rules apply
2873 for descendants of a formal fixed point type.
2874
2875 @ChgRef{Version=[2],Kind=[Added],ARef=[AI95-00269-01]}
2876 @ChgAdded{Version=[2],Text=[There is no requirement for exact evaluation or
2877 special rounding in an instance body (unless the expression is static in
2878 the generic body). This eliminates a potential contract issue where the
2879 exact value of a static expression depends on the actual parameters (which
2880 could then affect the legality of other code).]}
2881 @end{Reason}
2882 @begin{ImplNote}
2883
2884 Note that the implementation of static expressions has to keep track
2885 of plus and minus zero for a type whose Signed_Zeros attribute is
2886 True.
2887
2888 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00100-01]}
2889 Note that the only @Chg{Version=[2],New=[machine numbers],Old=[values]} of
2890 a fixed point type are the multiples of
2891 the small, so a static conversion to a fixed-point type, or division
2892 by an integer, must do truncation to a multiple of small.
2893 It is not correct for the implementation to do all static calculations
2894 in infinite precision.
2895
2896 @end{ImplNote}
2897
2898 @end{ImplReq}
2899
2900 @begin{ImplAdvice}
2901 @ChgRef{Version=[2],Kind=[Added],ARef=[AI95-00268-01]}
2902 @ChgAdded{Version=[2],Text=[For a real static expression that is not part of a
2903 larger static expression, and whose expected type is not a descendant of a
2904 formal type, the rounding should be the same as the default rounding
2905 for the target system.]}
2906 @ChgImplAdvice{Version=[2],Kind=[AddedNormal],Text=[@ChgAdded{Version=[2],
2907 Text=[A real static expression with a nonformal type that is not part of a
2908 larger static expression should be rounded the same as the target system.]}]}
2909 @end{ImplAdvice}
2910
2911 @begin{Notes}
2912 An expression can be static even if it occurs in a context where
2913 staticness is not required.
2914 @begin{Ramification}
2915
2916 @Leading@keepnext@;For example:
2917 @begin{Example}
2918 X : Float := Float'(1.0E+400) + 1.0 - Float'(1.0E+400);
2919 @end{Example}
2920
2921 The expression is static,
2922 which means that the value of X must be exactly 1.0,
2923 independent of the accuracy or range of the run-time floating point
2924 implementation.
2925
2926 The following kinds of expressions are never static:
2927 @nt{explicit_dereference},
2928 @nt{indexed_component},
2929 @nt{slice},
2930 @key{null},
2931 @nt{aggregate},
2932 @nt{allocator}.
2933 @end{Ramification}
2934
2935 A static (or run-time) @nt<type_conversion> from a real type to
2936 an integer type performs rounding. If the operand value is exactly half-way
2937 between two integers, the rounding is performed away from zero.
2938 @begin{Reason}
2939 We specify this for portability. The reason for not choosing
2940 round-to-nearest-even, for example, is that this method is easier
2941 to undo.
2942 @end{Reason}
2943 @begin{Ramification}
2944 The attribute Truncation
2945 (see @RefSecNum{Attributes of Floating Point Types})
2946 can be used to perform a (static) truncation prior to conversion,
2947 to prevent rounding.
2948 @end{Ramification}
2949 @begin{ImplNote}
2950
2951 The value of the literal
2952 0E999999999999999999999999999999999999999999999
2953 is zero.
2954 The implementation must take care to evaluate such literals properly.
2955
2956 @end{ImplNote}
2957 @end{Notes}
2958
2959 @begin{Examples}
2960 @Leading@keepnext@i(Examples of static expressions:)
2961 @begin{Example}
2962 1 + 1 @RI[-- 2]
2963 @key(abs)(-10)*3 @RI[-- 30]
2964
2965 Kilo : @key(constant) := 1000;
2966 Mega : @key(constant) := Kilo*Kilo; @RI[-- 1_000_000]
2967 Long : @key(constant) := Float'Digits*2;
2968
2969 Half_Pi : @key(constant) := Pi/2; @RI[-- see @RefSecNum(Number Declarations)]
2970 Deg_To_Rad : @key(constant) := Half_Pi/90;
2971 Rad_To_Deg : @key(constant) := 1.0/Deg_To_Rad; @RI[-- equivalent to 1.0/((3.14159_26536/2)/90)]
2972 @end{Example}
2973 @end{Examples}
2974
2975 @begin{Extend83}
2976 @Defn{extensions to Ada 83}
2977 The rules for static expressions and static subtypes are generalized
2978 to allow more kinds of compile-time-known expressions to be used
2979 where compile-time-known values are required, as follows:
2980 @begin(itemize)
2981 Membership tests and short-circuit control forms
2982 may appear in a static expression.
2983
2984 The bounds and length of
2985 statically constrained array objects or subtypes are static.
2986
2987 The Range attribute of a statically constrained array subtype or
2988 object gives a static range.
2989
2990 A @nt{type_conversion} is static if the @nt{subtype_mark} denotes a
2991 static scalar subtype and the operand is a static expression.
2992
2993 All numeric literals are now static, even if the expected
2994 type is a formal scalar type.
2995 This is useful in @nt{case_statement}s and @nt{variant_part}s,
2996 which both now allow a value of a formal scalar type to
2997 control the selection, to
2998 ease conversion of a package into a generic package.
2999 Similarly, named array aggregates are also permitted for array
3000 types with an index type that is a formal scalar type.
3001 @end(itemize)
3002
3003 The rules for the evaluation of static expressions
3004 are revised to require exact evaluation at compile time,
3005 and force a machine number result when crossing from the static realm
3006 to the dynamic realm,
3007 to enhance portability and predictability.
3008 Exact evaluation is not required for
3009 descendants of a formal scalar type,
3010 to simplify generic code sharing and to avoid generic
3011 contract model problems.
3012
3013 @Leading@;Static expressions are legal even if an intermediate
3014 in the expression goes outside the base range of the type. Therefore, the
3015 following will succeed in Ada 95, whereas it might raise an
3016 exception in Ada 83:
3017 @begin{Example}
3018 @key[type] Short_Int @key[is] @key[range] -32_768 .. 32_767;
3019 I : Short_Int := -32_768;
3020 @end{Example}
3021
3022 This might raise an exception in Ada 83 because "32_768" is out of range,
3023 even though "@en@;32_768" is not. In Ada 95, this will always succeed.
3024
3025
3026 Certain expressions involving string operations
3027 (in particular concatenation and membership tests)
3028 are considered static in Ada 95.
3029
3030
3031 The reason for this change is to simplify the rule requiring
3032 compile-time-known string expressions as the link name in an interfacing
3033 pragma, and to simplify the preelaborability rules.
3034 @end{Extend83}
3035
3036 @begin{Incompatible83}
3037 @Defn{incompatibilities with Ada 83}
3038 An Ada 83 program that uses an out-of-range static value
3039 is illegal in Ada 95, unless the expression is part of a larger
3040 static expression, or the expression is not evaluated due to being on
3041 the right-hand side of a short-circuit control form.
3042 @end{Incompatible83}
3043
3044 @begin{DiffWord83}
3045 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0299-1]}
3046 This @Chg{Version=[3],New=[subclause],Old=[clause]}
3047 (and @RefSec{Multiplying Operators})
3048 subsumes the RM83 section on Universal Expressions.
3049
3050 The existence of static string expressions
3051 necessitated changing the definition of static subtype to
3052 include string subtypes.
3053 Most occurrences of "static subtype" have been changed to "static scalar
3054 subtype",
3055 in order to preserve the effect of the Ada 83 rules.
3056 This has the added benefit of clarifying the difference between "static
3057 subtype" and "statically constrained subtype", which has been a source
3058 of confusion.
3059 In cases where we allow static string subtypes,
3060 we explicitly use phrases like "static string subtype"
3061 or "static (scalar or string) subtype",
3062 in order to clarify the meaning for those who have gotten used to the
3063 Ada 83 terminology.
3064
3065
3066 @Leading@;In Ada 83, an expression was considered nonstatic if it raised an
3067 exception.
3068 Thus, for example:
3069 @begin{Example}
3070 Bad: @key[constant] := 1/0; --@RI{ Illegal!}
3071 @end{Example}
3072
3073 was illegal because 1/0 was not static.
3074 In Ada 95, the above example is still illegal,
3075 but for a different reason:
3076 1/0 is static, but there's a separate rule forbidding the exception
3077 raising.
3078
3079 @end{DiffWord83}
3080
3081 @begin{Inconsistent95}
3082 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00268-01]}
3083 @ChgAdded{Version=[2],Text=[@Defn{inconsistencies with Ada 95}
3084 @b[Amendment Correction:] Rounding of
3085 static real expressions is implementation-defined in Ada 2005, while it was
3086 specified as away from zero in (original) Ada 95. This could make subtle
3087 differences in programs. However, the original Ada 95 rule required rounding
3088 that (probably) differed from the target processor, thus creating anomalies
3089 where the value of a static expression was required to be different than the
3090 same expression evaluated at run time.]}
3091 @end{Inconsistent95}
3092
3093 @begin{DiffWord95}
3094 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00263-01],ARef=[AI95-00268-01]}
3095 @ChgAdded{Version=[2],Text=[The Ada 95 wording that defined static subtypes
3096 unintentionally failed to exclude formal derived types that happen to be
3097 scalar (these aren't formal scalar types); and had a parenthetical remark
3098 excluding formal string types - but that was neither necessary nor
3099 parenthetical (it didn't follow from other wording). This issue also
3100 applies to the rounding rules for real static expressions.]}
3101
3102 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00269-01]}
3103 @ChgAdded{Version=[2],Text=[Ada 95 didn't clearly define the bounds of a value of
3104 a static expression for universal types and for "any integer/float/fixed
3105 type". We also make it clear that we do not intend exact evaluation of
3106 static expressions in an instance body if the expressions aren't static in the
3107 generic body.]}
3108
3109 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00311-01]}
3110 @ChgAdded{Version=[2],Text=[We clarify that the first subtype of a scalar
3111 formal type has a nonstatic, nonnull constraint.]}
3112 @end{DiffWord95}
3113
3114 @begin{DiffWord2005}
3115 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0147-1],ARef=[AI05-0188-1]}
3116 @ChgAdded{Version=[3],Text=[Added wording to define staticness and
3117 the lack of evaluation for @nt{if_expression}s and @nt{case_expression}s.
3118 These are new and defined elsewhere.]}
3119
3120 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0153-3]}
3121 @ChgAdded{Version=[3],Text=[Added wording to prevent subtypes that have
3122 dynamic predicates (see @RefSecNum{Subtype Predicates}) from being static.]}
3123
3124 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0158-1]}
3125 @ChgAdded{Version=[3],Text=[Revised wording for membership tests to allow
3126 for the new possibilities allowed by the @nt{membership_choice_list}.]}
3127 @end{DiffWord2005}
3128
3129 @begin{Incompatible2012}
3130 @ChgRef{Version=[5],Kind=[AddedNormal],ARef=[AI12-0201-1]}
3131 @ChgAdded{Version=[5],Text=[@Defn{incompatibilities with Ada 2012}
3132 Added a missing exclusion for concatenations of a string type descended from
3133 a formal array type. This could potentially make some expression non-static;
3134 but as that could only matter in a context where a static string is required
3135 (such as the Link_Name aspect), it is quite unlikely.]}
3136 @end{Incompatible2012}
3137
3138 @begin{Extend2012}
3139 @ChgRef{Version=[5],Kind=[AddedNormal],ARef=[AI12-0201-1]}
3140 @ChgAdded{Version=[5],Text=[@Defn{extensions to Ada 2012}Expressions
3141 involving string relational operators or string type conversions now can be
3142 static.]}
3143 @end{Extend2012}
3144
3145 @begin{Diffword2012}
3146 @ChgRef{Version=[5],Kind=[AddedNormal],ARef=[AI12-0064-2]}
3147 @ChgAdded{Version=[5],Text=[Defined the staticness of the Nonblocking
3148 attribute (see @RefSecNum{Intertask Communication}).]}
3149
3150 @ChgRef{Version=[5],Kind=[AddedNormal],ARef=[AI12-0075-1]}
3151 @ChgAdded{Version=[5],Text=[Expression functions can be static if declared
3152 correctly; this is documented as an extension in @RefSecNum{Expression Functions}.]}
3153
3154 @ChgRef{Version=[5],Kind=[AddedNormal],ARef=[AI12-0249-1]}
3155 @ChgAdded{Version=[5],Text=[A @nt{numeric_literal} can be non-static if
3156 they are defined by an Integer_Literal or Real_Literal aspect
3157 (see @RefSecNum{User-Defined Literals}).]}
3158
3159 @ChgRef{Version=[5],Kind=[AddedNormal],ARef=[AI12-0322-1]}
3160 @ChgAdded{Version=[5],Text=[Clarified that a target name symbol can statically
3161 denote an entity if the associated @SynI{variable_}@nt{name} statically
3162 denotes an entity. This is necessary so that target names participate in
3163 the anti-order-dependence checks of @RefSecNum{Parameter Associations}.]}
3164
3165 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI12-0368-1],ARef=[AI12-0373-1]}
3166 @ChgAdded{Version=[3],Text=[Added wording to define staticness for
3167 @nt{declare_expression}s. Also moved @ldquote@;statically names@rdquote@;
3168 definition here and used it in array attribute prefix wording.]}
3169
3170 @end{Diffword2012}
3171
3172
3173 @NotISORMNewPageVer{Version=[3]}@Comment{For printed version of Ada 2012 RM}
3174 @LabeledSubClause{Statically Matching Constraints and Subtypes}
3175
3176 @begin{StaticSem}
3177 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00311-01]}
3178 @Defn2{Term=[statically matching], Sec=(for constraints)}
3179 A constraint @i(statically matches) another
3180 constraint if@Chg{Version=[2],New=[:],Old=[ both are null constraints, both are
3181 static and have equal corresponding bounds or discriminant values,
3182 or both are nonstatic and result from the same elaboration of
3183 a @nt<constraint>
3184 of a @nt<subtype_@!indication> or the same evaluation of a @nt<range>
3185 of a @nt<discrete_@!subtype_@!definition>.]}
3186 @begin{Itemize}
3187 @ChgRef{Version=[2],Kind=[Added]}
3188
3189 @Chg{Version=[2],New=[both are null constraints;],Old=[]}
3190
3191 @begin{Discussion}
3192 @ChgRef{Version=[5],Kind=[AddedNormal]}
3193 @ChgAdded{Version=[5],Text=[A null constraint has nothing to do with
3194 null exclusions! Unconstrained array subtypes, subtypes with unknown
3195 discriminants, and subtypes with no explicit constraint have null
3196 constraints (see @RefSecNum{Types and Subtypes}). This terminology
3197 became confusing when null exclusions were introduced in the
3198 2007 Amendment.]}
3199 @end{Discussion}
3200
3201 @ChgRef{Version=[2],Kind=[Added]}
3202 @Chg{Version=[2],New=[both are static and have equal corresponding bounds or discriminant
3203 values;],Old=[]}
3204
3205 @ChgRef{Version=[2],Kind=[Added]}
3206 @Chg{Version=[2],New=[both are nonstatic and result from the same elaboration
3207 of a @nt<constraint>
3208 of a @nt<subtype_@!indication> or the same evaluation of a @nt<range>
3209 of a @nt<discrete_@!subtype_@!definition>; or],Old=[]}
3210
3211 @ChgRef{Version=[2],Kind=[Added],ARef=[AI95-00311-01]}
3212 @Chg{Version=[2],New=[both are nonstatic and come from the same
3213 @nt{formal_type_declaration}.],Old=[]}
3214 @end{Itemize}
3215
3216 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00231-01],ARef=[AI95-00254-01]}
3217 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0153-3]}
3218 @ChgRef{Version=[5],Kind=[Revised],ARef=[AI12-0059-1]}
3219 @Defn2{Term=[statically matching], Sec=(for subtypes)}
3220 A subtype @i(statically matches) another subtype of the same type
3221 if they have statically matching constraints@Chg{Version=[2],New=[,
3222 @Chg{Version=[3],New=[all predicate specifications that apply to
3223 them come from the same declarations, @Chg{Version=[5],New=[Object_Size (see
3224 @RefSecNum{Operational and Representation Attributes}) has been specified to
3225 have a nonconfirming value for either both or neither, and the nonconfirming
3226 values, if any, are the same, ],Old=[]}],Old=[]}and, for
3227 access subtypes, either both or neither exclude null],Old=[]}.
3228 Two anonymous access@Chg{Version=[2],New=[-to-object],Old=[]} subtypes
3229 statically match if their designated subtypes statically
3230 match@Chg{Version=[2],New=[, and either both or neither
3231 exclude null, and either both or neither are access-to-constant. Two anonymous
3232 access-to-subprogram subtypes statically match if their designated profiles are
3233 subtype conformant, and either both or neither exclude null],Old=[]}.
3234 @begin{Ramification}
3235 Statically matching constraints and subtypes are the basis
3236 for subtype conformance of profiles (see @RefSecNum(Conformance Rules)).
3237 @end{Ramification}
3238 @begin{Reason}
3239 @ChgRef{Version=[2],Kind=[AddedNormal]}
3240 @ChgAdded{Version=[2],Text=[Even though anonymous access types always
3241 represent different types, they can statically match. That's important so
3242 that they can be used widely. For instance, if this wasn't true, access
3243 parameters and access discriminants could never conform, so they couldn't
3244 be used in separate specifications.]}
3245 @end{Reason}
3246 @begin{Ramification}
3247 @ChgRef{Version=[5],Kind=[AddedNormal],ARef=[AI12-0059-1]}
3248 @ChgAdded{Version=[5],Text=[If one of the subtypes is not yet frozen, an
3249 implementation may have to repeat the check when the subtypes are both
3250 frozen (as it is impossible to check the Object_Size part before the subtypes
3251 are frozen). This recheck can only make a previously statically matching
3252 subtype fail to match; it cannot make a match legal.]}
3253 @end{Ramification}
3254 @begin{Discussion}
3255 @ChgRef{Version=[5],Kind=[AddedNormal],ARef=[AI12-0059-1]}
3256 @ChgAdded{Version=[5],Text=[We exclude the case where both Object_Sizes are
3257 confirming so that we don't introduce an incompatibility for
3258 existing Ada code. But practically the implementation can simply
3259 check that the Object_Size values are the same, as we have a rule in
3260 @RefSecNum{Operational and Representation Aspects} that the
3261 subtype-specific aspects (such as Object_Size) are always the same for
3262 statically matching subtypes. We wrote the rules this way to avoid having
3263 wording that appeared to require predicting the future ("would statically
3264 match if ...").]}
3265 @Comment{We generally do not reference particular paragraphs in the AARM;
3266 the paragraph referred to above is paragraph 14. In part, this is because
3267 we don't have a way in this tool to link to a particular paragraph,
3268 even though a user could add #P14 to the appropriate link and get directly
3269 there.}
3270 @end{Discussion}
3271
3272 @Defn2{Term=[statically matching], Sec=(for ranges)}
3273 Two ranges of the same type @i{statically match} if both result
3274 from the same evaluation of a @nt{range},
3275 or if both are static and have equal corresponding bounds.
3276 @begin{Ramification}
3277 The notion of static matching of ranges is used in
3278 @RefSec{Formal Array Types};
3279 the index ranges of formal and actual constrained array subtypes have to
3280 statically match.
3281 @end{Ramification}
3282
3283 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0086-1],ARef=[AI05-0153-3]}
3284 @Defn2{Term=[statically compatible],
3285 Sec=(for a constraint and a scalar subtype)}
3286 A constraint is @i(statically compatible) with a scalar subtype if
3287 it statically matches the constraint of the subtype, or if both
3288 are static and the constraint is compatible with the subtype.
3289 @Defn2{Term=[statically compatible],
3290 Sec=(for a constraint and an access or composite subtype)}
3291 A constraint is @i(statically compatible) with an access or composite subtype
3292 if it statically matches the constraint of the subtype, or
3293 if the subtype is unconstrained.@Chg{Version=[3],New=[],Old=[
3294 @Defn2{Term=[statically compatible],
3295 Sec=(for two subtypes)}
3296 One subtype is @i(statically compatible) with a second subtype if
3297 the constraint of the first is statically compatible with the
3298 second subtype.]}
3299 @begin{Discussion}
3300 Static compatibility is required when constraining a parent subtype
3301 with a discriminant from a new @nt<discriminant_part>.
3302 See @RefSecNum{Discriminants}. Static compatibility is also used
3303 in matching generic formal derived types.
3304
3305 Note that
3306 statically compatible with a subtype does not imply
3307 compatible with a type. It is OK since the terms are
3308 used in different contexts.
3309 @end{Discussion}
3310
3311 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0153-3]}
3312 @ChgAdded{Version=[3],Type=[Leading],Text=[@Defn2{Term=[statically compatible],
3313 Sec=(for two subtypes)}Two statically matching subtypes are statically
3314 compatible with each other. In addition, a subtype @i<S1> is statically
3315 compatible with a subtype @i<S2> if:]}
3316 @begin{Itemize}
3317
3318 @ChgRef{Version=[3],Kind=[AddedNormal]}
3319 @ChgAdded{Version=[3],Text=[the constraint of @i<S1> is statically compatible
3320 with @i<S2>, and]}
3321
3322 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0086-1]}
3323 @ChgAdded{Version=[3],Text=[if @i<S2> excludes null, so does @i<S1>, and]}
3324
3325 @ChgRef{Version=[3],Kind=[AddedNormal]}
3326 @ChgAdded{Version=[3],Type=[Leading],Text=[either:]}
3327 @begin{InnerItemize}
3328 @ChgRef{Version=[3],Kind=[AddedNormal]}
3329 @ChgAdded{Version=[3],Text=[all predicate specifications that apply to
3330 @i<S2> apply also to @i<S1>, or]}
3331
3332 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0290-1]}
3333 @ChgRef{Version=[4],Kind=[Revised],ARef=[AI12-0071-1]}
3334 @ChgAdded{Version=[3],Text=[both subtypes are static, every value that
3335 satisfies the @Chg{Version=[4],New=[predicates],Old=[predicate]} of @i<S1>
3336 also satisfies the @Chg{Version=[4],New=[predicates],Old=[predicate]} of
3337 @i<S2>, and it is not the case that both types each have at least one
3338 applicable predicate specification, predicate checks are enabled (see
3339 @RefSecNum{Pragmas Assert and Assertion_Policy}) for @i<S2>, and
3340 predicate checks are not enabled for @i<S1>.]}
3341 @end{InnerItemize}
3342 @end{Itemize}
3343 @end{StaticSem}
3344
3345 @begin{DiffWord83}
3346 This subclause is new to Ada 95.
3347 @end{DiffWord83}
3348
3349 @begin{DiffWord95}
3350 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00231-01],ARef=[AI95-00254-01]}
3351 @ChgAdded{Version=[2],Text=[Added static matching rules for null exclusions
3352 and anonymous access-to-subprogram types; both of these are new.]}
3353
3354 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00311-01]}
3355 @ChgAdded{Version=[2],Text=[We clarify that the constraint of the first
3356 subtype of a scalar formal type statically matches itself.]}
3357 @end{DiffWord95}
3358
3359 @begin{Incompatible2005}
3360 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0086-1]}
3361 @ChgAdded{Version=[3],Text=[@Defn{incompatibilities with Ada 2005}@b<Correction:>
3362 Updated the statically compatible rules to take null exclusions into account.
3363 This is technically incompatible, as it could cause a legal Ada 2005 program
3364 to be rejected; however, such a program violates the intent of the rules
3365 (for instance, @RefSecNum{Discriminants}(15)) and this probably will simply
3366 detect bugs.]}
3367 @end{Incompatible2005}
3368
3369 @begin{DiffWord2005}
3370 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0153-3],ARef=[AI05-0290-1]}
3371 @ChgAdded{Version=[3],Text=[Modified static matching and static compatibility
3372 to take predicate aspects (see @RefSecNum{Subtype Predicates}) into account.]}
3373 @end{DiffWord2005}
3374
3375 @begin{DiffWord2012}
3376 @ChgRef{Version=[4],Kind=[AddedNormal],ARef=[AI12-0071-1]}
3377 @ChgAdded{Version=[4],Text=[@b<Corrigendum:> Updated wording of
3378 static compatibility to use the new term "satisfies the predicates"
3379 (see @RefSecNum{Subtype Predicates}).]}
3380
3381 @ChgRef{Version=[5],Kind=[AddedNormal],ARef=[AI12-0059-1]}
3382 @ChgAdded{Version=[5],Text=[Updated wording to take nonconfirming values of
3383 Object_Size into account.]}
3384 @end{Diffword2012}
3385
3386
3387
3388 @LabeledAddedClause{Version=[5],Name=[Image Attributes]}
3389
3390
3391 @begin{Intro}
3392 @ChgRef{Version=[5],Kind=[AddedNormal],ARef=[AI12-0315-1]}
3393 @ChgAdded{Version=[5],Text=[An @i{image} of a value is a string representing
3394 the value in display form.@Defn2{Term=[image], Sec=(of a value)}
3395 The attributes Image, Wide_Image, and Wide_Wide_Image are available
3396 to produce the image of a value as a String, Wide_String, or
3397 Wide_Wide_String (respectively). User-defined images for a given type
3398 can be implemented by overriding the default implementation of the
3399 attribute Put_Image.]}
3400 @end{Intro}
3401
3402 @begin{StaticSem}
3403
3404 @ChgRef{Version=[5],Kind=[AddedNormal],ARef=[AI12-0020-1],ARef=[AI12-0315-1]}
3405 @ChgAdded{Version=[5],Type=[Leading],Keepnext=[T],Text=[For @PrefixType{every
3406 subtype S of a type T other than @i{universal_real} or @i{universal_fixed}},
3407 the following type-related operational attribute is defined:]}
3408
3409 @begin(description)
3410
3411 @ChgAttribute{Version=[5],Kind=[AddedNormal],ChginAnnex=[T],
3412 Leading=<T>, Prefix=<S>, AttrName=<Put_Image>, ARef=[AI12-0020-1], ARef=[AI12-0320-1], ARef=[AI12-0340-1],
3413 InitialVersion=[5], Text=[@Chg{Version=[5],New=[S'Put_Image denotes a
3414 procedure with the following specification:],Old=[]}
3415 @begin(Descexample)
3416 @ChgRef{Version=[5],Kind=[Added]}
3417 @ChgAdded{Version=[5],Text=[@b(procedure) S'Put_Image
3418 (@RI(Buffer) : @key[in out] Ada.Strings.Text_Buffers.Root_Buffer_Type'Class;
3419 @RI(Arg) : @key[in] T);]}
3420 @end(Descexample)
3421 @Comment{These two paragraphs have to be Added rather than AddedNormal so that
3422 the paragraphs in thee Annex have the correct paragraph numbers.}
3423 @ChgRef{Version=[5],Kind=[Added],ARef=[AI12-0315-1],ARef=[AI12-0340-1]}
3424 @ChgAdded{Version=[5],NoPrefix=[T],Text=[The
3425 default implementation of S'Put_Image writes
3426 (using Wide_Wide_Put) an @i<image> of the value of
3427 @i<Arg>.]}]}@Comment{End of Annex text here.}
3428
3429 @EndPrefixType{}
3430 @end{Description}
3431
3432 @ChgRef{Version=[5],Kind=[AddedNormal],ARef=[AI12-0020-1]}
3433 @ChgAdded{Version=[5],NoPrefix=[T],Text=[The Put_Image attribute may be
3434 specified for any specific type T either via an @nt{attribute_definition_clause}
3435 or via an @nt{aspect_specification} specifying the Put_Image aspect of the
3436 type.@AspectDefn{Put_Image}]}
3437
3438 @ChgAspectDesc{Version=[5],Kind=[AddedNormal],Aspect=[Put_Image],
3439 Text=[@ChgAdded{Version=[5],Text=[Procedure to define the image of a
3440 given type.]}]}
3441
3442 @begin{Discussion}
3443 @ChgRef{Version=[5],Kind=[AddedNormal]}
3444 @ChgAdded{Version=[5],Text=[In contrast, the Image, Wide_Image, and
3445 Wide_Wide_Image attributes and their associated aspects can not be
3446 specified. The behavior of any of these attributes is defined in terms of
3447 calls to the corresponding Put_Image procedure, so changes in their
3448 behavior may be accomplished via a Put_Image specification.]}
3449
3450 @ChgRef{Version=[5],Kind=[AddedNormal]}
3451 @ChgAdded{Version=[5],Text=[In earlier versions of Ada, Image and related
3452 attributes were defined only for scalar types. The definition of these
3453 attributes is now very different, but there should be
3454 no change in the behavior of existing programs as a result of these
3455 changes.]}
3456 @end{Discussion}
3457
3458
3459 @ChgRef{Version=[5],Kind=[AddedNormal],ARef=[AI12-0020-1],ARef=[AI12-0340-1]}
3460 @ChgAdded{Version=[5],Type=[Leading],Text=[The behavior of the default
3461 implementation of S'Put_Image depends on the class of T. For
3462 an elementary type, the implementation is equivalent to:]}
3463 @begin{Example}
3464 @ChgRef{Version=[5],Kind=[AddedNormal]}
3465 @ChgAdded{Version=[5],Text=[@key[procedure] Scalar_Type'Put_Image
3466 (Buffer : @key[in out] Ada.Strings.Text_Buffers.Root_Buffer_Type'Class;
3467 Arg : @key[in] Scalar_Type) @key[is]
3468 @key[begin]
3469 Buffer.Wide_Wide_Put (@i{<described below>});
3470 @key[end] Scalar_Type'Put_Image;]}
3471 @end{Example}
3472
3473 @ChgRef{Version=[5],Kind=[AddedNormal]}
3474 @ChgAdded{Version=[5],Type=[Leading],Text=[where the Wide_Wide_String value
3475 written out to the stream is defined as follows:]}
3476
3477 @ChgRef{Version=[5],Kind=[AddedNormal],ARef=[AI12-0020-1]}
3478 @ChgAdded{Version=[5],Text=[For an integer type, the image written out is the
3479 corresponding decimal literal, without underlines, leading zeros, exponent, or
3480 trailing spaces, but with a single leading character that is either a minus
3481 sign or a space.]}
3482
3483 @begin{ImplNote}
3484 @ChgRef{Version=[5],Kind=[AddedNormal]}
3485 @ChgAdded{Version=[5],Text=[If the machine supports negative zeros for signed
3486 integer types, it is not specified whether " 0" or "-0" should be returned
3487 for negative zero. We don't have enough experience with such machines to
3488 know what is appropriate, and what other languages do. In any case, the
3489 implementation should be consistent.]}
3490 @end{ImplNote}
3491
3492 @begin{Discussion}
3493 @ChgRef{Version=[5],Kind=[AddedNormal]}
3494 @ChgAdded{Version=[5],Text=[We allow S'Put_Image when S is
3495 @i{universal_integer} or @i{root_integer}, because the details of the
3496 desired string do not depend on properties of an integer type. While
3497 S'Put_Image cannot be called directly for these types (as they cannot be
3498 named), it can be called as part of evaluating an Image attribute. Note
3499 that other rules of the language ensure that an implementation can evaluate
3500 any @i{universal_integer} attribute using type @i{root_integer}; therefore,
3501 Constraint_Error could be raised by the evaluation of an Image attribute
3502 if the value of the prefix is outside of the range of
3503 @i{root_integer}.]}
3504 @end{Discussion}
3505
3506 @ChgRef{Version=[5],Kind=[AddedNormal],ARef=[AI12-0020-1]}
3507 @ChgAdded{Version=[5],Text=[For an enumeration type, the image written out is
3508 either the corresponding identifier in upper case or the corresponding
3509 character literal (including the two apostrophes); neither leading nor
3510 trailing spaces are included. For a @i{nongraphic character} (a value of a
3511 character type that has no enumeration literal associated with it), the value
3512 is a corresponding language-defined name in upper case (for example, the image
3513 of the nongraphic character identified as @i{nul} is @exam{"NUL"} @em the
3514 quotes are not part of the image).@Defn{nongraphic character}]}
3515
3516 @begin{ImplNote}
3517 @ChgRef{Version=[5],Kind=[AddedNormal]}
3518 @ChgAdded{Version=[5],Text=[For an enumeration type T that has "holes"
3519 (caused by an enumeration_representation_clause), T'Put_Image should raise
3520 Program_Error if the value is one of the holes (which is a bounded error
3521 anyway, since holes can be generated only via uninitialized variables and
3522 similar things).]}
3523 @end{ImplNote}
3524
3525 @ChgRef{Version=[5],Kind=[AddedNormal],ARef=[AI12-0020-1]}
3526 @ChgAdded{Version=[5],Text=[For a floating point type, the image written out is
3527 a decimal real literal best approximating the value (rounded away from zero
3528 if halfway between) with a single leading character that is either a minus
3529 sign or a space, a single digit (that is nonzero unless the value is zero), a
3530 decimal point, S'Digits-1 (see @RefSecNum{Operations of Floating Point Types})
3531 digits after the decimal point (but one if
3532 S'Digits is one), an upper case E, the sign of the exponent (either + or -),
3533 and two or more digits (with leading zeros if necessary) representing the
3534 exponent. If S'Signed_Zeros is True, then the leading character is a minus sign
3535 for a negatively signed zero.]}
3536
3537 @begin{Honest}
3538 @ChgRef{Version=[5],Kind=[AddedNormal]}
3539 @ChgAdded{Version=[5],Text=[Leading zeros are present in the exponent only
3540 if necessary to make the exponent at least two digits.]}
3541 @end{Honest}
3542
3543 @begin{Reason}
3544 @ChgRef{Version=[5],Kind=[AddedNormal]}
3545 @ChgAdded{Version=[5],Text=[This image is intended to conform to that
3546 produced by Text_IO.Float_IO.Put in its default format.]}
3547 @end{Reason}
3548
3549 @begin{ImplNote}
3550 @ChgRef{Version=[5],Kind=[AddedNormal]}
3551 @ChgAdded{Version=[5],Text=[The rounding direction is specified here to
3552 ensure portability of output results.]}
3553 @end{ImplNote}
3554
3555 @begin{Reason}
3556 @ChgRef{Version=[5],Kind=[AddedNormal],ARef=[AI12-0315-1]}
3557 @ChgAdded{Version=[5],Text=[We do not allow S'Put_Image when S is
3558 @i{universal_real}, as the details of the desired string depend on the
3559 properties of the (specific) type of S. Specifically, @i{universal_real}
3560 does not have a defined value for S'Digits.]}
3561 @end{Reason}
3562
3563 @ChgRef{Version=[5],Kind=[AddedNormal],ARef=[AI12-0020-1]}
3564 @ChgAdded{Version=[5],Text=[For a fixed point type, the image written out is a
3565 decimal real literal best approximating the value (rounded away from zero if
3566 halfway between) with a single leading character that is either a minus sign
3567 or a space, one or more digits before the decimal point (with no redundant
3568 leading zeros), a decimal point, and
3569 S'Aft (see @RefSecNum{Operations of Fixed Point Types}) digits after the
3570 decimal point.]}
3571
3572 @begin{Reason}
3573 @ChgRef{Version=[5],Kind=[AddedNormal]}
3574 @ChgAdded{Version=[5],Text=[This image is intended to conform to that produced by
3575 Text_IO.Fixed_IO.Put.]}
3576 @end{Reason}
3577
3578 @begin{ImplNote}
3579 @ChgRef{Version=[5],Kind=[AddedNormal]}
3580 @ChgAdded{Version=[5],Text=[The rounding direction is specified here to
3581 ensure portability of output results.]}
3582
3583 @ChgRef{Version=[5],Kind=[AddedNormal]}
3584 @ChgAdded{Version=[5],Text=[For a machine that supports negative zeros,
3585 it is not specified whether " 0.000" or "-0.000" is returned. See
3586 corresponding comment above about integer types with signed zeros.]}
3587 @end{ImplNote}
3588
3589 @begin{Reason}
3590 @ChgRef{Version=[5],Kind=[AddedNormal],ARef=[AI12-0315-1]}
3591 @ChgAdded{Version=[5],Text=[We do not allow S'Put_Image when S is
3592 @i{universal_fixed}, as the details of the desired string depend on the
3593 properties of the (specific) type of S. Specifically, @i{universal_fixed}
3594 does not have a defined value for S'Aft.]}
3595 @end{Reason}
3596
3597 @ChgRef{Version=[5],Kind=[AddedNormal],ARef=[AI12-0020-1]}
3598 @ChgAdded{Version=[5],Text=[For an access type (named or anonymous), the image
3599 written out depends on whether the value is @key[null]. If it is @key[null],
3600 then the image is @exam{"NULL"}. Otherwise the image is a left parenthesis
3601 followed by @exam{"ACCESS"}, a space, and a sequence of graphic characters,
3602 other than space or right parenthesis, representing the location of the
3603 designated object, followed by a right parenthesis, as in @exam{"(ACCESS
3604 FF0012AC)"}.]}
3605
3606 @begin{Honest}
3607 @ChgRef{Version=[5],Kind=[AddedNormal],ARef=[AI12-0315-1]}
3608 @ChgAdded{Version=[5],Text=[S'Put_Image is defined for @i{universal_access},
3609 but it can never be called (as no legal @nt{prefix} of Image has that type,
3610 and that type cannot be named preventing direct calls).]}
3611 @end{Honest}
3612
3613 @ChgRef{Version=[5],Kind=[AddedNormal],ARef=[AI12-0020-1]}
3614 @ChgAdded{Version=[5],Text=<For an array type T, the default implementation of
3615 T'Put_Image generates an image based on (named, not positional) array
3616 aggregate syntax (with '[' and ']' as the delimiters) using calls to the
3617 Put_Image procedures of the index type(s) and the element type to generate
3618 images for values of those types.>}
3619
3620 @begin{Discussion}
3621 @ChgRef{Version=[5],Kind=[AddedNormal]}
3622 @ChgAdded{Version=[5],Text=[In general, the default implementation of
3623 T'Put_Image for a composite type will involve some sequence of calls to
3624 Wide_Wide_String'Write and calls to the Put_Image procedures of component
3625 types and, in the case of an array type, index types. The
3626 Wide_Wide_String'Write calls may pass in either literal values (e.g., "(",
3627 ")", "'(", " => ", or ", "), or other things (such as component names for
3628 record values, task_id images for tasks, or the Wide_Wide_Expanded_Name of
3629 the tag in the class-wide case).]}
3630 @end{Discussion}
3631
3632 @begin{Discussion}
3633 @ChgRef{Version=[5],Kind=[AddedNormal]}
3634 @ChgAdded{Version=[5],Type=[Leading],Text=[An array type might generate
3635 an image such as:]}
3636 @begin{Example}
3637 @ChgRef{Version=[5],Kind=[AddedNormal]}
3638 @ChgAdded{Version=[5],Text={[ 1 => [ 1 => [ 123 => True, 124 => False]
3639 2 => [ 123 => False, 124 => False]],
3640 2 => [ 1 => [ 123 => True, 124 => True],
3641 2 => [ 123 => True, 124 => False]]]}}
3642 @end{example}
3643 @ChgRef{Version=[5],Kind=[AddedNormal]}
3644 @ChgAdded{Version=[5],Text=[although perhaps with different white space
3645 and/or line breaking.]}
3646 @end{Discussion}
3647
3648 @ChgRef{Version=[5],Kind=[AddedNormal],ARef=[AI12-0020-1]}
3649 @ChgAdded{Version=[5],Text=[The case of a null array is handled specially, using
3650 ranges for index bounds and @exam{"<>"} as a syntactic component-value
3651 placeholder.]}
3652
3653 @begin{Discussion}
3654 @ChgRef{Version=[5],Kind=[AddedNormal]}
3655 @ChgAdded{Version=[5],Text=[This might generate an image such as
3656 @exam{"[ 1 .. 3 => [ 1 .. 0 => [ 1 .. 5 => <>]]]"}, where the use
3657 of "<>" (among other things) indicates that the overall array is a
3658 null array and has no actual elements.]}
3659 @end{Discussion}
3660
3661 @ChgRef{Version=[5],Kind=[AddedNormal],ARef=[AI12-0020-1]}
3662 @ChgAdded{Version=[5],Text=[The order in which components are written for a
3663 composite type is the same canonical order in which components of a composite
3664 type T are written out by the default implementation of T'Write.
3665 @Redundant[This is also the order that is used in determining the meaning of a
3666 positional aggregate of type T.]]}
3667
3668 @ChgRef{Version=[5],Kind=[AddedNormal],ARef=[AI12-0020-1]}
3669 @ChgAdded{Version=[5],Text=[For a class-wide type, the default implementation of
3670 T'Put_Image generates an image based on qualified expression syntax.
3671 Wide_Wide_String'Write is called with Wide_Wide_Expanded_Name of @i{Arg}'Tag.
3672 Then S'Put_Image is called, where S is the specific type identified by
3673 @i{Arg}'Tag.]}
3674
3675 @begin{ImplNote}
3676 @ChgRef{Version=[5],Kind=[AddedNormal]}
3677 @ChgAdded{Version=[5],Text=[This will typically require a dispatching
3678 call.]}
3679 @end{ImplNote}
3680
3681 @begin{Discussion}
3682 @ChgRef{Version=[5],Kind=[AddedNormal]}
3683 @ChgAdded{Version=[5],Type=[Leading],Text=[This might generate an image such as:]}
3684 @begin{Example}
3685 @ChgRef{Version=[5],Kind=[AddedNormal]}
3686 @ChgAdded{Version=[5],Text={SOME_PACKAGE.SOME_TAGGED_TYPE'
3687 (COMPONENT_1 => 123, COMPONENT_2 => 456)}}
3688 @end{Example}
3689 @ChgRef{Version=[5],Kind=[AddedNormal]}
3690 @ChgAdded{Version=[5],Text=[The parentheses in this case are generated by
3691 the call to Some_Tagged_Type'Put_Image.]}
3692 @end{Discussion}
3693
3694 @ChgRef{Version=[5],Kind=[AddedNormal],ARef=[AI12-0020-1]}
3695 @ChgAdded{Version=[5],Text=[For a type extension, the default implementation of
3696 T'Put_Image depends on whether there exists a noninterface ancestor of T
3697 (other than T itself) for which the Put_Image aspect has been
3698 @Redundant[explicitly] specified. If so, then T'Put_Image will generate an
3699 image based on extension aggregate syntax where the ancestor type of the
3700 extension aggregate is the nearest ancestor type whose Put_Image aspect has
3701 been specified.]}
3702
3703 @begin{Discussion}
3704 @ChgRef{Version=[5],Kind=[AddedNormal]}
3705 @ChgAdded{Version=[5],Text=[This might generate an image such as
3706 @exam{"(This Text Was User-Generated with C1 => 123, C2 => 456)"}
3707 where the "This Text was User-Generated" portion of the text was
3708 generated by the call to the user-specified Put_Image routine.]}
3709 @end{Discussion}
3710
3711 @ChgRef{Version=[5],Kind=[AddedNormal],ARef=[AI12-0020-1]}
3712 @ChgAdded{Version=[5],Text=[If no such ancestor exists, then the default
3713 implementation of T'Put_Image is the same as described below for an untagged
3714 record type.]}
3715
3716 @ChgRef{Version=[5],Kind=[AddedNormal],ARef=[AI12-0020-1]}
3717 @ChgAdded{Version=[5],Text=[For an untagged record type, a specific tagged
3718 record type other than a type extension which meets the criteria described in
3719 the previous paragraph, or a protected type, the default implementation of
3720 T'Put_Image generates an image based on (named, not positional) record
3721 aggregate syntax (except that for a protected type, the initial left
3722 parenthesis is followed by @exam{"PROTECTED with "}). Component names are
3723 displayed in upper case, following the rules for the image of an enumeration
3724 value. Component values are displayed via calls to the component type's
3725 Put_Image procedure.]}
3726
3727 @begin{Discussion}
3728 @ChgRef{Version=[5],Kind=[AddedNormal]}
3729 @ChgAdded{Version=[5],Type=[Leading],Text=[This might generate an image such as:]}
3730 @begin{Example}
3731 @ChgRef{Version=[5],Kind=[AddedNormal]}
3732 @ChgAdded{Version=[5],Text={"(FOO => [1 => 'c', 2 => 'a', 3 => 't'], BAR => TRUE)"}}
3733 @end{Example}
3734 @end{Discussion}
3735
3736 @ChgRef{Version=[5],Kind=[AddedNormal],ARef=[AI12-0020-1]}
3737 @ChgAdded{Version=[5],Text=[The image written out for a record having no
3738 components (including any interface type) is @exam{"(NULL@ RECORD)"}. The
3739 image written out for a componentless protected type is
3740 @exam{"(PROTECTED@ NULL@ RECORD)"}. In the case of a protected type T, a call to the default
3741 implementation of T'Put_Image begins only one protected (read-only) action.]}
3742
3743 @begin{ImplNote}
3744 @ChgRef{Version=[5],Kind=[AddedNormal]}
3745 @ChgAdded{Version=[5],Text=[The expected, but not required, implementation
3746 model for generating the image of a protected record involves the compiler
3747 producing a "helper" protected function which T'Put_Image would call. The
3748 result type of this function might be a null record; it is only a function
3749 because it does not need a write-lock, not because it returns a meaningful
3750 result.]}
3751
3752 @ChgRef{Version=[5],Kind=[AddedNormal]}
3753 @ChgAdded{Version=[5],Type=[Leading],Text=[The assertion in the following example
3754 should succeed:]}
3755 @begin{Example}
3756 @ChgRef{Version=[5],Kind=[AddedNormal]}
3757 @ChgAdded{Version=[5],Text=[@key[type] T1 (D1, D2 : Positive) @key[is record] ... @key[end record]; -- @examcom{untagged}
3758 @key[type] T2 (D : Positive) @key[is new] T1 (D1 => D, D2 => D);
3759 X : T2 (D => 123) := ... ;
3760 @key[pragma] Assert (X'Image /= T1(X)'Image);]}
3761 @end{Example}
3762 @end{ImplNote}
3763
3764 @ChgRef{Version=[5],Kind=[AddedNormal],ARef=[AI12-0020-1]}
3765 @ChgAdded{Version=[5],Text=[For an undiscriminated task type, the default
3766 implementation of T'Put_Image generates an image of the form @exam{"(TASK
3767 <task_id_image>)"} where <task_id_image> is the result obtained by calling
3768 Task_Identification.Image with the id of the given task and then passing that
3769 String to Characters.Conversions.To_Wide_Wide_String.]}
3770
3771 @ChgRef{Version=[5],Kind=[AddedNormal],ARef=[AI12-0020-1]}
3772 @ChgAdded{Version=[5],Type=[Leading],Text=[For a discriminated task type, the
3773 default implementation of T'Put_Image also includes discriminant values, as in:]}
3774 @begin{Example}
3775 @ChgRef{Version=[5],Kind=[AddedNormal]}
3776 @ChgAdded{Version=[5],Text=["(TASK <task_id_image> with D1 => 123, D2 => 456)"]}
3777 @end{Example}
3778
3779 @begin{Ramification}
3780 @ChgRef{Version=[5],Kind=[AddedNormal]}
3781 @ChgAdded{Version=[5],Text=[If T is an unchecked union type, then the
3782 default implementation of T'Put_Image will raise Program_Error.]}
3783 @end{Ramification}
3784
3785 @ChgRef{Version=[5],Kind=[AddedNormal],ARef=[AI12-0020-1]}
3786 @ChgAdded{Version=[5],Type=[Leading],Keepnext=[T],Text=[For @PrefixType{every
3787 subtype S of a type T}, the following attributes are defined:]}
3788
3789 @begin{Description}
3790
3791 @ChgAttribute{Version=[5],Kind=[AddedNormal],ChginAnnex=[T],
3792 Leading=<T>, Prefix=<S>, AttrName=<Wide_Wide_Image>, ARef=[AI12-0020-1], ARef=[AI12-0340-1],
3793 InitialVersion=[2], Text=[@Chg{Version=[5],New=[S'Wide_Wide_Image
3794 denotes a function with the following specification:],Old=[]}
3795 @begin(Descexample)
3796 @ChgRef{Version=[5],Kind=[Added]}
3797 @ChgAdded{Version=[5],Text=[@b(function) S'Wide_Wide_Image(@RI(Arg) : S'Base)
3798 @b(return) Wide_Wide_String]}
3799 @end(Descexample)
3800 @Comment{We have to use "Added" on these two so that the annex paragraph
3801 numbers come out correctly. Only the initial text gets overridden.}
3802 @ChgRef{Version=[5],Kind=[Added]}
3803 @ChgAdded{Version=[5],NoPrefix=[T],Text=[S'Wide_Wide_Image calls
3804 S'Put_Image passing @i<Arg>
3805 (which will typically store a sequence of character values
3806 in a text buffer) and then returns the result of retrieving the
3807 contents of that buffer with Wide_Wide_Get.]}]}@Comment{End of Annex text here.}
3808 @ChgRef{Version=[5],Kind=[AddedNormal]}
3809 @ChgAdded{Version=[5],Text=[The lower bound of the
3810 result is one.]}
3811
3812 @ChgAttribute{Version=[5],Kind=[AddedNormal],ChginAnnex=[T],
3813 Leading=<T>, Prefix=<S>, AttrName=<Wide_Image>, ARef=[AI12-0020-1], ARef=[AI12-0340-1],
3814 InitialVersion=[0], Text=[@Chg{Version=[5],New=[S'Wide_Image denotes a
3815 function with the following specification:],Old=[]}
3816 @Comment{We use an InitialVersion of 0 here so this item uses the existing
3817 paragraph numbers in the Annex. It will leave the prefix uninserted, but that
3818 will save a vast amount of messing around.}
3819 @begin(Descexample)
3820 @ChgRef{Version=[5],Kind=[AddedNormal]}
3821 @ChgAdded{Version=[5],Text=[@b(function) S'Wide_Image(@RI(Arg) : S'Base)
3822 @b(return) Wide_String]}
3823 @end(Descexample)
3824
3825 @ChgRef{Version=[5],Kind=[AddedNormal]}
3826 @ChgAdded{Version=[5],NoPrefix=[T],Text=[S'Wide_Image calls S'Put_Image
3827 passing @i<Arg> (which will typically store a sequence of character values
3828 in a text buffer) and then returns the result of retrieving the
3829 contents of that buffer with Wide_Get.]}]}@Comment{End of Annex text here.}
3830 @ChgAdded{Version=[5],Text=[The lower bound of the result is one.]}
3831
3832 @ChgAttribute{Version=[5],Kind=[AddedNormal],ChginAnnex=[T],
3833 Leading=<T>, Prefix=<S>, AttrName=<Image>, ARef=[AI12-0020-1], ARef=[AI12-0340-1],
3834 InitialVersion=[0], Text=[@Chg{Version=[5],New=[S'Image denotes a function
3835 with the following specification:],Old=[]}
3836 @Comment{We use an InitialVersion of 0 here so this item uses the existing
3837 paragraph numbers in the Annex. It will leave the prefix uninserted, but that
3838 will save a vast amount of messing around.}
3839 @begin(Descexample)
3840 @ChgRef{Version=[5],Kind=[AddedNormal]}
3841 @ChgAdded{Version=[5],Text=[@b(function) S'Image(@RI(Arg) : S'Base)
3842 @b(return) String]}
3843 @end(Descexample)
3844
3845 @ChgRef{Version=[5],Kind=[AddedNormal]}
3846 @ChgAdded{Version=[5],NoPrefix=[T],Text=[S'Image calls S'Put_Image
3847 passing @i<Arg> (which will typically store a sequence of character values
3848 in a text buffer) and then returns the result of retrieving the
3849 contents of that buffer with Get.]}]}@Comment{End of Annex text here.}
3850 @ChgAdded{Version=[5],Text=[The lower bound of the result is one.]}
3851
3852 @EndPrefixType{}
3853 @end(description)
3854
3855
3856 @ChgRef{Version=[5],Kind=[AddedNormal],ARef=[AI12-0124-1],ARef=[AI12-0020-1],ARef=[AI12-0315-1]}
3857 @ChgAdded{Version=[5],Type=[Leading],Keepnext=[T],Text=[For @PrefixType{a
3858 @nt{prefix} X of a type T other than @i{universal_real} or
3859 @i{universal_fixed}}, the following attributes are defined:]}
3860
3861 @begin(description)
3862 @ChgAttribute{Version=[5],Kind=[AddedNormal],ChginAnnex=[T],
3863 Leading=<F>, Prefix=<X>, AttrName=<Wide_Wide_Image>,
3864 InitialVersion=[5], ARef=[AI12-0124-1], ARef=[AI12-0020-1],
3865 Text=[@Chg{Version=[5],New=[X'Wide_Wide_Image denotes the result of
3866 calling function S'Wide_Wide_Image with @i<Arg> being X, where S is the
3867 nominal subtype of X.],Old=[]}]}
3868
3869 @ChgAttribute{Version=[5],Kind=[AddedNormal],ChginAnnex=[T],
3870 Leading=<F>, Prefix=<X>, AttrName=<Wide_Image>,
3871 InitialVersion=[5], ARef=[AI12-0124-1], ARef=[AI12-0020-1],
3872 Text=[@Chg{Version=[5],New=[X'Wide_Image denotes the result of
3873 calling function S'Wide_Image with @i<Arg> being X, where S is the
3874 nominal subtype of X.],Old=[]}]}
3875
3876 @ChgAttribute{Version=[5],Kind=[AddedNormal],ChginAnnex=[T],
3877 Leading=<F>, Prefix=<X>, AttrName=<Image>,
3878 InitialVersion=[5], ARef=[AI12-0124-1], ARef=[AI12-0020-1],
3879 Text=[@Chg{Version=[5],New=[X'Image denotes the result of
3880 calling function S'Image with @i<Arg> being X, where S is the
3881 nominal subtype of X.],Old=[]}]}
3882 @EndPrefixType{}
3883 @end(description)
3884
3885 @end{StaticSem}
3886
3887 @begin{ImplPerm}
3888
3889 @ChgRef{Version=[5],Kind=[AddedNormal],ARef=[AI12-0020-1]}
3890 @ChgAdded{Version=[5],Type=[Leading],Text=[An implementation may transform the
3891 image generated by the default implementation of S'Put_Image for a composite
3892 subtype S in the following ways:]}
3893
3894 @begin{Itemize}
3895
3896 @ChgRef{Version=[5],Kind=[AddedNormal]}
3897 @ChgAdded{Version=[5],Text=[If S is a composite subtype, the leading character
3898 of the image of a component value or index value is a space, and the
3899 immediately preceding character is an open parenthesis or bracket, then the
3900 space may be omitted. The same transformation is also permitted if the leading
3901 character of the component image is a space (in which case one of the two
3902 spaces may be omitted).]}
3903 @begin{Discussion}
3904 @ChgRef{Version=[5],Kind=[AddedNormal]}
3905 @ChgAdded{Version=[5],Text={This means that it is permitted to generate
3906 @exam{"[1 => 123, 2 => 456]"} instead of @exam{"[ 1 => 123, 2 => 456]"}.}}
3907 @end{Discussion}
3908
3909 @ChgRef{Version=[5],Kind=[AddedNormal]}
3910 @ChgAdded{Version=[5],Text=[If S is an array subtype, the low bound of the
3911 array in each dimension equals the low bound of the corresponding index
3912 subtype, and the array value is not a null array value, then positional
3913 array aggregate syntax may be used.]}
3914
3915 @begin{Discussion}
3916 @ChgRef{Version=[5],Kind=[AddedNormal]}
3917 @ChgAdded{Version=[5],Text={This means that it is permitted to
3918 generate @exam{"[TRUE, TRUE, FALSE]"} instead of
3919 @exam{"[ 1 => TRUE, 2 => TRUE, 3 => FALSE]"} if the low bound of the
3920 index subtype is one.}}
3921 @end{Discussion}
3922
3923 @ChgRef{Version=[5],Kind=[AddedNormal]}
3924 @ChgAdded{Version=[5],Text=[If S is an array subtype and the given value can
3925 be displayed using @nt{named_array_aggregate} syntax where some
3926 @nt{discrete_choice_list} identifies more than one index value by
3927 identifying a sequence of one or more ranges and values separated by
3928 vertical bars, then this image may be generated instead; this may involve
3929 the reordering of component values.]}
3930
3931 @begin{Discussion}
3932 @ChgRef{Version=[5],Kind=[AddedNormal]}
3933 @ChgAdded{Version=[5],Text={This means that it is permitted to
3934 generate @exam{"[ 1 .. 2 | 5 => TRUE, 3 .. 4 => FALSE]"} instead of
3935 @exam{"[ 1 => TRUE, 2 => TRUE, 3 => FALSE, 4 => FALSE, 5 => TRUE]"}.}}
3936 @end{Discussion}
3937
3938 @ChgRef{Version=[5],Kind=[AddedNormal]}
3939 @ChgAdded{Version=[5],Text=[Similarly, if S is a record subtype (or a
3940 discriminated type) and the given value can be displayed using named
3941 component association syntax where the length of some component_choice_list
3942 is greater than one, then this image may be generated instead; this may
3943 involve the reordering of component values.]}
3944
3945 @begin{Discussion}
3946 @ChgRef{Version=[5],Kind=[AddedNormal]}
3947 @ChgAdded{Version=[5],Text=[This means that it is permitted to generate
3948 @exam{"(F1 | F2 => TRUE)"} instead of
3949 @exam{"(F1 => TRUE, F2 => TRUE)"}.]}
3950 @end{Discussion}
3951
3952 @ChgRef{Version=[5],Kind=[AddedNormal],ARef=[AI12-0020-1],ARef=[AI12-0340-1]}
3953 @ChgAdded{Version=[5],Text=[Additional spaces (Wide_Wide_Characters with
3954 position 32), and calls to the New_Line operation of a text buffer, may be
3955 inserted to improve readability of the generated image.]}
3956
3957 @end{Itemize}
3958
3959 @ChgRef{Version=[5],Kind=[AddedNormal],ARef=[AI12-0304-1]}
3960 @ChgAdded{Version=[5],Text=[For each language-defined nonscalar type T,
3961 T'Put_Image may be specified.]}
3962
3963 @begin{Discussion}
3964 @ChgRef{Version=[5],Kind=[AddedNormal]}
3965 @ChgAdded{Version=[5],Text=[This permission applies, in particular, to
3966 nonscalar types declared in language-defined generic packages,
3967 and to any language-defined private type, even if an implementation
3968 chooses to complete it as a scalar type.]}
3969 @end{Discussion}
3970
3971 @begin{Ramification}
3972 @ChgRef{Version=[5],Kind=[AddedNormal]}
3973 @ChgAdded{Version=[5],Text=[For any language-defined scalar type T, T'Put_Image should
3974 not be specified; the Image attribute needs to return the language-defined
3975 image for such types. This is important for compatibility: the Image
3976 attribute has been available for scalar types for many Ada revisions,
3977 and programs can (and do!) depend on its behavior.]}
3978 @end{Ramification}
3979
3980 @end{ImplPerm}
3981
3982 @begin{ImplReq}
3983
3984 @ChgRef{Version=[5],Kind=[AddedNormal],ARef=[AI12-0304-1]}
3985 @ChgAdded{Version=[5],Type=[Leading],Text=<For each language-defined container
3986 type T (that is, each of the Vector, List, Map, Set, Tree, and Holder types
3987 defined in the various children of Ada.Containers), T'Put_Image shall be
3988 specified so that T'Image produces a result consistent with array aggregate
3989 syntax (using '[' and ']' as delimiters) as follows:>}
3990
3991 @begin{Itemize}
3992 @ChgRef{Version=[5],Kind=[AddedNormal]}
3993 @ChgAdded{Version=[5],Text=[Vector images shall be consistent with the
3994 default image of an array type with the same index and component types.]}
3995
3996 @begin{Discussion}
3997 @ChgRef{Version=[5],Kind=[AddedNormal]}
3998 @ChgAdded{Version=[5],Text=[In particular, this means that the format is
3999 that of a named array aggregate. We have no recommendation on how to
4000 handle empty elements; if the implementation can identify them, it may
4001 wish to display them specially, but otherwise, they're just
4002 uninitialized elements.]}
4003 @end{Discussion}
4004
4005 @ChgRef{Version=[5],Kind=[AddedNormal]}
4006 @ChgAdded{Version=[5],Text=[Map images shall be consistent with named array
4007 aggregate syntax, using key value images in place of discrete choice names.
4008 For example, @exam{[Key1 => Value1, Key2 => Value2]}.]}
4009
4010 @begin{Discussion}
4011 @ChgRef{Version=[5],Kind=[AddedNormal]}
4012 @ChgAdded{Version=[5],Text=[There is no recommendation about the order
4013 in which key/element pairs occur within a map image. In the case of
4014 multiple key values whose corresponding element values have the same
4015 image, there is no recommendation about factoring (that is,
4016 generating @exam{Key1 | Key2 => Some_Value} instead of @exam{Key1 =>
4017 Some_Value, Key2 => Some_Value}).]}
4018 @end{Discussion}
4019
4020 @ChgRef{Version=[5],Kind=[AddedNormal]}
4021 @ChgAdded{Version=[5],Text=[Set, List, and Holder images shall be consistent
4022 with positional array aggregate syntax. List elements shall occur in order
4023 within an image of a list. The image of an empty holder shall be @exam{[]}.]}
4024
4025 @begin{Discussion}
4026 @ChgRef{Version=[5],Kind=[AddedNormal]}
4027 @ChgAdded{Version=[5],Text=[There is no recommendation about the order
4028 in which set elements occur within the image of a set.]}
4029 @end{Discussion}
4030
4031 @ChgRef{Version=[5],Kind=[AddedNormal]}
4032 @ChgAdded{Version=[5],Text=[Tree images (and images of subtrees of trees)
4033 shall be consistent with positional array aggregate syntax.
4034 For example, @exam{[[1, 2], [111, 222, 333]]}.]}
4035
4036 @end{Itemize}
4037
4038 @ChgRef{Version=[5],Kind=[AddedNormal],ARef=[AI12-0304-1]}
4039 @ChgAdded{Version=[5],Text=[For each language-defined nonscalar type T that has
4040 a primitive language-defined Image function whose profile is type conformant
4041 with that of T'Image (for example, Ada.Numerics.Float_Random.State has such an
4042 Image function), T'Put_Image shall be specified so that T'Image yields the same
4043 result as that Image function.]}
4044
4045 @end{ImplReq}
4046
4047 @begin{ImplAdvice}
4048
4049 @ChgRef{Version=[5],Kind=[AddedNormal]}
4050 @ChgAdded{Version=[5],Text=[For each language-defined private type T,
4051 T'Image should generate an image that would be meaningful based only on the
4052 relevant public interfaces, as opposed to requiring knowledge of the
4053 implementation of the private type.]}
4054
4055 @ChgImplAdvice{Version=[5],Kind=[AddedNormal],InitialVersion=[5],Text=[@ChgAdded{Version=[5],
4056 Text=[each language-defined private type T, T'Image should generate an image
4057 that would be meaningful based only on the relevant public interfaces.]}]}
4058
4059
4060 @end{ImplAdvice}
4061
4062
4063 @begin{Extend2012}
4064 @ChgRef{Version=[5],Kind=[AddedNormal],ARef=[AI12-0020-1],ARef=[AI12-0315-1],ARef=[AI12-0340-1]}
4065 @ChgAdded{Version=[5],Text=[@Defn{extensions to Ada 2012}Attribute
4066 Put_Image is new. Attributes Image, Wide_Image, and Wide_Wide_Image
4067 now can be used with any type, and are defined in terms of Put_Image so
4068 that they can be redefined.]}
4069 @end{Extend2012}
4070