Debian Codegraph @

source_2012/04a.mss

raw
1 @Part(04, Root="ada.mss")
2
3 @Comment{$Date: 2016/02/09 04:55:40 $}
4 @LabeledSection{Names and Expressions}
5
6 @Comment{$Source: e:\\cvsroot/ARM/Source/04a.mss,v $}
7 @Comment{$Revision: 1.140 $}
8
9 @begin{Intro}
10 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0299-1]}
11 @Redundant[The rules applicable to the different forms of @nt<name> and
12 expression, and to their evaluation, are given in this
13 @Chg{Version=[3],New=[clause],Old=[section]}.]
14 @end{Intro}
15
16 @LabeledClause{Names}
17
18 @begin{Intro}
19 @redundant[@nt<Name>s can denote declared entities, whether declared explicitly
20 or implicitly (see @RefSecNum(Declarations)). @nt<Name>s can also
21 denote objects or subprograms designated by access values; the
22 results of @nt<type_conversion>s or @nt<function_call>s; subcomponents
23 and slices of objects and values; protected subprograms,
24 single entries, entry families,
25 and entries in families of entries.
26 Finally, @nt<name>s can denote attributes of any of the foregoing.]
27 @end{Intro}
28
29 @begin{Syntax}
30 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0003-1],ARef=[AI05-0139-2]}
31 @Syn{tabs=[P22], lhs=<name>,rhs="
32 @Syn2{direct_name}@\| @Syn2{explicit_dereference}
33 | @Syn2{indexed_component}@\| @Syn2{slice}
34 | @Syn2{selected_component}@\| @Syn2{attribute_reference}
35 | @Syn2{type_conversion}@\| @Syn2{function_call}
36 | @Syn2{character_literal}@Chg{Version=[3],New=[@\| @Syn2{qualified_expression}
37 | @Syn2{generalized_reference}@\| @Syn2{generalized_indexing}],Old=[]}"}
38
39
40 @Syn{lhs=<direct_name>,
41 rhs="@Syn2{identifier} | @Syn2{operator_symbol}"}
42 @begin{Discussion}
43 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00114-01]}
44 @nt<character_literal> is no longer a @nt<direct_name>.
45 @nt<character_literal>s are usable even when the corresponding
46 @Chg{Version=[2],New=[enumeration type
47 declaration],Old=[@ntf<enumeration_type_declaration>]} is not visible. See
48 @RefSecNum(Literals).
49 @end{Discussion}
50
51 @Syn{lhs=<prefix>,rhs="@Syn2{name} | @Syn2{implicit_dereference}"}
52
53 @Syn{lhs=<explicit_dereference>,rhs="@Syn2{name}.@key{all}"}
54
55 @Syn{lhs=<implicit_dereference>,rhs="@Syn2{name}"}
56
57 @end{Syntax}
58
59 @begin{Intro}
60 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0004-1]}
61 @Redundant[Certain forms of @nt<name> (@nt<indexed_component>s,
62 @nt<selected_component>s, @nt<slice>s, and
63 @Chg{Version=[3],New=[@nt<attribute_reference>s],Old=[@ntf<attribute>s]})
64 include a @nt<prefix> that is either itself a @nt<name> that denotes
65 some related entity, or an @nt<implicit_dereference> of an access
66 value that designates some related entity.]
67 @end{Intro}
68
69 @begin{Resolution}
70 @Defn{dereference}
71 @PDefn2{Term=[expected type],
72 Sec=(dereference @nt{name})}
73 The @nt{name} in a @i(dereference) (either an
74 @nt<implicit_dereference> or an @nt<explicit_dereference>)
75 is expected to be of any access type.
76 @end{Resolution}
77
78 @begin{StaticSem}
79 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0008-1]}
80 @PDefn2{Term=[nominal subtype], Sec=(associated with a dereference)}
81 If the type of the @nt{name} in a dereference is some access-to-object
82 type @i(T), then the dereference denotes a view of an object, the
83 @i(nominal subtype) of the view being the designated subtype
84 of @i(T).@Chg{Version=[3],New=[ If the designated subtype has
85 unconstrained discriminants, the (actual) subtype of the view is constrained
86 by the values of the discriminants of the designated object, except when
87 there is a partial view of the type of the designated subtype that does not
88 have discriminants, in which case the dereference is not constrained by its
89 discriminant values.],Old=[]}
90 @begin{Ramification}
91 If the
92 value of the @nt<name> is the result of an access type conversion, the
93 dereference denotes a view created as part of the conversion.
94 The nominal subtype of the view is not necessarily
95 the same as that used to create the designated object.
96 See @RefSecNum{Type Conversions}.
97 @end{Ramification}
98 @begin{Honest}
99 @PDefn2{Term=[nominal subtype], Sec=(of a @nt<name>)}
100 We sometimes refer to the nominal subtype of a particular kind
101 of @nt<name> rather than the nominal subtype of the view denoted by
102 the @nt<name> (presuming the @nt<name> denotes a view of an object).
103 These two uses of nominal subtype are intended to mean the same
104 thing.
105 @end{Honest}
106
107 @begin{Reason}
108 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0008-1]}
109 @ChgAdded{Version=[3],Text=[The last sentence was not present in Ada 95;
110 it is necessary in Ada 2005 because general access types can designate
111 unconstrained objects, which was not possible in Ada 95. Thus, the rules
112 that had this effect in Ada 95 (the object being constrained by its initial
113 value) don't work in Ada 2005 and we have to say this explicitly.]}
114
115 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0008-1]}
116 @ChgAdded{Version=[3],Text=[The @ldquote@;except@rdquote@; part of the
117 last sentence prevents privacy
118 @ldquote@;breaking@rdquote@;, so that
119 if a private type has discriminants only in the full view, they don't
120 interfere with freely interassigning values between objects of the type,
121 even when the objects live in the heap.]}
122 @end{Reason}
123 @begin{ImplNote}
124 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0008-1]}
125 @ChgAdded{Version=[3],Text=[Since we don't depend on whether the designated
126 object is constrained, it is not necessary to include a constrained
127 bit in every object that could be designated by a general access type.]}
128 @end{ImplNote}
129
130 @PDefn2{Term=[profile], Sec=(associated with a dereference)}
131 If the type of the @nt<name> in a dereference is some access-to-subprogram
132 type @i(S), then the dereference denotes a view of a subprogram,
133 the @i(profile) of the view being the designated profile of @i(S).
134 @begin{Ramification}
135 This means
136 that the formal parameter names and default expressions to be used
137 in a call whose @nt<name> or @nt<prefix> is a dereference
138 are those of the designated profile, which need not be the same as those
139 of the subprogram designated by the access value, since 'Access
140 requires only subtype conformance, not full conformance.
141 @end{Ramification}
142 @end{StaticSem}
143
144 @begin{RunTime}
145 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00415-01]}
146 @PDefn2{Term=[evaluation], Sec=(name)}
147 The evaluation of a @nt<name> determines the entity denoted by the
148 @Chg{Version=[2],New=[@nt<name>],Old=[name]}. This evaluation has no other
149 effect for a @nt<name> that
150 is a @nt<direct_name> or a @nt<character_literal>.
151
152 @PDefn2{Term=[evaluation], Sec=(name that has a prefix)}
153 @Redundant[The evaluation of a @nt<name> that has a @nt<prefix> includes
154 the evaluation of the @nt<prefix>.]
155 @PDefn2{Term=[evaluation], Sec=(prefix)}
156 The evaluation of a @nt{prefix} consists of the evaluation of
157 the @nt{name} or the @nt{implicit_dereference}.
158 The @nt{prefix} denotes the entity denoted by the @nt{name} or the
159 @nt{implicit_dereference}.
160
161 @PDefn2{Term=[evaluation], Sec=(dereference)}
162 The evaluation of a dereference
163 consists of the evaluation of the @nt{name}
164 and the determination of the object or subprogram that is designated
165 by the value of the @nt{name}.
166 @IndexCheck{Access_Check}
167 A check is made that the value of the @nt{name} is not the null access
168 value.
169 @Defn2{Term=[Constraint_Error],Sec=(raised by failure of run-time check)}
170 Constraint_Error is raised if this check fails.
171 The dereference
172 denotes the object or subprogram designated by the value of the @nt{name}.
173 @end{RunTime}
174
175 @begin{Examples}
176 @Leading@keepnext@i(Examples of direct names:)
177 @begin(Example)
178 @tabclear()@tabset(P9, P47)
179 Pi @\@RI(-- the direct name of a number) @\(see @RefSecNum(Number Declarations))
180 Limit @\@RI(-- the direct name of a constant) @\(see @RefSecNum(Object Declarations))
181 Count @\@RI(-- the direct name of a scalar variable) @\(see @RefSecNum(Object Declarations))
182 Board @\@RI(-- the direct name of an array variable) @\(see @RefSecNum(Index Constraints and Discrete Ranges))
183 Matrix @\@RI(-- the direct name of a type) @\(see @RefSecNum(Array Types))
184 Random @\@RI(-- the direct name of a function) @\(see @RefSecNum(Subprogram Declarations))
185 Error @\@RI(-- the direct name of an exception) @\(see @RefSecNum(Exception Declarations))
186 @end(Example)
187
188 @begin{WideAbove}
189 @leading@keepnext@i{Examples of dereferences:}
190 @end{WideAbove}
191 @begin{Example}@tabclear()@tabset(P19)
192 Next_Car.@key[all]@\--@RI[ explicit dereference denoting the object designated by]
193 @\--@RI[ the access variable Next_Car (see @RefSecNum{Incomplete Type Declarations})]
194 Next_Car.Owner @\--@RI[ selected component with implicit dereference;]
195 @\--@RI[ same as Next_Car.@key[all].Owner]
196 @end{Example}
197 @end{Examples}
198
199 @begin{Extend83}
200 @Defn{extensions to Ada 83}
201 Type conversions and function calls are now considered names
202 that denote the result of the operation.
203 In the case of a type conversion used as an actual
204 parameter or that is of a tagged type, the type conversion is considered
205 a variable if the operand is a variable.
206 This simplifies the description of "parameters of the
207 form of a type conversion" as well as better supporting an
208 important OOP paradigm that requires the combination of a
209 conversion from a class-wide type to some specific
210 type followed immediately by component selection.
211 Function calls are considered names so that a type conversion
212 of a function call and the function call itself are treated
213 equivalently in the grammar.
214 A function call is considered the name of a constant,
215 and can be used anywhere such a name is permitted.
216 See @RefSecNum(Return Statements).
217
218 @ChgRef{Version=[1],Kind=[Revised]}@ChgNote{To be consistent with 8652/0006}
219 Type conversions of a tagged type are permitted anywhere
220 their operand is permitted. That is, if the operand
221 is a variable, then the type conversion can appear on the
222 left-hand side of an @nt{assignment_statement}.
223 If the operand is an object,
224 then the type conversion can appear in an object renaming
225 or as a @Chg{New=[@nt{prefix}],Old=[prefix]}.
226 See @RefSecNum(Type Conversions).
227 @end{Extend83}
228
229 @begin{DiffWord83}
230 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00114-01]}
231 Everything of the general syntactic form @nt{name}(...) is
232 now syntactically a @nt{name}. In any realistic parser,
233 this would be a necessity since distinguishing among the various
234 @nt{name}(...) constructs inevitably requires name resolution.
235 In cases where the construct yields a value rather than an object,
236 the name denotes @Chg{Version=[2],New=[a],Old=[the]} value rather than an
237 object. Names already denote values in Ada 83 with named numbers, components of
238 the result of a function call, etc. This is partly just a wording change, and
239 partly an extension of functionality (see Extensions heading above).
240
241 The syntax rule for @nt{direct_name} is new. It is used in places where
242 direct visibility is required.
243 It's kind of like Ada 83's @ntf{simple_name}, but @ntf{simple_name} applied
244 to both direct visibility and visibility by selection,
245 and furthermore, it didn't work right for @nt{operator_symbol}s.
246 The syntax rule for @ntf{simple_name} is removed,
247 since its use is covered by a combination of @nt{direct_name} and
248 @nt{selector_name}.
249 The syntactic categories @nt{direct_name} and @nt{selector_name} are similar;
250 it's mainly the visibility rules that distinguish the two.
251 The introduction of @nt{direct_name} requires the insertion of one new
252 explicit textual rule: to forbid @nt<statement_identifier>s from being
253 @nt<operator_symbol>s.
254 This is the only case where the explicit rule is needed,
255 because this is the only case where the declaration of the entity is
256 implicit.
257 For example, there is no need to syntactically forbid (say) @lquotes@;X: "Rem";@rquotes@;,
258 because it is impossible to declare a type whose name is an
259 @nt{operator_symbol} in the first place.
260
261 The syntax rules for @nt{explicit_dereference}
262 and @nt{implicit_dereference} are new;
263 this makes other rules simpler, since dereferencing an access value has
264 substantially different semantics from @nt{selected_component}s.
265 We also use @nt{name} instead of @nt{prefix} in the
266 @nt{explicit_dereference} rule
267 since that seems clearer. Note that these rules rely on the
268 fact that function calls are now names, so we don't need to
269 use prefix to allow functions calls in front of .@key{all}.
270 @begin{Discussion}
271 Actually, it would be reasonable to allow any @nt{primary} in front
272 of .@key{all}, since only the value is needed, but that would be a bit
273 radical.
274 @end{Discussion}
275
276 We no longer use the term @i(appropriate for a type)
277 since we now describe the semantics of a prefix in terms
278 of implicit dereference.
279 @end{DiffWord83}
280
281 @begin{Extend2005}
282 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0003-1]}
283 @ChgAdded{Version=[3],Text=[@Defn{extensions to Ada 2005}A
284 @nt{qualified_expression} is now a @nt{name} denoting a constant view;
285 this allows them to be used as a prefix and to be renamed as an object.
286 They are often used to remove ambiguity from function calls, and there
287 may be no other way to do that. Interestingly, a @nt{type_conversion} of
288 a @nt{qualified_expression} is already legal in these contexts, so this
289 change mainly reduces clutter by eliminating an otherwise unneeded
290 @nt{type_conversion} from some expressions.]}
291 @end{Extend2005}
292
293 @begin{DiffWord2005}
294 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0008-1]}
295 @ChgAdded{Version=[3],Text=[@b<Correction:> Added a missing rule so
296 that most dereferences are assumed constrained (without determining whether
297 the designated object is). This is just confirming the Ada 95 rules;
298 Ada 2005 failed to ensure that this property was unchanged.]}
299
300 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0139-2],ARef=[AI05-0299-1]}
301 @ChgAdded{Version=[3],Text=[Added @nt{generalized_reference} and
302 @nt{generalized_indexing} as types of @nt{name}; these are documented
303 as extensions in the appropriate subclauses.]}
304 @end{DiffWord2005}
305
306
307 @LabeledSubClause{Indexed Components}
308
309 @begin{Intro}
310 @Redundant[An @nt<indexed_component> denotes either
311 a component of an array or an entry
312 in a family of entries.
313 @IndexSee{Term=[array indexing],See=(indexed_component)}]
314 @end{Intro}
315
316 @begin{Syntax}
317 @Syn{lhs=<indexed_component>,rhs="@Syn2{prefix}(@Syn2{expression} {, @Syn2{expression}})"}
318 @end{Syntax}
319
320 @begin{Resolution}
321 The @nt{prefix} of an @nt{indexed_component} with a given
322 number of @nt<expression>s
323 shall resolve to denote an array (after any implicit dereference)
324 with the corresponding number of index positions,
325 or shall resolve to denote an entry family of a task or protected object
326 (in which case there shall be only one @nt<expression>).
327
328 @PDefn2{Term=[expected type], Sec=(indexed_component expression)}
329 The expected type for each @nt{expression} is the corresponding index type.
330
331 @end{Resolution}
332
333 @begin{StaticSem}
334 When the @nt<prefix> denotes an array,
335 the @nt<indexed_component> denotes the component of the
336 array with the specified index value(s).
337 @PDefn2{Term=[nominal subtype],
338 Sec=(associated with an @nt<indexed_component>)}
339 The nominal subtype of the @nt<indexed_component> is the
340 component subtype of the array type.
341 @begin{Ramification}
342 @ChgRef{Version=[2],Kind=[DeletedNoDelMsg],ARef=[AI95-00363-01]}
343 @ChgDeleted{Version=[2],Text=[In the case of an array whose components are
344 aliased, and
345 of an unconstrained discriminated subtype, the components
346 are constrained even though their nominal subtype is unconstrained.
347 (This is because all aliased discriminated objects are constrained.
348 See @RefSecNum(Operations of Access Types).)
349 In all other cases, an array component is constrained if and only
350 if its nominal subtype is constrained.]}
351 @end{Ramification}
352
353 When the @nt<prefix> denotes an entry family,
354 the @nt<indexed_component> denotes
355 the individual entry of the entry family with the specified index value.
356
357 @end{StaticSem}
358
359 @begin{RunTime}
360 @PDefn2{Term=[evaluation], Sec=(indexed_component)}
361 For the evaluation of an @nt<indexed_component>, the @nt{prefix} and the
362 @nt{expression}s are evaluated in an arbitrary order.@PDefn2{Term=[arbitrary order],Sec=[allowed]}
363 The value of
364 each @nt<expression> is converted to the corresponding index type.
365 @PDefn2{Term=[implicit subtype conversion],Sec=(array index)}
366 @IndexCheck{Index_Check}
367 A check is made that each index value
368 belongs to the corresponding index range of the array or entry family
369 denoted by the @nt<prefix>.
370 @Defn2{Term=[Constraint_Error],Sec=(raised by failure of run-time check)}
371 Constraint_Error is raised if this check fails.
372
373 @end{RunTime}
374
375 @begin{Examples}
376 @Leading@keepnext@i(Examples of indexed components:)
377 @begin{Example}
378 @tabclear()@tabset(P64)
379 My_Schedule(Sat) --@RI[ a component of a one-dimensional array @\(see @RefSecNum{Index Constraints and Discrete Ranges})]
380 Page(10) --@RI[ a component of a one-dimensional array @\(see @RefSecNum{Array Types})]
381 Board(M, J + 1) --@RI[ a component of a two-dimensional array @\(see @RefSecNum{Index Constraints and Discrete Ranges})]
382 Page(10)(20) --@RI[ a component of a component @\(see @RefSecNum{Array Types})]
383 Request(Medium) --@RI[ an entry in a family of entries @\(see @RefSecNum{Task Units and Task Objects})]
384 Next_Frame(L)(M, N) --@RI[ a component of a function call @\(see @RefSecNum{Subprogram Declarations})]
385 @end{Example}
386 @end{Examples}
387
388 @begin{Notes}
389 @i(Notes on the examples:)
390 Distinct notations are used for components of multidimensional arrays (such
391 as Board) and arrays of arrays (such as Page). The components of an array
392 of arrays are arrays and can therefore be indexed. Thus Page(10)(20)
393 denotes the 20th component of Page(10). In the last example Next_Frame(L)
394 is a function call returning an access value that designates a
395 two-dimensional array.
396
397 @end{Notes}
398
399 @LabeledSubClause{Slices}
400
401 @begin{Intro}
402 @redundant[@Defn{array slice}
403 A @nt<slice> denotes a one-dimensional array formed by a sequence of
404 consecutive components of a one-dimensional array. A @nt<slice> of
405 a variable is a variable; a @nt<slice> of a constant is a constant;]
406 a @nt<slice> of a value is a value.
407 @end{Intro}
408
409 @begin{Syntax}
410 @Syn{lhs=<slice>,rhs="@Syn2{prefix}(@Syn2{discrete_range})"}
411 @end{Syntax}
412
413 @begin{Resolution}
414 The @nt{prefix} of a @nt{slice}
415 shall resolve to denote a one-dimensional array
416 (after any implicit dereference).
417
418 @PDefn2{Term=[expected type], Sec=(slice discrete_range)}
419 The expected type for the @nt{discrete_range} of a @nt<slice>
420 is the index type of the array type.
421 @end{Resolution}
422
423 @begin{StaticSem}
424 A @nt<slice> denotes a one-dimensional array formed by the sequence of
425 consecutive components of the array denoted by the @nt<prefix>,
426 corresponding to the range of values
427 of the index given by the @nt<discrete_range>.
428
429 The type of the @nt<slice> is that of the @nt<prefix>.
430 Its bounds are those defined by the @nt{discrete_range}.
431
432 @end{StaticSem}
433
434 @begin{RunTime}
435 @PDefn2{Term=[evaluation], Sec=(slice)}
436 For the evaluation of a @nt{slice},
437 the @nt{prefix} and the @nt{discrete_range}
438 are evaluated in an arbitrary order.@PDefn2{Term=[arbitrary order],Sec=[allowed]}
439 @IndexCheck{Index_Check}
440 @Defn{null slice}
441 If the @nt{slice} is not a @i(null slice)
442 (a @nt<slice> where the @nt<discrete_range> is a null range),
443 then a check is made that the bounds of the @nt{discrete_range}
444 belong to the index range of the array denoted by the @nt{prefix}.
445 @Defn2{Term=[Constraint_Error],Sec=(raised by failure of run-time check)}
446 Constraint_Error is raised if this check fails.
447
448 @end{RunTime}
449
450 @begin{Notes}
451 A @nt<slice> is not permitted as the @nt<prefix> of an
452 Access @nt<attribute_reference>,
453 even if the components or the array as a whole are aliased.
454 See @RefSecNum(Operations of Access Types).
455 @begin{TheProof}
456 Slices are not aliased, by @RefSec{Access Types}.
457 @end{TheProof}
458 @begin(Reason)
459 This is to ease implementation of general-access-to-array.
460 If slices were aliased, implementations would need to store
461 array dope with the access values, which is not always desirable
462 given access-to-incomplete types completed in a package body.
463 @end(Reason)
464
465 For a one-dimensional array A, the @nt<slice> A(N .. N) denotes
466 an array that has only one component;
467 its type is the type of A. On the other hand, A(N) denotes a
468 component of the array A and has the corresponding component type.
469 @end{Notes}
470
471 @begin{Examples}
472 @Leading@keepnext@i(Examples of slices:)
473 @begin{Example}
474 @tabclear()@tabset(P58)
475 Stars(1 .. 15) --@RI[ a slice of 15 characters @\(see @RefSecNum{String Types})]
476 Page(10 .. 10 + Size) --@RI[ a slice of 1 + Size components @\(see @RefSecNum{Array Types})]
477 Page(L)(A .. B) --@RI[ a slice of the array Page(L) @\(see @RefSecNum{Array Types})]
478 Stars(1 .. 0) --@RI[ a null slice @\(see @RefSecNum{String Types})]
479 My_Schedule(Weekday) --@RI[ bounds given by subtype @\(see @RefSecNum{Index Constraints and Discrete Ranges} and @RefSecNum{Enumeration Types})]
480 Stars(5 .. 15)(K) --@RI[ same as Stars(K) @\(see @RefSecNum{String Types})]
481 --@RI[ provided that K is in 5 .. 15]
482 @end{Example}
483 @end{Examples}
484
485 @LabeledSubClause{Selected Components}
486
487 @begin{Intro}
488 @redundant[@nt{Selected_component}s are used to denote components (including
489 discriminants),
490 entries, entry families, and protected subprograms; they are
491 also used as expanded names as described below.
492 @IndexSee{Term=[dot selection],See=(selected_component)}]
493 @end{Intro}
494
495 @begin{Syntax}
496 @Syn{lhs=<selected_component>,rhs="@Syn2{prefix} . @Syn2{selector_name}"}
497
498
499 @Syn{lhs=<selector_name>,rhs="@Syn2{identifier} | @Syn2{character_literal} | @Syn2{operator_symbol}"}
500 @end{Syntax}
501
502 @begin{Resolution}
503 @Defn{expanded name}
504 A @nt<selected_component> is called an @i(expanded name)
505 if, according to the visibility rules, at least one possible
506 interpretation of its @nt<prefix> denotes
507 a package or an enclosing named construct (directly, not through
508 a @nt<subprogram_renaming_declaration>
509 or @nt<generic_renaming_declaration>).
510 @begin{Discussion}
511 See AI83-00187.
512 @end{Discussion}
513
514 @Leading@;A @nt{selected_component} that is not an expanded name
515 shall resolve to denote one of the following:
516 @begin(Ramification)
517 If the @nt<prefix> of a @nt<selected_component> denotes
518 an enclosing named construct, then the @nt<selected_component> is interpreted
519 only as an expanded name, even if the named construct
520 is a function that could be called without parameters.
521 @end(Ramification)
522 @begin{Itemize}
523 A component @Redundant[(including a discriminant)]:
524
525 @NoPrefix@;The @nt{prefix} shall resolve to denote an object or value of some
526 non-array composite type
527 (after any implicit dereference).
528 The @nt{selector_name} shall resolve to denote a
529 @nt{discriminant_specification} of the type, or, unless the type is
530 a protected type, a @nt<component_declaration>
531 of the type. The @nt{selected_component} denotes the
532 corresponding component of the object or value.
533 @begin{Reason}
534 @ChgRef{Version=[1],Kind=[Revised]}@ChgNote{Presentation AI-00015}
535 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0005-1]}
536 The components of a protected object cannot be named except
537 by an expanded name, even from within the corresponding protected body.
538 The protected body @Chg{Version=[3],New=[cannot],Old=[may not]} reference
539 @Chg{New=[],Old=[the ]}the private
540 components of some arbitrary object of the protected
541 type; the protected body may reference components of the current
542 instance only (by an expanded name or a @nt<direct_name>).
543 @end{Reason}
544 @begin{Ramification}
545 Only the discriminants and components visible at the place of the
546 @nt<selected_component> can be selected, since a @nt<selector_name>
547 can only denote declarations that are visible (see @RefSecNum{Visibility}).
548 @end{Ramification}
549
550 A single entry, an entry family, or a protected subprogram:
551
552 @NoPrefix@;The @nt{prefix} shall resolve to denote an object or value of some
553 task or protected type (after any implicit dereference).
554 The @nt{selector_name} shall resolve to denote an @nt{entry_declaration}
555 or @nt{subprogram_declaration} occurring (implicitly or explicitly)
556 within the visible part of that type.
557 The @nt{selected_component} denotes the
558 corresponding entry, entry family, or protected subprogram.
559 @begin{Reason}
560 This explicitly says @lquotes@;visible part@rquotes@; because even though the body
561 has visibility on the private part, it cannot call the
562 private operations of some arbitrary object of the task or protected
563 type, only those of the current instance (and expanded name notation
564 has to be used for that).
565 @end{Reason}
566
567 @ChgRef{Version=[2],Kind=[Added],ARef=[AI95-00252-01],ARef=[AI95-00407-01]}
568 @ChgAdded{Version=[2],Text=[A view of a subprogram whose first formal parameter is of
569 a tagged type or is an access parameter whose designated type is tagged:]}
570
571 @ChgRef{Version=[2],Kind=[Added],ARef=[AI95-00252-01],ARef=[AI95-00407-01]}
572 @ChgRef{Version=[3],Kind=[RevisedAdded],ARef=[AI05-0090-1]}
573 @ChgAdded{Version=[2],NoPrefix=[T],Text=[The @nt<prefix> (after any implicit
574 dereference) shall resolve to denote an object or value of a specific tagged
575 type @i<T> or class-wide type @i<T>'Class. The @nt<selector_name> shall resolve
576 to denote a view of a subprogram declared immediately within the declarative
577 region in which an ancestor of the type @i<T> is declared. The first formal
578 parameter of the subprogram shall be of type @i<T>, or a class-wide type that
579 covers @i<T>, or an access parameter designating one of these types. The
580 designator of the subprogram shall not be the same as that of a component of
581 the tagged type visible at the point of the @nt<selected_component>.
582 @Chg{Version=[3],New=[The subprogram shall not
583 be an implicitly declared primitive operation of type @i<T> that overrides
584 an inherited subprogram implemented by an entry or protected subprogram
585 visible at the point of the @nt{selected_component}. ],Old=[]}The
586 @nt<selected_component> denotes a view of this subprogram that omits the first
587 formal parameter. This view is called a @i{prefixed view} of the subprogram,
588 and the @nt{prefix} of the @nt<selected_component> (after any implicit
589 dereference) is called the @i<prefix> of the prefixed view.
590 @Defn{prefixed view}@Defn2{Term=[prefix],Sec=[of a prefixed view]}]}
591
592 @begin{Discussion}
593 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0090-1]}
594 @ChgAdded{Version=[3],Text=[The part of the rule that excludes a primitive
595 overriding subprogram as a selector applies only to the wrapper subprogram
596 that is implicitly declared to override a subprogram inherited from a
597 synchronized interface that is implemented by an operation of a task or
598 protected type (see @RefSecNum{Task Units and Task Objects} and
599 @RefSecNum{Protected Units and Protected Objects}). We don't want
600 calls that use a prefixed view to be ambiguous between the wrapper
601 subprogram and the implementing entry or protected operation. Note that
602 it is illegal to declare an explicit primitive that has a prefixed view
603 that is homographic with one of the type's operations, so
604 in normal cases it isn't possible to have an ambiguity in a prefix call.
605 However, a class-wide operation of an ancestor type that is declared in the
606 same declaration list with the ancestor type is also considered, and that
607 can still make a call ambiguous.]}
608 @end{Discussion}
609 @end{Itemize}
610
611 @Leading@;An expanded name shall resolve to denote a declaration that
612 occurs immediately within a named declarative region, as follows:
613 @begin(itemize)
614 The @nt<prefix> shall resolve to denote either a package @Redundant[(including
615 the current instance of a generic package, or a rename of a package)], or
616 an enclosing named construct.
617
618 The @nt{selector_name}
619 shall resolve to denote a declaration that occurs
620 immediately within the declarative region of the
621 package or enclosing construct @Redundant[(the declaration shall be visible
622 at the place of the expanded name @em see @RefSecNum(Visibility))].
623 The expanded name denotes that declaration.
624 @begin{Ramification}
625 Hence, a library unit or subunit can use an expanded
626 name to refer to the declarations within the private part of its
627 parent unit, as well as to other children that have been mentioned in
628 @nt<with_clause>s.
629 @end{Ramification}
630
631 If the @nt<prefix> does not denote a package, then it
632 shall be a @nt<direct_name> or an expanded name,
633 and it shall resolve to denote a program unit (other than a package),
634 the current instance of a type, a @nt{block_statement}, a @nt{loop_statement},
635 or an @nt{accept_@!statement}
636 (in the case of an @nt<accept_@!statement> or @nt<entry_@!body>,
637 no family index is allowed);
638 the expanded name shall occur within the
639 declarative region of this construct.
640 Further, if this construct is a callable construct
641 and the @nt<prefix> denotes more than one such enclosing callable construct,
642 then the expanded name is ambiguous, independently of the @nt<selector_name>.
643
644 @end(itemize)
645
646 @end{Resolution}
647
648 @begin{Legality}
649 @ChgRef{Version=[2],Kind=[Added],ARef=[AI95-00252-01],ARef=[AI95-00407-01]}
650 @ChgAdded{Version=[2],Text=[For a subprogram whose first parameter is an
651 access parameter, the prefix of any prefixed view shall denote an aliased
652 view of an object.]}
653
654 @ChgRef{Version=[2],Kind=[Added],ARef=[AI95-00407-01]}
655 @ChgAdded{Version=[2],Text=[For a subprogram whose first parameter is of mode
656 @b<in out> or @b<out>, or of an anonymous access-to-variable type, the prefix
657 of any prefixed view shall denote a variable.]}
658
659 @begin{Reason}
660 @ChgRef{Version=[2],Kind=[AddedNormal]}
661 @ChgAdded{Version=[2],Text=[We want calls through a prefixed view and through
662 a normal view to have the same legality. Thus, the implicit 'Access in
663 this new notation needs the same legality check that an explicit 'Access
664 would have. Similarly, we need to prohibit the object from being constant
665 if the first parameter of the subprogram is @key{in out}, because that is
666 (obviously) prohibited for passing a normal parameter.]}
667 @end{Reason}
668 @end{Legality}
669
670 @begin{RunTime}
671 @PDefn2{Term=[evaluation], Sec=(selected_component)}
672 The evaluation of a @nt{selected_component} includes the
673 evaluation of the @nt{prefix}.
674
675 @IndexCheck{Discriminant_Check}
676 For a @nt{selected_component} that denotes a component of a @nt{variant},
677 a check is made that the values of the discriminants are such that
678 the value or object denoted by the @nt<prefix> has this component.
679 @Defn2{Term=[Constraint_Error],Sec=(raised by failure of run-time check)}
680 @Defn2{Term=[Constraint_Error],Sec=(raised by failure of run-time check)}
681 The exception Constraint_Error is raised if this check fails.
682
683 @end{RunTime}
684
685 @begin{Examples}
686 @Leading@keepnext@i(Examples of selected components:)
687 @begin{Example}
688 @tabclear()@tabset(P60)
689 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00252-01],ARef=[AI95-00407-01]}
690 Tomorrow.Month --@RI[ a record component @\(see @RefSecNum{Record Types})]
691 Next_Car.Owner --@RI[ a record component @\(see @RefSecNum{Incomplete Type Declarations})]
692 Next_Car.Owner.Age --@RI[ a record component @\(see @RefSecNum{Incomplete Type Declarations})]
693 --@RI[ the previous two lines involve implicit dereferences]
694 Writer.Unit --@RI[ a record component (a discriminant) @\(see @RefSecNum{Variant Parts and Discrete Choices})]
695 Min_Cell(H).Value --@RI[ a record component of the result @\(see @RefSecNum{Subprogram Declarations})]
696 --@RI[ of the function call Min_Cell(H)]
697 @Chg{Version=[2],New=< Cashier.Append --@RI[ a prefixed view of a procedure @\(see @RefSecNum{Interface Types})]
698 >,Old=<>} Control.Seize --@RI[ an entry of a protected object @\(see @RefSecNum{Protected Units and Protected Objects})]
699 Pool(K).Write --@RI[ an entry of the task Pool(K) @\(see @RefSecNum{Protected Units and Protected Objects})]
700 @end{Example}
701
702 @begin{WideAbove}
703 @leading@keepnext@i(Examples of expanded names:)
704 @end{WideAbove}
705 @begin{Example}
706 @tabclear()@tabset(P67)
707 Key_Manager."<" --@RI[ an operator of the visible part of a package @\(see @RefSecNum{Private Operations})]
708 Dot_Product.Sum --@RI[ a variable declared in a function body @\(see @RefSecNum{Subprogram Declarations})]
709 Buffer.Pool --@RI[ a variable declared in a protected unit @\(see @RefSecNum{Example of Tasking and Synchronization})]
710 Buffer.Read --@RI[ an entry of a protected unit @\(see @RefSecNum{Example of Tasking and Synchronization})]
711 Swap.Temp --@RI[ a variable declared in a block statement @\(see @RefSecNum{Block Statements})]
712 Standard.Boolean --@RI[ the name of a predefined type @\(see @RefSecNum{The Package Standard})]
713 @end{Example}
714 @end{Examples}
715
716 @begin{Extend83}
717 @Defn{extensions to Ada 83}
718 We now allow an expanded name to use a prefix
719 that denotes a rename of a package, even if the
720 selector is for an entity local to the body or private
721 part of the package, so long as the entity is visible
722 at the place of the reference. This eliminates
723 a preexisting anomaly where references in a package
724 body may refer to declarations of its visible part
725 but not those of its private part or body when the
726 prefix is a rename of the package.
727 @end{Extend83}
728
729 @begin{DiffWord83}
730 The syntax rule for @nt{selector_name} is new. It is used in places where
731 visibility, but not necessarily direct visibility, is required.
732 See @RefSec{Names} for more information.
733
734 The description of dereferencing an access type has been moved
735 to @RefSec{Names}; @nt<name>.@key(all) is no longer considered
736 a @nt<selected_component>.
737
738 The rules have been restated to be consistent with our
739 new terminology, to accommodate class-wide types, etc.
740 @end{DiffWord83}
741
742 @begin{Extend95}
743 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00252-01]}
744 @ChgAdded{Version=[2],Text=[@Defn{extensions to Ada 95}The prefixed view notation
745 for tagged objects is new. This provides a similar notation to that used in other
746 popular languages, and also reduces the need for @nt{use_clause}s. This
747 is sometimes known as @lquotes@;distinguished receiver notation@rquotes@;.
748 @Defn{distinguished receiver notation}]}
749
750 @ChgRef{Version=[2],Kind=[AddedNormal]}
751 @ChgAdded{Version=[2],Type=[Leading],Text=[Given the following
752 definitions for a tagged type T:]}
753 @begin{Example}
754 @ChgRef{Version=[2],Kind=[AddedNormal]}
755 @ChgAdded{Version=[2],Text=[@key{procedure} Do_Something (Obj : @key{in out} T; Count : @key{in} Natural);
756 @key{procedure} Do_Something_Else (Obj : @key{access} T; Flag : @key{in} Boolean);
757 My_Object : @key{aliased} T;]}
758 @end{Example}
759 @ChgRef{Version=[2],Kind=[AddedNormal]}
760 @ChgAdded{Version=[2],Type=[Leading],Text=[the following calls are equivalent:]}
761 @begin{Example}
762 @ChgRef{Version=[2],Kind=[AddedNormal]}
763 @ChgAdded{Version=[2],Text=[Do_Something (My_Object, Count => 10);
764 My_Object.Do_Something (Count => 10);]}
765 @end{Example}
766 @ChgRef{Version=[2],Kind=[AddedNormal]}
767 @ChgAdded{Version=[2],Type=[Leading],Text=[as are the following calls:]}
768 @begin{Example}
769 @ChgRef{Version=[2],Kind=[AddedNormal]}
770 @ChgAdded{Version=[2],Text=[Do_Something_Else (My_Object'Access, Flag => True);
771 My_Object.Do_Something_Else (Flag => True);]}
772 @end{Example}
773 @end{Extend95}
774
775 @begin{DiffWord2005}
776 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0090-1]}
777 @ChgAdded{Version=[3],Text=[@b<Correction:> Corrected the definition of
778 a prefixed view to ignore the implicit subprograms declared for
779 @ldquote@;implemented by@rdquote entries and protected subprograms.]}
780 @end{DiffWord2005}
781
782
783 @RMNewPageVer{Version=[2]}@Comment{For printed version of Ada 2005 RM}
784 @LabeledSubClause{Attributes}
785
786 @begin{Intro}
787 @Defn{attribute}
788 @Redundant[An @i(attribute) is a characteristic of an entity that can be
789 queried via an @nt{attribute_@!reference}
790 or a @nt<range_@!attribute_@!reference>.]
791 @end{Intro}
792
793 @begin{Syntax}
794 @Syn{lhs=<attribute_reference>,
795 rhs="@Syn2{prefix}@SingleQuote@Syn2{attribute_designator}"}
796
797 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI05-0004-1]}
798 @Syn{lhs=<attribute_designator>,rhs="
799 @Syn2{identifier}[(@SynI{static_}@Syn2{expression})]
800 | Access | Delta | Digits@Chg{Version=[3],New=[ | Mod],Old=[]}"}
801
802
803 @Syn{lhs=<range_attribute_reference>,
804 rhs="@Syn2{prefix}@SingleQuote@Syn2{range_attribute_designator}"}
805
806 @Syn{lhs=<range_attribute_designator>,
807 rhs="Range[(@SynI{static_}@Syn2{expression})]"}
808 @end{Syntax}
809
810 @begin{Resolution}
811 In an @nt<attribute_reference>,
812 if the @nt<attribute_designator> is for an attribute defined
813 for (at least some) objects of an access type, then the @nt<prefix> is never
814 interpreted as an @nt<implicit_dereference>;
815 otherwise (and for all @nt<range_attribute_reference>s),
816 if the type of the @nt<name> within the @nt<prefix>
817 is of an access type, the @nt<prefix> is interpreted as an
818 @nt<implicit_dereference>.
819 Similarly, if the @nt{attribute_designator} is for an attribute defined for (at
820 least some) functions, then the @nt<prefix> is never interpreted as a
821 parameterless @nt{function_call}; otherwise
822 (and for all @nt<range_attribute_reference>s), if the @nt<prefix>
823 consists of a @nt<name> that denotes a function, it is interpreted
824 as a parameterless @nt<function_call>.
825 @begin{Discussion}
826 The first part of this rule is essentially a "preference"
827 against implicit dereference, so that it is possible
828 to ask for, say, 'Size of an access object,
829 without automatically getting the size of the object designated
830 by the access object.
831 This rule applies to 'Access, 'Unchecked_Access, 'Size, and 'Address,
832 and any other attributes that are defined for at least some
833 access objects.
834
835 The second part of this rule implies that, for a parameterless function F,
836 F'Address is the address of F, whereas
837 F'Size is the size of the anonymous constant returned by F.
838
839 @ChgRef{Version=[1],Kind=[Revised]}@ChgNote{To be consistent with 8652/0006}
840 We normally talk in terms of expected type or profile for
841 name resolution rules, but we don't do this for attributes
842 because certain attributes are legal independent of the type
843 or the profile of the @Chg{New=[@nt{prefix}],Old=[prefix]}.
844
845 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00114-01]}
846 @ChgAdded{Version=[2],Type=[Leading],Text=[Other than the rules given above,
847 the @ResolutionName@;s for the @nt{prefix} of each attribute are defined as
848 @ResolutionTitle for that attribute. If no such rules are defined, then no
849 context at all should be used when resolving
850 the @nt{prefix}. In particular, any knowledge about the kind of entities
851 required must not be used for resolution unless that is required by
852 @ResolutionTitle. This matters in obscure cases;
853 for instance, given the following declarations:]}
854 @begin{Example}
855 @ChgRef{Version=[2],Kind=[AddedNormal]}
856 @ChgAdded{Version=[2],Text=[ @key[function] Get_It @key[return] Integer @key[is] ... -- @RI[(1)]
857 @key[function] Get_It @key[return] Some_Record_Type @key[is] ... -- @RI[(2)]]}
858 @end{Example}
859 @ChgRef{Version=[2],Kind=[AddedNormal]}
860 @ChgAdded{Version=[2],Type=[Leading],Text=[the following @nt{attribute_reference} cannot be
861 resolved and is illegal:]}
862 @begin{Example}
863 @ChgRef{Version=[2],Kind=[AddedNormal]}
864 @ChgAdded{Version=[2],Text=[ @key[if] Get_It'Valid @key[then]]}
865 @end{Example}
866 @ChgRef{Version=[2],Kind=[AddedNormal]}
867 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0005-1]}
868 @ChgAdded{Version=[2],Text=[even though the Valid attribute is only defined
869 for objects of scalar types, and thus cannot be applied to the result of
870 function (2). That information cannot be used to resolve the @nt{prefix}.
871 The same would be true if (2) @Chg{Version=[3],New=[had],Old=[was]} been
872 a procedure; even though the procedure does not denote an object, the
873 @nt{attribute_reference} is still illegal.]}
874 @end{Discussion}
875
876 @PDefn2{Term=[expected type],
877 Sec=(attribute_designator expression)}
878 @PDefn2{Term=[expected type],
879 Sec=(range_attribute_designator expression)}
880 The @nt{expression}, if any, in an
881 @nt{attribute_designator} or @nt{range_attribute_designator}
882 is expected to be of any integer type.
883 @end{Resolution}
884
885 @begin{Legality}
886 The @nt{expression}, if any, in an @nt{attribute_designator}
887 or @nt{range_attribute_designator} shall be static.
888 @end{Legality}
889
890 @begin{StaticSem}
891 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0006-1]}
892 @ChgRef{Version=[4],Kind=[Revised],ARef=[AI12-0032-1],ARef=[AI12-0159-1]}
893 An @nt{attribute_reference} denotes a
894 value, an object, a subprogram, or some
895 other kind of program entity.@Chg{Version=[3],New=[
896 @Chg{Version=[4],New=[Unless explicitly specified otherwise, for],Old=[For]}
897 an @nt{attribute_reference} that denotes a value or an object, if
898 its type is scalar, then its nominal subtype is the base subtype of
899 the type; if its type is tagged, its nominal subtype is the first
900 subtype of the type; otherwise, its nominal subtype is a subtype of the type
901 without any constraint@Chg{Version=[4],New=[,],Old=[ or]}
902 @nt{null_exclusion}@Chg{Version=[4],New=[, or predicate],Old=[]}.
903 Similarly, unless explicitly specified otherwise, for an
904 @nt{attribute_reference} that denotes a function, when its result
905 type is scalar, its result subtype is the base subtype of the type,
906 when its result type is tagged, the result subtype is the first
907 subtype of the type, and when the result type is some other type,
908 the result subtype is a subtype of the type without any
909 constraint@Chg{Version=[4],New=[,],Old=[ or]}
910 @nt{null_exclusion}@Chg{Version=[4],New=[, or predicate],Old=[]}.],Old=[]}
911 @begin{Ramification}
912 The attributes defined by the language are summarized in
913 @RefSecNum{Language-Defined Attributes}.
914 Implementations can define additional attributes.
915 @end{Ramification}
916 @begin{Discussion}
917 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0006-1]}
918 @ChgAdded{Version=[3],Text=[The nominal subtype is primarily
919 a concern when an @nt{attribute_reference}, or
920 a call on an @nt{attribute_reference}, is used as the @nt{expression}
921 of a case statement, due to the full coverage requirement based on
922 the nominal subtype. For nondiscrete cases, we define the
923 nominal subtype mainly for completeness. Implementations may
924 specify otherwise for implementation-defined attribute functions.]}
925
926 @ChgRef{Version=[3],Kind=[AddedNormal]}
927 @ChgAdded{Version=[3],Text=[The rule is written to match the meaning
928 of the italicized @i{T} in the definition of attributes such as Input;
929 see @RefSecNum{Logical Operators and Short-circuit Control Forms}.]}
930 @end{Discussion}
931 @begin{Honest}
932 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0006-1]}
933 @ChgAdded{Version=[3],Text=[We don't worry about the fact that
934 @ldquote@;base subtype@rdquote is not explicitly defined for the
935 universal types. Since it is
936 not possible to constrain a universal numeric type, all subtypes
937 are unconstrained, and hence can be considered base subtypes.
938 The wording above could be altered to bypass this issue, but it
939 doesn't seem necessary, since universal integer is handled
940 specially in the rules for case expression full coverage, and
941 we don't allow user-defined functions for attribute functions
942 whose result type is universal.]}
943 @end{Honest}
944
945 @Redundant[A @nt{range_attribute_reference}
946 X'Range(N) is equivalent to the @nt<range> X'First(N) ..
947 X'Last(N), except that the @nt{prefix} is only evaluated once.
948 Similarly,
949 X'Range is equivalent to X'First .. X'Last, except that the @nt{prefix}
950 is only evaluated once.]
951
952 @end{StaticSem}
953
954 @begin{RunTime}
955 @PDefn2{Term=[evaluation], Sec=(attribute_reference)}
956 @PDefn2{Term=[evaluation], Sec=(range_attribute_reference)}
957 The evaluation of an @nt{attribute_reference}
958 (or @nt{range_attribute_reference}) consists
959 of the evaluation of the @nt{prefix}.
960 @end{RunTime}
961
962 @begin{ImplPerm}
963 @ChgRef{Version=[1],Kind=[Revised],Ref=[8652/0015],ARef=[AI95-00093-01]}
964 An implementation may provide implementation-defined attributes;
965 the @nt{identifier} for an implementation-defined
966 attribute shall differ from those of the language-defined
967 attributes@Chg{New=[ unless supplied for compatibility with a previous edition of
968 this International Standard],Old=[]}.
969 @ImplDef{Implementation-defined attributes.}
970 @begin{Ramification}
971 They cannot be reserved words because reserved words are not legal
972 identifiers.
973
974 The semantics of implementation-defined attributes,
975 and any associated rules, are, of course, implementation defined.
976 For example, the implementation defines whether a given
977 implementation-defined attribute can be used in a static expression.
978
979 @ChgRef{Version=[1],Kind=[Added],Ref=[8652/0015],ARef=[AI95-00093-01]}
980 @Chg{New=[Implementations are allowed to support the Small attribute for
981 floating types, as this was defined in Ada 83, even though the name would
982 conflict with a language-defined attribute.],Old=[]}
983 @end{Ramification}
984 @end{ImplPerm}
985
986 @begin{Notes}
987 Attributes are defined throughout this International Standard,
988 and are summarized in
989 @RefSecNum{Language-Defined Attributes}.
990
991 @ChgRef{Version=[1],Kind=[Revised]}@ChgNote{To be consistent with 8652/0006}
992 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00235]}
993 In general, the @nt<name> in a @nt<prefix> of an @nt<attribute_reference>
994 (or a @nt<range_attribute_reference>) has to be resolved
995 without using any context.
996 However, in the case of the Access attribute,
997 the expected type for the @Chg{Version=[2],New=[@nt{attribute_reference}],
998 Old=[@Chg{New=[@nt{prefix}],Old=[prefix]}]} has to be a
999 single access type, and@Chg{Version=[2],New=[],Old=[ if it is an
1000 access-to-subprogram type (see @RefSecNum(Operations of Access Types)) then]}
1001 the resolution of the @nt<name> can use the fact that
1002 the@Chg{Version=[2],New=[ type of the object or the],Old=[]} profile of the
1003 callable entity denoted by the @nt<prefix>
1004 has to @Chg{Version=[2],New=[match the designated type or ],Old=[]}be type
1005 conformant with the designated profile of the access type.
1006 @Defn2{Term=[type conformance],Sec=(required)}
1007 @begin(TheProof)
1008 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00235]}
1009 In the general case, there is no @lquotes@;expected type@rquotes@; for
1010 the @nt<prefix> of an @nt<attribute_reference>.
1011 In the special case of 'Access,
1012 there is an @Chg{Version=[2],New=[@lquotes@;expected type@rquotes@; or ],
1013 Old=[]}@lquotes@;expected profile@rquotes@; for the @nt<prefix>.
1014 @end(TheProof)
1015 @begin(Reason)
1016 'Access is a special case, because without it,
1017 it would be very difficult to take 'Access of an overloaded
1018 subprogram.
1019 @end(Reason)
1020 @end{Notes}
1021
1022 @begin{Examples}
1023 @Leading@keepnext@i(Examples of attributes:)
1024 @begin{Example}
1025 @tabclear()@tabset(P64)
1026 Color'First --@RI[ minimum value of the enumeration type Color @\(see @RefSecNum{Enumeration Types})]
1027 Rainbow'Base'First --@RI[ same as Color'First @\(see @RefSecNum{Enumeration Types})]
1028 Real'Digits --@RI[ precision of the type Real @\(see @RefSecNum{Floating Point Types})]
1029 Board'Last(2) --@RI[ upper bound of the second dimension of Board @\(see @RefSecNum{Index Constraints and Discrete Ranges})]
1030 Board'Range(1) --@RI[ index range of the first dimension of Board @\(see @RefSecNum{Index Constraints and Discrete Ranges})]
1031 Pool(K)'Terminated --@RI[ True if task Pool(K) is terminated @\(see @RefSecNum{Task Units and Task Objects})]
1032 Date'Size --@RI[ number of bits for records of type Date @\(see @RefSecNum{Record Types})]
1033 Message'Address --@RI[ address of the record variable Message @\(see @RefSecNum{Discriminant Constraints})]
1034 @end{Example}
1035 @end{Examples}
1036
1037 @begin{Extend83}
1038 @Defn{extensions to Ada 83}
1039 We now uniformly treat X'Range as X'First..X'Last,
1040 allowing its use with scalar subtypes.
1041
1042 We allow any integer type in the @SynI{static_}@nt{expression}
1043 of an attribute designator, not
1044 just a value of @i(universal_integer). The preference rules
1045 ensure upward compatibility.
1046 @end{Extend83}
1047
1048 @begin{DiffWord83}
1049 We use the syntactic category @nt{attribute_reference} rather
1050 than simply "attribute" to avoid confusing the name of something with
1051 the thing itself.
1052
1053 The syntax rule for @nt{attribute_reference}
1054 now uses @nt{identifier} instead of
1055 @ntf{simple_name}, because attribute @nt{identifier}s are not required to
1056 follow the normal visibility rules.
1057
1058 We now separate @nt{attribute_reference}
1059 from @nt{range_attribute_reference},
1060 and enumerate the reserved words that are legal attribute or range attribute
1061 designators.
1062 We do this because @nt{identifier} no longer includes reserved
1063 words.
1064
1065 The Ada 95 name resolution rules are a bit more explicit than in Ada 83.
1066 The Ada 83 rule said that the
1067 "meaning of the prefix of an attribute must be determinable
1068 independently of the attribute designator and independently
1069 of the fact that it is the prefix of an attribute." That isn't
1070 quite right since the meaning even in Ada 83 embodies whether or not
1071 the prefix is interpreted as a parameterless function call,
1072 and in Ada 95, it also embodies whether or not the prefix is interpreted
1073 as an implicit_dereference. So the attribute designator does
1074 make a difference @em just not much.
1075
1076 Note however that if the attribute designator is Access,
1077 it makes a big difference in the interpretation of the
1078 prefix (see @RefSecNum(Operations of Access Types)).
1079 @end{DiffWord83}
1080
1081 @begin{DiffWord95}
1082 @ChgRef{Version=[2],Kind=[AddedNormal],Ref=[8652/0015],ARef=[AI95-00093-01]}
1083 @ChgAdded{Version=[2],Text=[@b<Corrigendum:> The wording
1084 was changed to allow implementations to continue to implement the Ada 83
1085 Small attribute. This was always intended to be allowed.]}
1086
1087 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00235-01]}
1088 @ChgAdded{Version=[2],Text=[The note about resolving prefixes of attributes
1089 was updated to reflect that the prefix of an Access attribute now has an
1090 expected type (see @RefSecNum{Operations of Access Types}).]}
1091 @end{DiffWord95}
1092
1093 @begin{DiffWord2005}
1094 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0006-1]}
1095 @ChgAdded{Version=[3],Text=[@b<Correction:> Defined the nominal
1096 subtype of an @nt{attribute_reference} to close a minor language hole.]}
1097 @end{DiffWord2005}
1098
1099 @begin{DiffWord2012}
1100 @ChgRef{Version=[4],Kind=[AddedNormal],ARef=[AI12-0032-1]}
1101 @ChgAdded{Version=[4],Text=[@b<Corrigendum:> Allowed overriding the
1102 nominal subtype of an @nt{attribute_reference} for an object; that is used
1103 elsewhere in this standard.]}
1104
1105 @ChgRef{Version=[4],Kind=[AddedNormal],ARef=[AI12-0159-1]}
1106 @ChgAdded{Version=[4],Text=[@b<Corrigendum:> Added wording so it is clear that
1107 predicates don't apply to the result of an attribute.]}
1108 @end{DiffWord2012}
1109
1110
1111 @LabeledAddedSubClause{Version=[3],Name=[User-Defined References]}
1112
1113 @begin{StaticSem}
1114 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0139-2]}
1115 @ChgAdded{Version=[3],Type=[Leading],Text=[Given a discriminated type @i<T>,
1116 the following type-related operational aspect may be specified:]}
1117
1118 @begin{Description}
1119 @ChgRef{Version=[3],Kind=[AddedNormal]}
1120 @ChgAdded{Version=[3],Text=[Implicit_Dereference@\This aspect is specified by a
1121 @nt{name} that denotes an access discriminant declared for the
1122 type @i<T>.@AspectDefn{Implicit_Dereference}]}
1123
1124 @ChgAspectDesc{Version=[3],Kind=[AddedNormal],Aspect=[Implicit_Dereference],
1125 Text=[@ChgAdded{Version=[3],Text=[Mechanism for user-defined implicit .@key[all].]}]}
1126
1127 @end{Description}
1128
1129 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0139-2]}
1130 @ChgAdded{Version=[3],Text=[A (view of a) type with a specified
1131 Implicit_Dereference aspect is a @i{reference type}.@Defn{reference type}
1132 A @i{reference object} is an object of a reference type.@Defn{reference object}
1133 The discriminant named by the Implicit_Dereference aspect is the @i{reference
1134 discriminant} of the reference type or reference object.@Defn{reference discriminant}
1135 @Redundant[A @nt{generalized_reference} is a @nt{name} that identifies a
1136 reference object, and denotes the object or subprogram designated by the
1137 reference discriminant of the reference object.]]}
1138
1139 @ChgToGlossary{Version=[3],Kind=[Added],Term=<Reference type>,
1140 Text=<@ChgAdded{Version=[3],Text=[A reference type is one that has user-defined
1141 behavior for @ldquote.@key[all]@rdquote, defined by the
1142 Implicit_Dereference aspect.]}>}
1143 @end{StaticSem}
1144
1145 @begin{Syntax}
1146
1147 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0139-2]}
1148 @AddedSyn{Version=[3],lhs=<@Chg{Version=[3],New=<generalized_reference>,Old=<>}>,
1149 rhs="@Chg{Version=[3],New=<@SynI{reference_object_}@Syn2{name}>,Old=<>}"}
1150
1151 @end{Syntax}
1152
1153 @begin{Resolution}
1154
1155 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0139-2],ARef=[AI05-0269-1]}
1156 @ChgAdded{Version=[3],Text=[The expected type for the @SynI{reference_object_}@nt{name}
1157 in a @nt{generalized_reference} is any reference type.@PDefn2{Term=[expected type],
1158 Sec=(@SynI{reference_object_}@nt{name})}]}
1159 @end{Resolution}
1160
1161 @begin{StaticSem}
1162
1163 @ChgRef{Version=[4],Kind=[Added],ARef=[AI12-0138-1]}
1164 @ChgAdded{Version=[4],Text=[The Implicit_Dereference aspect
1165 is nonoverridable (see @RefSecNum{Aspect Specifications}).]}
1166
1167 @begin{Reason}
1168 @ChgRef{Version=[4],Kind=[AddedNormal]}
1169 @ChgAdded{Version=[4],Text=[This ensures that all descendants of a
1170 reference type have the same reference discriminant. This prevents
1171 generic contract problems with formal derived types.]}
1172 @end{Reason}
1173
1174
1175 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0139-2]}
1176 @ChgAdded{Version=[3],Text=[A @nt{generalized_reference} denotes a view
1177 equivalent to that of a dereference of the reference discriminant of the
1178 reference object.]}
1179
1180 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0139-2]}
1181 @ChgAdded{Version=[3],Text=[Given a reference type @i<T>, the
1182 Implicit_Dereference aspect is inherited by descendants of type @i<T> if not
1183 overridden. If a descendant type constrains the value of the reference
1184 discriminant of @i<T> by a new discriminant, that new discriminant is the
1185 reference discriminant of the descendant. @Redundant[If the descendant type
1186 constrains the value of the reference discriminant of @i<T> by an
1187 @nt{expression} other than the @nt{name} of a new discriminant, a
1188 @nt{generalized_reference} that identifies an object of the descendant type
1189 denotes the object or subprogram designated by the value of this constraining
1190 expression.]]}
1191
1192 @end{StaticSem}
1193
1194 @begin{RunTime}
1195
1196 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0139-2]}
1197 @ChgAdded{Version=[3],Text=[@PDefn2{Term=[evaluation], Sec=(generalized_reference)}
1198 The evaluation of a @nt{generalized_reference}
1199 consists of the evaluation of the @SynI{reference_object_}@nt{name} and
1200 a determination of the object or subprogram designated by the
1201 reference discriminant of the named reference object.
1202 @IndexCheck{Access_Check}
1203 A check is made that the value of the reference
1204 discriminant is not the null access value.
1205 @Defn2{Term=[Constraint_Error],Sec=(raised by failure of run-time check)}
1206 Constraint_Error is raised if this check fails. The
1207 @nt{generalized_reference} denotes the object or
1208 subprogram designated by the value of the reference discriminant of the
1209 named reference object.]}
1210
1211 @end{RunTime}
1212
1213 @begin{Examples}
1214 @begin{Example}
1215 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0268-1]}
1216 @ChgAdded{Version=[3],Text=[@key[type] Barrel @key[is tagged] ... -- @Examcom{holds objects of type Element}]}
1217
1218 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0139-2],ARef=[AI05-0299-1]}
1219 @ChgAdded{Version=[3],Text=[@key[type] Ref_Element(Data : @key[access] Element) @key[is limited private]
1220 @key[with] Implicit_Dereference => Data;
1221 -- @Examcom{This Ref_Element type is a "reference" type.}
1222 -- @ExamCom{"Data" is its reference discriminant.}]}
1223
1224 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0139-2],ARef=[AI05-0268-1]}
1225 @ChgAdded{Version=[3],Text=[@key[function] Find (B : @key[aliased in out] Barrel; Key : String) @key[return] Ref_Element;
1226 -- @Examcom{Return a reference to an element of a barrel.}]}
1227
1228 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0268-1],ARef=[AI05-0299-1]}
1229 @ChgAdded{Version=[3],Text=[B: @key[aliased] Barrel;]}
1230
1231 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0139-2]}
1232 @ChgAdded{Version=[3],Text=[...]}
1233
1234 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0139-2],ARef=[AI05-0268-1]}
1235 @ChgAdded{Version=[3],Text=[Find (B, "grape") := Element'(...); -- @Examcom{Assign through a reference.}]}
1236
1237 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0139-2],ARef=[AI05-0268-1]}
1238 @ChgAdded{Version=[3],Text=[-- @Examcom{This is equivalent to:}
1239 Find (B, "grape").Data.@key[all] := Element'(...);]}
1240
1241 @end{Example}
1242 @end{Examples}
1243
1244 @begin{Extend2005}
1245 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0139-2]}
1246 @ChgAdded{Version=[3],Text=[@Defn{extensions to Ada 2005}The aspect
1247 Implicit_Dereference and the @nt{generalized_reference} are new.]}
1248 @end{Extend2005}
1249
1250 @begin{Incompatible2012}
1251 @ChgRef{Version=[4],Kind=[AddedNormal],ARef=[AI12-0138-1]}
1252 @ChgAdded{Version=[4],Text=[@Defn{incompatibilities with Ada 2012}@b<Corrigendum:>
1253 Defined Implicit_Dereference to be nonoveridable, which makes redefinitions
1254 and hiding of the aspect illegal. It's possible that some program could
1255 violate one of these new restrictions, but this is not very likely as
1256 reference types are not likely to be used in a hierarchy.]}
1257 @end{Incompatible2012}
1258
1259
1260 @LabeledAddedSubClause{Version=[3],Name=[User-Defined Indexing]}
1261
1262 @begin{StaticSem}
1263
1264 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0139-2]}
1265 @ChgAdded{Version=[3],Type=[Leading],Text=[Given a tagged type @i<T>,
1266 the following type-related, operational aspects
1267 may be specified:]}
1268
1269 @begin{Description}
1270 @ChgRef{Version=[3],Kind=[AddedNormal]}
1271 @ChgAdded{Version=[3],Text=[Constant_Indexing@\This aspect shall be specified by
1272 a @nt{name} that denotes one or more functions declared immediately within the
1273 same declaration list in which @i<T> is declared. All such functions shall
1274 have at least two parameters, the first of which is of type @i<T> or
1275 @i<T>'Class, or is an access-to-constant parameter with designated type @i<T> or
1276 @i<T>'Class.@AspectDefn{Constant_Indexing}]}
1277
1278 @ChgAspectDesc{Version=[3],Kind=[AddedNormal],Aspect=[Constant_Indexing],
1279 Text=[@ChgAdded{Version=[3],Text=[Defines function(s) to implement
1280 user-defined @nt{indexed_component}s.]}]}
1281
1282 @ChgRef{Version=[3],Kind=[AddedNormal]}
1283 @ChgAdded{Version=[3],Text=[Variable_Indexing@\This aspect shall be specified
1284 by a @nt{name} that denotes one or more functions declared immediately within
1285 the same declaration list in which @i<T> is declared. All such functions
1286 shall have at least two parameters, the first of which is of type @i<T> or
1287 @i<T>'Class, or is an access parameter with designated type @i<T> or @i<T>'Class.
1288 All such functions shall have a return type that is a reference
1289 type (see @RefSecNum{User-Defined References}), whose reference discriminant
1290 is of an access-to-variable type.@AspectDefn{Variable_Indexing}]}
1291 @begin{Reason}
1292 @ChgRef{Version=[3],Kind=[AddedNormal]}
1293 @ChgAdded{Version=[3],Text=[We require these functions to return a reference
1294 type so that the object returned from the function can act like a variable.
1295 We need no similar rule for Constant_Indexing, since all functions return
1296 constant objects.]}
1297 @end{Reason}
1298
1299 @ChgAspectDesc{Version=[3],Kind=[AddedNormal],Aspect=[Variable_Indexing],
1300 Text=[@ChgAdded{Version=[3],Text=[Defines function(s) to implement
1301 user-defined @nt{indexed_component}s.]}]}
1302
1303 @end{Description}
1304
1305 @ChgRef{Version=[3],Kind=[AddedNormal]}
1306 @ChgRef{Version=[4],Kind=[Revised],ARef=[AI12-0104-1]}
1307 @ChgAdded{Version=[3],Text=[These aspects are inherited by descendants of @i<T>
1308 (including the class-wide type @i<T>'Class).@Chg{Version=[4],New=[],Old=[
1309 @Redundant[The aspects shall not be overridden, but the functions they denote
1310 may be.]]}]}
1311
1312 @begin{Ramification}
1313 @ChgRef{Version=[3],Kind=[AddedNormal]}
1314 @ChgAdded{Version=[3],Text=[Indexing can be provided for multiple index types
1315 by overloading routines with different parameter profiles. For instance, the
1316 map containers provide indexing on both cursors and keys by providing
1317 pairs of overloaded routines to the Constant_Indexing and Variable_Indexing
1318 aspects.]}
1319 @end{Ramification}
1320
1321 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0139-2],ARef=[AI05-0292-1]}
1322 @ChgAdded{Version=[3],Text=[An @i<indexable container type> is (a view of) a
1323 tagged type with at least one of the aspects Constant_Indexing or
1324 Variable_Indexing specified.@Defn{indexable container type}
1325 An @i<indexable container object> is an object of an indexable container
1326 type.@Defn{indexable container object} @Redundant[A @nt{generalized_indexing} is
1327 a @nt{name} that denotes the result of calling a function named by a
1328 Constant_Indexing or Variable_Indexing aspect.]]}
1329
1330 @ChgToGlossary{Version=[3],Kind=[Added],Term=<Indexable container type>,
1331 Text=<@ChgAdded{Version=[3],Text=[An indexable container type is one that has
1332 user-defined behavior for indexing, via the Constant_Indexing or
1333 Variable_Indexing aspects.]}>}
1334
1335 @ChgRef{Version=[4],Kind=[Added],ARef=[AI12-0138-1]}
1336 @ChgAdded{Version=[4],Text=[The Constant_Indexing and Variable_Indexing aspects
1337 are nonoverridable (see @RefSecNum{Aspect Specifications}).]}
1338
1339 @begin{Reason}
1340 @ChgRef{Version=[4],Kind=[AddedNormal]}
1341 @ChgAdded{Version=[4],Text=[This ensures that all descendants of an
1342 indexable container type have aspects with the same properties. This prevents
1343 generic contract problems with formal derived types.]}
1344
1345 @ChgRef{Version=[4],Kind=[AddedNormal],ARef=[AI12-0104-1],ARef=[AI12-0138-1]}
1346 @ChgAdded{Version=[4],Text=[A nonoverridable aspect allows the replacement
1347 of the implementation of an indexing function and the addition of a
1348 new indexing function for a derived type, but not the removal of an
1349 indexing function. This is necessary so that indexing can be used on
1350 objects of T'Class. So long as the tag of O is that of its nominal
1351 subtype, we do not want T'Class(O)(I) to mean something different
1352 than O(I). Thus we cannot allow a change in the function identified.
1353 As T'Class(O)(I) expands into a dispatching call, we need to ensure that
1354 there is a body for each such function -- but it is OK for that body to be
1355 changed from the original body (that's just normal dispatching).]}
1356 @end{Reason}
1357
1358 @begin{NotIso}
1359 @ChgAdded{Version=[4],Noparanum=[T],Text=[@Shrink{@i<Paragraphs 6 through 9
1360 were deleted.>}]}@Comment{This message should be
1361 deleted if the paragraphs are ever renumbered. Note that this is under the
1362 wrong heading, so that the heading can also be eliminated.}
1363 @end{NotIso}
1364
1365 @end{StaticSem}
1366
1367 @NotISORMNewPageVer{Version=[3]}@Comment{For printed version of Ada 2012 RM}
1368 @begin{Legality}
1369 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0139-2]}
1370 @ChgRef{Version=[4],Kind=[DeletedNoDelMsg],ARef=[AI12-0138-1]}
1371 @ChgDeleted{Version=[4],Type=[Leading],Text=[@Chg{Version=[3],New=[The
1372 Constant_Indexing or Variable_Indexing aspect shall not be specified:],Old=[]}]}
1373 @begin{Itemize}
1374 @ChgRef{Version=[3],Kind=[AddedNormal]}
1375 @ChgRef{Version=[4],Kind=[DeletedNoDelMsg]}
1376 @ChgDeleted{Version=[4],Text=[@Chg{Version=[3],New=[on a derived type
1377 if the parent type has the
1378 corresponding aspect specified or inherited; or],Old=[]}]}
1379
1380 @ChgRef{Version=[3],Kind=[AddedNormal]}
1381 @ChgRef{Version=[4],Kind=[DeletedNoDelMsg]}
1382 @ChgDeleted{Version=[4],Text=[@Chg{Version=[3],New=[on a
1383 @nt{full_type_declaration} if the type has
1384 a tagged partial view.],Old=[]}]}
1385 @end{Itemize}
1386 @ChgRef{Version=[3],Kind=[AddedNormal]}
1387 @ChgRef{Version=[4],Kind=[DeletedNoDelMsg]}
1388 @ChgDeleted{Version=[4],Text=[@Chg{Version=[3],New=[@PDefn{generic contract issue}
1389 In addition to the places where @LegalityTitle normally apply
1390 (see @RefSecNum{Generic Instantiation}),
1391 these rules apply also in the private part of an instance of a
1392 generic unit.],Old=[]}]}
1393
1394 @begin{Ramification}
1395 @ChgNote{The following notes were moved to @RefSecNum{Aspect Specifications}
1396 along with the rules (now part of the definition of "nonoverridable aspect").}
1397 @ChgRef{Version=[3],Kind=[AddedNormal]}
1398 @ChgRef{Version=[4],Kind=[DeletedNoDelMsg]}
1399 @ChgDeleted{Version=[4],Text=[@Chg{Version=[3],New=[In order to enforce
1400 these rules without breaking privacy, we cannot allow a tagged private type
1401 to have hidden indexing aspects. There is no problem if the private type
1402 is not tagged (as the indexing aspects cannot be specified on
1403 descendants in that case).],Old=[]}]}
1404
1405 @ChgRef{Version=[3],Kind=[AddedNormal]}
1406 @ChgRef{Version=[4],Kind=[DeletedNoDelMsg]}
1407 @ChgDeleted{Version=[4],Text=[@Chg{Version=[3],New=[We don't need
1408 an assume-the-worst rule as deriving from formal tagged types is not
1409 allowed in generic bodies.],Old=[]}]}
1410 @end{Ramification}
1411
1412 @end{Legality}
1413
1414 @begin{Syntax}
1415
1416 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0139-2],ARef=[AI05-0292-1]}
1417 @AddedSyn{Version=[3],lhs=<@Chg{Version=[3],New=<generalized_indexing>,Old=<>}>,
1418 rhs="@Chg{Version=[3],New=<@SynI{indexable_container_object_}@Syn2{prefix} @Syn2{actual_parameter_part}>,Old=<>}"}
1419
1420 @end{Syntax}
1421
1422 @begin{Resolution}
1423
1424 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0139-2],ARef=[AI05-0292-1]}
1425 @ChgAdded{Version=[3],Text=[The expected type for the
1426 @Syni{indexable_container_object_}@nt{prefix} of a @nt{generalized_indexing}
1427 is any indexable container type.@PDefn2{Term=[expected type],
1428 Sec=(@SynI{indexable_container_object_}@nt{prefix})}]}
1429
1430 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0139-2],ARef=[AI05-0292-1]}
1431 @ChgAdded{Version=[3],Type=[Leading],Text=[If the Constant_Indexing aspect is
1432 specified for the type of the @SynI{indexable_container_object_}@nt{prefix} of a
1433 @nt{generalized_indexing}, then the @nt{generalized_indexing} is interpreted as
1434 a @i<constant indexing> under the following
1435 circumstances:@Defn{constant indexing}@Defn2{Term=[indexing],Sec=[constant]}]}
1436
1437 @begin{Itemize}
1438
1439 @ChgRef{Version=[3],Kind=[AddedNormal]}
1440 @ChgAdded{Version=[3],Text=[when the Variable_Indexing aspect is not specified
1441 for the type of the @SynI{indexable_container_object_}@nt{prefix};]}
1442
1443 @ChgRef{Version=[3],Kind=[AddedNormal]}
1444 @ChgAdded{Version=[3],Text=[when the @SynI{indexable_container_object_}@nt{prefix}
1445 denotes a constant;]}
1446
1447 @ChgRef{Version=[3],Kind=[AddedNormal]}
1448 @ChgAdded{Version=[3],Text=[when the @nt{generalized_indexing} is used within
1449 a @nt{primary} where a @nt{name} denoting a constant is permitted.]}
1450
1451 @begin{Ramification}
1452 @ChgRef{Version=[3],Kind=[AddedNormal]}
1453 @ChgAdded{Version=[3],Text=[This means it is not interpreted as a
1454 constant indexing for the @SynI{variable_}@nt{name} in the LHS of an
1455 assignment (not inside a @nt{primary}), nor for the @nt{name} used
1456 for an @key[out] or @key[in out] parameter (not allowed to be
1457 a constant), nor for the @nt{name} in an object renaming
1458 (not inside a primary), unless
1459 there is no Variable_Indexing aspect defined.]}
1460 @end{Ramification}
1461
1462 @end{Itemize}
1463
1464 @ChgRef{Version=[3],Kind=[AddedNormal]}
1465 @ChgAdded{Version=[3],Text=[Otherwise, the @nt{generalized_indexing} is
1466 interpreted as a
1467 @i{variable indexing}.@Defn{variable indexing}@Defn2{Term=[indexing],Sec=[variable]}]}
1468
1469 @ChgRef{Version=[3],Kind=[AddedNormal]}
1470 @ChgAdded{Version=[3],Text=[When a @nt{generalized_indexing} is interpreted as a
1471 constant (or variable) indexing, it is equivalent to a call on a prefixed view
1472 of one of the functions named by the Constant_Indexing (or Variable_Indexing)
1473 aspect of the type of the @Syni{indexable_container_object_}@nt{prefix} with the given
1474 @nt{actual_parameter_part}, and with the @Syni{indexable_container_object_}@nt{prefix} as
1475 the @nt{prefix} of the prefixed view.]}
1476
1477 @begin{Ramification}
1478 @ChgRef{Version=[3],Kind=[AddedNormal]}
1479 @ChgAdded{Version=[3],Type=[Leading],Text=[In other words, the
1480 @nt{generalized_indexing} is equivalent to:]}
1481
1482 @begin{Example}
1483 @ChgRef{Version=[3],Kind=[AddedNormal]}
1484 @ChgAdded{Version=[3],Text=[@SynI{indexable_container_object_}@nt{prefix}.Indexing @nt{actual_parameter_part}]}
1485 @end{Example}
1486
1487 @ChgRef{Version=[3],Kind=[AddedNormal]}
1488 @ChgRef{Version=[4],Kind=[Revised],ARef=[AI12-0005-1]}
1489 @ChgAdded{Version=[3],Type=[Trailing],Text=[where Indexing is the @nt{name}
1490 specified for the Constant_Indexing or Variable_Indexing
1491 aspect.@Chg{Version=[4],New=[ This equivalence is then resolved in the
1492 normal way; the aspect specifies a @nt{name}, it does not denote
1493 declarations.],Old=[]}]}
1494 @end{Ramification}
1495
1496 @end{Resolution}
1497
1498 @begin{Notes}
1499 @ChgRef{Version=[4],Kind=[AddedNormal],ARef=[AI12-0104-1]}
1500 @ChgAdded{Version=[4],Text=[The Constant_Indexing and Variable_Indexing
1501 aspects cannot be redefined when inherited for a derived type, but the
1502 functions that they denote can be modified by overriding or overloading.]}
1503 @end{Notes}
1504
1505 @begin{Examples}
1506 @begin{Example}
1507
1508 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0268-1],ARef=[AI05-0292-1]}
1509 @ChgAdded{Version=[3],Text=[@key[type] Indexed_Barrel @key[is tagged] ...
1510 @key[with] Variable_Indexing => Find;
1511 -- @Examcom{Indexed_Barrel is an indexable container type,}
1512 -- @Examcom{Find is the generalized indexing operation.}]}
1513
1514 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0268-1]}
1515 @ChgAdded{Version=[3],Text=[@key[function] Find (B : @key[aliased in out] Indexed_Barrel; Key : String) @key[return] Ref_Element;
1516 -- @Examcom{Return a reference to an element of a barrel (see @RefSecNum{User-Defined References}).}]}
1517
1518 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0268-1]}
1519 @ChgAdded{Version=[3],Text=[IB: @key[aliased] Indexed_Barrel;]}
1520
1521 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0268-1]}
1522 @ChgAdded{Version=[3],Text=[-- @Examcom{All of the following calls are then equivalent:}
1523 Find (IB,"pear").Data.@key[all] := Element'(...); -- @Examcom{Traditional call}
1524 IB.Find ("pear").Data.@key[all] := Element'(...); -- @Examcom{Call of prefixed view}
1525 IB.Find ("pear") := Element'(...); -- @Examcom{Implicit dereference (see @RefSecNum{User-Defined References})}
1526 IB ("pear") := Element'(...); -- @Examcom{Implicit indexing and dereference}
1527 IB ("pear").Data.@key[all] := Element'(...); -- @Examcom{Implicit indexing only}]}
1528
1529 @end{Example}
1530 @end{Examples}
1531
1532 @begin{Extend2005}
1533 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0139-2]}
1534 @ChgAdded{Version=[3],Text=[@Defn{extensions to Ada 2005}Aspects
1535 Constant_Indexing and Variable_Indexing, and the @nt{generalized_indexing}
1536 syntax are new.]}
1537 @end{Extend2005}
1538
1539 @begin{DiffWord2012}
1540 @ChgRef{Version=[4],Kind=[AddedNormal],ARef=[AI12-0104-1]}
1541 @ChgAdded{Version=[4],Text=[@b<Corrigendum:> Converted confusing and
1542 unnecessary normative wording about "overriding an aspect" into a note.]}
1543
1544 @ChgRef{Version=[4],Kind=[AddedNormal],ARef=[AI12-0138-1]}
1545 @ChgAdded{Version=[4],Text=[@b<Corrigendum:>
1546 Defined Constant_Indexing and Variable_Indexing to be nonoveridable.
1547 This is merely a new description for @LegalityTitle which already applied
1548 to these aspects.]}
1549 @end{DiffWord2012}
1550
1551
1552 @NotISORMNewPageVer{Version=[3]}@Comment{For printed version of Ada 2012 RM}
1553 @LabeledClause{Literals}
1554
1555 @begin{Intro}
1556 @Redundant[@Defn{literal}
1557 A @i(literal) represents a value literally, that is, by means
1558 of notation suited to its kind.]
1559 A literal is either a @nt<numeric_literal>, a @nt<character_literal>,
1560 the literal @key(null), or a @nt<string_literal>.
1561 @IndexSeeAlso{Term=[constant],See=(literal)}
1562 @begin(Discussion)
1563 An enumeration literal that is an @nt<identifier>
1564 rather than a @nt<character_literal> is not considered a @i(literal)
1565 in the above sense, because it involves no special notation
1566 @lquotes@;suited to its kind.@rquotes@;
1567 It might more properly be called an @ntf<enumeration_identifier>,
1568 except for historical reasons.
1569 @end(Discussion)
1570 @end{Intro}
1571
1572 @begin{Resolution}
1573 @ChgRef{Version=[2],Kind=[Deleted],ARef=[AI95-00230-01]}
1574 @ChgDeleted{Version=[2],Text=[@PDefn2{Term=[expected type],Sec=(null literal)}
1575 The expected type for a literal @key(null) shall be a single
1576 access type.]}
1577 @begin{Discussion}
1578 @ChgRef{Version=[2],Kind=[DeletedNoDelMsg]}
1579 @ChgDeleted{Version=[2],Text=[This new wording ("expected type ... shall be a
1580 single ... type") replaces the old "shall be determinable" stuff. It reflects
1581 an attempt to simplify and unify the description of the rules for resolving
1582 aggregates, literals, type conversions, etc. See
1583 @RefSec{The Context of Overload Resolution} for the details.]}
1584 @end{Discussion}
1585
1586 @PDefn2{Term=[expected type],Sec=(character_literal)}
1587 @PDefn2{Term=[expected profile],Sec=(character_literal)}
1588 For a @nt<name> that consists of a @nt<character_literal>,
1589 either its expected type shall be a single character type, in which case
1590 it is interpreted as a parameterless @nt<function_call> that yields
1591 the corresponding value of the character type,
1592 or its expected profile shall correspond to a parameterless
1593 function with a character result type, in which case it
1594 is interpreted as the name of the corresponding parameterless
1595 function declared as part of the character type's definition
1596 (see @RefSecNum(Enumeration Types)).
1597 In either case, the @nt{character_literal} denotes the
1598 @nt{enumeration_literal_specification}.
1599 @begin{Discussion}
1600 See @RefSecNum(Selected Components) for the resolution rules for a
1601 @nt<selector_name> that is a @nt<character_literal>.
1602 @end{Discussion}
1603
1604 @PDefn2{Term=[expected type],Sec=(string_literal)}
1605 The expected type for a @nt{primary} that is a @nt<string_literal>
1606 shall be a single string type.
1607 @end{Resolution}
1608
1609 @begin{Legality}
1610 A @nt{character_literal} that is a @nt<name> shall correspond to a
1611 @nt<defining_character_literal> of the expected type, or
1612 of the result type of the expected profile.
1613
1614 For each character of a @nt{string_literal} with a given
1615 expected string type, there shall be
1616 a corresponding @nt<defining_character_literal> of
1617 the component type of the expected string type.
1618
1619 @ChgRef{Version=[2],Kind=[Deleted],ARef=[AI95-00230-01],ARef=[AI95-00231-01]}
1620 @ChgDeleted{Version=[2],Text=[A literal @s<null>@ChgNote{We use @S since this
1621 isn't a nonterminal, and since it is deleted we don't want to fix it.} shall
1622 not be of an anonymous
1623 access type@Redundant[, since such types do not have a null value
1624 (see @RefSecNum{Access Types})].]}
1625 @begin{Reason}
1626 @ChgRef{Version=[2],Kind=[DeletedNoDelMsg]}
1627 @ChgDeleted{Version=[2],Text=[This is a legality rule rather than an overloading
1628 rule, to simplify implementations.]}
1629 @end{Reason}
1630 @end{Legality}
1631
1632 @begin{StaticSem}
1633 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00230-01]}
1634 An integer literal is of type @i{universal_integer}.
1635 A real literal is of type @i{universal_real}.@Chg{Version=[2],New=[ The literal
1636 @key<null> is of type @i<universal_access>.@Chg{Version=[3],
1637 New=[@PDefn{universal_integer}@PDefn{universal_real}@PDefn{universal_access}],Old=[]}],Old=[]}
1638 @end{StaticSem}
1639
1640 @begin{RunTime}
1641 @PDefn2{Term=[evaluation], Sec=(numeric literal)}
1642 @PDefn2{Term=[evaluation], Sec=(null literal)}
1643 @Defn{null access value}
1644 @IndexSee{Term=[null pointer],See=(null access value)}
1645 The evaluation of a numeric literal, or the literal @key(null),
1646 yields the represented value.
1647
1648 @PDefn2{Term=[evaluation], Sec=(string_literal)}
1649 The evaluation of a @nt{string_literal} that is a @nt<primary>
1650 yields an array value containing the value of each character of the
1651 sequence of characters of the @nt<string_literal>,
1652 as defined in @RefSecNum{String Literals}.
1653 The bounds of this array value are determined according to the rules for
1654 @nt<positional_array_aggregate>s (see @RefSecNum{Array Aggregates}),
1655 except that for a null string literal, the upper bound is the predecessor
1656 of the lower bound.
1657
1658 @IndexCheck{Range_Check}
1659 For the evaluation of a @nt<string_literal> of type @i(T),
1660 a check is made that the value of each
1661 character of the @nt<string_literal> belongs to the component
1662 subtype of @i(T).
1663 For the evaluation of a null string literal, a check is made that its
1664 lower bound is greater than the lower bound of the base range
1665 of the index type.
1666 @Defn2{Term=[Constraint_Error],Sec=(raised by failure of run-time check)}
1667 The exception Constraint_Error is raised if either of these checks fails.
1668 @begin{Ramification}
1669 The checks on the characters need not involve more than two
1670 checks altogether, since one need only check the characters
1671 of the string with the
1672 lowest and highest position numbers against the range of the
1673 component subtype.
1674 @end{Ramification}
1675 @end{RunTime}
1676
1677 @begin{Notes}
1678 Enumeration literals that are @nt<identifier>s rather than
1679 @nt<character_literal>s follow the normal rules for @nt<identifier>s
1680 when used in a @nt<name>
1681 (see @RefSecNum{Names} and @RefSecNum{Selected Components}).
1682 @nt<Character_literal>s used as @nt<selector_name>s follow the normal
1683 rules for expanded names (see @RefSecNum{Selected Components}).
1684 @end{Notes}
1685
1686 @begin{Examples}
1687 @Leading@keepnext@i(Examples of literals:)
1688 @begin{Example}
1689 @tabclear()@tabset(P16)
1690 3.14159_26536 @\--@RI[ a real literal]
1691 1_345 @\--@RI[ an integer literal]
1692 'A' @\--@RI[ a character literal]
1693 "Some Text" @\--@RI[ a string literal ]
1694 @end{Example}
1695 @end{Examples}
1696
1697 @begin{Incompatible83}
1698 @Defn{incompatibilities with Ada 83}
1699 Because @nt<character_literal>s are now treated like
1700 other literals, in that they are resolved using context
1701 rather than depending on direct visibility, additional
1702 qualification might be necessary when passing a @nt<character_literal>
1703 to an overloaded subprogram.
1704 @end{Incompatible83}
1705
1706 @begin{Extend83}
1707 @Defn{extensions to Ada 83}
1708 @nt<Character_literal>s are now treated
1709 analogously to @key(null) and @nt<string_literal>s, in that
1710 they are resolved using context, rather than their content;
1711 the declaration of the corresponding @nt<defining_character_literal>
1712 need not be directly visible.
1713 @end{Extend83}
1714
1715 @begin{DiffWord83}
1716 Name Resolution rules for enumeration literals that are not
1717 @nt<character_literal>s are not included anymore, since
1718 they are neither syntactically
1719 nor semantically "literals" but are rather names of parameterless
1720 functions.
1721 @end{DiffWord83}
1722
1723 @begin{Extend95}
1724 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00230-01],ARef=[AI95-00231-01]}
1725 @ChgAdded{Version=[2],Text=[@Defn{extensions to Ada 95}@key{Null} now has
1726 type @i<universal_access>, which is similar to other literals. @key{Null}
1727 can be used with anonymous access types.]}
1728 @end{Extend95}
1729
1730
1731 @LabeledClause{Aggregates}
1732
1733 @begin{Intro}
1734 @Redundant[@Defn{aggregate}
1735 An @i(aggregate) combines component values
1736 into a composite value of an array type, record type, or record extension.]
1737 @IndexSeeAlso{Term={literal},See=(aggregate)}
1738 @end{Intro}
1739
1740 @begin{Syntax}
1741 @Syn{lhs=<aggregate>,rhs="@Syn2{record_aggregate} | @Syn2{extension_aggregate} | @Syn2{array_aggregate}"}
1742 @end{Syntax}
1743
1744 @begin{Resolution}
1745 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00287-01]}
1746 @PDefn2{Term=[expected type],Sec=(aggregate)}
1747 The expected type for an @nt{aggregate} shall be a
1748 single @Chg{Version=[2],New=[],Old=[nonlimited ]}array
1749 type, record type, or record extension.
1750 @begin{Discussion}
1751 See @RefSec{The Context of Overload Resolution}
1752 for the meaning of @lquotes@;shall be a single ... type.@rquotes@;
1753 @end{Discussion}
1754 @begin{Ramification}
1755 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0005-1]}
1756 @ChgAdded{Version=[3],Text=[There are additional rules for each kind of
1757 aggregate. These aggregate rules are additive; a legal expression needs to
1758 satisfy all of the applicable rules. That means the rule given here must be
1759 satisfied even when it is syntactically possible to tell which specific kind of
1760 aggregate is being used.]}
1761 @end{Ramification}
1762 @end{Resolution}
1763
1764 @begin{Legality}
1765 An @nt{aggregate} shall not be of a class-wide type.
1766 @begin{Ramification}
1767 When the
1768 expected type in some context is class-wide, an aggregate has to
1769 be explicitly qualified by the specific type of value to be created,
1770 so that the expected type for the aggregate itself is specific.
1771 @end{Ramification}
1772 @begin{Discussion}
1773 We used to disallow @nt<aggregate>s of a type with unknown
1774 discriminants. However, that was unnecessarily restrictive
1775 in the case of an extension aggregate, and irrelevant to
1776 a record aggregate (since a type that is legal for a record
1777 aggregate could not possibly have unknown discriminants) and
1778 to an array aggregate (the only specific types that can
1779 have unknown discriminants are private types, private extensions,
1780 and types derived from them).
1781 @end{Discussion}
1782
1783 @end{Legality}
1784
1785 @begin{RunTime}
1786 @PDefn2{Term=[evaluation], Sec=(aggregate)}
1787 For the evaluation of an @nt<aggregate>, an anonymous object
1788 is created and values for the components or ancestor part
1789 are obtained (as described in the subsequent subclause for each
1790 kind of the @nt<aggregate>) and assigned into the corresponding
1791 components or ancestor part of the anonymous object.
1792 @Defn2{Term=[assignment operation],
1793 Sec=(during evaluation of an @nt{aggregate})}
1794 Obtaining the values and the assignments occur in an
1795 arbitrary order.@PDefn2{Term=[arbitrary order],Sec=[allowed]}
1796 The value of the @nt{aggregate} is the value of this object.
1797 @begin{Discussion}
1798 The ancestor part is the set of components inherited from the
1799 ancestor type. The syntactic category @nt<ancestor_part> is
1800 the @nt<expression> or @nt<subtype_mark> that specifies
1801 how the ancestor part of the anonymous object should be initialized.
1802 @end{Discussion}
1803 @begin{Ramification}
1804 The assignment operations do the necessary
1805 value adjustment, as described in
1806 @RefSecNum{Assignment and Finalization}.
1807 Note that the value as a whole is not adjusted
1808 @em just the subcomponents (and ancestor part, if any).
1809 @RefSecNum{Assignment and Finalization} also describes
1810 when this anonymous object is finalized.
1811
1812 If the @nt<ancestor_part> is a @nt<subtype_mark>
1813 the Initialize procedure for the ancestor type is applied
1814 to the ancestor part after default-initializing it,
1815 unless the procedure is abstract, as described
1816 in @RefSecNum{Assignment and Finalization}.
1817 The Adjust procedure for the ancestor type is not called
1818 in this case, since there is no assignment to the ancestor
1819 part as a whole.
1820 @end{Ramification}
1821
1822 @IndexCheck{Discriminant_Check}
1823 If an @nt{aggregate} is of a tagged type, a check is made that
1824 its value belongs to the first subtype of the type.
1825 @Defn2{Term=[Constraint_Error],Sec=(raised by failure of run-time check)}
1826 Constraint_Error is raised if this check fails.
1827 @begin{Ramification}
1828 This check ensures that no values of a tagged type are
1829 ever outside the first subtype, as required
1830 for inherited dispatching operations to work properly
1831 (see @RefSecNum(Derived Types and Classes)). This check will always
1832 succeed if the first subtype is unconstrained.
1833 This check is not extended to untagged types
1834 to preserve upward compatibility.
1835 @end{Ramification}
1836 @end{RunTime}
1837
1838 @begin{Extend83}
1839 @Defn{extensions to Ada 83}
1840 We now allow @nt{extension_aggregate}s.
1841 @end{Extend83}
1842
1843 @begin{DiffWord83}
1844 We have adopted new wording
1845 for expressing the
1846 rule that the type of an aggregate shall be determinable
1847 from the outside, though using the fact that
1848 it is nonlimited record (extension) or array.
1849
1850 An @nt{aggregate} now creates an anonymous object.
1851 This is necessary so that controlled types
1852 will work (see @RefSecNum{Assignment and Finalization}).
1853 @end{DiffWord83}
1854
1855 @begin{Incompatible95}
1856 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00287-01]}
1857 @ChgAdded{Version=[2],Type=[Leading],Text=[@Defn{incompatibilities with Ada 95}
1858 In Ada 95, a limited type is not considered when resolving an @nt{aggregate}.
1859 Since Ada 2005 now allows limited @nt{aggregate}s, we can have
1860 incompatibilities. For example:]}
1861 @begin{Example}
1862 @ChgRef{Version=[2],Kind=[AddedNormal]}
1863 @Chg{Version=[2],New=[@key{type} Lim @key{is} @key{limited}
1864 @key{record}
1865 Comp: Integer;
1866 @key{end} @key{record};],Old=[]}
1867
1868 @ChgRef{Version=[2],Kind=[AddedNormal]}
1869 @Chg{Version=[2],New=[@key{type} Not_Lim @key{is}
1870 @key{record}
1871 Comp: Integer;
1872 @key{end} @key{record};],Old=[]}
1873
1874 @ChgRef{Version=[2],Kind=[AddedNormal]}
1875 @Chg{Version=[2],New=[@key{procedure} P(X: Lim);
1876 @key{procedure} P(X: Not_Lim);],Old=[]}
1877
1878 @ChgRef{Version=[2],Kind=[AddedNormal]}
1879 @ChgAdded{Version=[2],Text=[P((Comp => 123)); -- @RI[Illegal in Ada 2005, legal in Ada 95]]}
1880 @end{Example}
1881
1882 @ChgRef{Version=[2],Kind=[AddedNormal]} @ChgAdded{Version=[2],Text=[The call
1883 to P is ambiguous in Ada 2005, while it would not be ambiguous in Ada 95 as
1884 the @nt{aggregate} could not have a limited type. Qualifying the
1885 @nt{aggregate} will eliminate any ambiguity. This construction would be
1886 rather confusing to a maintenance programmer, so it should be avoided, and
1887 thus we expect it to be rare.]}
1888 @end{Incompatible95}
1889
1890 @begin{Extend95}
1891 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00287-01]}
1892 @ChgAdded{Version=[2],Text=[@Defn{extensions to Ada 95}@nt{Aggregate}s can
1893 be of a limited type.]}
1894 @end{Extend95}
1895
1896
1897 @LabeledSubClause{Record Aggregates}
1898
1899 @begin{Intro}
1900 @Redundant[In a @nt<record_aggregate>, a value is specified for
1901 each component of the record or record extension value,
1902 using either a named or a positional association.]
1903 @end{Intro}
1904
1905 @begin{Syntax}
1906 @Syn{lhs=<record_aggregate>,rhs="(@Syn2{record_component_association_list})"}
1907
1908 @Syn{lhs=<record_component_association_list>,rhs="
1909 @Syn2{record_component_association} {, @Syn2{record_component_association}}
1910 | @key<null record>"}
1911
1912
1913 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00287-01]}
1914 @Syn{lhs=<record_component_association>,rhs="
1915 [@Syn2{component_choice_list} =>] @Syn2{expression}@Chg{Version=[2],New=[
1916 | @Syn2{component_choice_list} => <>],Old=[]}"}
1917
1918 @Syn{lhs=<component_choice_list>,rhs="
1919 @SynI{component_}@Syn2{selector_name} {| @SynI{component_}@Syn2{selector_name}}
1920 | @key{others}"}
1921
1922 @begin(SyntaxText)
1923 @Defn{named component association}
1924 A @nt<record_@!component_@!association> is a @i(named component association)
1925 if it has a @nt<component_choice_list>;
1926 @Defn{positional component association}
1927 otherwise, it is a @i(positional component association).
1928 Any positional component associations shall precede any
1929 named component associations.
1930 If there is a named association with a @nt<component_choice_list>
1931 of @key(others), it shall come last.
1932 @begin{Discussion}
1933 These rules were
1934 implied by the BNF in an early version of the RM9X, but it
1935 made the grammar harder to read, and was inconsistent
1936 with how we handle discriminant constraints.
1937 Note that for array aggregates we still express
1938 some of the rules in the grammar, but array aggregates
1939 are significantly different because an array aggregate
1940 is either all positional (with a possible @key(others) at the
1941 end), or all named.
1942 @end{Discussion}
1943
1944 In the @nt<record_@!component_@!association_@!list> for a @nt<record_@!aggregate>,
1945 if there is only one association, it shall be a named association.
1946 @begin{Reason}
1947 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0264-1]}
1948 Otherwise@Chg{Version=[3],New=[,],Old=[]} the construct would be interpreted
1949 as a parenthesized expression.
1950 This is considered a syntax rule, since it is relevant to
1951 overload resolution. We choose not to express it with BNF so we
1952 can share the definition of @nt<record_component_association_list>
1953 in both @nt<record_aggregate> and @nt<extension_aggregate>.
1954 @end{Reason}
1955 @begin{Ramification}
1956 The @nt<record_component_association_list> of an @nt<extension_aggregate>
1957 does not have such a restriction.
1958 @end{Ramification}
1959 @end(SyntaxText)
1960 @end{Syntax}
1961
1962 @begin{Resolution}
1963 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00287-01]}
1964 @PDefn2{Term=[expected type],Sec=(record_aggregate)}
1965 The expected type for a @nt{record_aggregate} shall be
1966 a single @Chg{Version=[2],New=[],Old=[nonlimited ]}record
1967 type or record extension.
1968 @begin{Ramification}
1969 This rule is used to resolve whether an @nt{aggregate} is
1970 an @nt{array_aggregate} or a @nt{record_aggregate}.
1971 The presence of a @key(with) is used to resolve between
1972 a @nt{record_aggregate} and an @nt{extension_aggregate}.
1973 @end{Ramification}
1974
1975 @Defn2{Term=[needed component],
1976 Sec=(@nt<record_aggregate> @nt<record_component_association_list>)}
1977 For the @nt<record_@!component_@!association_@!list>
1978 of a @nt<record_@!aggregate>,
1979 all components of the composite value defined by
1980 the aggregate are @i(needed)@Redundant[; for the association list of
1981 an @nt<extension_aggregate>,
1982 only those components not determined by the ancestor expression or
1983 subtype are needed
1984 (see @RefSecNum{Extension Aggregates}).]
1985 Each @nt{selector_@!name} in a @nt{record_@!component_@!association} shall denote
1986 a needed component @Redundant[(including possibly a discriminant)].
1987 @begin{Ramification}
1988 For the association list of a @nt{record_aggregate},
1989 @lquotes@;needed components@rquotes@; includes every component of the composite value, but
1990 does not include those in unchosen @nt{variant}s (see AI83-309).
1991 If there are @nt<variant>s, then
1992 the value specified for
1993 the discriminant that governs them
1994 determines which @nt<variant> is chosen, and hence which components
1995 are needed.
1996
1997 If an extension defines a new @nt{known_discriminant_part}, then all of
1998 its discriminants are needed in the component association list of
1999 an extension
2000 aggregate for that type, even if the discriminants have the same
2001 names and types as discriminants of the type of the ancestor
2002 expression.
2003 This is necessary to ensure that the positions in
2004 the @nt<record_@!component_@!association_@!list>
2005 are well defined, and that discriminants that govern @nt{variant_part}s
2006 can be given by static expressions.
2007 @end{Ramification}
2008
2009 @Leading@Keepnext@PDefn2{Term=[expected type],
2010 Sec=(record_component_association expression)}
2011 The expected type for the @nt<expression> of a
2012 @nt<record_@!component_@!association> is the type
2013 of the @i(associated) component(s);
2014 @Defn2{Term=[associated components],
2015 Sec=(of a @nt<record_component_association>)}
2016 the associated component(s) are as follows:
2017 @begin(itemize)
2018 For a positional association,
2019 the component @Redundant[(including possibly a discriminant)]
2020 in the corresponding relative position (in the declarative region of
2021 the type), counting only the
2022 needed components;
2023 @begin{Ramification}
2024 This means that for
2025 an association list of an @nt<extension_aggregate>,
2026 only noninherited components are counted to determine
2027 the position.
2028
2029 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0005-1]}
2030 @ChgAdded{Version=[3],Text=[For a derived type (including type extensions),
2031 the order of declaration is defined in @RefSec{Derived Types and Classes}.
2032 In particular, all discriminants come first, regardless of whether they are
2033 defined for the parent type or are newly added to the derived type.]}
2034 @end{Ramification}
2035
2036 For a named association with one or more
2037 @i(component_)@nt<selector_name>s,
2038 the named component(s);
2039
2040 For a named association with the reserved word @key(others),
2041 all needed components
2042 that are not associated with some previous association.
2043 @end(itemize)
2044 @end{Resolution}
2045
2046 @begin{Legality}
2047
2048 If the type of a @nt{record_aggregate} is a record extension,
2049 then it shall be a descendant of a record type, through one
2050 or more record extensions (and no private extensions).
2051
2052 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0016-1]}
2053 @Chg{Version=[3],New=[The reserved words @key[null record] may appear only if],
2054 Old=[If]} there are no components needed in a given
2055 @nt<record_@!component_@!association_@!list>@Chg{Version=[3],New=[],Old=[,
2056 then the reserved words @key(null record) shall appear rather
2057 than a list of @nt<record_@!component_@!association>s]}.
2058 @begin{Ramification}
2059 For example, "(@key(null record))" is a @nt<record_aggregate>
2060 for a null record type. Similarly, "(T'(A) @key(with null record))" is
2061 an @nt<extension_aggregate> for a type defined as a null
2062 record extension of T.
2063
2064 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0016-1]}
2065 @ChgAdded{Version=[3],Text=[If no components are needed and @key[null record]
2066 is not used, the @nt{record_@!component_@!association} must necessarily be
2067 @key[others] => <>, as that is the only
2068 @nt{record_@!component_@!association} that does not require an associated
2069 component.]}
2070 @end{Ramification}
2071
2072 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00287-01]}
2073 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0199-1]}
2074 @ChgRef{Version=[4],Kind=[Revised],ARef=[AI12-0046-1]}
2075 Each @nt<record_component_association>@Chg{Version=[2],New=[ other than an
2076 @key{others} choice with a <>],Old=[]} shall have at least
2077 one associated component, and each needed component
2078 shall be associated with exactly
2079 one @nt<record_@!component_@!association>.
2080 If a @nt<record_@!component_@!association> @Chg{Version=[2],New=[with an
2081 @nt{expression} ],Old=[]}has two or more associated components, all of them
2082 shall be of the same type@Chg{Version=[3],New=[, or all of them shall be of
2083 anonymous access types whose subtypes
2084 statically match],Old=[]}.@Chg{Version=[4],New=[
2085 In addition, @LegalityTitle are enforced separately for each associated
2086 component.],Old=[]}
2087
2088 @begin{Ramification}
2089 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00287-01]}
2090 These rules apply to an association with an @key(others)
2091 choice@Chg{Version=[2],New=[ with an expression. An @key(others) choice with
2092 a <> can match zero components or several components with different
2093 types],Old=[]}.
2094 @end{Ramification}
2095 @begin{Reason}
2096 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00287-01]}
2097 Without these rules, there would be no way to know what
2098 was the expected type for the @nt<expression> of the association.
2099 @Chg{Version=[2],New=[Note that some of the rules do not apply to <>
2100 associations, as we do not need to resolve anything. We allow @key{others}
2101 => <> to match no components as this is similar to array aggregates.
2102 That means that (@key{others} => <>) always represents a default-initialized
2103 record or array value.],Old=[]}
2104 @end{Reason}
2105 @begin{Discussion}
2106 @ChgRef{Version=[4],Kind=[Revised],ARef=[AI12-0046-1]}
2107 @ChgAdded{Version=[4],Type=[Leading],Text=[]}@ChgNote{Fake to get conditional "leading"}
2108 AI83-00244 also requires that the @nt{expression} shall
2109 be legal for each associated component. @Chg{Version=[4],New=[Ada 95
2110 omitted this wording, as it was thought that all cases of
2111 difference had been eliminated. That probably was true, but Ada 2005
2112 reintroduced cases where the types match but the legality differs.
2113 For example:],Old=[This is
2114 because even though two components have the same type, they might have
2115 different subtypes. Therefore, the legality of the
2116 @nt<expression>, particularly if it is an array aggregate,
2117 might differ depending on the associated component's subtype.
2118 However, we have relaxed the rules on array aggregates slightly for Ada 95,
2119 so the staticness of an applicable index constraint has no
2120 effect on the legality of the array aggregate to which it applies.
2121 See @RefSecNum{Array Aggregates}. This was the only case (that we know of)
2122 where a subtype provided by context affected the legality
2123 of an @nt{expression}.]}
2124
2125 @begin{Example}
2126 @ChgRef{Version=[4],Kind=[Added]}
2127 @ChgAdded{Version=[4],Text=[@key[type] Rec (D : @key[access] Integer) @key[is record]
2128 F : @key[access] Integer;
2129 @key[end record];]}
2130
2131 @ChgRef{Version=[4],Kind=[Added]}
2132 @ChgAdded{Version=[4],Text=[...
2133 X : @key[aliased] Integer;
2134 R : Rec := (D | F => X'Access); -- @examcom<Legal for D, illegal for F>]}
2135 @end{Example}
2136
2137 @ChgRef{Version=[4],Kind=[Added]}
2138 @ChgAdded{Version=[4],Text=[There are additional ways for this to happen;
2139 because of cases like the above we require that the @LegalityTitle are checked
2140 individually for each associated component.]}
2141 @end{Discussion}
2142 @begin{Ramification}
2143 The rule that requires at least one associated component for
2144 each @nt<record_component_association>
2145 implies that there can be no extra associations for
2146 components that don't exist in the composite value, or that
2147 are already determined by the ancestor expression or subtype of
2148 an @nt<extension_aggregate>.
2149
2150 The second part of the first sentence ensures that no
2151 needed components are left out,
2152 nor specified twice.
2153 @end{Ramification}
2154
2155 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0220-1]}
2156 @Chg{Version=[3],New=[The],Old=[If the components of a @nt{variant_part}
2157 are needed, then the]} value of a discriminant that governs
2158 @Chg{Version=[3],New=[a],Old=[the]} @nt{variant_part}
2159 @Chg{Version=[3],New=[@i<P> ],Old=[]}shall be given
2160 by a static expression@Chg{Version=[3],New=[, unless @i<P> is nested within
2161 a @nt{variant} @i<V> that is not selected by the discriminant value
2162 governing the @nt{variant_part} enclosing @i<V>],Old=[]}.
2163 @begin{Ramification}
2164 This expression might either be given within the aggregate itself,
2165 or in a constraint on the parent subtype in a @nt<derived_type_definition>
2166 for some ancestor of the type of the aggregate.
2167 @end{Ramification}
2168
2169 @ChgRef{Version=[2],Kind=[Added],ARef=[AI95-00287-01]}
2170 @ChgAdded{Version=[2],Text=[A @nt<record_component_association> for a discriminant
2171 without a @nt<default_expression> shall have an @nt<expression> rather
2172 than <>.]}
2173 @begin{Reason}
2174 @ChgRef{Version=[2],Kind=[AddedNormal]}
2175 @ChgAdded{Version=[2],Text=[A discriminant must always have a defined value,
2176 but <> means uninitialized for a discrete type unless the component has a
2177 default value.]}
2178 @end{Reason}
2179
2180 @end{Legality}
2181
2182 @begin{RunTime}
2183 @PDefn2{Term=[evaluation], Sec=(record_aggregate)}
2184 The evaluation of a @nt<record_aggregate> consists of the
2185 evaluation of the @nt<record_@!component_@!association_@!list>.
2186
2187 @PDefn2{Term=[evaluation], Sec=(record_component_association_list)}
2188 For the evaluation of a @nt{record_@!component_@!association_@!list},
2189 any per-object constraints (see @RefSecNum(Record Types))
2190 for components specified in the association list are elaborated and
2191 any @nt<expression>s are evaluated and converted to the subtype of the
2192 associated component.
2193 @PDefn2{Term=[implicit subtype conversion],Sec=(expressions in aggregate)}
2194 Any constraint elaborations and @nt{expression} evaluations (and conversions)
2195 occur in an arbitrary order, except that the @nt<expression>
2196 for a discriminant is evaluated (and converted) prior to the
2197 elaboration of any per-object constraint that depends on it, which in
2198 turn occurs prior to the evaluation and conversion of the @nt{expression} for
2199 the component with the per-object constraint.@PDefn2{Term=[arbitrary order],Sec=[allowed]}
2200 @begin{Ramification}
2201 The conversion in the first rule might raise Constraint_Error.
2202 @end{Ramification}
2203 @begin{Discussion}
2204 This check in the first rule presumably happened as part of the dependent
2205 compatibility check in Ada 83.
2206 @end{Discussion}
2207
2208 @ChgRef{Version=[2],Kind=[Added],ARef=[AI95-00287-01]}
2209 @ChgAdded{Version=[2],Text=[For a @nt<record_component_association> with an
2210 @nt<expression>, the @nt<expression> defines the value for the associated
2211 component(s). For a @nt<record_component_association> with <>, if the
2212 @nt<component_declaration> has a @nt<default_expression>, that
2213 @nt<default_expression> defines the value for the associated component(s);
2214 otherwise, the associated component(s) are initialized by default as for a
2215 stand-alone object of the component subtype
2216 (see @RefSecNum{Object Declarations}).]}
2217
2218 The @nt<expression> of a @nt{record_component_association}
2219 is evaluated (and converted) once for each associated component.
2220
2221 @begin{Ramification}
2222 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0005-1]}
2223 @ChgAdded{Version=[3],Text=[We don't need similar language for <>,
2224 as we're considering the value of <> for each individual component.
2225 Each component has its own default expression or its own
2226 default initialization (they can be different for each component;
2227 the components even could have different types), and each one
2228 has to be evaluated. So there is no need to repeat that.]}
2229 @end{Ramification}
2230
2231 @end{RunTime}
2232
2233 @begin{Notes}
2234 For a @nt<record_aggregate> with positional associations, expressions
2235 specifying discriminant
2236 values appear first since the @nt<known_discriminant_part>
2237 is given first in the declaration of the type; they have to
2238 be in the same order as in the @nt<known_discriminant_part>.
2239 @end{Notes}
2240
2241 @begin{Examples}
2242 @Leading@keepnext@i(Example of a record aggregate with positional associations:)
2243 @begin{Example}
2244 (4, July, 1776) --@RI[ see @RefSecNum{Record Types} ]
2245 @end{Example}
2246
2247 @begin{WideAbove}
2248 @leading@keepnext@i(Examples of record aggregates with named associations:)
2249 @end{WideAbove}
2250 @begin{Example}
2251 (Day => 4, Month => July, Year => 1776)
2252 (Month => July, Day => 4, Year => 1776)
2253
2254 (Disk, Closed, Track => 5, Cylinder => 12) --@RI[ see @RefSecNum{Variant Parts and Discrete Choices}]
2255 (Unit => Disk, Status => Closed, Cylinder => 9, Track => 1)
2256 @end{Example}
2257
2258 @begin{WideAbove}
2259 @leading@keepnext@ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00287-01]}
2260 @i(@Chg{Version=[2],New=[Examples],Old=[Example]} of component
2261 @Chg{Version=[2],New=[associations],Old=[association]} with
2262 several choices:)
2263 @end{WideAbove}
2264 @begin{Example}
2265 @tabclear()@tabset(P50)
2266 (Value => 0, Succ|Pred => @key(new) Cell'(0, @key(null), @key(null))) @\--@RI[ see @RefSecNum{Incomplete Type Declarations}]
2267
2268 --@RI[ The allocator is evaluated twice: Succ and Pred designate different cells]
2269
2270 @ChgRef{Version=[2],Kind=[Added]}
2271 @Chg{Version=[2],New=[(Value => 0, Succ|Pred => <>) @\--@RI[ see @RefSecNum{Incomplete Type Declarations}]],Old=[]}
2272
2273 @ChgRef{Version=[2],Kind=[Added]}
2274 @Chg{Version=[2],New=[ --@RI[ Succ and Pred will be set to @key{null}]],Old=[]}
2275
2276 @end{Example}
2277
2278 @begin{WideAbove}
2279 @leading@keepnext@i{Examples of record aggregates for tagged types
2280 (see @RefSecNum(Tagged Types and Type Extensions)
2281 and @RefSecNum{Type Extensions}):}
2282 @end{WideAbove}
2283 @begin{Example}
2284 Expression'(@key{null record})
2285 Literal'(Value => 0.0)
2286 Painted_Point'(0.0, Pi/2.0, Paint => Red)
2287 @end{Example}
2288
2289 @end{Examples}
2290
2291 @begin{Extend83}
2292 @Defn{extensions to Ada 83}
2293 Null record aggregates may now be specified, via "(@key(null record))".
2294 However, this syntax is more useful for null record extensions in
2295 extension aggregates.
2296 @end{Extend83}
2297
2298 @begin{DiffWord83}
2299 Various AIs have been incorporated (AI83-00189, AI83-00244, and AI83-00309).
2300 In particular, Ada 83 did not explicitly disallow extra values in
2301 a record aggregate. Now we do.
2302 @end{DiffWord83}
2303
2304 @begin{Extend95}
2305 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00287-01]}
2306 @ChgAdded{Version=[2],Text=[@Defn{extensions to Ada 95}<> can be used in
2307 place of an @nt{expression} in a @nt{record_aggregate}, default
2308 initializing the component.]}
2309 @end{Extend95}
2310
2311 @begin{DiffWord95}
2312 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00287-01]}
2313 @ChgAdded{Version=[2],Text=[Limited @nt{record_aggregate}s are allowed (since
2314 all kinds of aggregates can now be limited, see @RefSecNum{Aggregates}).]}
2315 @end{DiffWord95}
2316
2317 @begin{Incompatible2005}
2318 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0220-1]}
2319 @ChgAdded{Version=[3],Text=[@Defn{incompatibilities with Ada 2005}@b<Correction:>
2320 Corrected wording so that the rule for discriminants governing @nt{variant_part}s
2321 was not effectively circular. The change makes a few @nt{aggregate}s where a
2322 nonstatic discriminant governs an empty @nt{variant_part} illegal. However,
2323 most Ada implementations already enforce some version of the new rule and
2324 already reject these @nt{aggregate}s. So it is unlikely that any
2325 incompatibility will be noticed in practice.]}
2326 @end{Incompatible2005}
2327
2328 @begin{Extend2005}
2329 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0016-1]}
2330 @ChgAdded{Version=[3],Text=[@Defn{extensions to Ada 2005}@b<Correction:> Fixed the wording so that
2331 @key[others] => <> can be used in place of @key[null record].
2332 This is needed to avoid a generic contract issue for generic bodies:
2333 we do not want to have to assume the worst to disallow @key[others] => <>
2334 if the record type @i{might} be a null record.]}
2335
2336 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0199-1]}
2337 @ChgAdded{Version=[3],Text=[@b<Correction:> We now allow multiple components
2338 with anonymous access types to be specified with a single component
2339 association. This is to be consistent with the capabilities of a named
2340 access type.]}
2341 @end{Extend2005}
2342
2343 @begin{DiffWord2012}
2344 @ChgRef{Version=[4],Kind=[AddedNormal],ARef=[AI12-0046-1]}
2345 @ChgAdded{Version=[4],Text=[@b<Corrigendum:> We explicitly say that the
2346 @LegalityTitle have to be rechecked for each component individually.
2347 This @i<seems> obvious, but as the AARM note @RefSecNum{Record Aggregates}
2348 (16.c) appeared to say that this was not necessary, and since we explicitly
2349 state this sort of thing for generic instances, it seemed better to be
2350 explicit.]}
2351 @end{DiffWord2012}
2352
2353
2354 @RMNewPageVer{Version=[2]}@Comment{For printed version of Ada 2005 RM}
2355 @LabeledSubClause{Extension Aggregates}
2356
2357 @begin{Intro}
2358 @Redundant[An @nt<extension_aggregate> specifies a value
2359 for a type that is a record extension by specifying a value
2360 or subtype
2361 for an ancestor of the type,
2362 followed by associations for
2363 any components not determined by the @nt<ancestor_part>.]
2364 @end{Intro}
2365
2366 @begin{MetaRules}
2367 The model underlying this syntax is that a record extension
2368 can also be viewed as a regular record type with an ancestor "prefix."
2369 The @nt<record_@!component_@!association_@!list> corresponds to
2370 exactly what would be needed
2371 if there were no ancestor/prefix type.
2372 The @nt{ancestor_part}
2373 determines the value of the ancestor/prefix.
2374 @end{MetaRules}
2375
2376 @begin{Syntax}
2377 @Syn{lhs=<extension_aggregate>,rhs="
2378 (@Syn2{ancestor_part} @key(with) @Syn2{record_component_association_list})"}
2379
2380 @Syn{lhs=<ancestor_part>,
2381 rhs="@Syn2{expression} | @Syn2{subtype_mark}"}
2382 @end{Syntax}
2383
2384 @begin{Resolution}
2385 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00287-01]}
2386 @PDefn2{Term=[expected type], Sec=(extension_aggregate)}
2387 The expected type for an @nt{extension_aggregate} shall be
2388 a single @Chg{Version=[2],New=[],Old=[nonlimited ]}type that is a
2389 record extension.
2390 @PDefn2{Term=[expected type],
2391 Sec=(extension_aggregate ancestor expression)}
2392 If the @nt<ancestor_part> is an @nt<expression>,
2393 it is expected to be of any @Chg{Version=[2],New=[],Old=[nonlimited ]}tagged
2394 type.
2395 @begin{Reason}
2396 We could have made
2397 the expected type @i(T')Class where @i(T) is the ultimate ancestor of
2398 the type of the aggregate, or we could have made it even more
2399 specific than that. However, if the overload resolution rules
2400 get too complicated, the implementation gets more difficult and
2401 it becomes harder to produce good error messages.
2402 @end{Reason}
2403 @begin{Ramification}
2404 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0005-1]}
2405 @ChgAdded{Version=[3],Text=[This rule is additive with the rule given in
2406 @RefSecNum{Aggregates}. That means the @RefSecNum{Aggregates} rule must be
2407 satisfied even though it is always syntactically possible to tell that
2408 something is an extension aggregate rather than another kind of aggregate.
2409 Specifically, that means that an extension aggregate is ambiguous if the
2410 context is overloaded on array and/or untagged record types, even though
2411 those are never legal contexts for an extension aggregate. Thus, this rule
2412 acts more like a @LegalityName than a @ResolutionName.]}
2413 @end{Ramification}
2414 @end{Resolution}
2415
2416 @begin{Legality}
2417 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00306-01]}
2418 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0115-1]}
2419 If the @nt<ancestor_part> is a @nt<subtype_mark>, it shall
2420 denote a specific tagged subtype.
2421 @Chg{Version=[2],New=[If the @nt{ancestor_part} is an @nt{expression}, it
2422 shall not be dynamically tagged. ],Old=[]}
2423 The type of the @nt{extension_aggregate} shall be
2424 @Chg{Version=[3],New=[a descendant of],Old=[derived from]} the type of the
2425 @nt<ancestor_part>@Chg{Version=[3],New=[ (the @i<ancestor> type)@Defn2{Term=[ancestor type],
2426 Sec=<of an @nt<extension_aggregate>>}],Old=[]},
2427 through one or more record extensions (and no private
2428 extensions).@Chg{Version=[3],New=[ If the @nt{ancestor_part} is a
2429 @nt{subtype_mark}, the view of the ancestor type from which the type
2430 is descended (see @RefSecNum{Private Operations})
2431 shall not have unknown discriminants.],Old=[]}
2432 @begin{Reason}
2433 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00306-01]}
2434 @ChgAdded{Version=[2],Text=[The expression cannot be dynamically tagged to
2435 prevent implicit "truncation" of a dynamically-tagged value to the specific
2436 ancestor type. This is similar to the
2437 rules in @RefSecNum{Dispatching Operations of Tagged Types}.]}
2438 @end{Reason}
2439
2440 @ChgRef{Version=[3],Kind=[Added],ARef=[AI05-0067-1],ARef=[AI05-0244-1]}
2441 @ChgAdded{Version=[3],Type=[Leading],Text=[If the type of the @nt{ancestor_part}
2442 is limited and at least one component is needed
2443 in the @nt{record_component_association_list}, then the @nt{ancestor_part}
2444 shall not be:]}
2445 @begin{Itemize}
2446 @ChgRef{Version=[3],Kind=[Added]}
2447 @ChgAdded{Version=[3],Text=[a call to a function with an unconstrained result
2448 subtype; nor]}
2449
2450 @ChgRef{Version=[3],Kind=[Added]}
2451 @ChgAdded{Version=[3],Text=[a parenthesized or qualified expression whose
2452 operand would violate this rule; nor]}
2453
2454 @ChgRef{Version=[3],Kind=[Added]}
2455 @ChgAdded{Version=[3],Text=[a @nt{conditional_expression} having at least one
2456 @SynI{dependent_}@nt{expression} that would violate this rule.]}
2457 @end{Itemize}
2458 @begin{Reason}
2459 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0067-1],ARef=[AI05-0244-1]}
2460 @ChgAdded{Version=[3],Text=[This restriction simplifies implementation,
2461 because it ensures that either the caller or the callee knows the size to
2462 allocate for the aggregate. Without this restriction, information from both
2463 caller and callee would have to be combined to determine the appropriate
2464 size.]}
2465
2466 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0067-1]}
2467 @ChgAdded{Version=[3],Text=[The (F(...) with null record) case is exempt from
2468 this rule, because such extension
2469 aggregates are created internally for inherited functions returning
2470 null-extension types @em we can't very well make those illegal. Moreover, we
2471 don't need the rule for null extensions, as the result can simply use
2472 the space returned by the function call.]}
2473 @end{Reason}
2474 @end{Legality}
2475
2476 @begin{StaticSem}
2477 @Defn2{Term=[needed component],
2478 Sec=(@nt<extension_aggregate> @nt<record_component_association_list>)}
2479 For the @nt{record_@!component_@!association_@!list}
2480 of an @nt{extension_@!aggregate},
2481 the only components @i(needed) are those of the composite value defined
2482 by the aggregate that are not inherited from the type of
2483 the @nt<ancestor_@!part>, plus any inherited discriminants
2484 if the @nt<ancestor_@!part> is a @nt<subtype_@!mark> that
2485 denotes an unconstrained subtype.
2486 @end{StaticSem}
2487
2488 @begin{RunTime}
2489 @PDefn2{Term=[evaluation], Sec=(extension_aggregate)}
2490 For the evaluation of an @nt{extension_aggregate},
2491 the @nt{record_@!component_@!association_@!list} is evaluated.
2492 If the @nt<ancestor_part> is an @nt<expression>, it is also evaluated;
2493 if the @nt<ancestor_part> is a @nt<subtype_mark>,
2494 the components of the value of the aggregate not given by the
2495 @nt<record_@!component_@!association_@!list> are initialized by default
2496 as for an object of the ancestor type.
2497 Any implicit initializations or evaluations are performed
2498 in an arbitrary order, except that the @nt<expression>
2499 for a discriminant is evaluated prior to any other evaluation
2500 or initialization that depends on it.@PDefn2{Term=[arbitrary order],Sec=[allowed]}
2501
2502 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0282-1]}
2503 @IndexCheck{Discriminant_Check}
2504 If the type of the @nt<ancestor_part> has
2505 discriminants @Chg{Version=[3],New=[and],Old=[that are not inherited by the
2506 type of the @nt{extension_aggregate},
2507 then, unless]} the @nt<ancestor_part> is@Chg{Version=[3],New=[ not],Old=[]}
2508 a @nt<subtype_mark> that
2509 denotes an unconstrained subtype,@Chg{Version=[3],New=[ then],Old=[]}
2510 a check is made that each discriminant @Chg{Version=[3],New=[determined by the
2511 @nt{ancestor_part}],Old=[of the ancestor]}
2512 has the value specified for a corresponding discriminant,@Chg{Version=[3],New=[ if any,],Old=[]}
2513 either in the @nt{record_@!component_@!association_@!list}, or in
2514 the @nt<derived_type_definition> for some ancestor of the type of
2515 the @nt{extension_aggregate}.
2516 @Defn2{Term=[Constraint_Error],Sec=(raised by failure of run-time check)}
2517 Constraint_Error is raised if this check fails.
2518 @begin{Ramification}
2519 Corresponding and specified
2520 discriminants are defined in @RefSecNum{Discriminants}.
2521 The rules requiring static compatibility between
2522 new discriminants of a derived type
2523 and the parent discriminant(s) they constrain
2524 ensure that at most one check is required per discriminant
2525 of the ancestor expression.
2526
2527 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0282-1]}
2528 @ChgAdded{Version=[3],Text=[The check needs to be made any time that the
2529 ancestor is constrained; the source of the discriminants or the constraints
2530 is irrelevant.]}
2531 @end{Ramification}
2532 @end{RunTime}
2533
2534 @begin{Notes}
2535 If all components of the value of the @nt<extension_aggregate>
2536 are determined by the @nt<ancestor_part>, then
2537 the @nt<record_@!component_@!association_@!list> is required to be
2538 simply @key(null record).
2539
2540 If the @nt<ancestor_part> is a @nt<subtype_mark>,
2541 then its type can be abstract. If its type is controlled,
2542 then as the last step of evaluating the aggregate,
2543 the Initialize procedure of the ancestor type is called,
2544 unless the Initialize procedure is abstract
2545 (see @RefSecNum{Assignment and Finalization}).
2546 @end{Notes}
2547
2548 @begin{Examples}
2549 @Leading@keepnext@i{Examples of extension aggregates (for types defined in @RefSecNum{Type Extensions}):}
2550 @begin(example)
2551 Painted_Point'(Point @key{with} Red)
2552 (Point'(P) @key{with} Paint => Black)
2553
2554 (Expression @key{with} Left => 1.2, Right => 3.4)
2555 Addition'(Binop @key{with null record})
2556 --@RI[ presuming Binop is of type Binary_Operation]
2557 @end(example)
2558
2559 @end{Examples}
2560
2561 @begin{Extend83}
2562 @Defn{extensions to Ada 83}
2563 The extension aggregate syntax is new.
2564 @end{Extend83}
2565
2566 @begin{Incompatible95}
2567 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00306-01]}
2568 @ChgAdded{Version=[2],Text=[@Defn{incompatibilities with Ada 95}
2569 @b[Amendment Correction:] Eliminated implicit @lquotes@;truncation@rquotes
2570 of a dynamically tagged value when it is used as an ancestor
2571 @nt{expression}. If an @nt{aggregate} includes such an @nt{expression},
2572 it is illegal in Ada 2005. Such @nt{aggregate}s are thought to be rare;
2573 the problem can be fixed with a type conversion to the appropriate
2574 specific type if it occurs.]}
2575 @end{Incompatible95}
2576
2577 @begin{DiffWord95}
2578 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00287-01]}
2579 @ChgAdded{Version=[2],Text=[Limited @nt{extension_aggregate}s are allowed (since
2580 all kinds of aggregates can now be limited, see @RefSecNum{Aggregates}).]}
2581 @end{DiffWord95}
2582
2583 @begin{Inconsistent2005}
2584 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0282-1]}
2585 @ChgAdded{Version=[3],Text=[@Defn{inconsistencies with Ada 2005}@b[Correction:]
2586 An @nt{extension_aggregate} with an @nt{ancestor_part} whose discriminants
2587 are constrained and inherited might now raise Constraint_Error if the
2588 @nt{aggregate}'s type is constrained, while it was OK in Ada 2005. In almost
2589 all cases, this will make no difference as the constraint will be checked
2590 by the immediately following use of the @nt{aggregate}, but it is possible to
2591 compare such an aggregate for equality;
2592 in this case, no exception would be raised by Ada 2005, while Ada 2012 will
2593 raise Constraint_Error. This should be very rare, and having the possibility
2594 means that the representation of the aggregate type has to be able to support
2595 unconstrained values of the type, even if the first subtype is constrained
2596 and no such objects can be created any other way.]}
2597 @end{Inconsistent2005}
2598
2599 @begin{Incompatible2005}
2600 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0067-1]}
2601 @ChgAdded{Version=[3],Text=[@Defn{incompatibilities with Ada 2005}@b[Correction:]
2602 A limited unconstrained ancestor expression that is a function call is now
2603 illegal unless the extension part is null.
2604 Such @nt{aggregate}s were first introduced in Ada 2005 and are very complex
2605 to implement as they must be built-in-place with an unknown size; as such,
2606 it is unlikely that they are implemented correctly in existing compilers and
2607 thus not often used in existing code.]}
2608
2609 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0115-1]}
2610 @ChgAdded{Version=[3],Text=[@b[Correction:] An @nt{ancestor_part} that is a
2611 subtype with unknown discriminants is now explicitly illegal. Such a
2612 subtype should not be used to declare an object, and the @nt{ancestor_part}
2613 acts like an object. The Ada 95 rules did not disallow such cases, so it
2614 is possible that code exists that uses such an ancestor, but this should
2615 be rare.]}
2616 @end{Incompatible2005}
2617
2618
2619 @LabeledSubClause{Array Aggregates}
2620
2621 @begin{Intro}
2622
2623 @Redundant[In an @nt<array_aggregate>, a value is specified
2624 for each component of an array, either positionally or by
2625 its index.]
2626 For a @nt{positional_array_aggregate},
2627 the components are given in increasing-index order,
2628 with a final @key[others], if any,
2629 representing any remaining components.
2630 For a @nt{named_array_aggregate},
2631 the components are identified by the values covered by the
2632 @nt{discrete_choice}s.
2633
2634 @end{Intro}
2635
2636 @begin{MetaRules}
2637 @ChgRef{Version=[1],Kind=[Revised]}
2638 The rules in this subclause are based on
2639 terms and rules for @nt{discrete_choice_list}s
2640 defined in @RefSec{Variant Parts and Discrete Choices}.
2641 @Chg{New=[For example, the requirements that @key(others) come last and stand
2642 alone are found there.],Old=[]}@Comment{This question is asked periodically, so
2643 we answer it explicitly.}
2644 @end{MetaRules}
2645
2646 @begin{Syntax}
2647 @Syn{lhs=<array_aggregate>,rhs="
2648 @Syn2{positional_array_aggregate} | @Syn2{named_array_aggregate}"}
2649
2650
2651 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00287-01]}
2652 @Syn{lhs=<positional_array_aggregate>,rhs="
2653 (@Syn2{expression}, @Syn2{expression} {, @Syn2{expression}})
2654 | (@Syn2{expression} {, @Syn2{expression}}, @key(others) => @Syn2{expression})@Chg{Version=[2],New=[
2655 | (@Syn2{expression} {, @Syn2{expression}}, @key(others) => <>)],Old=[]}"}
2656
2657
2658 @Syn{lhs=<named_array_aggregate>,rhs="
2659 (@Syn2{array_component_association} {, @Syn2{array_component_association}})"}
2660
2661
2662 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00287-01]}
2663 @Syn{lhs=<array_component_association>,rhs="
2664 @Syn2{discrete_choice_list} => @Syn2{expression}@Chg{Version=[2],New=[
2665 | @Syn2{discrete_choice_list} => <>],Old=[]}"}
2666
2667 @end{Syntax}
2668
2669 @begin{Intro}
2670 @Defn{n-dimensional @nt<array_aggregate>}
2671 An @i(n-dimensional) @nt<array_aggregate> is one that is written as
2672 n levels of nested @nt{array_aggregate}s (or at the bottom level,
2673 equivalent @nt{string_literal}s).
2674 @Defn2{Term=[subaggregate], Sec=(of an @nt{array_aggregate})}
2675 For the multidimensional case (n >= 2) the @nt<array_aggregate>s
2676 (or equivalent @nt<string_literal>s)
2677 at the n@en@;1 lower levels are called @i(subaggregate)s of the
2678 enclosing n-dimensional @nt<array_aggregate>.
2679 @Defn{array component expression}
2680 The @nt<expression>s of the bottom level subaggregates (or of the
2681 @nt<array_aggregate> itself if one-dimensional)
2682 are called the @i(array component expressions) of the enclosing
2683 n-dimensional @nt<array_aggregate>.
2684 @begin(Ramification)
2685 Subaggregates do not have a type. They correspond to part of
2686 an array. For example, with a matrix, a subaggregate would correspond to
2687 a single row of the matrix.
2688 The definition of "n-dimensional" @nt<array_aggregate>
2689 applies to subaggregates as well
2690 as @nt<aggregate>s that have a type.
2691 @end(Ramification)
2692 @begin(Honest)
2693 @Defn{others choice}
2694 An @i(@key(others) choice) is
2695 the reserved word @key(others) as it appears in
2696 a @nt{positional_array_aggregate} or as the
2697 @nt{discrete_choice} of the @nt{discrete_choice_list}
2698 in an @nt{array_component_association}.
2699 @end(Honest)
2700
2701 @end{Intro}
2702
2703 @begin{Resolution}
2704 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00287-01]}
2705 @PDefn2{Term=[expected type], Sec=(array_aggregate)}
2706 The expected type for an @nt{array_aggregate} (that is not
2707 a subaggregate) shall be a
2708 single @Chg{Version=[2],New=[],Old=[nonlimited ]}array type.
2709 @PDefn2{Term=[expected type],
2710 Sec=(array_aggregate component expression)}
2711 The component type of this array type is the
2712 expected type for each array component expression of
2713 the @nt<array_aggregate>.
2714 @begin{Ramification}
2715 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00287-01]}
2716 We already require a single array or record type or
2717 record extension for an @nt{aggregate}.
2718 The above rule requiring a single @Chg{Version=[2],New=[],
2719 Old=[nonlimited ]}array type
2720 (and similar ones for record and extension aggregates)
2721 resolves which kind of aggregate you have.
2722 @end{Ramification}
2723
2724 @PDefn2{Term=[expected type],
2725 Sec=(array_aggregate discrete_choice)}
2726 The expected type for each
2727 @nt{discrete_choice} in any @nt{discrete_choice_list} of
2728 a @nt{named_array_aggregate} is the type of the @i(corresponding index);
2729 @Defn2{Term=[corresponding index], Sec=(for an @nt{array_aggregate})}
2730 the corresponding index for an @nt<array_aggregate> that is not
2731 a subaggregate is the first index of its type; for an (n@en@;m)-dimensional
2732 subaggregate within an @nt<array_aggregate> of an n-dimensional type,
2733 the corresponding index is the index in position m+1.
2734 @end{Resolution}
2735
2736 @begin{Legality}
2737 An @nt<array_aggregate> of an n-dimensional array type shall be
2738 written as an n-dimensional @nt<array_aggregate>.
2739 @begin(Ramification)
2740 In an m-dimensional @nt<array_aggregate> @Redundant[(including a subaggregate)],
2741 where m >= 2, each of the @nt<expression>s
2742 has to be an (m@en@;1)-dimensional subaggregate.
2743 @end(Ramification)
2744
2745 @Leading@;An @key(others) choice is allowed for an @nt<array_aggregate>
2746 only if an @i(applicable index
2747 constraint) applies to the @nt{array_aggregate}.
2748 @Defn{applicable index constraint}
2749 @Redundant[An applicable index constraint is
2750 a constraint provided by certain contexts where an @nt{array_aggregate}
2751 is permitted that can be used
2752 to determine the bounds of the array value specified by the aggregate.]
2753 Each of the following contexts (and none other)
2754 defines an applicable index constraint:
2755 @begin(itemize)
2756 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00318-02]}
2757 @ChgRef{Version=[4],Kind=[Revised],ARef=[AI12-0157-1]}
2758 For an @nt{explicit_actual_parameter},
2759 an @nt{explicit_generic_actual_parameter},
2760 the @nt{expression} of a
2761 @Chg{Version=[2],New=[return statement],Old=[@nt{return_statement}]},
2762 @Chg{Version=[4],New=[the return expression of an expression
2763 function, ],Old=[]}the initialization expression
2764 in an @nt{object_@!declaration}, or a @nt{default_@!expression}
2765 @Redundant[(for a parameter or a component)],
2766 when the nominal subtype
2767 of the corresponding formal parameter, generic formal parameter,
2768 function @Chg{Version=[2],New=[return object],Old=[result]},
2769 @Chg{Version=[4],New=[expression function return object, ],Old=[]}object, or
2770 component is a constrained array subtype, the
2771 applicable index constraint is the constraint of the subtype;
2772
2773 For the @nt{expression} of an @nt{assignment_statement} where
2774 the @nt{name} denotes an array variable, the
2775 applicable index constraint is the constraint of the array variable;
2776 @begin{Reason}
2777 This case is broken out because the constraint comes from the actual
2778 subtype of the variable (which is always constrained)
2779 rather than its nominal subtype (which might be unconstrained).
2780 @end{Reason}
2781
2782 For the operand of a @nt{qualified_expression}
2783 whose @nt{subtype_mark}
2784 denotes a constrained array subtype, the applicable index constraint
2785 is the constraint of the subtype;
2786
2787 For a component @nt{expression} in an @nt{aggregate},
2788 if the component's nominal subtype is a constrained
2789 array subtype, the applicable index constraint is the constraint
2790 of the subtype;
2791 @begin{Discussion}
2792 Here, the @nt{array_aggregate} with @key[others]
2793 is being used within a larger aggregate.
2794 @end{Discussion}
2795
2796 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0147-1]}
2797 For a parenthesized @nt{expression}, the
2798 applicable index constraint is that, if any, defined for the
2799 @nt{expression}@Chg{Version=[3],New=[;],Old=[.]}
2800 @begin{Discussion}
2801 RM83 omitted this
2802 case, presumably as an oversight. We want to minimize situations
2803 where an @nt{expression} becomes illegal if parenthesized.
2804 @end{Discussion}
2805 @ChgRef{Version=[3],Kind=[Added],ARef=[AI05-0147-1]}
2806 @ChgAdded{Version=[3],Text=[For a @nt{conditional_expression}, the
2807 applicable index constraint for each @SynI<dependent_>@nt{expression} is that,
2808 if any, defined for the @nt{conditional_expression}.]}
2809 @end(itemize)
2810
2811 The applicable index constraint @i(applies) to an @nt{array_aggregate}
2812 that appears in such a context, as well as to any subaggregates thereof.
2813 In the case of an @nt<explicit_actual_parameter> (or @nt<default_expression>)
2814 for a call on a generic formal subprogram,
2815 no applicable index constraint is defined.
2816 @begin(Reason)
2817 This avoids generic contract model problems,
2818 because only mode conformance is required when matching
2819 actual subprograms with generic formal subprograms.
2820 @end(Reason)
2821
2822 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0153-3]}
2823 The @nt{discrete_choice_list} of an
2824 @nt{array_component_association} is allowed to
2825 have a @nt{discrete_choice} that is a nonstatic
2826 @Chg{Version=[3],New=[@nt<choice_expression>],Old=[@nt<expression>]}
2827 or that is a @Chg{Version=[3],New=[@nt{subtype_indication} or @nt{range}],
2828 Old=[@nt{discrete_range}]} that defines a nonstatic or
2829 null range, only if it is the single @nt{discrete_choice} of
2830 its @nt{discrete_choice_list}, and there is only one
2831 @nt{array_component_association} in the @nt<array_aggregate>.
2832 @begin{Discussion}
2833 We now allow a nonstatic @key(others) choice even if there are
2834 other array component expressions as well.
2835 @end{Discussion}
2836
2837 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0262-1]}
2838 In a @nt<named_array_aggregate>
2839 @Chg{Version=[3],New=[where all @nt{discrete_choice}s are
2840 static],Old=[with more than one @nt<discrete_choice>]},
2841 no two @nt<discrete_choice>s are allowed to
2842 cover the same value (see @RefSecNum{Variant Parts and Discrete Choices});
2843 if there is no @key[others] choice, the @nt<discrete_choice>s taken
2844 together shall
2845 exactly cover a contiguous sequence of values of the corresponding index type.
2846 @begin{Ramification}
2847 This implies that each component must be
2848 specified exactly once. See AI83-309.
2849 @end{Ramification}
2850 @begin{Reason}
2851 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0262-1]}
2852 @ChgAdded{Version=[3],Text=[This has to apply even if there is only one
2853 static @nt{discrete_choice}; a single choice has to represent a contiguous
2854 range (a @nt{subtype_mark} with a static predicate might represent a
2855 discontiguous set of values). If the (single) choice is a dynamic subtype, we
2856 don't need to make this check as no predicates are allowed (see
2857 @RefSecNum{Subtype Predicates}) and
2858 thus the range has to be contiguous.]}
2859 @end{Reason}
2860
2861 A bottom level subaggregate of a multidimensional @nt<array_aggregate>
2862 of a given array type
2863 is allowed to be a @nt<string_literal> only if the component type of the
2864 array type is a character type;
2865 each character of such a @nt{string_literal} shall correspond to
2866 a @nt<defining_character_literal> of the component type.
2867 @end{Legality}
2868
2869 @begin{StaticSem}
2870 A subaggregate that is a @nt<string_literal> is equivalent
2871 to one that is a @nt<positional_array_aggregate> of the same length,
2872 with each @nt<expression> being the @nt<character_literal>
2873 for the corresponding character of the @nt<string_literal>.
2874 @end{StaticSem}
2875
2876 @begin{RunTime}
2877 @Leading@PDefn2{Term=[evaluation], Sec=(array_aggregate)}
2878 The evaluation of an @nt{array_aggregate} of a given array type
2879 proceeds in two steps:
2880 @begin(enumerate)
2881 Any @nt{discrete_choice}s of this aggregate and of its subaggregates
2882 are evaluated in an arbitrary order, and converted to the corresponding
2883 index type;@PDefn2{Term=[arbitrary order],Sec=[allowed]}
2884 @PDefn2{Term=[implicit subtype conversion],Sec=(choices of aggregate)}
2885
2886 The array component expressions of the aggregate
2887 are evaluated in an arbitrary order and
2888 their values are converted to the component subtype of
2889 the array type; an array component expression
2890 is evaluated once for each associated component.
2891 @PDefn2{Term=[implicit subtype conversion],Sec=(expressions of aggregate)}
2892 @PDefn2{Term=[arbitrary order],Sec=[allowed]}
2893 @end(enumerate)
2894 @begin(Ramification)
2895 Subaggregates are not separately evaluated.
2896 The conversion of the value of the component expressions
2897 to the component subtype might raise Constraint_Error.
2898
2899 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0005-1]}
2900 @ChgAdded{Version=[3],Text=[We don't need to say that <> is
2901 evaluated once for each component, as <> means that each component
2902 is @i{initialized by default}. That means that the actions defined
2903 for default initialization are applied to each component individually.
2904 Initializing one component by default and copying
2905 that to the others would be an incorrect implementation in general
2906 (although it might be OK if the default initialization is known
2907 to be constant).]}
2908 @end(Ramification)
2909
2910 @ChgRef{Version=[2],Kind=[Added],ARef=[AI95-00287-01]}
2911 @ChgRef{Version=[4],Kind=[RevisedAdded],ARef=[AI12-0084-1]}
2912 @ChgAdded{Version=[2],Text=[Each @nt<expression> in an
2913 @nt<array_component_association> defines the value for the associated
2914 component(s). For an @nt<array_component_association> with <>, the associated
2915 component(s) are initialized @Chg{Version=[4],New=[to the Default_Component_Value
2916 of the array type if this aspect has been specified for the array type;
2917 otherwise, they are initialized ],Old=[]}by default
2918 as for a stand-alone object of the
2919 component subtype (see @RefSecNum{Object Declarations}).]}
2920
2921 @Leading@Defn2{Term=[bounds],
2922 Sec=(of the index range of an @nt{array_aggregate})}
2923 The bounds of the index range of an @nt{array_aggregate} @Redundant[(including
2924 a subaggregate)]
2925 are determined as follows:
2926 @begin(itemize)
2927 For an @nt{array_aggregate} with an @key(others) choice, the bounds are
2928 those of the corresponding index range from the applicable
2929 index constraint;
2930
2931 For a @nt{positional_array_aggregate} @Redundant[(or equivalent
2932 @nt<string_literal>)]
2933 without an @key(others)
2934 choice, the lower bound is that of the corresponding index range in the
2935 applicable index constraint, if defined, or that of the corresponding
2936 index subtype, if not; in either case, the upper bound is
2937 determined from the lower bound and the number of @nt<expression>s
2938 @Redundant[(or the length of the @nt<string_literal>)];
2939
2940 For a @nt{named_array_aggregate} without an @key(others) choice,
2941 the bounds are determined by the smallest and largest index values
2942 covered by any @nt{discrete_choice_list}.
2943 @begin{Reason}
2944 We don't need to say that each index value has to be covered exactly
2945 once, since that is a ramification of the general rule
2946 on @nt{aggregate}s that each component's value has to be specified
2947 exactly once.
2948 @end{Reason}
2949 @end(itemize)
2950
2951 @IndexCheck{Range_Check}
2952 For an @nt<array_aggregate>, a check is made
2953 that the index range defined by its bounds
2954 is compatible with the corresponding index subtype.
2955 @begin{Discussion}
2956 In RM83, this was
2957 phrased more explicitly, but once we define "compatibility"
2958 between a range and a subtype, it seems to make sense to
2959 take advantage of that definition.
2960 @end{Discussion}
2961 @begin(Ramification)
2962 The definition of compatibility handles the special case
2963 of a null range, which is always compatible with
2964 a subtype. See AI83-00313.
2965 @end(Ramification)
2966
2967 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0037-1]}
2968 @IndexCheck{Index_Check}
2969 For an @nt{array_aggregate} with an @key(others) choice,
2970 a check is made that no @nt<expression>@Chg{Version=[3],New=[ or <>],Old=[]}
2971 is specified for an index value outside the bounds determined by the
2972 applicable index constraint.
2973 @begin{Discussion}
2974 RM83 omitted this case,
2975 apparently through an oversight. AI83-00309 defines this
2976 as a dynamic check, even though other Ada 83 rules ensured
2977 that this check could be performed statically. We now allow
2978 an @key(others) choice to be dynamic, even if
2979 it is not the only choice, so this check now needs to be
2980 dynamic, in some cases. Also, within a generic unit,
2981 this would be a nonstatic check in some cases.
2982 @end{Discussion}
2983
2984 @IndexCheck{Index_Check}
2985 For a multidimensional @nt{array_aggregate}, a check is made
2986 that all subaggregates that correspond to the same index have the same bounds.
2987 @begin{Ramification}
2988 No array bounds @lquotes@;sliding@rquotes@; is performed on subaggregates.
2989 @end{Ramification}
2990 @begin{Reason}
2991 If sliding were performed, it would not be obvious which
2992 subaggregate would determine the bounds of the corresponding index.
2993 @end{Reason}
2994
2995 @Defn2{Term=[Constraint_Error],Sec=(raised by failure of run-time check)}
2996 The exception Constraint_Error is raised if any of the above
2997 checks fail.
2998 @end{RunTime}
2999
3000 @begin{Notes}
3001 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0004-1]}
3002 In an @nt<array_aggregate>, positional notation may only be used
3003 with two or more @nt<expression>s; a single @nt<expression>
3004 in parentheses is interpreted as a
3005 @Chg{Version=[3],New=[parenthesized expression],Old=[@ntf{parenthesized_expression}]}.
3006 A @nt<named_array_aggregate>, such as (1 => X), may be used to specify
3007 an array with a single component.
3008 @end{Notes}
3009
3010 @begin{Examples}
3011 @Leading@keepnext@i(Examples of array aggregates with positional associations:)
3012 @begin{Example}
3013 (7, 9, 5, 1, 3, 2, 4, 8, 6, 0)
3014 Table'(5, 8, 4, 1, @key(others) => 0) --@RI[ see @RefSecNum{Array Types} ]
3015 @end{Example}
3016
3017 @begin{WideAbove}
3018 @leading@keepnext@i(Examples of array aggregates with named associations:)
3019 @end{WideAbove}
3020 @begin{Example}
3021 (1 .. 5 => (1 .. 8 => 0.0)) --@RI[ two-dimensional]
3022 (1 .. N => @key(new) Cell) --@RI[ N new cells, in particular for N = 0]
3023
3024 Table'(2 | 4 | 10 => 1, @key(others) => 0)
3025 Schedule'(Mon .. Fri => True, @key(others) => False) --@RI[ see @RefSecNum{Array Types}]
3026 Schedule'(Wed | Sun => False, @key(others) => True)
3027 Vector'(1 => 2.5) --@RI[ single-component vector]
3028 @end{Example}
3029
3030 @begin{WideAbove}
3031 @leading@keepnext@i(Examples of two-dimensional array aggregates:)
3032 @end{WideAbove}
3033 @begin{Example}
3034 --@RI[ Three aggregates for the same value of subtype Matrix(1..2,1..3) (see @RefSecNum{Array Types}):]
3035
3036 ((1.1, 1.2, 1.3), (2.1, 2.2, 2.3))
3037 (1 => (1.1, 1.2, 1.3), 2 => (2.1, 2.2, 2.3))
3038 (1 => (1 => 1.1, 2 => 1.2, 3 => 1.3), 2 => (1 => 2.1, 2 => 2.2, 3 => 2.3))
3039 @end{Example}
3040
3041 @begin{WideAbove}
3042 @leading@keepnext@i(Examples of aggregates as initial values:)
3043 @end{WideAbove}
3044 @begin{Example}
3045 A : Table := (7, 9, 5, 1, 3, 2, 4, 8, 6, 0); --@RI[ A(1)=7, A(10)=0]
3046 B : Table := (2 | 4 | 10 => 1, @key(others) => 0); --@RI[ B(1)=0, B(10)=1]
3047 C : @key(constant) Matrix := (1 .. 5 => (1 .. 8 => 0.0)); --@RI[ C'Last(1)=5, C'Last(2)=8]
3048
3049 D : Bit_Vector(M .. N) := (M .. N => True); --@RI[ see @RefSecNum{Array Types}]
3050 E : Bit_Vector(M .. N) := (@key(others) => True);
3051 F : String(1 .. 1) := (1 => 'F'); --@RI[ a one component aggregate: same as "F"]
3052 @end{Example}
3053
3054 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00433-01]}
3055 @ChgAdded{Version=[2],Type=[Leading],KeepNext=[T],Text=[@i{Example of an array
3056 aggregate with defaulted others choice and with an applicable index constraint
3057 provided by an enclosing record aggregate:}]}
3058
3059 @begin{Example}
3060 @ChgRef{Version=[2],Kind=[AddedNormal]}
3061 @ChgAdded{Version=[2],Text=[Buffer'(Size => 50, Pos => 1, Value => String'('x', @key(others) => <>)) --@RI[ see @RefSecNum{Discriminants}]]}
3062 @end{Example}
3063 @end{Examples}
3064
3065 @begin{Incompatible83}
3066 @ChgRef{Version=[1],Kind=[Added]}@ChgNote{Presentation AI-00016}
3067 @ChgAdded{Version=[1],Type=[Leading],Text=[@Defn{incompatibilities with Ada 83}
3068 In Ada 95, no applicable index constraint is defined for a parameter
3069 in a call to a generic formal subprogram; thus, some aggregates that are
3070 legal in Ada 83 are illegal in Ada 95. For example:]}
3071 @begin{Example}
3072 @ChgRef{Version=[1],Kind=[Added]}@ChgNote{Presentation AI-00016}
3073 @Chg{New=[@key[subtype] S3 @key[is] String (1 .. 3);
3074 ...
3075 @key[generic]
3076 @key[with function] F (The_S3 : @key[in] S3) @key[return] Integer;
3077 @key[package] Gp @key[is]
3078 I : constant Integer := F ((1 => '!', others => '?'));
3079 -- @RI{The aggregate is legal in Ada 83, illegal in Ada 95.}
3080 @key[end] Gp;],Old=[]}
3081 @end{Example}
3082 @ChgRef{Version=[1],Kind=[Added]}@ChgNote{Presentation AI-00016}
3083 @Chg{New=[This change eliminates generic contract model problems.],Old=[]}
3084 @end{Incompatible83}
3085
3086 @begin{Extend83}
3087 @Defn{extensions to Ada 83}
3088 We now allow "named with others" aggregates in all contexts
3089 where there is an applicable index constraint, effectively
3090 eliminating what was RM83-4.3.2(6). Sliding never occurs
3091 on an aggregate with others, because its bounds come from
3092 the applicable index constraint, and therefore already match
3093 the bounds of the target.
3094
3095 The legality of an @key(others) choice is no longer affected
3096 by the staticness of the applicable index constraint.
3097 This substantially simplifies several rules, while being slightly
3098 more flexible for the user. It obviates the rulings
3099 of AI83-00244 and AI83-00310, while taking advantage of the dynamic nature
3100 of the "extra values" check required by AI83-00309.
3101
3102 Named array aggregates are permitted even if the
3103 index type is descended from a formal scalar type.
3104 See @RefSecNum(Static Expressions and Static Subtypes) and AI83-00190.
3105 @end{Extend83}
3106
3107 @begin{DiffWord83}
3108 We now separate named and positional array aggregate syntax,
3109 since, unlike other aggregates, named and positional
3110 associations cannot be mixed in array aggregates (except
3111 that an @key(others) choice is allowed in a positional array aggregate).
3112
3113 We have also reorganized the presentation to handle
3114 multidimensional and one-dimensional aggregates more uniformly,
3115 and to incorporate the rulings of AI83-00019, AI83-00309, etc.
3116 @end{DiffWord83}
3117
3118
3119 @begin{Extend95}
3120 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00287-01]}
3121 @ChgAdded{Version=[2],Text=[@Defn{extensions to Ada 95}<> can be used in
3122 place of an @nt{expression} in an @nt{array_aggregate}, default-initializing
3123 the component.]}
3124 @end{Extend95}
3125
3126 @begin{DiffWord95}
3127 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00287-01]}
3128 @ChgAdded{Version=[2],Text=[Limited @nt{array_aggregate}s are allowed (since
3129 all kinds of aggregates can now be limited, see @RefSecNum{Aggregates}).]}
3130
3131 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00318-02]}
3132 @ChgAdded{Version=[2],Text=[Fixed @nt{aggregate}s to use the subtype of
3133 the return object of a function, rather than the result subtype, because
3134 they can be different for an @nt{extended_return_statement}, and we want
3135 to use the subtype that's explicitly in the code at the point of the
3136 @nt{expression}.]}
3137 @end{DiffWord95}
3138
3139 @begin{Inconsistent2005}
3140 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0037-1]}
3141 @ChgAdded{Version=[3],Text=[@Defn{inconsistencies with Ada 2005}@b<Correction:>
3142 Fixed so the check
3143 for components outside of the array applies to both @nt<expression>s and
3144 <>s. As <> was a new feature in Ada 2005, there should be little existing
3145 code that depends on a <> component that is specified outside of the array
3146 (and that is nonsense anyway, that a compiler is likely to detect even
3147 without an explicit language rule disallowing it).]}
3148 @end{Inconsistent2005}
3149
3150 @begin{DiffWord2005}
3151 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0147-1]}
3152 @ChgAdded{Version=[3],Text=[Added a definition of the applicable index
3153 constraint for @nt{conditional_expression}s (which are new).]}
3154 @end{DiffWord2005}
3155
3156 @begin{Inconsistent2012}
3157 @ChgRef{Version=[4],Kind=[AddedNormal],ARef=[AI05-0084-1]}
3158 @ChgAdded{Version=[4],Text=[@Defn{inconsistencies with Ada 2012}@b<Corrigendum:>
3159 Fixed so that the Default_Component_Value (if any) is used to initialize
3160 components specified with <>. This is what users would expect, and all
3161 Ada 2012 implementation known at the time of this writing initialize with
3162 the Default_Component_Value, so it is unlikely that anyone will be affected
3163 by this inconsistency.]}
3164 @end{Inconsistent2012}
3165
3166 @begin{DiffWord2012}
3167 @ChgRef{Version=[4],Kind=[AddedNormal],ARef=[AI05-0157-1]}
3168 @ChgAdded{Version=[4],Text=[@b<Corrigendum:>
3169 Added expression functions to the contexts that provide an applicable
3170 index constraint, because expression functions are handled separately in
3171 static semantics and legality rules.]}
3172 @end{DiffWord2012}
3173
3174
3175 @LabeledClause{Expressions}
3176
3177 @begin{Intro}
3178 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0147-1],ARef=[AI05-0158-1],ARef=[AI05-0176-1]}
3179 @Defn{expression}
3180 An @i(expression) is a formula that defines the computation or retrieval
3181 of a value.
3182 In this International Standard, the term @lquotes@;expression@rquotes@; refers to a construct
3183 of the syntactic category @nt<expression> or of any of the
3184 @Chg{Version=[3],New=[following categories: @nt{choice_expression}, @nt{choice_relation},
3185 @nt{relation}, @nt{simple_expression}, @nt{term}, @nt{factor}, @nt{primary},
3186 @nt{conditional_expression}, @nt{quantified_expression}],Old=[other five syntactic categories defined
3187 below]}.
3188 @Defn{and operator}@Defn2{Term=[operator],Sec=(and)}
3189 @Defn{or operator}@Defn2{Term=[operator],Sec=(or)}
3190 @Defn{xor operator}@Defn2{Term=[operator],Sec=(xor)}
3191 @Defn{and then (short-circuit control form)}
3192 @Defn{or else (short-circuit control form)}
3193 @Defn{= operator}@Defn2{Term=[operator],Sec=(=)}
3194 @Defn{equal operator}@Defn2{Term=[operator],Sec=(equal)}
3195 @Defn{/= operator}@Defn2{Term=[operator],Sec=(/=)}
3196 @Defn{not equal operator}@Defn2{Term=[operator],Sec=(not equal)}
3197 @Defn{< operator}@Defn2{Term=[operator],Sec=(<)}
3198 @Defn{less than operator}@Defn2{Term=[operator],Sec=(less than)}
3199 @Defn{<= operator}@Defn2{Term=[operator],Sec=(<=)}
3200 @Defn{less than or equal operator}@Defn2{Term=[operator],Sec=(less than or equal)}
3201 @Defn{> operator}@Defn2{Term=[operator],Sec=(>)}
3202 @Defn{greater than operator}@Defn2{Term=[operator],Sec=(greater than)}
3203 @Defn{>= operator}@Defn2{Term=[operator],Sec=(>=)}
3204 @Defn{greater than or equal operator}@Defn2{Term=[operator],Sec=(greater than or equal)}
3205 @Defn{in (membership test)}
3206 @Defn{not in (membership test)}
3207 @Defn{+ operator}@Defn2{Term=[operator],Sec=(+)}
3208 @Defn{plus operator}@Defn2{Term=[operator],Sec=(plus)}
3209 @Defn{- operator}@Defn2{Term=[operator],Sec=(-)}
3210 @Defn{minus operator}@Defn2{Term=[operator],Sec=(minus)}
3211 @Defn{& operator}@Defn2{Term=[operator],Sec=(&)}
3212 @Defn{ampersand operator}@Defn2{Term=[operator],Sec=(ampersand)}
3213 @Defn{concatenation operator}@Defn2{Term=[operator],Sec=(concatenation)}
3214 @IndexSee{Term=[catenation operator],See=(concatenation operator)}
3215 @Defn{* operator}@Defn2{Term=[operator],Sec=(*)}
3216 @Defn{multiply operator}@Defn2{Term=[operator],Sec=(multiply)}
3217 @Defn{times operator}@Defn2{Term=[operator],Sec=(times)}
3218 @Defn{/ operator}@Defn2{Term=[operator],Sec=(/)}
3219 @Defn{divide operator}@Defn2{Term=[operator],Sec=(divide)}
3220 @Defn{mod operator}@Defn2{Term=[operator],Sec=(mod)}
3221 @Defn{rem operator}@Defn2{Term=[operator],Sec=(rem)}
3222 @Defn{** operator}@Defn2{Term=[operator],Sec=(**)}
3223 @Defn{exponentiation operator}@Defn2{Term=[operator],Sec=(exponentiation)}
3224 @Defn{abs operator}@Defn2{Term=[operator],Sec=(abs)}
3225 @Defn{absolute value}
3226 @Defn{not operator}@Defn2{Term=[operator],Sec=(not)}
3227 @end{Intro}
3228
3229 @begin{Syntax}
3230 @Syn{tabs=[P23], lhs=<expression>,rhs="
3231 @Syn2{relation} {@key{and} @Syn2{relation}} @\| @Syn2{relation} {@key{and} @key{then} @Syn2{relation}}
3232 | @Syn2{relation} {@key{or} @Syn2{relation}} @\| @Syn2{relation} {@key{or} @key{else} @Syn2{relation}}
3233 | @Syn2{relation} {@key{xor} @Syn2{relation}}"}
3234
3235 @ChgRef{Version=[3],Kind=[Added],ARef=[AI05-0158-1]}
3236 @AddedSyn{Version=[3],lhs=<@Chg{Version=[3],New=<choice_expression>,Old=<>}>,
3237 rhs="@Chg{Version=[3],New=<
3238 @Syn2[choice_relation] {@key[and] @Syn2[choice_relation]}
3239 | @Syn2[choice_relation] {@key[or] @Syn2[choice_relation]}
3240 | @Syn2[choice_relation] {@key[xor] @Syn2[choice_relation]}
3241 | @Syn2[choice_relation] {@key[and then] @Syn2[choice_relation]}
3242 | @Syn2[choice_relation] {@key[or else] @Syn2[choice_relation]}>,Old=<>}"}
3243
3244 @ChgRef{Version=[3],Kind=[Added],ARef=[AI05-0158-1]}
3245 @AddedSyn{Version=[3],lhs=<@Chg{Version=[3],New=<choice_relation>,Old=<>}>,
3246 rhs="@Chg{Version=[3],New=<
3247 @Syn2{simple_expression} [@Syn2{relational_operator} @Syn2{simple_expression}]>,Old=<>}"}
3248
3249 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0158-1]}
3250 @ChgRef{Version=[4],Kind=[Revised],ARef=[AI12-0022-1],ARef=[AI12-0039-1]}
3251 @Syn{lhs=<relation>,rhs="
3252 @Syn2{simple_expression} [@Syn2{relational_operator} @Syn2{simple_expression}]
3253 | @Chg{Version=[4],New=[@SynI{tested_}@Syn2{simple_expression}],Old=[@Syn2{simple_expression}]} [@key{not}] @key{in} @Chg{Version=[3],New=[@Syn2{membership_choice_list}@Chg{Version=[4],New=[
3254 | @Syn2{raise_expression}],Old=[]}],Old="@Syn2{range}
3255 | @Syn2{simple_expression} [@key{not}] @key{in} @Syn2{subtype_mark}"}"}
3256
3257 @ChgRef{Version=[3],Kind=[Added],ARef=[AI05-0158-1]}
3258 @AddedSyn{Version=[3],lhs=<@Chg{Version=[3],New=<membership_choice_list>,Old=<>}>,
3259 rhs="@Chg{Version=[3],New=<@Syn2{membership_choice} {| @Syn2{membership_choice}}>,Old=<>}"}
3260
3261 @ChgRef{Version=[3],Kind=[Added],ARef=[AI05-0158-1]}
3262 @ChgRef{Version=[4],Kind=[RevisedAdded],ARef=[AI12-0039-1]}
3263 @AddedSyn{Version=[3],lhs=<@Chg{Version=[3],New=<membership_choice>,Old=<>}>,
3264 rhs="@Chg{Version=[3],New=<@Chg{Version=[4],New=<@SynI{choice_}@Syn2{simple_expression}>,Old=<@Syn2{choice_expression}>} | @Syn2{range} | @Syn2{subtype_mark}>,Old=<>}"}
3265
3266 @Syn{lhs=<simple_expression>,rhs="[@Syn2{unary_adding_operator}] @Syn2{term} {@Syn2{binary_adding_operator} @Syn2{term}}"}
3267
3268
3269 @Syn{lhs=<term>,rhs="@Syn2{factor} {@Syn2{multiplying_operator} @Syn2{factor}}"}
3270
3271
3272 @Syn{lhs=<factor>,rhs="@Syn2{primary} [** @Syn2{primary}] | @key{abs} @Syn2{primary} | @key{not} @Syn2{primary}"}
3273
3274 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0003-1],ARef=[AI05-0147-1],ARef=[AI05-0176-1]}
3275 @Syn{lhs=<primary>,rhs="
3276 @Syn2{numeric_literal} | @key{null} | @Syn2{string_literal} | @Syn2{aggregate}
3277 | @Syn2{name} | @Chg{Version=[3],New=[],Old=[@Syn2{qualified_expression} | ]}@Syn2{allocator} | (@Syn2{expression})@Chg{Version=[3],New=[
3278 | (@Syn2{conditional_expression}) | (@Syn2{quantified_expression})],Old=[]}"}
3279 @end{Syntax}
3280
3281 @begin{Resolution}
3282 A @nt<name> used as a @nt<primary> shall resolve to denote an object
3283 or a value.
3284 @begin{Discussion}
3285 This replaces RM83-4.4(3). We don't need to mention named numbers
3286 explicitly, because the name of a named number denotes a value.
3287 We don't need to mention attributes explicitly, because
3288 attributes now denote (rather than yield) values in general.
3289 Also, the new wording allows attributes that denote objects,
3290 which should always have been allowed (in case the implementation chose to
3291 have such a thing).
3292 @end{Discussion}
3293 @begin{Reason}
3294 It might seem odd that this is an overload resolution rule,
3295 but it is relevant during overload resolution. For example,
3296 it helps ensure that a @nt<primary> that consists of only
3297 the identifier of a parameterless function is interpreted as a
3298 @nt<function_call> rather than directly as a @nt<direct_name>.
3299 @end{Reason}
3300 @end{Resolution}
3301
3302 @begin{StaticSem}
3303 Each expression has a type; it specifies the
3304 computation or retrieval of a value of that type.
3305 @end{StaticSem}
3306
3307 @begin{RunTime}
3308 @PDefn2{Term=[evaluation], Sec=(primary that is a name)}
3309 The value of a @nt<primary> that is a @nt{name} denoting an object
3310 is the value of the object.
3311 @end{RunTime}
3312
3313 @begin{ImplPerm}
3314 @IndexCheck{Overflow_Check}
3315 @Defn2{Term=[Constraint_Error],Sec=(raised by failure of run-time check)}
3316 For the evaluation of
3317 a @nt<primary> that is a @nt<name> denoting an object of an
3318 unconstrained numeric subtype,
3319 if the value of the object is outside the base range of its type,
3320 the implementation may either raise Constraint_Error
3321 or return the value of the object.
3322 @begin{Ramification}
3323 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0299-1]}
3324 This means that if extra-range intermediates are used to
3325 hold the value of an object of an unconstrained numeric subtype,
3326 a Constraint_Error can be raised on a read of the object, rather than
3327 only on an assignment to it. Similarly, it means that
3328 computing the value of an object of such a subtype
3329 can be deferred until the first read of the object
3330 (presuming no side effects other than failing an Overflow_Check
3331 are possible). This permission is over and above that provided
3332 by @Chg{Version=[3],New=[subclause],Old=[clause]}
3333 @RefSecNum(Exceptions and Optimization), since
3334 this allows the Constraint_Error to move to a different handler.
3335 @end{Ramification}
3336 @begin{Reason}
3337 This permission is intended to allow extra-range registers
3338 to be used efficiently to hold parameters and local variables,
3339 even if they might need to be transferred into smaller registers
3340 for performing certain predefined operations.
3341 @end{Reason}
3342 @begin{Discussion}
3343 There is no need to mention other kinds of @nt<primary>s, since any
3344 Constraint_Error to be raised can be @lquotes@;charged@rquotes@; to the evaluation
3345 of the particular kind of @nt<primary>.
3346 @end{Discussion}
3347 @end{ImplPerm}
3348
3349 @begin{Examples}
3350 @Leading@keepnext@i(Examples of primaries:)
3351 @begin{Example}
3352 @Trailing@;4.0 --@RI[ real literal]
3353 Pi --@RI[ named number]
3354 (1 .. 10 => 0) --@RI[ array aggregate]
3355 Sum --@RI[ variable]
3356 Integer'Last --@RI[ attribute]
3357 Sine(X) --@RI[ function call]
3358 Color'(Blue) --@RI[ qualified expression]
3359 Real(M*N) --@RI[ conversion]
3360 (Line_Count + 10) --@RI[ parenthesized expression ]
3361 @end{Example}
3362
3363 @leading@keepnext@i(Examples of expressions:)
3364 @begin{Example}
3365 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00433-01]}
3366 Volume --@RI[ primary]
3367 @key(not) Destroyed --@RI[ factor]
3368 2*Line_Count --@RI[ term]
3369 -4.0 --@RI[ simple expression]
3370 -4.0 + A --@RI[ simple expression]
3371 B**2 - 4.0*A*C --@RI[ simple expression]@Chg{Version=[2],New=[
3372 R*Sin(@unicode<952>)*Cos(@unicode<966>) --@RI[ simple expression]],Old=[]}
3373 Password(1 .. 3) = "Bwv" --@RI[ relation]
3374 Count @key(in) Small_Int --@RI[ relation]
3375 Count @key(not) @key(in) Small_Int --@RI[ relation]
3376 Index = 0 @key(or) Item_Hit --@RI[ expression]
3377 (Cold @key(and) Sunny) @key(or) Warm --@RI[ expression (parentheses are required)]
3378 A**(B**C) --@RI[ expression (parentheses are required)]
3379 @end{Example}
3380 @end{Examples}
3381
3382 @begin{Extend83}
3383 @Defn{extensions to Ada 83}
3384 In Ada 83, @key{out} parameters and their nondiscriminant
3385 subcomponents are not allowed as @ntf{primaries}.
3386 These restrictions are eliminated in Ada 95.
3387
3388 In various contexts throughout the language where Ada 83 syntax rules
3389 had @nt<simple_expression>, the corresponding Ada 95 syntax
3390 rule has @nt<expression> instead. This reflects the inclusion
3391 of modular integer types, which makes the logical operators
3392 "@key[and]", "@key[or]", and "@key[xor]" more useful in expressions of
3393 an integer type.
3394 Requiring parentheses to use these operators in such contexts
3395 seemed unnecessary and potentially confusing.
3396 Note that the bounds of a @nt<range> still have to be
3397 specified by @nt<simple_expression>s, since otherwise @nt<expression>s
3398 involving membership tests might be ambiguous.
3399 Essentially, the operation ".." is of higher precedence than the
3400 logical operators, and hence uses of logical operators
3401 still have to be parenthesized when used in a bound of a range.
3402 @end{Extend83}
3403
3404 @begin{DiffWord2005}
3405 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0003-1]}
3406 @ChgAdded{Version=[3],Text=[Moved @nt{qualified_expression}
3407 from @nt{primary} to @nt{name} (see @RefSecNum{Names}). This allows the
3408 use of @nt{qualified_expression}s in more places.]}
3409
3410 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0147-1],ARef=[AI05-0176-1]}
3411 @ChgAdded{Version=[3],Text=[Added @nt{conditional_expression} and
3412 @nt{quantified_expression} to @nt{primary}.]}
3413
3414 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0158-1]}
3415 @ChgAdded{Version=[3],Text=[Expanded membership test syntax (see
3416 @RefSecNum{Relational Operators and Membership Tests}).]}
3417 @end{DiffWord2005}
3418
3419 @begin{Inconsistent2012}
3420 @ChgRef{Version=[4],Kind=[AddedNormal],ARef=[AI12-0039-1]}
3421 @ChgAdded{Version=[4],Text=[@Defn{inconsistencies with Ada 2012}@b<Corrigendum:>
3422 Revised membership syntax to eliminate ambiguities. In some cases,
3423 previously ambiguous membership expressions will now have an unambiguous
3424 meaning. If an Ada 2012 implementation chose the "wrong" meaning, the
3425 expression could silently change meaning. Virtually all such expressions
3426 will become illegal because of type mismatches (and thus be incompatible,
3427 not inconsistent). However, if the choices
3428 are all of a Boolean type, resolution might succeed. For instance, @exam{A
3429 @key[in] B | C @key[and] D} now always means @exam{(A @key[in] B | C)
3430 @key[and] D}, but the original Ada 2012 syntax would have allowed it to mean
3431 @exam{A @key[in] B | (C @key[and] D)}. If a compiler allowed the expression
3432 and interpreted it as the latter, the meaning of the expression would silently
3433 change. We expect this to be extremely rare as membership operations on
3434 Boolean types are unlikely (and this can happen only in code written for Ada
3435 2012).]}
3436 @end{Inconsistent2012}
3437
3438 @begin{Incompatible2012}
3439 @ChgRef{Version=[4],Kind=[AddedNormal],ARef=[AI12-0039-1]}
3440 @ChgAdded{Version=[4],Text=[@Defn{incompatibilities with Ada 2012}@b<Corrigendum:>
3441 The revised membership syntax will require
3442 parentheses in @nt{membership_choice_list}s in some cases where the
3443 Ada 2012 grammar did not require them. For instance,
3444 @exam{A @key[in] B @key[in] C | D}
3445 is now illegal. However, such expressions can be interpreted in multiple ways
3446 (either @exam{A @key[in] (B @key[in] C) | D} or
3447 @exam{A @key[in] (B @key[in] C | D)} for this example), so using such
3448 expressions is likely to be dangerous (another compiler might interpret the
3449 expression differently). In addition, all such expressions occur only in
3450 Ada 2012 syntax; so they should be rare.]}
3451 @end{Incompatible2012}
3452
3453
3454
3455 @LabeledClause{Operators and Expression Evaluation}
3456
3457 @begin{Intro}
3458 @Redundant[@Defn{precedence of operators}
3459 @Defn{operator precedence}
3460 The language defines the following six categories
3461 of operators (given in order of increasing
3462 precedence). The corresponding @nt<operator_symbol>s,
3463 and only those, can be used as @nt<designator>s in declarations
3464 of functions for user-defined operators. See @RefSec(Overloading of Operators).]
3465 @end{Intro}
3466
3467 @begin{Syntax}
3468 @Syn{tabs=[P36], lhs=<logical_operator>,
3469 rhs="@\ @key{and} | @key{or} | @key{xor}"}
3470 @Syn{tabs=[P36], lhs=<relational_operator>,rhs="@\ = | /= | < | <= | > | >="}
3471 @Syn{tabs=[P36], lhs=<binary_adding_operator>,rhs="@\ + | @en | &"}
3472 @Syn{tabs=[P36], lhs=<unary_adding_operator>,rhs="@\ + | @en"}
3473 @Syn{tabs=[P36], lhs=<multiplying_operator>,rhs="@\ * | / | @key{mod} | @key{rem}"}
3474 @Syn{tabs=[P36], lhs=<highest_precedence_operator>,rhs="@\ ** | @key{abs} | @key{not}"}
3475 @begin(Discussion)
3476 Some of the above syntactic categories are not used in other
3477 syntax rules. They are just used for classification.
3478 The others are used for both classification and parsing.
3479 @end(Discussion)
3480 @end{Syntax}
3481
3482 @begin{StaticSem}
3483 For a sequence of operators of the same precedence level, the
3484 operators are associated with their operands
3485 in textual order from left to right.
3486 Parentheses can be used to impose specific associations.
3487 @begin{Discussion}
3488 The left-associativity is not directly inherent in the grammar of
3489 @RefSecNum{Expressions},
3490 though in @RefSecNum{Method of Description and Syntax Notation}
3491 the definition of the metasymbols @b({}) implies left
3492 associativity. So this could be seen as redundant, depending on
3493 how literally one interprets the definition of the @b({}) metasymbols.
3494
3495 See the Implementation Permissions below regarding flexibility
3496 in reassociating operators of the same precedence.
3497 @end{Discussion}
3498
3499 @Defn{predefined operator}@Defn2{Term=[operator],Sec=(predefined)}
3500 For each form of type definition, certain of the above operators are
3501 @i(predefined);
3502 that is, they are implicitly declared immediately after the type definition.
3503 @Defn{binary operator}@Defn2{Term=[operator],Sec=(binary)}
3504 @Defn{unary operator}@Defn2{Term=[operator],Sec=(unary)}
3505 For each such implicit operator declaration, the
3506 parameters are called Left and Right for @i(binary) operators;
3507 the single parameter is called Right for @i(unary) operators.
3508 @redundant[An expression of the form X op Y,
3509 where op is a binary operator,
3510 is equivalent to a @nt<function_call> of the form "op"(X, Y).
3511 An expression of the form op Y,
3512 where op is a unary operator,
3513 is equivalent to a @nt<function_call> of the form "op"(Y).
3514 The predefined operators and their effects are described
3515 in subclauses @RefSecNum(Logical Operators and Short-Circuit Control Forms)
3516 through @RefSecNum(Highest Precedence Operators).]
3517 @end{StaticSem}
3518
3519 @begin{RunTime}
3520 @redundant[@Defn2{Term=[Constraint_Error],Sec=(raised by failure of run-time check)}
3521 The predefined operations on integer types either yield the mathematically
3522 correct result or raise the exception Constraint_Error.
3523 For implementations that support the Numerics Annex,
3524 the predefined operations on real types yield results whose
3525 accuracy is defined in @RefSecNum(Numerics), or
3526 raise the exception Constraint_Error.
3527 ]
3528 @begin{Honest}
3529 Predefined operations on real types can @lquotes@;silently@rquotes@; give wrong results
3530 when the Machine_Overflows attribute is false, and the
3531 computation overflows.
3532 @end{Honest}
3533
3534 @end{RunTime}
3535
3536 @begin{ImplReq}
3537 @Defn2{Term=[Constraint_Error],Sec=(raised by failure of run-time check)}
3538 The implementation of a predefined operator
3539 that delivers a result of an integer or fixed point type may
3540 raise Constraint_Error only if the result is outside
3541 the base range of the result type.
3542
3543 @Defn2{Term=[Constraint_Error],Sec=(raised by failure of run-time check)}
3544 The implementation of a predefined operator
3545 that delivers a result of a floating point type may raise Constraint_Error
3546 only if the result is outside the safe range of the
3547 result type.
3548 @begin{Honest}
3549
3550 An exception is made for exponentiation by a negative exponent in
3551 @RefSecNum{Highest Precedence Operators}.
3552
3553 @end{Honest}
3554 @end{ImplReq}
3555
3556 @begin{ImplPerm}
3557 For a sequence of predefined operators of the same precedence
3558 level (and in the absence of parentheses imposing a specific association),
3559 an implementation may impose any association of the operators with
3560 operands so long as the result produced is
3561 an allowed result for the left-to-right association, but ignoring
3562 the potential for failure of language-defined checks in either the
3563 left-to-right or chosen order of association.
3564 @begin{Discussion}
3565 Note that the permission to reassociate the operands in
3566 any way subject to producing a result allowed for
3567 the left-to-right association is not much help
3568 for most floating point operators, since reassociation may
3569 introduce significantly different round-off errors, delivering
3570 a result that is outside the model interval for the left-to-right
3571 association. Similar problems arise for division with
3572 integer or fixed point operands.
3573
3574 Note that this permission does not apply to user-defined
3575 operators.
3576 @end{Discussion}
3577 @end{ImplPerm}
3578
3579 @begin{Notes}
3580 The two operands of an expression of the form X op Y, where
3581 op is a binary operator, are evaluated in an arbitrary order,
3582 as for any @nt<function_call> (see @RefSecNum(Subprogram Calls)).
3583
3584 @end{Notes}
3585
3586 @begin{Examples}
3587 @Leading@keepnext@i(Examples of precedence:)
3588 @begin{Example}
3589 @key(not) Sunny @key(or) Warm --@RI[ same as (not Sunny) or Warm]
3590 X > 4.0 @key(and) Y > 0.0 --@RI[ same as (X > 4.0) and (Y > 0.0)]
3591
3592 -4.0*A**2 --@RI[ same as @en@;(4.0 * (A**2))]
3593 @key(abs)(1 + A) + B --@RI[ same as (abs (1 + A)) + B]
3594 Y**(-3) --@RI[ parentheses are necessary]
3595 A / B * C --@RI[ same as (A/B)*C]
3596 A + (B + C) --@RI[ evaluate B + C before adding it to A ]
3597 @end{Example}
3598 @end{Examples}
3599
3600 @begin{DiffWord83}
3601 We don't give a detailed definition of precedence, since
3602 it is all implicit in the syntax rules anyway.
3603
3604 The permission to reassociate is moved here from RM83-11.6(5), so
3605 it is closer to the rules defining operator association.
3606 @end{DiffWord83}
3607
3608
3609 @LabeledSubClause{Logical Operators and Short-circuit Control Forms}
3610
3611 @begin{Resolution}
3612 @Defn{short-circuit control form}
3613 @Defn{and then (short-circuit control form)}
3614 @Defn{or else (short-circuit control form)}
3615 An @nt<expression> consisting of two @nt<relation>s
3616 connected by @key(and then) or @key(or else)
3617 (a @i(short-circuit control form))
3618 shall resolve to be of some boolean type;
3619 @PDefn2{Term=[expected type],Sec=(short-circuit control form relation)}
3620 the expected type for both @nt<relation>s
3621 is that same boolean type.
3622 @begin(Reason)
3623 This rule is written this way so that overload resolution treats
3624 the two operands symmetrically; the resolution of overloading
3625 present in either one can benefit from the resolution of the other.
3626 Furthermore, the type expected by context can help.
3627 @end(Reason)
3628 @end{Resolution}
3629
3630 @begin{StaticSem}
3631 @Leading@Defn{logical operator}@Defn2{Term=[operator],Sec=(logical)}
3632 @Defn{and operator}@Defn2{Term=[operator],Sec=(and)}
3633 @Defn{or operator}@Defn2{Term=[operator],Sec=(or)}
3634 @Defn{xor operator}@Defn2{Term=[operator],Sec=(xor)}
3635 The following logical operators are predefined for every
3636 boolean type @i(T),
3637 for every modular type @i(T), and
3638 for every one-dimensional array type @i(T) whose
3639 component type is a boolean type:
3640 @IndexSee{Term=[bit string],See=(logical operators on boolean arrays)}
3641 @begin{example}
3642 @tabclear()
3643 @key[function] "@key(and)"(Left, Right : @RI(T)) @key[return] @RI(T)
3644 @key[function] "@key(or)" (Left, Right : @RI(T)) @key[return] @RI(T)
3645 @key[function] "@key(xor)"(Left, Right : @RI(T)) @key[return] @RI(T)
3646 @end{example}
3647 @begin{Honest}
3648 @ChgRef{Version=[2],Kind=[Deleted],ARef=[AI95-00145-01]}
3649 @ChgDeleted{Version=[2],Text=[For predefined operators, the parameter
3650 and result subtypes shown as @i(T) are actually the unconstrained
3651 subtype of the type.]}
3652 @ChgNote{Sorry, Bob, but there is no "honesty" issue here. And
3653 "unconstrained" is wrong.}
3654 @end{Honest}
3655 @begin{Ramification}
3656 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00145-01]}
3657 @ChgAdded{Version=[2],Text=[For these operators, we are talking about
3658 the type without any (interesting) subtype, and not some subtype with a
3659 constraint or exclusion. Since it's possible that there is no name for
3660 the @lquotes@;uninteresting@rquotes subtype, we denote the type
3661 with an italicized @i(T).
3662 This applies to the italicized @i(T) in many other predefined operators and
3663 attributes as well.@Defn2{Term=[T],Sec=[italicized]}]}
3664
3665 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00145-01]}
3666 @ChgAdded{Version=[2],Type=[Leading],Text=[In many cases, there is a subtype
3667 with the correct properties available. The italicized @i(T) means:]}
3668 @begin{Itemize}
3669 @ChgRef{Version=[2],Kind=[AddedNormal]}
3670 @ChgAdded{Version=[2],Text=[@i(T)'Base, for scalars;]}
3671
3672 @ChgRef{Version=[2],Kind=[AddedNormal]}
3673 @ChgAdded{Version=[2],Text=[the first subtype of @i(T), for tagged types;]}
3674
3675 @ChgRef{Version=[2],Kind=[AddedNormal]}
3676 @ChgAdded{Version=[2],Text=[a subtype of the type @i(T) without any
3677 constraint or null exclusion, in other cases.]}
3678 @end{Itemize}
3679
3680 @ChgRef{Version=[2],Kind=[AddedNormal]}
3681 @ChgAdded{Version=[2],Text=[Note that @lquotes@;without a constraint@rquotes
3682 is not the same as unconstrained. For instance, a record type with no
3683 discriminant part is considered constrained; no subtype of it has a
3684 constraint, but the subtype is still constrained.]}
3685
3686 @ChgRef{Version=[2],Kind=[AddedNormal]}
3687 @ChgAdded{Version=[2],Text=[Thus, the last case often is the same as
3688 the first subtype of @i(T), but that isn't the case for constrained array
3689 types (where the correct subtype is unconstrained) and for access types
3690 with a @nt{null_exclusion} (where the correct subtype does not
3691 exclude null).]}
3692
3693 @ChgRef{Version=[2],Kind=[AddedNormal]}
3694 @ChgAdded{Version=[2],Text=[This italicized @i(T) is used for defining
3695 operators and attributes of the language. The meaning is intended to be
3696 as described here.]}
3697 @end{Ramification}
3698
3699 For boolean types, the predefined logical operators
3700 @key{and}, @key{or}, and @key{xor}
3701 perform the conventional operations of conjunction, inclusive
3702 disjunction, and exclusive disjunction, respectively.
3703
3704 For modular types, the predefined logical operators
3705 are defined on a bit-by-bit basis, using the binary
3706 representation of the value of the operands to
3707 yield a binary representation for the result,
3708 where zero represents False and one represents True.
3709 If this result is outside the base range of the type,
3710 a final subtraction by the modulus is performed to bring the
3711 result into the base range of the type.
3712
3713 The logical operators on arrays are performed on a
3714 component-by-component basis on
3715 matching components (as for equality @em
3716 see @RefSecNum{Relational Operators and Membership Tests}),
3717 using the predefined logical operator for the component type. The bounds of
3718 the resulting array are those of the left operand.
3719
3720 @end{StaticSem}
3721
3722 @begin{RunTime}
3723 @PDefn2{Term=[evaluation], Sec=(short-circuit control form)}
3724 The short-circuit control forms @key{and then} and @key{or else}
3725 deliver the same result as the corresponding predefined @key{and} and @key{or}
3726 operators for boolean types, except that the left operand is always
3727 evaluated first, and the right operand is not evaluated if the
3728 value of the left operand determines the result.
3729
3730 @IndexCheck{Length_Check}
3731 For the logical operators on arrays,
3732 a check is made that
3733 for each component of the left operand there is a matching component of the
3734 right operand, and vice versa.
3735 @IndexCheck{Range_Check}
3736 Also, a check is made that each component
3737 of the result belongs to the component subtype.
3738 @Defn2{Term=[Constraint_Error],Sec=(raised by failure of run-time check)}
3739 The exception Constraint_Error is raised if
3740 either of the above checks fails.
3741 @begin{Discussion}
3742 The check against the component subtype is per AI83-00535.
3743 @end{Discussion}
3744
3745 @end{RunTime}
3746
3747 @begin{Notes}
3748 @Leading@;The conventional meaning of the logical operators is given by the
3749 following truth table:
3750 @begin(Display)
3751 @TabClear()
3752 @TabSet(P4, P20, P36, P52, P68)
3753 @\@ @ A@\@ @ B@\(A @key(and) B)@\(A @key(or) B)@\(A @key(xor) B)@*
3754 @\True @\True @\True @\True @\False
3755 @\True @\False @\False @\True @\True
3756 @\False @\True @\False @\True @\True
3757 @\False @\False @\False @\False @\False
3758 @end(Display)
3759 @end{Notes}
3760
3761 @begin{Examples}
3762 @Leading@keepnext@i(Examples of logical operators:)
3763 @begin{Example}
3764 Sunny @key(or) Warm
3765 Filter(1 .. 10) @key(and) Filter(15 .. 24) --@RI[ see @RefSecNum{Index Constraints and Discrete Ranges} ]
3766 @end{Example}
3767
3768 @begin{WideAbove}
3769 @leading@keepnext@i(Examples of short-circuit control forms:)
3770 @end{WideAbove}
3771 @begin{Example}
3772 Next_Car.Owner /= @key(null) @key(and) @key(then) Next_Car.Owner.Age > 25 --@RI[ see @RefSecNum{Incomplete Type Declarations}]
3773 N = 0 @key(or) @key(else) A(N) = Hit_Value
3774 @end{Example}
3775 @end{Examples}
3776
3777
3778 @LabeledSubClause{Relational Operators and Membership Tests}
3779
3780 @begin{Intro}
3781 @redundant[@Defn{relational operator}@Defn2{Term=[operator],Sec=(relational)}
3782 @IndexSee{Term=[comparison operator],See=(relational operator)}
3783 @Defn{equality operator}@Defn2{Term=[operator],Sec=(equality)}
3784 The @i(equality operators)
3785 = (equals) and /= (not equals) are predefined for nonlimited types.
3786 @Defn{ordering operator}@Defn2{Term=[operator],Sec=(ordering)}
3787 The other @nt<relational_operator>s are the @i(ordering operators)
3788 < (less than), <= (less than or
3789 equal), > (greater than), and >= (greater than or equal).
3790 @Defn{= operator}@Defn2{Term=[operator],Sec=(=)}
3791 @Defn{equal operator}@Defn2{Term=[operator],Sec=(equal)}
3792 @Defn{/= operator}@Defn2{Term=[operator],Sec=(/=)}
3793 @Defn{not equal operator}@Defn2{Term=[operator],Sec=(not equal)}
3794 @Defn{< operator}@Defn2{Term=[operator],Sec=(<)}
3795 @Defn{less than operator}@Defn2{Term=[operator],Sec=(less than)}
3796 @Defn{<= operator}@Defn2{Term=[operator],Sec=(<=)}
3797 @Defn{less than or equal operator}@Defn2{Term=[operator],Sec=(less than or equal)}
3798 @Defn{> operator}@Defn2{Term=[operator],Sec=(>)}
3799 @Defn{greater than operator}@Defn2{Term=[operator],Sec=(greater than)}
3800 @Defn{>= operator}@Defn2{Term=[operator],Sec=(>=)}
3801 @Defn{greater than or equal operator}@Defn2{Term=[operator],Sec=(greater than or equal)}
3802 @Defn{discrete array type}
3803 The ordering operators are predefined for scalar
3804 types, and for @i(discrete array types), that is,
3805 one-dimensional array types whose components are of
3806 a discrete type.
3807 @begin{Ramification}
3808 The equality operators are not defined for @i{every} nonlimited
3809 type @em see below for the exact rule.
3810 @end{Ramification}
3811
3812 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0262-1],ARef=[AI05-0269-1]}
3813 @Defn{membership test}
3814 @Defn{in (membership test)}
3815 @Defn{not in (membership test)}
3816 A @i(membership test), using @key(in) or @key(not in),
3817 determines whether or not a value
3818 belongs to @chg{Version=[3],New=[any],Old=[a]} given subtype or range,
3819 @chg{Version=[3],New=[is equal to any given value,],Old=[or]} has a tag
3820 that identifies a type that is covered by a given type@chg{Version=[3],New=[,
3821 or is convertible to and has an accessibility level appropriate for a given
3822 access type],Old=[]}. Membership tests are allowed for all types.]
3823
3824 @end{Intro}
3825
3826 @begin{Resolution}
3827
3828 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00251-01]}
3829 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0158-1]}
3830 @PDefn2{Term=[expected type],
3831 Sec=(membership test simple_expression)}
3832 @Defn2{Term=[tested type], Sec=(of a membership test)}
3833 The @i(tested type) of a membership test
3834 is@Chg{Version=[3],New=[],Old=[ the type of the @nt<range> or the type]}
3835 determined by the @Chg{Version=[3],New=[@nt<membership_choice>s of the
3836 @nt<membership_choice_list>. Either all @nt{membership_choice}s of the
3837 @nt{membership_choice_list} shall resolve to the same type, which is the tested
3838 type; or each @nt{membership_choice} shall be of an elementary type, and the
3839 tested type shall be covered by each of these elementary
3840 types.],Old=[@nt<subtype_mark>. If the tested type is tagged, then the
3841 @nt<simple_expression> shall resolve to be of a type that
3842 @Chg{Version=[2],New=[is convertible (see @RefSecNum{Type Conversions})
3843 to],Old=[covers or is covered by]} the tested type; if untagged, the expected
3844 type for the @nt<simple_expression> is the tested type.]}
3845
3846 @ChgRef{Version=[3],Kind=[Added],ARef=[AI05-0158-1]}
3847 @ChgRef{Version=[4],Kind=[RevisedAdded],ARef=[AI12-0039-1]}
3848 @ChgAdded{Version=[3],Text=[If the tested type is tagged, then the
3849 @Chg{Version=[4],New=[@SynI{tested_}@nt{simple_expression}],Old=[@nt{simple_expression}]}
3850 shall resolve to be of a type that is
3851 convertible (see @RefSecNum{Type Conversions}) to the tested
3852 type; if untagged, the expected type for the
3853 @Chg{Version=[4],New=[@SynI{tested_}@nt{simple_expression}],Old=[@nt{simple_expression}]}
3854 is the tested type. The expected type of a
3855 @Chg{Version=[4],New=[@SynI{choice_}@nt{simple_expression}],Old=[@nt{choice_expression}]}
3856 in a @nt{membership_choice}, and of a @nt{simple_expression} of a @nt{range} in
3857 a @nt{membership_choice}, is the tested type of the membership operation.]}
3858
3859 @begin{Reason}
3860 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00230-01]}
3861 The part of the rule for untagged types is stated in a way
3862 that ensures that operands
3863 like @Chg{Version=[2],New=[a string literal],Old=[@key(null)]} are still
3864 legal as operands of a membership test.
3865
3866 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00251-01]}
3867 @ChgRef{Version=[4],Kind=[Revised],ARef=[AI12-0039-1]}
3868 The significance of @lquotes@;@Chg{Version=[2],New=[is convertible to],
3869 Old=[covers or is covered by]}@rquotes@; is that we allow the
3870 @Chg{Version=[4],New=[@SynI{tested_}@nt{simple_expression}],Old=[@nt{simple_expression}]}
3871 to be of any class-wide type that @Chg{Version=[2],
3872 New=[could be converted to],Old=[covers]} the tested type, not just the
3873 one rooted at the tested type.@Chg{Version=[2],New=[ This includes any
3874 class-wide type that covers the tested type, along with class-wide interfaces
3875 in some cases.],Old=[]}
3876
3877 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0158-1]}
3878 @ChgAdded{Version=[3],Text=[The special rule for determining the tested type for
3879 elementary types is to allow numeric literals in @nt{membership_choice_list}s.
3880 Without the rule, @exam{A @key[in] B | 1} would be illegal as B and 1 would
3881 have different types (the literal having type @i<universal integer>).]}
3882 @end{Reason}
3883
3884 @end{Resolution}
3885
3886 @begin{Legality}
3887 @ChgRef{Version=[4],Kind=[Revised],ARef=[AI12-0039-1]}
3888 For a membership test, if the
3889 @Chg{Version=[4],New=[@SynI{tested_}@nt{simple_expression}],Old=[@nt{simple_expression}]}
3890 is of a tagged class-wide type,
3891 then the tested type shall be (visibly) tagged.
3892 @begin{Ramification}
3893 Untagged types covered by the tagged class-wide type
3894 are not permitted. Such types can exist if they are
3895 descendants of a private type whose full type is tagged.
3896 This rule is intended to avoid confusion since such derivatives
3897 don't have their @lquotes@;own@rquotes@; tag, and hence are indistinguishable
3898 from one another at run time once converted to a covering
3899 class-wide type.
3900 @end{Ramification}
3901
3902 @ChgRef{Version=[3],Kind=[Added],ARef=[AI05-0158-1]}
3903 @ChgRef{Version=[4],Kind=[RevisedAdded],ARef=[AI12-0039-1]}
3904 @ChgAdded{Version=[3],Text=[If a membership test includes one or more
3905 @Chg{Version=[4],New=[@SynI{choice_}@nt{simple_expression}s],Old=[@nt{choice_expression}s]}
3906 and the tested type of the membership test is limited, then the
3907 tested type of the membership test shall have a visible primitive equality
3908 operator.]}
3909 @begin{Reason}
3910 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0158-1]}
3911 @ChgAdded{Version=[3],Text=[A visible equality operator is required in order
3912 to avoid breaking privacy; that is, we don't want to depend on a hidden
3913 equality operator.]}
3914 @end{Reason}
3915 @end{Legality}
3916
3917 @begin{StaticSem}
3918 The result type of a membership test is the predefined type Boolean.
3919
3920 @Leading@;The equality operators are predefined for every specific
3921 type @i(T) that is not limited,
3922 and not an anonymous access type,
3923 with the following specifications:
3924 @begin(example)
3925 @key(function) "=" (Left, Right : @RI(T)) @key(return) Boolean
3926 @key(function) "/="(Left, Right : @RI(T)) @key(return) Boolean
3927 @end(example)
3928
3929 @ChgRef{Version=[2],Kind=[Added],ARef=[AI95-00230-01]}
3930 @ChgAdded{Version=[2],Type=[Leading],Text=[The following additional equality
3931 operators for the
3932 @i<universal_access> type are declared in package Standard for use with
3933 anonymous access types:]}
3934 @begin(example)
3935 @ChgRef{Version=[2],Kind=[Added]}
3936 @ChgAdded{Version=[2],Text=[@key<function> "=" (Left, Right : @i<universal_access>) @key<return> Boolean
3937 @key<function> "/="(Left, Right : @i<universal_access>) @key<return> Boolean]}
3938 @end(example)
3939
3940 @Leading@;The ordering operators are predefined for every specific
3941 scalar type @i(T), and for every discrete array type
3942 @i(T), with the following specifications:
3943 @begin(example)
3944 @key(function) "<" (Left, Right : @RI(T)) @key(return) Boolean
3945 @key(function) "<="(Left, Right : @RI(T)) @key(return) Boolean
3946 @key(function) ">" (Left, Right : @RI(T)) @key(return) Boolean
3947 @key(function) ">="(Left, Right : @RI(T)) @key(return) Boolean
3948 @end(example)
3949 @end{StaticSem}
3950
3951 @begin{Resolution}
3952 @ChgRef{Version=[2],Kind=[Added],ARef=[AI95-00230-01],ARef=[AI95-00420-01]}
3953 @ChgAdded{Version=[2],Type=[Leading],Text=[At least one of the operands of an equality
3954 operator for @i<universal_access> shall be of a specific anonymous access type.
3955 Unless the predefined equality operator is identified using an expanded name
3956 with @nt{prefix} denoting the package Standard, neither operand shall be of an
3957 access-to-object type whose designated type is @i<D> or @i<D>'Class, where
3958 @i<D> has a user-defined primitive equality operator such that:]}
3959 @begin{Itemize}
3960 @ChgRef{Version=[2],Kind=[Added]}
3961 @ChgAdded{Version=[2],Text=[its result type is Boolean;]}
3962
3963 @ChgRef{Version=[2],Kind=[Added]}
3964 @ChgRef{Version=[3],Kind=[Added],ARef=[AI05-0020-1]}
3965 @ChgAdded{Version=[2],Text=[it is declared immediately within the same
3966 declaration list as @i<D>@Chg{Version=[3],New=[ or any partial or incomplete
3967 view of @i<D>],Old=[]}; and]}
3968
3969 @ChgRef{Version=[2],Kind=[Added]}
3970 @ChgAdded{Version=[2],Text=[at least one of its operands is an
3971 access parameter with designated type @i<D>.]}
3972 @end{Itemize}
3973
3974 @begin{Reason}
3975 @ChgRef{Version=[2],Kind=[AddedNormal]}
3976 @ChgAdded{Version=[2],Text=[The first sentence prevents compatibility
3977 problems by ensuring that these operators are not used for named access
3978 types. Also, universal access types do not count for the purposes of this
3979 rule. Otherwise, equality expressions like (X = @key{null}) would be
3980 ambiguous for normal access types.]}
3981
3982 @ChgRef{Version=[2],Kind=[AddedNormal]}
3983 @ChgAdded{Version=[2],Text=[The rest of the rule makes it possible to
3984 call (including a dispatching call) user-defined "=" operators for anonymous
3985 access-to-object types (they'd be hidden
3986 otherwise), and to write user-defined "=" operations for anonymous access
3987 types (by making it possible to see the universal operator using the
3988 Standard prefix).]}
3989 @end{Reason}
3990 @begin{Ramification}
3991 @ChgRef{Version=[2],Kind=[AddedNormal]}
3992 @ChgAdded{Version=[2],Text=[We don't need a similar rule for anonymous
3993 access-to-subprogram types because they can't be primitive for any type.
3994 Note that any nonprimitive user-defined equality operators still are hidden
3995 by the universal operators; they'll have to be called with a package
3996 prefix, but they are likely to be very uncommon.]}
3997 @end{Ramification}
3998 @end{Resolution}
3999
4000 @begin{Legality}
4001 @ChgRef{Version=[2],Kind=[Added],ARef=[AI95-00230-01]}
4002 @ChgAdded{Version=[2],Text=[At least one of the operands of the equality
4003 operators for @i<universal_access> shall be of type @i<universal_access>, or
4004 both shall be of access-to-object types, or both shall be of
4005 access-to-subprogram types. Further:]}
4006 @begin{Itemize}
4007 @ChgRef{Version=[2],Kind=[Added]}
4008 @ChgAdded{Version=[2],Text=[When both are of access-to-object types, the
4009 designated types shall be the same or one shall cover the
4010 other, and if the designated types are elementary or array types,
4011 then the designated subtypes shall statically match;]}
4012
4013 @ChgRef{Version=[2],Kind=[Added]}
4014 @ChgAdded{Version=[2],Text=[When both are of access-to-subprogram types,
4015 the designated profiles shall be subtype conformant.]}
4016 @end{Itemize}
4017 @begin{Reason}
4018 @ChgRef{Version=[2],Kind=[AddedNormal]}
4019 @ChgAdded{Version=[2],Text=[We don't want to allow completely arbitrary
4020 comparisons, as we don't want to insist that all access types are represented
4021 in ways that are convertible to one another. For instance, a compiler could
4022 use completely separate address spaces or incompatible representations.
4023 Instead, we allow compares if there exists an access parameter to which both
4024 operands could be converted. Since the user could write such an subprogram,
4025 and any reasonable meaning for "=" would allow using it in such a subprogram,
4026 this doesn't impose any further restrictions on Ada implementations.]}
4027 @end{Reason}
4028
4029 @ChgRef{Version=[3],Kind=[Added],ARef=[AI05-0123-1]}
4030 @ChgRef{Version=[4],Kind=[RevisedAdded],ARef=[AI12-0101-1]}
4031 @ChgAdded{Version=[3],Text=[If the profile of an explicitly declared primitive
4032 equality operator of an untagged record type is type conformant with that of the
4033 corresponding predefined equality operator, the declaration shall occur before
4034 the type is frozen.@Chg{Version=[4],New=[],Old=[ In addition, if the untagged
4035 record type has a nonlimited partial view, then the declaration shall occur
4036 in the visible part of the enclosing package.]}
4037 @PDefn{generic contract issue}
4038 In addition to the places where @LegalityTitle normally apply
4039 (see @RefSecNum{Generic Instantiation}),
4040 this rule applies also in the private part of an instance of a generic unit.]}
4041 @end{Legality}
4042
4043 @begin{RunTime}
4044 For discrete types, the predefined relational operators are
4045 defined in terms of corresponding mathematical operations on
4046 the position numbers of the values of the operands.
4047
4048 For real types, the predefined relational operators are
4049 defined in terms of the corresponding mathematical operations
4050 on the values of the operands, subject to the accuracy of the
4051 type.
4052 @begin{Ramification}
4053 For floating point types, the results of comparing
4054 @i(nearly) equal values depends on the accuracy of
4055 the implementation
4056 (see @RefSec{Model of Floating Point Arithmetic}
4057 for implementations that support the Numerics Annex).
4058 @end{Ramification}
4059 @begin{ImplNote}
4060 On a machine with signed zeros,
4061 if the generated code generates both plus zero and minus zero,
4062 plus and minus zero must be equal
4063 by the predefined equality operators.
4064 @end{ImplNote}
4065
4066 Two access-to-object values are equal if they designate the same
4067 object, or if both are equal to the null value of the access type.
4068
4069 Two access-to-subprogram values are equal if they are the
4070 result of the same evaluation of an Access @nt<attribute_reference>,
4071 or if both
4072 are equal to the null value of the access type. Two
4073 access-to-subprogram values are unequal if they designate
4074 different subprograms.
4075 @PDefn{unspecified}
4076 @Redundant[It is unspecified whether
4077 two access values that designate the same subprogram but are
4078 the result of distinct evaluations of
4079 Access @nt<attribute_reference>s are equal
4080 or unequal.]
4081 @begin{Reason}
4082 This allows each Access @nt<attribute_reference>
4083 for a subprogram to designate a distinct @lquotes@;wrapper@rquotes@; subprogram
4084 if necessary to support an indirect call.
4085 @end{Reason}
4086
4087 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0123-1]}
4088 @Defn2{Term=[equality operator],Sec=(special inheritance rule for tagged types)}
4089 For a type extension, predefined equality
4090 is defined in terms of the primitive @Redundant[(possibly
4091 user-defined)] equals operator
4092 @Chg{Version=[3],New=[for],Old=[of]} the parent type and
4093 @Chg{Version=[3],New=[for],Old=[of]} any @Chg{Version=[3],New=[],Old=[tagged ]}components
4094 @Chg{Version=[3],New=[that have a record type in],Old=[of]} the extension part, and
4095 predefined equality
4096 for any other components not inherited from the parent type.
4097 @begin{Ramification}
4098 Two values of a type extension are not equal if there is
4099 a @nt<variant_part> in the extension part and the two
4100 values have different @nt<variant>s present.
4101 This is a ramification of the requirement that a
4102 discriminant governing such a @nt<variant_part> has to be a @lquotes@;new@rquotes@;
4103 discriminant, and so has to be equal in the two values for
4104 the values to be equal. Note that @nt<variant_part>s in
4105 the parent part need not match if the primitive equals operator
4106 for the parent type considers them equal.
4107
4108 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00349-01]}
4109 @ChgAdded{Version=[2],Type=[Leading],Text=[The full type extension's operation
4110 is used for a private extension. This follows as only full types have parent types;
4111 the type specified in a private extension is an ancestor, but not necessarily
4112 the parent type. For instance, in:]}
4113 @begin(Example)
4114 @ChgRef{Version=[2],Kind=[AddedNormal]}
4115 @Chg{Version=[2],New=[@key{with} Pak1;
4116 @key{package} Pak2 @key{is}
4117 @key{type} Typ3 @key{is} @key{new} Pak1.Typ1 @key{with} @key{private};
4118 @key{private}
4119 @key{type} Typ3 @key{is} @key{new} Pak1.Typ2 @key{with} @key{null} @key{record};
4120 @key{end} Pak2;],Old=[]}
4121 @end(Example)
4122 @ChgRef{Version=[2],Kind=[AddedNormal]}
4123 @Chg{Version=[2],New=[the parent type is Pak1.Typ2, not Pak1.Typ1, and the
4124 equality operator of Pak1.Typ2 is used to create predefined equality for
4125 Typ3.],Old=[]}
4126 @end{Ramification}
4127
4128 @ChgRef{Version=[3],Kind=[Added],ARef=[AI05-0123-1]}
4129 @ChgAdded{Version=[3],Text=[For a derived type whose parent is an untagged
4130 record type, predefined equality is defined in terms of the primitive (possibly
4131 user-defined) equals operator of the parent type.]}
4132 @begin{Reason}
4133 @ChgRef{Version=[3],Kind=[AddedNormal]}
4134 @ChgAdded{Version=[3],Text=[This prevents predefined equality from
4135 reemerging in generic units for untagged record types. For other uses
4136 the primitive equality is inherited and the inherited routine is primitive.]}
4137 @end{Reason}
4138
4139 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0123-1]}
4140 For a private type, if its full type is
4141 @Chg{Version=[3],New=[a record type],Old=[tagged]}, predefined
4142 equality is defined in terms of the primitive equals operator of the
4143 full type; @Chg{Version=[3],New=[otherwise],Old=[if the full type is untagged]},
4144 predefined equality for the private type is that of its full type.
4145
4146 @Leading@Defn{matching components}
4147 For other composite types, the predefined equality operators
4148 @Redundant[(and
4149 certain other predefined operations on composite types @em
4150 see @RefSecNum(Logical Operators and Short-circuit Control Forms)
4151 and @RefSecNum(Type Conversions))] are defined
4152 in terms of the corresponding operation on
4153 @i(matching components), defined as follows:
4154 @begin(itemize)
4155 For two composite objects or values of the same non-array type,
4156 matching components are those that correspond to the
4157 same @nt<component_declaration> or @nt<discriminant_specification>;
4158
4159 For two one-dimensional arrays of the same type, matching components are
4160 those (if any) whose index values match in the following sense: the
4161 lower bounds of the index ranges are defined to match, and the successors
4162 of matching indices are defined to match;
4163
4164 For two multidimensional arrays of the same type, matching components
4165 are those whose index values match in successive index positions.
4166 @end(itemize)
4167
4168 The analogous definitions apply if the types of the two objects or values
4169 are convertible, rather than being the same.
4170 @begin{Discussion}
4171 Ada 83 seems to
4172 omit this part of the definition, though it is used in array type
4173 conversions. See @RefSecNum{Type Conversions}.
4174 @end{Discussion}
4175
4176 @Leading@;Given the above definition of matching components,
4177 the result of the predefined equals operator for composite types (other than
4178 for those composite types covered earlier) is defined as follows:
4179 @begin(Itemize)
4180 If there are no components, the result is defined to be True;
4181
4182 If there are unmatched components, the result is defined to be False;
4183
4184 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0123-1]}
4185 Otherwise, the result is defined in terms of
4186 the primitive equals operator for any
4187 matching @Chg{Version=[3],New=[],Old=[tagged ]}components@Chg{Version=[3],New=[ that
4188 are records],Old=[]}, and
4189 the predefined equals for any @Chg{Version=[3],New=[other ],Old=[]}matching
4190 @Chg{Version=[3],New=[],Old=[untagged ]}components.
4191 @begin{Reason}
4192 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0123-1]}
4193 This asymmetry between @Chg{Version=[3],New=[],Old=[tagged and
4194 untagged ]}components @Chg{Version=[3],New=[with and without a record type ],Old=[]}is
4195 necessary to preserve @Chg{Version=[3],New=[most ],Old=[]}upward compatibility and corresponds
4196 with the corresponding situation with generics, where the
4197 predefined operations @lquotes@;reemerge@rquotes@; in a generic for
4198 @Chg{Version=[3],New=[non-record],Old=[untagged]} types, but do not
4199 for @Chg{Version=[3],New=[record],Old=[tagged]} types. Also, only
4200 tagged types support user-defined assignment
4201 (see @RefSecNum{Assignment and Finalization}),
4202 so only tagged types
4203 can fully handle levels of indirection in the implementation
4204 of the type. For untagged types, one reason for
4205 a user-defined equals operator might be to allow values with different
4206 bounds or discriminants to compare equal in certain cases.
4207 When such values are matching components, the bounds or discriminants
4208 will necessarily match anyway if the
4209 discriminants of the enclosing values match.
4210 @end{Reason}
4211 @end(Itemize)
4212 @begin{Ramification}
4213 Two null arrays of the same type are always equal;
4214 two null records of the same type are always equal.
4215
4216 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0123-1]}
4217 Note that if a composite object has a component
4218 of a floating point type, and the floating point type
4219 has both a plus and minus zero, which are considered
4220 equal by the predefined equality, then a block compare
4221 cannot be used for the predefined composite equality.
4222 Of course, with user-defined equals operators for
4223 @Chg{Version=[3],New=[],Old=[tagged ]}components@Chg{Version=[3],New=[ that
4224 are records],Old=[]},
4225 a block compare breaks down anyway, so this is not the only
4226 special case that requires component-by-component comparisons.
4227 On a one's complement machine, a similar situation might
4228 occur for integer types, since one's complement machines
4229 typically have both a plus and minus (integer) zero.
4230 @end{Ramification}
4231 @begin{Honest}
4232 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00230-01]}
4233 @ChgAdded{Version=[2],Text=[For a component with an anonymous access type,
4234 @lquotes@;predefined equality@rquotes@; is that defined for the
4235 @i<universal_access> type (anonymous access types have no equality operators
4236 of their own).]}
4237
4238 @ChgRef{Version=[2],Kind=[AddedNormal]}
4239 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0123-1]}
4240 @ChgAdded{Version=[2],Text=[For a component with a @Chg{Version=[3],New=[record],
4241 Old=[tagged]} type @i{T},
4242 @lquotes@;the primitive equals operator@rquotes@; is the one with two
4243 parameters of @i(T) which returns Boolean. We're not talking about some
4244 random other primitive function named "=".]}
4245 @end{Honest}
4246
4247 @ChgRef{Version=[3],Kind=[Added],ARef=[AI05-0123-1]}
4248 @ChgAdded{Version=[3],Text=[If the primitive equals operator for an untagged
4249 record type is abstract, then Program_Error is raised at the point of any
4250 (implicit) call to that abstract subprogram.]}
4251 @begin{Reason}
4252 @ChgRef{Version=[3],Kind=[AddedNormal]}
4253 @ChgAdded{Version=[3],Text=[An explicit call to an abstract subprogram is
4254 illegal. This rule is needed in order to define the effect of an implicit call
4255 such as a call that is part of the predefined equality operation for an
4256 enclosing composite type that has a component of an untagged record type that
4257 has an abstract primitive equals operator. For tagged types, an abstract
4258 primitive equals operator is only allowed for an abstract type, and abstract
4259 types cannot be components, so this case does not occur.]}
4260 @end{Reason}
4261
4262 @ChgRef{Version=[1],Kind=[Added],Ref=[8652/0016],ARef=[AI95-00123-01]}
4263 @ChgAdded{Version=[1],Text=[For any composite type, the order in which "="
4264 is called for components is unspecified. Furthermore, if the result can be
4265 determined before calling "=" on some components, it is unspecified whether
4266 "=" is called on those components.@PDefn{Unspecified}]}
4267
4268 The predefined "/=" operator gives the complementary result
4269 to the predefined "=" operator.
4270 @begin{Ramification}
4271 Furthermore,
4272 if the user defines an "=" operator that returns Boolean,
4273 then a "/=" operator is implicitly declared in terms of
4274 the user-defined "=" operator so as to give the complementary
4275 result. See @RefSecNum(Overloading of Operators).
4276 @end{Ramification}
4277
4278 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0264-1]}
4279 @Defn{lexicographic order}
4280 For a discrete array type, the predefined ordering operators
4281 correspond to @i(lexicographic order) using the predefined order
4282 relation of the component type: A null array is lexicographically
4283 less than any array having at least one component.
4284 In the case of nonnull arrays, the left operand is lexicographically
4285 less than the right operand if the first component of
4286 the left operand is less than that of the right; otherwise@Chg{Version=[3],New=[,],Old=[]}
4287 the left operand is lexicographically less than the right operand
4288 only if their first components are equal and the tail of the
4289 left operand is lexicographically less than that of the right (the
4290 @i(tail) consists of the remaining components beyond the first and
4291 can be null).
4292
4293 @ChgRef{Version=[3],Kind=[Added],ARef=[AI05-0269-1]}
4294 @ChgAdded{Version=[3],Text=[An @i<individual membership test> is the
4295 membership test of a single @nt{membership_choice}.@Defn{individual membership test}]}
4296
4297 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0158-1]}
4298 @ChgRef{Version=[4],Kind=[Revised],ARef=[AI12-0039-1]}
4299 @PDefn2{Term=[evaluation], Sec=(membership test)}
4300 For the evaluation of a membership test@Chg{Version=[3],New=[ using @key[in]
4301 whose @nt{membership_choice_list} has a single @nt{membership_choice}],Old=[]},
4302 the
4303 @Chg{Version=[4],New=[@SynI{tested_}@nt{simple_expression}],Old=[@nt{simple_expression}]}
4304 and the @Chg{Version=[3],New=[@nt{membership_choice}],Old=[@nt<range> (if any)]}
4305 are evaluated in an arbitrary order@Chg{Version=[3],New=[; the result is the
4306 result of the individual membership test for
4307 the @nt{membership_choice}],Old=[]}.@PDefn2{Term=[arbitrary order],Sec=[allowed]}
4308
4309 @ChgRef{Version=[3],Kind=[Added],ARef=[AI05-0158-1]}
4310 @ChgRef{Version=[4],Kind=[RevisedAdded],ARef=[AI12-0039-1]}
4311 @ChgAdded{Version=[3],Text=[For the evaluation of a membership test using
4312 @key[in] whose @nt{membership_choice_list} has more than one
4313 @nt{membership_choice}, the
4314 @Chg{Version=[4],New=[@SynI{tested_}@nt{simple_expression}],Old=[@nt{simple_expression}]}
4315 of the membership test is evaluated first and the
4316 result of the operation is equivalent to that of a sequence consisting
4317 of an individual membership test on each @nt{membership_choice}
4318 combined with the short-circuit control form @b[or else].]}
4319
4320 @begin{Ramification}
4321 @ChgRef{Version=[3],Kind=[Added],ARef=[AI05-0158-1]}
4322 @ChgAdded{Version=[3],Text=[This equivalence includes the evaluation of the
4323 @nt{membership_choice}s; evaluation stops as soon as an individual choice
4324 evaluates to True.]}
4325 @end{Ramification}
4326
4327 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0158-1],ARef=[AI05-0269-1]}
4328 @Leading@;@Chg{Version=[3],New=[An individual membership test],Old=[A
4329 membership test using @key(in)]} yields the result True if:
4330 @begin(itemize)
4331 @ChgRef{Version=[3],Kind=[Added],ARef=[AI05-0158-1],ARef=[AI05-0264-1]}
4332 @ChgRef{Version=[4],Kind=[RevisedAdded],ARef=[AI12-0039-1]}
4333 @ChgAdded{Version=[3],Text=[The @nt{membership_choice} is a
4334 @Chg{Version=[4],New=[@SynI{choice_}@nt{simple_expression}],Old=[@nt{choice_expression}]},
4335 and the
4336 @Chg{Version=[4],New=[@SynI{tested_}@nt{simple_expression}],Old=[@nt{simple_expression}]}
4337 is equal to the value of the @nt{membership_choice}.
4338 If the tested type is a record type or a limited type, the test uses the
4339 primitive equality for the type; otherwise, the test uses predefined equality.]}
4340
4341 @ChgRef{Version=[3],Kind=[Added],ARef=[AI05-0153-3],ARef=[AI05-0158-1]}
4342 @ChgRef{Version=[4],Kind=[RevisedAdded],ARef=[AI12-0039-1]}
4343 @ChgAdded{Version=[3],Text=[The @nt{membership_choice} is a @nt{range}
4344 and the value of the
4345 @Chg{Version=[4],New=[@SynI{tested_}@nt{simple_expression}],Old=[@nt{simple_expression}]}
4346 belongs to the given @nt<range>.]}
4347
4348 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0153-3],ARef=[AI05-0158-1]}
4349 @ChgRef{Version=[4],Kind=[Revised],ARef=[AI12-0039-1],ARef=[AI12-0071-1]}
4350 @Chg{Version=[3],New=[The @nt{membership_choice} is a @nt{subtype_mark},
4351 the],Old=[The]} tested type is scalar, @Chg{Version=[3],New=[],Old=[and ]}the
4352 value of the
4353 @Chg{Version=[4],New=[@SynI{tested_}@nt{simple_expression}],Old=[@nt{simple_expression}]}
4354 belongs to the
4355 @Chg{Version=[3],New=[],Old=[given @nt<range>, or the ]}range of the
4356 named subtype@Chg{Version=[3],New=[, and the @Chg{Version=[4],New=[value
4357 satisfies the predicates],Old=[predicate]} of the named
4358 subtype@Chg{Version=[4],New=[],Old=[ evaluates to True]}.@Chg{Version=[4],
4359 New=[@Defn2{Term=[predicates satisfied required],Sec=[membership]}],Old=[@Defn2{Term=[predicate evaluated],Sec=[membership]}]}],Old=[; or]}
4360 @begin{Ramification}
4361 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0153-3]}
4362 The scalar membership test only does a range check@Chg{Version=[3],New=[
4363 and a predicate check],Old=[]}.
4364 It does not perform any other check, such as whether
4365 a value falls in a @lquotes@;hole@rquotes@; of a @lquotes@;holey@rquotes@; enumeration type.
4366 The Pos attribute function can be used for that purpose.
4367
4368 Even though Standard.Float is an unconstrained subtype,
4369 the test @lquotes@;X in Float@rquotes@; will still return False
4370 (presuming the evaluation of X does not raise Constraint_Error)
4371 when X is outside Float'Range.
4372 @end{Ramification}
4373
4374 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00231-01]}
4375 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0153-3],ARef=[AI05-0158-1]}
4376 @ChgRef{Version=[4],Kind=[Revised],ARef=[AI12-0039-1],ARef=[AI12-0071-1]}
4377 @ChgAdded{Version=[2],Type=[Leading],Text=[]}@ChgNote{To get conditional Leading}
4378 @Chg{Version=[3],New=[The @nt<membership_choice> is a
4379 @nt<subtype_mark>, the],Old=[The]} tested type is not scalar, @Chg{Version=[3],New=[],Old=[and ]}
4380 the value of the
4381 @Chg{Version=[4],New=[@SynI{tested_}@nt{simple_expression}],Old=[@nt{simple_expression}]}
4382 satisfies any constraints
4383 of the named subtype, @Chg{Version=[3],New=[the @Chg{Version=[4],New=[value
4384 satisfies the predicates],Old=[predicate]} of the named
4385 subtype@Chg{Version=[4],New=[],Old=[ evaluates to
4386 True]}, ],Old=[]}and@Chg{Version=[2],New=[:],Old=[, if the type of
4387 the @nt{simple_expression} is class-wide, the value has a tag that
4388 identifies a type covered by the tested type.]}
4389 @begin{Inneritemize}
4390 @ChgRef{Version=[2],Kind=[Added],ARef=[AI95-00231-01]}
4391 @ChgRef{Version=[4],Kind=[RevisedAdded],ARef=[AI12-0039-1]}
4392 @ChgAdded{Version=[2],Text=[if the type of the
4393 @Chg{Version=[4],New=[@SynI{tested_}@nt{simple_expression}],Old=[@nt{simple_expression}]}
4394 is class-wide, the value has a tag that identifies a type covered by the
4395 tested type;]}
4396 @begin{Ramification}
4397 @ChgRef{Version=[4],Kind=[Revised],ARef=[AI12-0039-1]}
4398 Note that the tag is not checked if the
4399 @Chg{Version=[4],New=[@SynI{tested_}@nt{simple_expression}],Old=[@nt{simple_expression}]}
4400 is of a specific type.
4401 @end{Ramification}
4402 @ChgRef{Version=[2],Kind=[Added],ARef=[AI95-00231-01]}
4403 @ChgRef{Version=[3],Kind=[RevisedAdded],ARef=[AI05-0149-1]}
4404 @ChgRef{Version=[4],Kind=[RevisedAdded],ARef=[AI12-0039-1]}
4405 @ChgAdded{Version=[2],Text=[if the tested type is an access type and the
4406 named subtype excludes null, the value of the
4407 @Chg{Version=[4],New=[@SynI{tested_}@nt{simple_expression}],Old=[@nt{simple_expression}]}
4408 is not null@Chg{Version=[3],New=[;],Old=[.]}]}
4409
4410 @ChgRef{Version=[3],Kind=[Added],ARef=[AI05-0149-1]}
4411 @ChgRef{Version=[4],Kind=[RevisedAdded],ARef=[AI12-0039-1]}
4412 @ChgAdded{Version=[3],Text=[if the tested type is a general access-to-object
4413 type, the type of the
4414 @Chg{Version=[4],New=[@SynI{tested_}@nt{simple_expression}],Old=[@nt{simple_expression}]}
4415 is convertible to the tested
4416 type and its accessibility level is no deeper than that of the tested type;
4417 further, if the designated type of the tested type is tagged and the
4418 @Chg{Version=[4],New=[@SynI{tested_}@nt{simple_expression}],Old=[@nt{simple_expression}]}
4419 is nonnull, the tag of the object designated by the
4420 value of the
4421 @Chg{Version=[4],New=[@SynI{tested_}@nt{simple_expression}],Old=[@nt{simple_expression}]}
4422 is covered by the designated type of the tested type.]}
4423 @end{Inneritemize}
4424 @end(itemize)
4425
4426 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0264-1]}
4427 Otherwise@Chg{Version=[3],New=[,],Old=[]} the test yields the result False.
4428
4429 A membership test using @key(not in) gives the complementary result to
4430 the corresponding membership test using @key(in).
4431
4432 @begin{Honest}
4433 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0158-1]}
4434 @ChgRef{Version=[4],Kind=[Revised],ARef=[AI12-0039-1]}
4435 @ChgAdded{Version=[3],Text=[@exam{@i<X> @key[not in] @i<A> | @i<B> | @i<C>}
4436 is intended to be exactly equivalent to @exam{@key[not] (@i<X> @key[in] @i<A> | @i<B> | @i<C>)},
4437 including the order of evaluation of the
4438 @Chg{Version=[4],New=[@SynI{tested_}@nt{simple_expression}],Old=[@nt{simple_expression}]}
4439 and @nt{membership_choice}s.]}
4440 @end{Honest}
4441 @end{RunTime}
4442
4443 @begin{ImplReq}
4444 @ChgRef{Version=[1],Kind=[Added],Ref=[8652/0016],ARef=[AI95-00123-01]}
4445 @ChgAdded{Version=[1],Text=[For all nonlimited types declared in
4446 language-defined packages, the "=" and "/=" operators of the type shall behave
4447 as if they were the predefined equality operators for the purposes of the
4448 equality of composite types and generic formal types.]}
4449 @begin{Ramification}
4450 @ChgRef{Version=[1],Kind=[Added],ARef=[AI95-00123-01]}
4451 @ChgRef{Version=[3],Kind=[RevisedAdded],ARef=[AI05-0123-1]}
4452 @ChgAdded{Version=[1],Text=[If any language-defined types are implemented with
4453 a user-defined "=" operator, then either the full type must be @Chg{Version=[3],
4454 New=[a record type],Old=[tagged]}, or the compiler must
4455 use @lquotes@;magic@rquotes@; to implement equality for this type. A normal
4456 user-defined "=" operator for @Chg{Version=[3],New=[a non-record],Old=[an untagged]}
4457 type does @i{not} meet this requirement.]}
4458 @end{Ramification}
4459 @end{ImplReq}
4460
4461 @begin{Notes}
4462 @ChgRef{Version=[2],Kind=[Deleted],ARef=[AI95-00230-01]}
4463 @ChgDeleted{Version=[2],Text=[No exception is ever raised by a membership test,
4464 by a predefined ordering operator, or by a predefined equality operator for an
4465 elementary type, but an exception can be raised by the evaluation of the
4466 operands. A predefined equality operator for a composite type can only raise an
4467 exception if the type has a tagged part whose primitive equals operator
4468 propagates an exception.]}
4469
4470 If a composite type has components that depend on discriminants, two values
4471 of this type have matching components if and only if their
4472 discriminants are equal. Two nonnull arrays have matching components
4473 if and only if the length of each dimension is the same for both.
4474 @end{Notes}
4475
4476 @begin{Examples}
4477 @Leading@keepnext@i(Examples of expressions involving relational operators and
4478 membership tests:)
4479 @begin{Example}
4480 X /= Y
4481
4482 "" < "A" @key(and) "A" < "Aa" --@RI[ True]
4483 "Aa" < "B" @key(and) "A" < "A " --@RI[ True]
4484
4485 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0264-1]}
4486 My_Car = @key(null) --@RI[ @Chg{Version=[3],New=[True],Old=[true]} if My_Car has been set to null (see @RefSecNum{Incomplete Type Declarations})]
4487 My_Car = Your_Car --@RI[ @Chg{Version=[3],New=[True],Old=[true]} if we both share the same car]
4488 My_Car.@key[all] = Your_Car.@key[all] --@RI[ @Chg{Version=[3],New=[True],Old=[true]} if the two cars are identical]
4489
4490 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0158-1]}
4491 N @key(not) @key(in) 1 .. 10 --@RI[ range membership test]
4492 Today @key(in) Mon .. Fri --@RI[ range membership test]
4493 Today @key(in) Weekday --@RI[ subtype membership test (see @RefSecNum{Enumeration Types})]@Chg{Version=[3],New=[
4494 Card @key(in) Clubs | Spades --@RI[ list membership test (see @RefSecNum{Enumeration Types})]],Old=[]}
4495 Archive @key(in) Disk_Unit --@RI[ subtype membership test (see @RefSecNum{Variant Parts and Discrete Choices})]
4496 Tree.@key(all) @key(in) Addition'Class --@RI[ class membership test (see @RefSecNum{Type Extensions})]
4497 @end{Example}
4498 @end{Examples}
4499
4500 @begin{Extend83}
4501 @Defn{extensions to Ada 83}
4502 Membership tests can be used to test the tag of a class-wide value.
4503
4504 Predefined equality for a composite type
4505 is defined in terms of the primitive equals operator
4506 for tagged components or the parent part.
4507 @end{Extend83}
4508
4509 @begin{DiffWord83}
4510 The term @lquotes@;membership test@rquotes@; refers to the @nt<relation> "X in S" rather
4511 to simply the reserved word @key(in) or @key(not in).
4512
4513 We use the term @lquotes@;equality operator@rquotes@; to refer to both
4514 the = (equals) and /= (not equals) operators.
4515 Ada 83 referred to = as @i(the) equality operator, and
4516 /= as the inequality operator. The new wording is more
4517 consistent with the ISO 10646 name for "=" (equals sign) and provides a
4518 category similar to @lquotes@;ordering operator@rquotes@; to refer to both
4519 = and /=.
4520
4521 We have changed the term @lquotes@;catenate@rquotes@; to @lquotes@;concatenate@rquotes@;.
4522 @end{DiffWord83}
4523
4524 @begin{Extend95}
4525 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00230-01],ARef=[AI95-00420-01]}
4526 @ChgAdded{Version=[2],Text=[@Defn{extensions to Ada 95}The @i{universal_access}
4527 equality operators are new. They provide equality operations (most
4528 importantly, testing against @key{null}) for anonymous access types.]}
4529 @end{Extend95}
4530
4531 @begin{DiffWord95}
4532 @ChgRef{Version=[2],Kind=[AddedNormal],Ref=[8652/0016],ARef=[AI95-00123-01]}
4533 @Chg{Version=[2],New=[@b<Corrigendum:> Wording was added to clarify that
4534 the order of calls (and whether the calls are made at all) on "=" for
4535 components is unspecified. Also clarified that "=" must compose properly for
4536 language-defined types.],Old=[]}
4537
4538 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00251-01]}
4539 @Chg{Version=[2],New=[Memberships were adjusted to allow interfaces which don't
4540 cover the tested type, in order to be consistent with type
4541 conversions.],Old=[]}
4542 @end{DiffWord95}
4543
4544 @begin{Inconsistent2005}
4545 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0123-1]}
4546 @ChgAdded{Version=[3],Text=[@Defn{inconsistencies with Ada 2005}
4547 User-defined untagged record equality is now defined to compose and be used in
4548 generics. Any code which assumes that the predefined equality reemerges
4549 in generics and in predefined equals for composite types could fail.
4550 However, it is much more likely that this change will fix bugs, as the
4551 behavior that would be expected (the user-defined "=" is used) will be
4552 true in more cases.]}
4553
4554 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0123-1]}
4555 @ChgAdded{Version=[3],Text=[If a composite type contains
4556 a component of an untagged record type with an abstract equality operation,
4557 calling "=" on the composite type will raise Program_Error, while in the
4558 past a result will be returned using the predefined equality. This is
4559 quite possible in ASIS programs; it will detect a bug in such programs but
4560 of course the programs will need to be fixed before they will work.]}
4561 @end{Inconsistent2005}
4562
4563 @begin{Incompatible2005}
4564 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0123-1]}
4565 @ChgAdded{Version=[3],Text=[@Defn{incompatibilities with Ada 2005}
4566 Late and hidden overriding of equality for untagged record types is now
4567 prohibited. This is necessary to make composition of equality predictable.
4568 It should always be possible to move the overriding to an earlier spot
4569 where it will be legal.]}
4570 @end{Incompatible2005}
4571
4572 @begin{Extend2005}
4573 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0149-1]}
4574 @ChgAdded{Version=[3],Text=[@Defn{extensions to Ada 2005}Membership tests
4575 for valid accessibility levels and tag coverage by the designated type
4576 for general access types are new.]}
4577
4578 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0153-3]}
4579 @ChgAdded{Version=[3],Text=[Membership tests now include a predicate check.]}
4580
4581 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0158-1]}
4582 @ChgAdded{Version=[3],Text=[Membership tests now allow multiple choices.]}
4583 @end{Extend2005}
4584
4585 @begin{DiffWord2005}
4586 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0020-1]}
4587 @ChgAdded{Version=[3],Text=[@b<Correction:> Wording was added to clarify
4588 that @i{universal_access} "=" does not apply if an appropriate operator is
4589 declared for a partial or incomplete view of the designated type.
4590 Otherwise, adding a partial or incomplete view could make some "=" operators
4591 ambiguous.]}
4592 @end{DiffWord2005}
4593
4594 @begin{Inconsistent2012}
4595 @ChgRef{Version=[4],Kind=[AddedNormal],ARef=[AI12-0101-1]}
4596 @ChgAdded{Version=[4],Text=[@Defn{inconsistencies with Ada 2012}@b{Corrigendum:}
4597 Removed the incompatible rule preventing the declaration of "=" in the
4598 private part of a package specification for an untagged record type that
4599 completes a private type. Any code that calls the
4600 predefined "=" on the private type will now execute the body for the
4601 redefined "=" instead for the predefined "=". Eliminating the rule eliminates
4602 an unnecessary incompatibility (especially for programs that never call the
4603 predefined "="). Moreover, (like the composition of untagged record "=" in
4604 Ada 2012) this is more likely to fix bugs than cause
4605 them (who defines an "=" with a presumably different result and does not want
4606 clients to us it?).]}
4607 @end{Inconsistent2012}
4608
4609 @begin{DiffWord2012}
4610 @ChgRef{Version=[4],Kind=[AddedNormal],ARef=[AI12-0039-1]}
4611 @ChgAdded{Version=[4],Text=[@b<Corrigendum:> Reworded membership tests to use
4612 the syntax items @SynI{tested_}@nt{simple_expression} and
4613 @SynI{choice_}@nt{simple_expression}. This was necessary to eliminate
4614 wording ambiguities introduced when the grammar was corrected to eliminate
4615 syntax ambiguities. (Both of the above are now @nt{simple_expression}s, so
4616 merely talking about a @nt{simple_expression} is insufficient.)]}
4617
4618 @ChgRef{Version=[4],Kind=[AddedNormal],ARef=[AI12-0071-1]}
4619 @ChgAdded{Version=[4],Text=[@b<Corrigendum:> Updated wording of the
4620 membership tests to use the new term "satisfies the predicates"
4621 (see @RefSecNum{Subtype Predicates}).]}
4622 @end{DiffWord2012}
4623
4624
4625
4626 @LabeledSubClause{Binary Adding Operators}
4627
4628 @begin{StaticSem}
4629 @Leading@Defn{binary adding operator}@Defn2{Term=[operator],Sec=(binary adding)}
4630 @Defn{+ operator}@Defn2{Term=[operator],Sec=(+)}
4631 @Defn{plus operator}@Defn2{Term=[operator],Sec=(plus)}
4632 @Defn{- operator}@Defn2{Term=[operator],Sec=(-)}
4633 @Defn{minus operator}@Defn2{Term=[operator],Sec=(minus)}
4634 The binary adding operators + (addition) and @en (subtraction) are predefined
4635 for every specific numeric type @i(T) with their
4636 conventional meaning.
4637 They have the following specifications:
4638 @begin(example)
4639 @key(function) "+"(Left, Right : @RI(T)) @key(return) @RI(T)
4640 @key(function) "-"(Left, Right : @RI(T)) @key(return) @RI(T)
4641 @end(example)
4642
4643 @Leading@Defn{& operator}@Defn2{Term=[operator],Sec=(&)}
4644 @Defn{ampersand operator}@Defn2{Term=[operator],Sec=(ampersand)}
4645 @Defn{concatenation operator}@Defn2{Term=[operator],Sec=(concatenation)}
4646 @IndexSee{Term=[catenation operator],See=(concatenation operator)}
4647 The concatenation operators & are predefined for
4648 every nonlimited,
4649 one-dimensional array type @i(T) with component type @i(C).
4650 They have the following specifications:
4651 @begin(example)
4652 @key(function) "&"(Left : @RI(T); Right : @RI(T)) @key(return) @RI(T)
4653 @key(function) "&"(Left : @RI(T); Right : @RI(C)) @key(return) @RI(T)
4654 @key(function) "&"(Left : @RI(C); Right : @RI(T)) @key(return) @RI(T)
4655 @key(function) "&"(Left : @RI(C); Right : @RI(C)) @key(return) @RI(T)
4656 @end(example)
4657 @end{StaticSem}
4658
4659 @begin{RunTime}
4660
4661 @Leading@PDefn2{Term=[evaluation], Sec=(concatenation)}
4662 For the evaluation of a concatenation with result type @i(T),
4663 if both operands are of type @i(T), the result of the concatenation
4664 is a one-dimensional array whose length is the sum of the lengths
4665 of its operands, and whose components comprise the components of
4666 the left operand followed by the components of the right operand.
4667 If the left operand is a null array, the result of the
4668 concatenation is the right operand.
4669 Otherwise, the lower bound of the result is determined as
4670 follows:
4671 @begin(Itemize)
4672 If the ultimate ancestor of the array type was defined
4673 by a @nt<constrained_array_definition>, then
4674 the lower bound of the result is that of the index subtype;
4675 @begin(Reason)
4676 This rule avoids Constraint_Error when using concatenation
4677 on an array type whose first subtype is constrained.
4678 @end(Reason)
4679
4680 If the ultimate ancestor of the array type was defined
4681 by an @nt<unconstrained_array_definition>, then
4682 the lower bound of the result is that of the left operand.
4683 @end(Itemize)
4684
4685 @Redundant[The upper bound is determined by the lower bound and the length.]
4686 @IndexCheck{Index_Check}
4687 A check is made that the upper bound of the result of the
4688 concatenation belongs to the range of the index subtype, unless the
4689 result is a null array.
4690 @Defn2{Term=[Constraint_Error],Sec=(raised by failure of run-time check)}
4691 Constraint_Error is raised if this check fails.
4692
4693 If either operand is of the component type @i(C), the result of the
4694 concatenation is given by the above rules, using in place of such an operand
4695 an array having this operand as its only component (converted
4696 to the component subtype)
4697 and having the lower bound
4698 of the index subtype of the array type as its lower bound.
4699 @PDefn2{Term=[implicit subtype conversion],Sec=(operand of concatenation)}
4700 @begin{Ramification}
4701 The conversion might raise Constraint_Error.
4702 The conversion provides @lquotes@;sliding@rquotes@;
4703 for the component in the case of an array-of-arrays, consistent with
4704 the normal Ada 95 rules that allow sliding during parameter passing.
4705 @end{Ramification}
4706
4707 @Defn2{Term=[assignment operation], Sec=(during evaluation of concatenation)}
4708 The result of a concatenation is defined in terms of an
4709 assignment to an anonymous object,
4710 as for any function call (see @RefSecNum{Return Statements}).
4711 @begin{Ramification}
4712 This implies that value adjustment is performed as appropriate
4713 @em see @RefSecNum{Assignment and Finalization}.
4714 We don't bother saying this for other predefined operators,
4715 even though they are all function calls,
4716 because this is the only one where it matters.
4717 It is the only one that can return a value having controlled parts.
4718 @end{Ramification}
4719 @end{RunTime}
4720
4721 @begin{Notes}
4722 As for all predefined operators on modular types, the binary adding
4723 operators + and @en on modular types include a final
4724 reduction modulo the modulus if the result is outside
4725 the base range of the type.
4726 @begin{ImplNote}
4727 A full "modulus" operation need not be performed after
4728 addition or subtraction of modular types. For binary moduli,
4729 a simple mask is sufficient. For nonbinary moduli, a check after
4730 addition to see if the value is greater than the high bound of
4731 the base range can be followed by a conditional subtraction of the modulus.
4732 Conversely, a check after subtraction to see if a "borrow" was
4733 performed can be followed by a conditional addition of the modulus.
4734 @end{ImplNote}
4735 @end{Notes}
4736
4737 @begin{Examples}
4738 @Leading@keepnext@i(Examples of expressions involving binary adding operators:)
4739 @begin{Example}
4740 Z + 0.1 --@RI[ Z has to be of a real type ]
4741
4742 "A" & "BCD" --@RI[ concatenation of two string literals]
4743 'A' & "BCD" --@RI[ concatenation of a character literal and a string literal]
4744 'A' & 'A' --@RI[ concatenation of two character literals ]
4745 @end{Example}
4746 @end{Examples}
4747
4748 @begin{Inconsistent83}
4749 @Defn{inconsistencies with Ada 83}
4750 The lower bound of the result of concatenation,
4751 for a type whose first subtype is constrained, is
4752 now that of the index subtype. This is inconsistent with Ada 83,
4753 but generally only for Ada 83 programs that raise Constraint_Error.
4754 For example, the concatenation operator in
4755 @begin(Example)
4756 X : @key(array)(1..10) @key(of) Integer;
4757 @key(begin)
4758 X := X(6..10) & X(1..5);
4759 @end(Example)
4760
4761 would raise Constraint_Error in Ada 83 (because
4762 the bounds of the result of the concatenation would be 6..15, which is outside
4763 of 1..10),
4764 but would succeed and swap the halves of X (as expected) in Ada 95.
4765 @end{Inconsistent83}
4766
4767 @begin{Extend83}
4768 @Defn{extensions to Ada 83}
4769 Concatenation is now useful for array types whose
4770 first subtype is constrained.
4771 When the result type of a concatenation
4772 is such an array type,
4773 Constraint_Error is avoided by effectively
4774 first sliding the left operand (if nonnull) so that
4775 its lower bound is that of the index subtype.
4776 @end{Extend83}
4777
4778 @LabeledSubClause{Unary Adding Operators}
4779
4780 @begin{StaticSem}
4781 @Leading@Defn{unary adding operator}@Defn2{Term=[operator],Sec=(unary adding)}
4782 @Defn{+ operator}@Defn2{Term=[operator],Sec=(+)}
4783 @Defn{plus operator}@Defn2{Term=[operator],Sec=(plus)}
4784 @Defn{- operator}@Defn2{Term=[operator],Sec=(-)}
4785 @Defn{minus operator}@Defn2{Term=[operator],Sec=(minus)}
4786 The unary adding operators + (identity) and @en (negation) are predefined
4787 for every specific numeric type @i(T) with their
4788 conventional meaning.
4789 They have the following specifications:
4790 @begin(example)
4791 @key(function) "+"(Right : @RI(T)) @key(return) @RI(T)
4792 @key(function) "-"(Right : @RI(T)) @key(return) @RI(T)
4793 @end(example)
4794 @end{StaticSem}
4795
4796 @begin{Notes}
4797 For modular integer types, the unary adding operator @en, when
4798 given a nonzero operand, returns the result of subtracting
4799 the value of the operand from the modulus;
4800 for a zero operand, the result is zero.
4801 @end{Notes}
4802
4803 @LabeledSubClause{Multiplying Operators}
4804
4805 @begin{StaticSem}
4806 @Leading@Defn{multiplying operator}@Defn2{Term=[operator],Sec=(multiplying)}
4807 @Defn{* operator}@Defn2{Term=[operator],Sec=(*)}
4808 @Defn{multiply operator}@Defn2{Term=[operator],Sec=(multiply)}
4809 @Defn{times operator}@Defn2{Term=[operator],Sec=(times)}
4810 @Defn{/ operator}@Defn2{Term=[operator],Sec=(/)}
4811 @Defn{divide operator}@Defn2{Term=[operator],Sec=(divide)}
4812 @Defn{mod operator}@Defn2{Term=[operator],Sec=(mod)}
4813 @Defn{rem operator}@Defn2{Term=[operator],Sec=(rem)}
4814 The multiplying operators * (multiplication), / (division),
4815 @key(mod) (modulus), and @key(rem) (remainder)
4816 are predefined for every specific integer type @i(T):
4817 @begin(example)
4818 @key(function) "*" (Left, Right : @RI(T)) @key(return) @RI(T)
4819 @key(function) "/" (Left, Right : @RI(T)) @key(return) @RI(T)
4820 @key(function) "@key(mod)"(Left, Right : @RI(T)) @key(return) @RI(T)
4821 @key(function) "@key(rem)"(Left, Right : @RI(T)) @key(return) @RI(T)
4822 @end(example)
4823
4824 Signed integer multiplication has its conventional meaning.
4825
4826 @Leading@keepnext@;Signed integer division and remainder are defined by the relation:
4827 @begin(example)
4828 A = (A/B)*B + (A @key(rem) B)
4829 @end(example)
4830
4831 @Leading@;where (A @key(rem) B) has the sign of A and an absolute value less than
4832 the absolute value of B. Signed integer division satisfies the identity:
4833 @begin(example)
4834 (-A)/B = -(A/B) = A/(-B)
4835 @end(example)
4836
4837 @begin{WideAbove}
4838 @Leading@ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0260-1]}
4839 The signed integer modulus operator is defined such
4840 that the result of A @key(mod) B @Chg{Version=[3],New=[is either zero,
4841 or ],Old=[]}has the sign of B and an absolute value less than the
4842 absolute value of B; in addition, for some signed integer value N, this result
4843 satisfies the relation:
4844 @begin(example)
4845 A = B*N + (A @key(mod) B)
4846 @end(example)
4847
4848 The multiplying operators on modular types are defined in terms
4849 of the corresponding signed integer operators@Redundant[, followed by a reduction
4850 modulo the modulus if the result is outside
4851 the base range of the type] @Redundant[(which is only possible for the "*"
4852 operator)].
4853 @begin{Ramification}
4854 The above identity satisfied by signed integer
4855 division is not satisfied by modular division
4856 because of the difference in effect of negation.
4857 @end{Ramification}
4858 @end{WideAbove}
4859
4860 @Leading@;Multiplication and division operators are predefined for
4861 every specific floating point type @i(T):
4862 @begin(example)
4863 @key(function) "*"(Left, Right : @RI(T)) @key(return) @RI(T)
4864 @key(function) "/"(Left, Right : @RI(T)) @key(return) @RI(T)
4865 @end(example)
4866
4867 @Leading@;The following multiplication and division operators, with
4868 an operand of the predefined type Integer, are predefined
4869 for every specific fixed point type @i(T):
4870 @begin(example)
4871 @key(function) "*"(Left : @RI(T); Right : Integer) @key(return) @RI(T)
4872 @key(function) "*"(Left : Integer; Right : @RI(T)) @key(return) @RI(T)
4873 @key(function) "/"(Left : @RI(T); Right : Integer) @key(return) @RI(T)
4874 @end(example)
4875
4876 @Leading@Redundant[All of the above multiplying operators
4877 are usable with an operand
4878 of an appropriate universal numeric type.] The following additional
4879 multiplying operators for @i(root_real) are predefined@Redundant[,
4880 and are usable when both operands are of an appropriate universal or
4881 root numeric type, and the result is allowed to be of
4882 type @i(root_real), as in a @nt<number_declaration>]:
4883 @begin{Ramification}
4884 These operators
4885 are analogous to the multiplying operators
4886 involving fixed or floating point types
4887 where @i(root_real) substitutes for the
4888 fixed or floating point type,
4889 and @i(root_integer) substitutes for Integer.
4890 Only values of the corresponding universal numeric types are
4891 implicitly convertible to these root numeric types,
4892 so these operators are really restricted to use with
4893 operands of a universal type, or the specified
4894 root numeric types.
4895 @end{Ramification}
4896 @begin(example)
4897 @key(function) "*"(Left, Right : @RI(root_real)) @key(return) @RI(root_real)
4898 @key(function) "/"(Left, Right : @RI(root_real)) @key(return) @RI(root_real)
4899
4900 @key(function) "*"(Left : @RI(root_real); Right : @RI(root_integer)) @key(return) @RI(root_real)
4901 @key(function) "*"(Left : @RI(root_integer); Right : @RI(root_real)) @key(return) @RI(root_real)
4902 @key(function) "/"(Left : @RI(root_real); Right : @RI(root_integer)) @key(return) @RI(root_real)
4903 @end(example)
4904
4905 @Leading@;Multiplication and division between any two fixed point types are
4906 provided by the following two predefined operators:
4907 @begin{Ramification}
4908 @i(Universal_fixed) is the universal type for the class of
4909 fixed point types, meaning that these operators take operands
4910 of any fixed point types (not necessarily the same)
4911 and return a result that is implicitly (or explicitly) convertible to
4912 any fixed point type.
4913 @end{Ramification}
4914 @begin(example)
4915 @key(function) "*"(Left, Right : @RI(universal_fixed)) @key(return) @RI(universal_fixed)
4916 @key(function) "/"(Left, Right : @RI(universal_fixed)) @key(return) @RI(universal_fixed)
4917 @end(example)
4918 @end{StaticSem}
4919
4920 @begin{Resolution}
4921 @ChgRef{Version=[2],Kind=[Added],ARef=[AI95-00364-01],ARef=[AI95-00420-01]}
4922 @ChgAdded{Version=[2],Type=[Leading],Text=[The above two fixed-fixed
4923 multiplying operators shall
4924 not be used in a context where the expected type for the result is itself
4925 @i(universal_fixed) @Redundant[@em the context has to identify some other
4926 numeric type to which the result is to be converted, either explicitly or
4927 implicitly]. Unless the predefined universal operator is identified using an
4928 expanded name with @nt{prefix} denoting the package Standard, an explicit
4929 conversion is required on the result when using the above fixed-fixed
4930 multiplication operator if either operand is of a type having a user-defined
4931 primitive multiplication operator such that:]}
4932 @begin{Itemize}
4933 @ChgRef{Version=[2],Kind=[Added]}
4934 @ChgRef{Version=[3],Kind=[RevisedAdded],ARef=[AI05-0020-1],ARef=[AI05-0209-1]}
4935 @ChgAdded{Version=[2],Text=[it is declared immediately within the same
4936 declaration list as the type@Chg{Version=[3],New=[ or any partial
4937 or incomplete view thereof],Old=[]}; and]}
4938
4939 @ChgRef{Version=[2],Kind=[Added]}
4940 @ChgAdded{Version=[2],Text=[both of its formal parameters are of a
4941 fixed-point type.]}
4942 @end{Itemize}
4943 @ChgRef{Version=[2],Kind=[Added],ARef=[AI95-00364-01],ARef=[AI95-00420-01]}
4944 @ChgAdded{Version=[2],Text=[A corresponding requirement applies to the
4945 universal fixed-fixed division operator.]}
4946
4947 @begin(Discussion)
4948 @ChgRef{Version=[2],Kind=[AddedNormal]}
4949 @ChgAdded{Version=[2],Text=[The @i(small) of @i(universal_fixed) is
4950 infinitesimal; no loss of precision is permitted.
4951 However, fixed-fixed division is impractical to implement when
4952 an exact result is required,
4953 and multiplication will sometimes result in unanticipated overflows
4954 in such circumstances,
4955 so we require an explicit conversion to be inserted in
4956 expressions like A * B * C if A, B, and C are each of some fixed point
4957 type.]}
4958
4959 @ChgRef{Version=[2],Kind=[AddedNormal]}
4960 @ChgAdded{Version=[2],Text=[On the other hand, X := A * B; is permitted by
4961 this rule, even if X, A, and B
4962 are all of different fixed point types, since the expected type
4963 for the result of the multiplication is the type of X, which is necessarily
4964 not @i(universal_fixed).]}
4965
4966 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00364-01],ARef=[AI95-00420-01]}
4967 @ChgAdded{Version=[2],Text=[We have made these into Name Resolution rules to
4968 ensure that user-defined primitive fixed-fixed operators are not made unusable
4969 due to the presence of these universal fixed-fixed operators. But we do allow
4970 these operators to be used if prefixed by package Standard, so that they can be
4971 used in the definitions of user-defined operators.]}
4972 @end(Discussion)
4973 @end{Resolution}
4974
4975 @begin{Legality}
4976 @ChgRef{Version=[2],Kind=[DeletedNoDelMsg],ARef=[AI95-00364-01]}
4977 @ChgDeleted{Version=[2],Text=[The above two fixed-fixed multiplying operators
4978 shall not be used in a context where the expected type for the result
4979 is itself @i(universal_fixed) @em @Redundant[the context has to
4980 identify some other numeric type to which the result is to be converted,
4981 either explicitly or implicitly].]}
4982 @begin(Discussion)
4983 @ChgRef{Version=[2],Kind=[DeletedNoDelMsg]}
4984 @ChgDeleted{Version=[2],Text=[The @i(small) of @i(universal_fixed) is infinitesimal; no loss
4985 of precision is permitted.
4986 However, fixed-fixed division is impractical to implement when
4987 an exact result is required,
4988 and multiplication will sometimes result in unanticipated overflows
4989 in such circumstances,
4990 so we require an explicit conversion to be inserted in
4991 expressions like A * B * C if A, B, and C are each of some fixed point
4992 type.]}
4993
4994 @ChgRef{Version=[2],Kind=[DeletedNoDelMsg]}
4995 @ChgDeleted{Version=[2],Text=[On the other hand, X := A * B; is permitted by this rule, even if X, A, and B
4996 are all of different fixed point types, since the expected type
4997 for the result of the multiplication is the type of X, which is necessarily
4998 not @i(universal_fixed).]}
4999 @end(Discussion)
5000 @end{Legality}
5001 @begin{NotIso}
5002 @ChgAdded{Version=[2],Noparanum=[T],Text=[@Shrink{@i<Paragraph 20 was
5003 deleted.>}]}@Comment{This message should be deleted if the paragraphs
5004 are ever renumbered.}
5005 @end{NotIso}
5006
5007 @begin{RunTime}
5008 The multiplication and division operators for real types have
5009 their conventional meaning.
5010 @redundant[For floating point types, the accuracy of the result is
5011 determined by the precision of the result type.
5012 For decimal fixed point types, the result is truncated toward zero
5013 if the mathematical result is between two multiples of the @i(small)
5014 of the specific result type (possibly determined by context);
5015 for ordinary fixed point types, if the mathematical result is
5016 between two multiples of the @i(small), it is unspecified
5017 which of the two is the result.
5018 @PDefn{unspecified}]
5019
5020 @IndexCheck{Division_Check}
5021 @Defn2{Term=[Constraint_Error],Sec=(raised by failure of run-time check)}
5022 The exception Constraint_Error is raised by
5023 integer division, @key(rem),
5024 and @key(mod) if the right operand is zero.
5025 @Redundant[Similarly, for a real type @i(T) with @i(T')Machine_Overflows
5026 True, division by zero raises Constraint_Error.]
5027 @end{RunTime}
5028
5029 @begin{Notes}
5030 @Leading@Keepnext@;For positive A and B, A/B is the quotient and A @key(rem) B is
5031 the remainder when A is divided by B. The following relations are satisfied
5032 by the rem operator:
5033 @begin{Example}
5034 A @key(rem) (-B) = A @key(rem) B
5035 (-A) @key(rem) B = -(A @key(rem) B)
5036 @end{Example}
5037
5038 @Leading@keepnext@;For any signed integer K, the following identity holds:
5039 @begin{Example}
5040 A @key(mod) B = (A + K*B) @key(mod) B
5041 @end{Example}
5042 @begin{Bundle}
5043 @NoPrefix@Leading@;The relations between signed integer
5044 division, remainder, and modulus are
5045 illustrated by the following table:
5046 @begin{Example}
5047 A B A/B A @key(rem) B A @key(mod) B A B A/B A @key(rem) B A @key(mod) B
5048
5049 10 5 2 0 0 -10 5 -2 0 0
5050 11 5 2 1 1 -11 5 -2 -1 4
5051 12 5 2 2 2 -12 5 -2 -2 3
5052 13 5 2 3 3 -13 5 -2 -3 2
5053 14 5 2 4 4 -14 5 -2 -4 1
5054
5055 A B A/B A @key(rem) B A @key(mod) B A B A/B A @key(rem) B A @key(mod) B@*
5056 10 -5 -2 0 0 -10 -5 2 0 0
5057 11 -5 -2 1 -4 -11 -5 2 -1 -1
5058 12 -5 -2 2 -3 -12 -5 2 -2 -2
5059 13 -5 -2 3 -2 -13 -5 2 -3 -3
5060 14 -5 -2 4 -1 -14 -5 2 -4 -4
5061 @end{Example}
5062 @end{Bundle}
5063 @end{Notes}
5064
5065 @begin{Examples}
5066 @Leading@keepnext@i(Examples of expressions involving multiplying operators:)
5067 @begin{Example}
5068 I : Integer := 1;
5069 J : Integer := 2;
5070 K : Integer := 3;
5071
5072 X : Real := 1.0; --@RI[ see @RefSecNum{Floating Point Types}]
5073 Y : Real := 2.0;
5074
5075 F : Fraction := 0.25; --@RI[ see @RefSecNum{Fixed Point Types}]
5076 G : Fraction := 0.5;
5077 @end{Example}
5078 @begin{Example}
5079 @tabclear()@tabset(P19, P31)
5080 @RI(Expression) @\@RI(Value) @\@RI(Result Type)@*
5081 @R{I*J} @\@R{2} @\@RI(same as I and J, that is, Integer)
5082 @R{K/J} @\@R{1} @\@RI(same as K and J, that is, Integer)
5083 @R{K @key(mod) J} @\@R{1} @\@RI(same as K and J, that is, Integer)@*
5084 @R{X/Y} @\@R{0.5} @\@RI(same as X and Y, that is, Real)
5085 @R{F/2} @\@R{0.125} @\@RI(same as F, that is, Fraction)@*
5086 @R{3*F} @\@R{0.75} @\@RI(same as F, that is, Fraction)
5087 @R{0.75*G} @\@R{0.375} @\@RI(universal_fixed, implicitly convertible)
5088 @\ @\@RI(to any fixed point type)
5089 @R{Fraction(F*G)} @\@R{0.125} @\@RI(Fraction, as stated by the conversion)
5090 @R{Real(J)*Y} @\@R{4.0} @\@RI(Real, the type of both operands after)
5091 @\ @\@RI(conversion of J)
5092 @end{Example}
5093 @end{Examples}
5094
5095 @begin{Incompatible83}
5096 @ChgRef{Version=[2],Kind=[Added],ARef=[AI95-00364-01],ARef=[AI95-00420-01]}
5097 @Chg{Version=[2],New=[@Defn{incompatibilities with Ada 83}The universal
5098 fixed-fixed multiplying operators are now directly available (see below).
5099 Any attempt to use user-defined fixed-fixed multiplying operators
5100 will be ambiguous with the universal ones. The only way to use the user-defined
5101 operators is to fully qualify them in a prefix call. This problem was not
5102 documented during the design of Ada 95, and has been mitigated by
5103 Ada 2005.],Old=[]}
5104 @end{Incompatible83}
5105
5106 @begin{Extend83}
5107 @Defn{extensions to Ada 83}
5108 Explicit conversion of the result of multiplying
5109 or dividing two fixed point numbers is no longer required,
5110 provided the context uniquely determines some specific
5111 fixed point result type.
5112 This is to improve support for decimal fixed point, where
5113 requiring explicit conversion on every fixed-fixed multiply
5114 or divide was felt to be inappropriate.
5115
5116 The type @i(universal_fixed) is covered by @i(universal_real),
5117 so real literals and fixed point operands may be multiplied
5118 or divided directly, without any explicit conversions required.
5119 @end{Extend83}
5120
5121 @begin{DiffWord83}
5122 We have used the normal syntax for function definition
5123 rather than a tabular format.
5124 @end{DiffWord83}
5125
5126
5127 @begin{Incompatible95}
5128 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00364-01]}
5129 @Chg{Version=[2],New=[@Defn{incompatibilities with Ada 95}We have changed the
5130 resolution rules for the universal fixed-fixed multiplying operators to remove
5131 the incompatibility with Ada 83 discussed above. The solution is to hide
5132 the universal operators in some circumstances. As a result, some legal Ada 95
5133 programs will require the insertion of an explicit conversion around a
5134 fixed-fixed multiply operator. This change is likely to catch as many bugs as
5135 it causes, since it is unlikely that the user wanted to use predefined
5136 operators when they had defined user-defined versions.],Old=[]}
5137 @end{Incompatible95}
5138
5139 @begin{DiffWord2005}
5140 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0020-1],ARef=[AI05-0209-1]}
5141 @ChgAdded{Version=[3],Text=[@b<Correction:> Wording was added to clarify
5142 that @i{universal_fixed} "*" and "/" does not apply if an appropriate
5143 operator is declared for a partial (or incomplete) view of the designated type.
5144 Otherwise, adding a partial (or incomplete) view could make some
5145 "*" and "/" operators ambiguous.]}
5146
5147 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0260-1]}
5148 @ChgAdded{Version=[3],Text=[@b<Correction:> The wording for the @key[mod]
5149 operator was corrected so that a result of 0 does not have to have
5150 "the sign of B" (which is impossible if B is negative).]}
5151 @end{DiffWord2005}
5152
5153
5154 @LabeledSubClause{Highest Precedence Operators}
5155
5156 @begin{StaticSem}
5157 @Leading@Defn{highest precedence operator}@Defn2{Term=[operator],Sec=(highest precedence)}
5158 @Defn{abs operator}@Defn2{Term=[operator],Sec=(abs)}
5159 @Defn{absolute value}
5160 The highest precedence unary operator @key(abs) (absolute value)
5161 is predefined for every specific numeric type @i(T),
5162 with the following specification:
5163 @begin(example)
5164 @key(function) "@key(abs)"(Right : @RI(T)) @key(return) @RI(T)
5165 @end(example)
5166
5167 @Leading@Defn{not operator}@Defn2{Term=[operator],Sec=(not)}
5168 @IndexSeeAlso{Term=[logical operator],See=(not operator)}
5169 The highest precedence unary operator @key(not) (logical negation) is
5170 predefined for every boolean type @i(T),
5171 every modular type @i(T),
5172 and for every one-dimensional array type @i(T) whose
5173 components are of a boolean type,
5174 with the following specification:
5175 @begin(example)
5176 @key(function) "@key(not)"(Right : @RI(T)) @key(return) @RI(T)
5177 @end(example)
5178
5179 The result of the operator @key(not) for a modular type is
5180 defined as the difference between the high bound of the base range
5181 of the type and the value of the operand. @Redundant[For
5182 a binary modulus, this corresponds to a bit-wise complement
5183 of the binary
5184 representation of the value
5185 of the operand.]
5186
5187 The operator @key(not) that applies
5188 to a one-dimensional array of boolean
5189 components yields a one-dimensional boolean array with the same bounds;
5190 each component of the result is obtained by logical negation of the
5191 corresponding component of the operand (that is, the component that
5192 has the same index value).
5193 @IndexCheck{Range_Check}
5194 @Defn2{Term=[Constraint_Error],Sec=(raised by failure of run-time check)}
5195 A check is made that each component of the result belongs to the
5196 component subtype; the exception Constraint_Error is raised if this
5197 check fails.
5198 @begin{Discussion}
5199 The check against the component subtype is per AI83-00535.
5200 @end{Discussion}
5201
5202 @Leading@Defn{exponentiation operator}@Defn2{Term=[operator],Sec=(exponentiation)}
5203 @Defn{** operator}@Defn2{Term=[operator],Sec=(**)}
5204 The highest precedence @i(exponentiation) operator ** is predefined
5205 for every specific integer type @i(T)
5206 with the following specification:
5207 @begin(example)
5208 @key(function) "**"(Left : @RI(T); Right : Natural) @key(return) @RI(T)
5209 @end(example)
5210
5211 @Leading@;Exponentiation is also predefined for
5212 every specific floating point type
5213 as well as @i{root_real},
5214 with the following specification (where @i(T) is @i{root_real}
5215 or the floating point type):
5216 @begin(example)
5217 @key(function) "**"(Left : @RI(T); Right : Integer'Base) @key(return) @RI(T)
5218 @end(example)
5219
5220 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0088-1]}
5221 @Defn{exponent}
5222 The right operand of an exponentiation is the @i(exponent).
5223 The @Chg{Version=[3],New=[value of],Old=[expression]} X**N with the value of
5224 the exponent N positive is @Chg{Version=[3],New=[the same as the value of],
5225 Old=[equivalent to the expression]} X*X*...X (with N@en@;1 multiplications)
5226 except that the multiplications
5227 are associated in an arbitrary order. With N equal to zero, the result is one.
5228 With the value of N negative
5229 @Redundant[(only defined for a floating point operand)],
5230 the result is the reciprocal of the result using the absolute value of
5231 N as the exponent.
5232 @begin{Ramification}
5233 The language does not specify the order of association of the multiplications
5234 inherent in an exponentiation. For a floating point type,
5235 the accuracy of the result might depend on the particular
5236 association order chosen.
5237 @end{Ramification}
5238
5239 @end{StaticSem}
5240
5241 @begin{ImplPerm}
5242 @Defn2{Term=[Constraint_Error],Sec=(raised by failure of run-time check)}
5243 The implementation of
5244 exponentiation for the case of a negative exponent
5245 is allowed to raise Constraint_Error
5246 if the intermediate result of the repeated multiplications
5247 is outside the safe range of the type, even though the final
5248 result (after taking the reciprocal)
5249 would not be.
5250 (The best machine approximation to the
5251 final result in this case would generally be 0.0.)
5252 @end{ImplPerm}
5253
5254 @begin{Notes}
5255 @IndexCheck{Range_Check}
5256 As implied by the specification given above
5257 for exponentiation of an integer type, a check is made that
5258 the exponent is not negative.
5259 @Defn2{Term=[Constraint_Error],Sec=(raised by failure of run-time check)}
5260 Constraint_Error is raised if this check fails.
5261 @end{Notes}
5262
5263 @begin{Inconsistent83}
5264 @ChgRef{Version=[1],Kind=[Added],Ref=[8652/0100],ARef=[AI95-00018-01]}
5265 @ChgAdded{Version=[1],Text=[@Defn{inconsistencies with Ada 83}
5266 The definition of "**" allows arbitrary association of the
5267 multiplications which make up the result. Ada 83 required left-to-right
5268 associations (confirmed by AI83-00137). Thus it is possible that "**"
5269 would provide a slightly different (and more potentially accurate) answer in
5270 Ada 95 than in the same Ada 83 program.]}
5271 @end{Inconsistent83}
5272
5273 @begin{DiffWord83}
5274 We now show the specification for "**" for integer types
5275 with a parameter subtype of Natural rather than Integer for the exponent.
5276 This reflects the fact that Constraint_Error is raised if
5277 a negative value is provided for the exponent.
5278 @end{DiffWord83}
5279
5280 @begin{DiffWord2005}
5281 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0088-1]}
5282 @ChgAdded{Version=[3],Text=[@b<Correction:> The equivalence definition
5283 for "**" was corrected so that it does not imply that the operands
5284 are evaluated multiple times.]}
5285 @end{DiffWord2005}
5286
5287
5288 @LabeledAddedSubclause{Version=[3],Name=[Conditional Expressions]}
5289
5290 @begin{Intro}
5291 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0147-1],ARef=[AI05-0188-1],ARef=[AI05-0262-1]}
5292 @ChgAdded{Version=[3],Text=[A @nt{conditional_expression} selects for evaluation
5293 at most one of the enclosed @SynI<dependent_>@nt{expression}s, depending on
5294 a decision among the alternatives. One
5295 kind of @nt{conditional_expression} is the @nt{if_expression}, which selects for
5296 evaluation a @SynI<dependent_>@nt{expression} depending on the value of one or more
5297 corresponding conditions. The other kind of @nt{conditional_expression} is the
5298 @nt{case_expression}, which selects for evaluation one of a number of alternative
5299 @SynI<dependent_>@nt{expression}s; the chosen alternative is determined by the
5300 value of a @SynI<selecting_>@nt{expression}.]}
5301 @end{Intro}
5302
5303 @begin{MetaRules}
5304 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0188-1]}
5305 @ChgAdded{Version=[3],Text=[As previously noted, there are two kinds of
5306 @nt{conditional_expression}, @nt{if_expression}s and @nt{case_expression}s.
5307 Whenever possible, we have written the rules in terms of
5308 @nt{conditional_expression}s to avoid duplication.]}
5309
5310 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0147-1]}
5311 @ChgAdded{Version=[3],Text=[The rules for @nt{conditional_expression}s
5312 have been designed as much as possible to work similarly to a parenthesized
5313 expression. The intent is that as much as possible, wherever a parenthesized
5314 expression would be allowed, a @nt{conditional_expression} would be allowed,
5315 and it should work the same way.]}
5316 @end{MetaRules}
5317
5318 @begin{Syntax}
5319 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0188-1]}
5320 @AddedSyn{Version=[3],lhs=<@Chg{Version=[3],New=<conditional_expression>,Old=<>}>,
5321 rhs="@Chg{Version=[3],New=<@Syn2{if_expression} | @Syn2{case_expression}>,Old=<>}"}
5322
5323 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0147-1],ARef=[AI05-0188-1]}
5324 @AddedSyn{Version=[3],lhs=<@Chg{Version=[3],New=<if_expression>,Old=<>}>,
5325 rhs="
5326 @Chg{Version=[3],New=<@key[if] @Syn2{condition} @key[then] @SynI{dependent_}@Syn2{expression}
5327 {@key[elsif] @Syn2{condition} @key[then] @SynI{dependent_}@Syn2{expression}}
5328 [@key[else] @SynI{dependent_}@Syn2{expression}]>,Old=<>}"}
5329
5330 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0147-1]}
5331 @AddedSyn{Version=[3],lhs=<@Chg{Version=[3],New=<condition>,Old=<>}>,
5332 rhs="@Chg{Version=[3],New=<@SynI{boolean_}@Syn2{expression}>,Old=<>}"}
5333 @Comment{Moved from "If Statements"}
5334
5335 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0188-1]}
5336 @AddedSyn{Version=[3],lhs=<@Chg{Version=[3],New=<case_expression>,Old=<>}>,
5337 rhs="@Chg{Version=[3],New=<
5338 @key[case] @SynI{selecting_}@Syn2{expression} @key[is]
5339 @Syn2[case_expression_alternative] {,
5340 @Syn2[case_expression_alternative]}>,Old=<>}"}
5341
5342 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0188-1]}
5343 @AddedSyn{Version=[3],lhs=<@Chg{Version=[3],New=<case_expression_alternative>,Old=<>}>,
5344 rhs="@Chg{Version=[3],New=[
5345 @key[when] @Syn2{discrete_choice_list} =>
5346 @SynI{dependent_}@Syn2{expression}],Old=<>}"}
5347
5348 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0147-1]}
5349 @ChgAdded{Version=[3],Text=[Wherever the Syntax Rules allow an @nt{expression},
5350 a @nt{conditional_expression} may be used in place of the @nt{expression}, so
5351 long as it is immediately surrounded by parentheses.]}
5352
5353 @begin{Discussion}
5354 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0147-1]}
5355 @ChgAdded{Version=[3],Text=[The syntactic category @nt{conditional_expression}
5356 appears only as a primary that is parenthesized. The above rule allows it to
5357 additionally be used in other contexts where it would be directly surrounded
5358 by parentheses.]}
5359
5360 @ChgRef{Version=[3],Kind=[AddedNormal]}
5361 @ChgAdded{Version=[3],Type=[Leading],Text=[The grammar makes the following directly legal:]}
5362
5363 @begin{Example}
5364 @ChgRef{Version=[3],Kind=[AddedNormal]}
5365 @ChgAdded{Version=[3],Text=[A := (@key[if] X @key[then] Y @key[else] Z); --@examcom{ parentheses required}
5366 A := B + (@key[if] X @key[then] Y @key[else] Z) + C; --@examcom{ parentheses required}]}
5367 @end{Example}
5368
5369 @ChgRef{Version=[3],Kind=[AddedNormal]}
5370 @ChgAdded{Version=[3],Type=[Leading],Text=[The following procedure calls are
5371 syntactically legal; the first uses the above rule to eliminate the redundant
5372 parentheses found in the second:]}
5373
5374 @begin{Example}
5375 @ChgRef{Version=[3],Kind=[AddedNormal]}
5376 @ChgAdded{Version=[3],Text=[P(@key[if] X @key[then] Y @key[else] Z);
5377 P((@key[if] X @key[then] Y @key[else] Z)); --@Examcom{ redundant parentheses}]}
5378
5379 @ChgRef{Version=[3],Kind=[AddedNormal]}
5380 @ChgAdded{Version=[3],Text=[P((@key[if] X @key[then] Y @key[else] Z), Some_Other_Param);
5381 P(Some_Other_Param, (@key[if] X @key[then] Y @key[else] Z));
5382 P(Formal => (@key[if] X @key[then] Y @key[else] Z));]}
5383 @end{Example}
5384
5385 @ChgRef{Version=[3],Kind=[AddedNormal]}
5386 @ChgAdded{Version=[3],Type=[Leading],Text=[whereas the following are illegal:]}
5387
5388 @begin{Example}
5389 @ChgRef{Version=[3],Kind=[AddedNormal]}
5390 @ChgAdded{Version=[3],Text=[P(@key[if] X @key[then] Y @key[else] Z, Some_Other_Param);
5391 P(Some_Other_Param, @key[if] X @key[then] Y @key[else] Z);
5392 P(Formal => @key[if] X @key[then] Y @key[else] Z);]}
5393 @end{Example}
5394
5395 @ChgRef{Version=[3],Kind=[AddedNormal]}
5396 @ChgAdded{Version=[3],Text=[because in these latter cases, the
5397 @nt{conditional_expression} is not immediately surrounded by parentheses (which
5398 means on both sides!).]}
5399
5400 @ChgRef{Version=[3],Kind=[AddedNormal]}
5401 @ChgAdded{Version=[3],Text=[The English-language rule applies in all places
5402 that could surround an expression with parentheses, including pragma
5403 arguments, type conversion and qualified expression operands, and array index
5404 expressions.]}
5405
5406 @ChgRef{Version=[3],Kind=[AddedNormal]}
5407 @ChgAdded{Version=[3],Text=[This English-language rule could have been
5408 implemented instead by adding a nonterminal
5409 @ntf{expression_within_parentheses}, which would consist of @nt{expression}s
5410 and @nt{conditional_expression}s. Then, that could be used in all of the
5411 syntax which could consist of parens directly around an @nt{expression}. We
5412 did not do that because of the large amount of change required. A complete
5413 grammar is given in @AILink{AI=[AI05-0147-1],Text=[AI05-0147-1]}.]}
5414 @end{Discussion}
5415
5416 @begin{ImplNote}
5417 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0147-1]}
5418 @ChgAdded{Version=[3],Text=[Implementers are cautioned to consider error
5419 detection when implementing the syntax for @nt{conditional_expression}s. An
5420 @nt{if_expression} and an @nt{if_statement} are very similar syntactically, (as
5421 are a @nt{case_expression} and a @nt{case_statement}) and simple mistakes can
5422 appear to change one into the other, potentially causing errors to be moved
5423 far away from their actual location. The absence of @key[end if] to terminate
5424 an @nt{if_expression} (and @key[end case] for a @nt{case_expression}) also
5425 may make error handling harder.]}
5426 @end{ImplNote}
5427
5428 @end{Syntax}
5429
5430 @begin{Resolution}
5431 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0147-1]}
5432 @ChgAdded{Version=[3],Type=[Leading],Text=[If a @nt{conditional_expression} is
5433 expected to be of a type @i<T>, then each @SynI{dependent_}@nt{expression} of
5434 the @nt{conditional_expression} is expected to be of type @i<T>. Similarly, if a
5435 @nt{conditional_expression} is expected to be of some class of types, then each
5436 @SynI{dependent_}@nt{expression} of the @nt{conditional_expression} is subject
5437 to the same expectation. If a @nt{conditional_expression} shall resolve to be of
5438 a type @i<T>, then each @SynI{dependent_}@nt{expression} shall resolve to be of
5439 type @i<T>.@PDefn2{Term=[expected type],Sec=[dependent_expression]}]}
5440
5441 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0147-1]}
5442 @ChgAdded{Version=[3],Type=[Leading],Text=[The possible types of a
5443 @nt{conditional_expression} are further determined as follows:]}
5444
5445 @begin{Itemize}
5446 @ChgRef{Version=[3],Kind=[AddedNormal]}
5447 @ChgAdded{Version=[3],Text=[If the @nt{conditional_expression} is the operand
5448 of a type conversion, the type of the @nt{conditional_expression} is the
5449 target type of the conversion; otherwise,]}
5450
5451 @begin{Reason}
5452 @ChgRef{Version=[3],Kind=[AddedNormal]}
5453 @ChgAdded{Version=[3],Type=[Leading],Text=[This rule distributes an enclosing
5454 type conversion to the @SynI{dependent_}@nt{expression}s. This means that]}
5455 @begin{Example}
5456 @ChgRef{Version=[3],Kind=[AddedNormal]}
5457 @ChgAdded{Version=[3],Text=[T(@key[if] C @key[then] A @key[else] B)]}
5458 @end{Example}
5459 @ChgRef{Version=[3],Kind=[AddedNormal]}
5460 @ChgAdded{Version=[3],Type=[Leading],Text=[has the same semantics as]}
5461 @begin{Example}
5462 @ChgRef{Version=[3],Kind=[AddedNormal]}
5463 @ChgAdded{Version=[3],Text=[(@key[if] C @key[then] T(A) @key[else] T(B))]}
5464 @end{Example}
5465 @end{Reason}
5466
5467 @ChgRef{Version=[3],Kind=[AddedNormal]}
5468 @ChgAdded{Version=[3],Text=[If all of the @SynI{dependent_}@nt{expression}s
5469 are of the same type, the type of the @nt{conditional_expression} is that
5470 type; otherwise,]}
5471
5472 @ChgRef{Version=[3],Kind=[AddedNormal]}
5473 @ChgAdded{Version=[3],Text=[If a @SynI{dependent_}@nt{expression} is of an
5474 elementary type, the type of the @nt{conditional_expression} shall be covered
5475 by that type; otherwise,]}
5476
5477 @begin{Reason}
5478 @ChgRef{Version=[3],Kind=[AddedNormal]}
5479 @ChgAdded{Version=[3],Text=[This rule supports the use of
5480 numeric literals and universal expressions within a
5481 @nt{conditional_expression}.]}
5482 @end{Reason}
5483
5484 @ChgRef{Version=[3],Kind=[AddedNormal]}
5485 @ChgAdded{Version=[3],Text=[If the @nt{conditional_expression} is expected to
5486 be of type @i<T> or shall resolve to type @i<T>, then the
5487 @nt{conditional_expression} is of type @i<T>.]}
5488
5489 @begin{Ramification}
5490 @ChgRef{Version=[3],Kind=[AddedNormal]}
5491 @ChgAdded{Version=[3],Text=[If the type of the @nt{conditional_expression}
5492 cannot be determined by one of these rules, then Name Resolution has failed for
5493 that expression, even if the @SynI{dependent_}@nt{expression}s would
5494 resolve individually.]}
5495 @end{Ramification}
5496 @end{Itemize}
5497
5498 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0147-1]}
5499 @ChgAdded{Version=[3],Text=[@PDefn2{Term=[expected type], Sec=(condition)}
5500 A @nt{condition} is expected to be of any boolean type.]}
5501 @Comment{Moved from "If Statements"}
5502
5503 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0188-1]}
5504 @ChgAdded{Version=[3],Text=[The expected type for the
5505 @SynI<selecting_>@nt{expression} and the @nt{discrete_choice}s are as for case
5506 statements
5507 (see @RefSecNum{Case Statements}).@PDefn2{Term=[expected type],Sec=[case_expression selecting_expression]}
5508 @PDefn2{Term=[expected type],Sec=[case_expression_alternative discrete_choice]}
5509 @PDefn2{Term=[expected type],Sec=[selecting_expression case_expression]}]}
5510
5511 @end{Resolution}
5512
5513 @begin{Legality}
5514 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0147-1],ARef=[AI05-0188-1]}
5515 @ChgAdded{Version=[3],Text=[All of the @SynI{dependent_}@nt{expression}s
5516 shall be convertible (see @RefSecNum{Type Conversions}) to the type of the
5517 @nt{conditional_expression}.]}
5518
5519 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0147-1],ARef=[AI05-0188-1],ARef=[AI05-0269-1]}
5520 @ChgAdded{Version=[3],Text=[If the expected type of a
5521 @nt{conditional_expression} is a specific tagged type, all of the
5522 @SynI{dependent_}@nt{expression}s of the @nt{conditional_expression} shall be
5523 dynamically tagged, or none shall be dynamically tagged. In this case, the
5524 @nt{conditional_expression} is dynamically tagged if all of the
5525 @SynI{dependent_}@nt{expression}s are dynamically tagged, is tag-indeterminate
5526 if all of the @SynI{dependent_}@nt{expression}s are tag-indeterminate, and is
5527 statically tagged otherwise.]}
5528
5529 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0147-1],ARef=[AI05-0262-1]}
5530 @ChgAdded{Version=[3],Text=[If there is no @key[else]
5531 @SynI{dependent_}@nt{expression}, the @nt{if_expression} shall be of
5532 a boolean type.]}
5533
5534 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0188-1],ARef=[AI05-0269-1]}
5535 @ChgAdded{Version=[3],Text=[All @LegalityTitle that apply to the
5536 @nt{discrete_choice}s of a @nt{case_statement} (see @RefSecNum{Case Statements})
5537 also apply to the @nt{discrete_choice}s of a @nt{case_expression} except
5538 within an instance of a generic unit.]}
5539 @begin{Reason}
5540 @ChgRef{Version=[3],Kind=[AddedNormal]}
5541 @ChgAdded{Version=[3],Type=[Leading],Text=[The exemption for a case expression
5542 that occurs in an instance allows the following example:]}
5543 @begin{Example}
5544 @ChgRef{Version=[3],Kind=[AddedNormal]}
5545 @ChgAdded{Version=[3],Text=[@key[generic]
5546 @key[with function] Int_Func @key[return] Integer;
5547 @key[package] G @key[is]
5548 X : Float := (@key[case] Int_Func @key[is]
5549 @key[when] Integer'First .. -1 => -1.0,
5550 @key[when] 0 => 0.0,
5551 @key[when] Positive => 1.0);
5552 @key[end] G;]}
5553
5554 @ChgRef{Version=[3],Kind=[AddedNormal]}
5555 @ChgAdded{Version=[3],Text=[@key[function] Nat_Func @key[return] Natural @key[is] (123);]}
5556
5557 @ChgRef{Version=[3],Kind=[AddedNormal]}
5558 @ChgAdded{Version=[3],Text=[@key[package] I @key[is new] G (Int_Func => Nat_Func); -- @Examcom{Legal}]}
5559 @end{Example}
5560 @ChgRef{Version=[3],Kind=[AddedNormal]}
5561 @ChgAdded{Version=[3],Text=[Note that the @LegalityTitle still apply in the
5562 generic unit itself; they are just not enforced in an instance of the unit.]}
5563 @end{Reason}
5564 @end{Legality}
5565
5566 @begin{Runtime}
5567 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0147-1],ARef=[AI05-0188-1]}
5568 @ChgAdded{Version=[3],Text=[For the evaluation of an @nt{if_expression}, the
5569 @nt{condition} specified after @key[if], and any @nt{condition}s specified
5570 after @key[elsif], are evaluated in succession (treating a final @key[else]
5571 as @key[elsif] True @key[then]), until one evaluates to True or
5572 all @nt{condition}s are evaluated and yield False. If a @nt{condition}
5573 evaluates to True, the associated @synI{dependent_}@nt{expression} is evaluated,
5574 converted to the type of the @nt{if_expression}, and the resulting value is the
5575 value of the @nt{if_expression}. Otherwise (when there is no @key[else] clause),
5576 the value of the @nt{if_expression} is True.@PDefn2{Term=[evaluation],Sec=[if_expression]}]}
5577
5578 @begin{Ramification}
5579 @ChgRef{Version=[3],Kind=[AddedNormal]}
5580 @ChgAdded{Version=[3],Text=[@key[Else] is required unless the
5581 @nt{if_expression} has a boolean type, so the last sentence can only apply to
5582 @nt{if_expression}s with a boolean type.]}
5583 @end{Ramification}
5584
5585 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0188-1]}
5586 @ChgAdded{Version=[3],Text=[For the evaluation of a @nt{case_expression}, the
5587 @SynI<selecting_>@nt{expression} is first evaluated.
5588 If the value of the @SynI<selecting_>@nt{expression}
5589 is covered by the @nt{discrete_choice_list} of some
5590 @nt{case_expression_alternative}, then the @SynI<dependent_>@nt{expression} of
5591 the @nt{case_expression_alternative} is evaluated, converted to the type of the
5592 @nt{case_expression}, and the resulting value is the value of the
5593 @nt{case_expression}.@IndexCheck{Overflow_Check}
5594 @Defn2{Term=[Constraint_Error],Sec=(raised by failure of run-time check)}
5595 Otherwise (the value is not covered by any
5596 @nt{discrete_choice_list}, perhaps due to being outside the base range),
5597 Constraint_Error is raised.@PDefn2{Term=[evaluation],Sec=[case_expression]}]}
5598
5599 @end{Runtime}
5600
5601
5602 @begin{Extend2005}
5603 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0147-1]}
5604 @ChgAdded{Version=[3],Text=[@Defn{extensions to Ada 2005}If expressions
5605 and case expressions are new.]}
5606 @end{Extend2005}
5607
5608
5609 @LabeledAddedSubclause{Version=[3],Name=[Quantified Expressions]}
5610
5611 @ChgRef{Version=[4],Kind=[Added],ARef=[AI12-0158-1]}
5612 @ChgAdded{Version=[4],Text=[Quantified expressions provide a way to write
5613 universally and existentially quantified predicates over containers and
5614 arrays.]}
5615
5616 @begin{Syntax}
5617 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0176-1]}
5618 @AddedSyn{Version=[3],lhs=<@Chg{Version=[3],New=<quantified_expression>,Old=<>}>,
5619 rhs="@Chg{Version=[3],New=[@key[for] @Syn2{quantifier} @Syn2{loop_parameter_specification} => @Syn2{predicate}
5620 | @key[for] @Syn2{quantifier} @Syn2{iterator_specification} => @Syn2{predicate}],Old=<>}"}
5621
5622 @ChgRef{Version=[3],Kind=[AddedNormal]}
5623 @AddedSyn{Version=[3],lhs=<@Chg{Version=[3],New=<quantifier>,Old=<>}>,
5624 rhs="@Chg{Version=[3],New=<@key[all] | @key[some]>,Old=<>}"}
5625
5626 @ChgRef{Version=[3],Kind=[AddedNormal]}
5627 @AddedSyn{Version=[3],lhs=<@Chg{Version=[3],New=<predicate>,Old=<>}>,
5628 rhs="@Chg{Version=[3],New=<@SynI<boolean_>@Syn2{expression}>,Old=<>}"}
5629
5630 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0176-1]}
5631 @ChgAdded{Version=[3],Text=[Wherever the Syntax Rules allow an @nt{expression}, a
5632 @nt{quantified_expression} may be used in place of the @nt{expression}, so
5633 long as it is immediately surrounded by parentheses.]}
5634
5635 @begin{Discussion}
5636 @ChgRef{Version=[3],Kind=[AddedNormal]}
5637 @ChgAdded{Version=[3],Text=[The syntactic category @nt{quantified_expression}
5638 appears only as a @nt{primary} that is parenthesized. The above rule allows it to additionally
5639 be used in other contexts where it would be directly surrounded by
5640 parentheses. This is the same rule that is used for @nt{conditional_expression}s;
5641 see @RefSecNum{Conditional Expressions} for a detailed discussion of the
5642 meaning and effects of this rule.]}
5643 @end{Discussion}
5644 @end{Syntax}
5645
5646 @begin{Resolution}
5647 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0176-1]}
5648 @ChgAdded{Version=[3],Text=[@PDefn2{Term=[expected type],Sec=[quantified_expression]}
5649 The expected type of a @nt{quantified_expression} is
5650 any Boolean type. The @nt{predicate} in a @nt{quantified_expression} is
5651 expected to be of the same type.@Defn{quantified expressions}]}
5652 @end{Resolution}
5653
5654 @begin{Runtime}
5655
5656 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0176-1]}
5657 @ChgRef{Version=[4],Kind=[Revised],ARef=[AI12-0158-1]}
5658 @ChgAdded{Version=[3],Text=[For the evaluation of a @nt{quantified_expression},
5659 the @nt{loop_parameter_specification} or @nt{iterator_specification} is first elaborated. The evaluation of a
5660 @nt{quantified_expression} then evaluates the @nt{predicate} for
5661 @Chg{Version=[4],New=[the values],Old=[each value]} of the loop
5662 parameter@Chg{Version=[4],New=[],Old=[. These values are examined]} in the
5663 order specified by the
5664 @nt{loop_parameter_specification} (see @RefSecNum{Loop Statements}) or
5665 @nt{iterator_specification} (see @RefSecNum{Generalized Loop Iteration}).@PDefn2{Term=[evaluation],Sec=[quantified_expression]}]}
5666
5667 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0176-1]}
5668 @ChgAdded{Version=[3],Type=[Leading],Text=[The value of the
5669 @nt{quantified_expression} is determined as follows:]}
5670
5671 @begin{Itemize}
5672 @ChgRef{Version=[3],Kind=[AddedNormal]}
5673 @ChgRef{Version=[4],Kind=[Revised],ARef=[AI12-0158-1]}
5674 @ChgAdded{Version=[3],Text=[If the @nt{quantifier} is @key[all], the
5675 expression is @Chg{Version=[4],New=[False],Old=[True]} if the evaluation
5676 of @Chg{Version=[4],New=[any],Old=[the]} @nt{predicate} yields
5677 @Chg{Version=[4],New=[False; evaluation of the
5678 @nt{quantified_expression} stops at that point. Otherwise (every
5679 predicate has been evaluated and yielded True), the expression is
5680 True],Old=[True for
5681 each value of the loop parameter. It is False otherwise. Evaluation of
5682 the @nt{quantified_expression} stops when all values of the domain have been
5683 examined, or when the @nt{predicate} yields False for a given value]}. Any
5684 exception raised by evaluation of the @nt{predicate} is propagated.]}
5685
5686 @begin{Ramification}
5687 @ChgRef{Version=[3],Kind=[AddedNormal]}
5688 @ChgAdded{Version=[3],Text=[The @nt{expression} is True if the domain
5689 contains no values.]}
5690 @end{Ramification}
5691
5692 @ChgRef{Version=[3],Kind=[AddedNormal]}
5693 @ChgRef{Version=[4],Kind=[Revised],ARef=[AI12-0158-1]}
5694 @ChgAdded{Version=[3],Text=[If the @nt{quantifier} is @key[some], the
5695 expression is True if the evaluation of
5696 @Chg{Version=[4],New=[any],Old=[the]} @nt{predicate} yields
5697 True@Chg{Version=[4],New=[; evaluation of the
5698 @nt{quantified_expression} stops at that point. Otherwise (every
5699 predicate has been evaluated and yielded False), the expression is
5700 False],Old=[ for
5701 some value of the loop parameter. It is False otherwise. Evaluation of
5702 the @nt{quantified_expression} stops when all values of the domain have been
5703 examined, or when the @nt{predicate} yields True for a given value]}. Any
5704 exception raised by evaluation of the @nt{predicate} is propagated.]}
5705
5706 @begin{Ramification}
5707 @ChgRef{Version=[3],Kind=[AddedNormal]}
5708 @ChgAdded{Version=[3],Text=[The @nt{expression} is False if the domain
5709 contains no values.]}
5710 @end{Ramification}
5711 @end{Itemize}
5712 @end{Runtime}
5713
5714 @begin{Examples}
5715
5716 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0176-1]}
5717 @ChgAdded{Version=[3],Type=[Leading],Text=[The postcondition for a sorting
5718 routine on an array A with an index subtype T can be written:]}
5719
5720 @begin{Example}
5721 @ChgRef{Version=[3],Kind=[AddedNormal]}
5722 @ChgAdded{Version=[3],Text=[Post => (A'Length < 2 @key[or else]
5723 (@key[for all] I @key[in] A'First .. T'Pred(A'Last) => A (I) <= A (T'Succ (I))))]}
5724 @end{Example}
5725
5726 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0176-1]}
5727 @ChgAdded{Version=[3],Type=[Leading],Text=[The assertion that a positive number
5728 is composite (as opposed to prime) can be written:]}
5729
5730 @begin{Example}
5731 @ChgRef{Version=[3],Kind=[AddedNormal]}
5732 @ChgAdded{Version=[3],Text=[@key[pragma] Assert (@key[for some] X @key[in] 2 .. N / 2 => N @key[mod] X = 0);]}
5733 @end{Example}
5734
5735 @end{Examples}
5736
5737 @begin{Extend2005}
5738 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0176-1]}
5739 @ChgAdded{Version=[3],Text=[@Defn{extensions to Ada 2005}Quantified
5740 expressions are new.]}
5741 @end{Extend2005}
5742
5743 @begin{DiffWord2012}
5744 @ChgRef{Version=[4],Kind=[AddedNormal],ARef=[AI12-0158-1]}
5745 @ChgAdded{Version=[4],Text=[@b<Corrigendum:> Revised the wording to make it
5746 clear that the semantics is short-circuited, and what the result is when
5747 there are no values for the loop parameter.]}
5748 @end{DiffWord2012}