Debian Codegraph @

source_2020/03a.mss

raw
1 @Part(03, Root="ada.mss")
2
3 @Comment{$Date: 2020/06/03 00:09:00 $}
4 @LabeledSection{Declarations and Types}
5
6 @Comment{$Source: e:\\cvsroot/ARM/Source/03a.mss,v $}
7 @Comment{$Revision: 1.146 $}
8
9 @begin{Intro}
10 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0299-1]}
11 This @Chg{Version=[3],New=[clause],Old=[section]} describes the types
12 in the language and the rules for declaring constants, variables, and
13 named numbers.
14 @end{Intro}
15
16 @LabeledClause{Declarations}
17
18 @begin{Intro}
19 @ChgRef{Version=[5],Kind=[Revised],ARef=[AI12-0373-1]}
20 @PDefn{entity}
21 The language defines
22 several kinds of named @i(entities) that are declared
23 by declarations.
24 @PDefn{name}
25 The entity's @i(name)
26 is defined by the declaration, usually by a
27 @nt<defining_@!identifier>,
28 but sometimes by a @nt{defining_@!character_@!literal}
29 or @nt{defining_@!operator_@!symbol}.@Chg{Version=[5],New=[
30 There are also entities that are not directly declared; some
31 of these are elements of other entities, or are
32 allocated dynamically. Such entities can be denoted using
33 @nt{indexed_component}, @nt{selected_component}, or dereference @nt{name}s
34 (see @RefSecNum{Names}).],Old=[]}
35
36 @begin{Discussion}
37 @ChgRef{Version=[5],Kind=[AddedNormal],ARef=[AI12-0373-1]}
38 @ChgAdded{Version=[5],Text=[Some entities are always anonymous. For instance,
39 a type is never named (the name represents the first subtype).
40 We don't mention those here as this paragraph is about @i{named} entities.]}
41 @end{Discussion}
42
43 There are several forms of declaration. A @nt<basic_declaration>
44 is a form of declaration defined as follows.
45 @end{Intro}
46
47 @begin{Syntax}
48 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00348-01]}
49 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0177-1]}
50 @Syn{tabs=[P27], lhs=<basic_declaration>,rhs="
51 @Syn2{type_declaration}@\| @Syn2{subtype_declaration}
52 | @Syn2{object_declaration}@\| @Syn2{number_declaration}
53 | @Syn2{subprogram_declaration}@\| @Syn2{abstract_subprogram_declaration}
54 | @Chg{Version=[2],New=[@Syn2{null_procedure_declaration}@\| @Chg{Version=<3>,New=<@Syn2{expression_function_declaration}
55 | >,Old=<>}],Old=[]}@Syn2{package_declaration}@Chg{Version=[2],New=[@Chg{Version=[3],New=[@\|],Old=[
56 |]}],Old=[@\|]} @Syn2{renaming_declaration}@Chg{Version=[2],New=[@Chg{Version=[3],New=[
57 | ],Old=[@\|]}],Old=[
58 | ]}@Syn2{exception_declaration}@Chg{Version=[2],New=[@Chg{Version=[3],New=[@\|],Old=[
59 |]}],Old=[@\|]} @Syn2{generic_declaration}@Chg{Version=[2],New=[@Chg{Version=[3],New=[
60 | ],Old=[@\|]}],Old=[
61 | ]}@Syn2{generic_instantiation}"}
62
63 @Syn{lhs=<defining_identifier>,rhs="@Syn2{identifier}"}
64 @end{Syntax}
65
66 @begin{StaticSem}
67 @ToGlossaryAlso{Term=<Declaration>,
68 Text=<A @i(declaration) is a language construct that associates a name
69 with (a view of) an entity.
70 @Defn(explicit declaration)
71 @Defn(implicit declaration)
72 A declaration may appear explicitly in the program
73 text (an @i(explicit) declaration), or may be supposed to
74 occur at a given place in the text as a
75 consequence of the semantics of another construct (an @i(implicit)
76 declaration).>}
77 @begin{Discussion}
78 An implicit declaration generally declares
79 a predefined or inherited operation associated with the definition
80 of a type. This term is
81 used primarily when allowing explicit declarations to override
82 implicit declarations, as part of a type declaration.
83 @end{Discussion}
84
85 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00318-02]}
86 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0255-1],ARef=[AI05-0277-1]}
87 @ChgRef{Version=[5],Kind=[Revised],ARef=[AI12-0061-1],ARef=[AI12-0308-1]}
88 @Defn{declaration}
89 Each of the following is defined to be a declaration:
90 any @nt{basic_@!declaration};
91 an @nt{enumeration_@!literal_@!specification};
92 a @nt{discriminant_@!specification};
93 a @nt{component_@!declaration};@Chg{Version=[5],New=[
94 a @nt{defining_identifier} of an @nt{iterated_@!component_@!association};],Old=[]}
95 a @nt{loop_@!parameter_@!specification};@Chg{Version=[5],New=[
96 a @nt{defining_identifier} of a @nt{chunk_@!specification};],Old=[]}@Chg{Version=[3],New=[
97 an @nt{iterator_@!specification};],Old=[]}@Chg{Version=[5],New=[
98 a @nt{defining_identifier} of an @nt{iterator_@!parameter_@!specification};],Old=[]}
99 a @nt{parameter_@!specification};
100 a @nt{subprogram_@!body};@Chg{Version=[3],New=[
101 an @nt{extended_@!return_@!object_@!declaration};],Old=[]}
102 an @nt{entry_@!declaration};
103 an @nt{entry_@!index_@!specification};
104 a @nt{choice_@!parameter_@!specification};
105 a @nt{generic_@!formal_@!parameter_@!declaration}.@Chg{Version=[3],New=[],Old=[@Chg{Version=[2],New=[
106 In addition, an @nt{extended_return_statement} is a declaration of its
107 @nt{defining_identifier}.],Old=[]}]}
108 @begin(Discussion)
109 This list (when @nt<basic_declaration> is expanded out)
110 contains all syntactic categories that end in "_declaration"
111 or "_specification", except for program unit _specifications.
112 Moreover, it contains @nt{subprogram_body}.
113 A @nt{subprogram_body} is a declaration,
114 whether or not it completes a previous declaration.
115 This is a bit strange, @nt{subprogram_body} is not part of the syntax
116 of @nt{basic_declaration} or @nt{library_unit_declaration}.
117 A renaming-as-body is considered a declaration.
118 An @nt{accept_statement} is not considered a declaration.
119 Completions are sometimes declarations, and sometimes not.
120 @end(Discussion)
121
122 @Defn(view)@Defn(definition)
123 All declarations contain a @i(definition) for a @i(view) of an entity.
124 A view consists of an identification of the entity
125 (the entity @i(of) the view),
126 plus view-specific characteristics that affect the use
127 of the entity through that view (such as mode of access to an object,
128 formal parameter names and defaults for a subprogram, or visibility to
129 components of a type).
130 In most cases, a declaration also contains the definition for the
131 entity itself (a @nt(renaming_declaration) is an example of a declaration
132 that does not define a new entity,
133 but instead defines a view of an existing entity
134 (see @RefSecNum(Renaming Declarations))).
135
136 @ChgToGlossary{Version=[2],Kind=[Revised],Term=<View>,
137 Text=<@Chg{Version=[2],New=[A view of an entity reveals some or all of the
138 properties of the entity. A single entity may have multiple views.],
139 Old=[(See @b[Definition].)]}>}
140 @begin{Discussion}
141 Most declarations define a view (of some entity) whose
142 view-specific characteristics are unchanging for the
143 life of the view. However, subtypes are somewhat unusual
144 in that they inherit characteristics from whatever view
145 of their type is currently visible. Hence, a subtype is not a
146 @i(view) of a type; it is more of an indirect reference.
147 By contrast, a private type provides a single, unchanging (partial)
148 view of its full type.
149 @end{Discussion}
150
151 @ChgToGlossary{Version=[2],Kind=[Deleted],Term=<Definition>,
152 Text=<@ChgDeleted{Version=[2],Text=[@Defn(view)
153 All declarations contain a @i(definition) for a @i(view) of an entity.
154 A view consists of an identification of the entity
155 (the entity @i(of) the view),
156 plus view-specific characteristics that affect the use
157 of the entity through that view (such as mode of access to an object,
158 formal parameter names and defaults for a subprogram, or visibility to
159 components of a type).
160 In most cases, a declaration also contains the definition for the
161 entity itself (a @nt(renaming_declaration) is an example of a declaration
162 that does not define a new entity,
163 but instead defines a view of an existing entity
164 (see @RefSecNum(Renaming Declarations))).]}>}
165
166 @ChgRef{Version=[3],Kind=[Added],ARef=[AI05-0080-1]}
167 @ChgAdded{Version=[3],Text=[When it is clear from context, the term @i<object>
168 is used in place of @i<view of an object>. Similarly, the terms @i<type> and
169 @i<subtype> are used in place of @i<view of a type> and @i<view of a subtype>,
170 respectively.@Defn2{Term=[view],Sec=[of an object (implied)]}@Defn2{Term=[view],
171 Sec=[of a type (implied)]}@Defn2{Term=[view],Sec=[of a subtype (implied)]}]}
172
173 @begin{Discussion}
174 @ChgRef{Version=[3],Kind=[AddedNormal]}
175 @ChgAdded{Version=[3],Text=[Rules interpreted at compile time generally
176 refer to views of entities, rather than the entities themselves. This is
177 necessary to preserve privacy; characteristics that are not visible should
178 not be used in compile-time rules. Thus, @StaticSemTitle and
179 @LegalityTitle generally implicitly have @ldquote@;view of@rdquote.
180 @LegalityTitle that need to look into the private part
181 are the exception to this interpretation.]}
182
183 @ChgRef{Version=[3],Kind=[AddedNormal]}
184 @ChgAdded{Version=[3],Text=[On the other hand, run-time rules can work
185 either way, so @ldquote@;view of@rdquote should not be assumed
186 in @RunTimeTitle rules.]}
187
188 @ChgRef{Version=[5],Kind=[AddedNormal],ARef=[AI12-0191-1]}
189 @ChgAdded{Version=[5],Text=[For example, a reference to the components of
190 an object in a rule that is interpreted at compile-time would not apply to
191 components that are not visible. On the other hand, a reference
192 to the components of an object in a dynamic semantics rule would
193 apply to all components of the object, visible or not, including
194 (for tagged objects) components which are not components of the nominal
195 type of the object (see @RefSecNum{Type Extensions}). Other terms, such
196 as @ldquote@;subcomponent@rdquote and @ldquote@;part@rdquote, are
197 interpreted analogously.]}
198 @end{Discussion}
199
200 @PDefn2{Term=[scope], Sec=(informal definition)}
201 For each declaration, the language rules define a certain
202 region of text called the @i(scope) of the declaration
203 (see @RefSecNum(Scope of Declarations)). Most declarations
204 associate an @nt<identifier>
205 with a declared entity. Within its scope,
206 and only there, there are places where it is possible to use the
207 @nt<identifier> to refer to the declaration, the view it defines,
208 and the associated entity; these places are defined by
209 the visibility rules (see @RefSecNum(Visibility)).
210 @Defn2{Term=[name], Sec={of (a view of) an entity}}
211 At such places
212 the @nt<identifier> is said to be a @i(name) of the entity (the
213 @nt<direct_name> or @nt<selector_name>);
214 @PDefn2{Term=[denote], Sec={informal definition}}
215 the name is said to @i(denote) the declaration,
216 the view, and the associated entity
217 (see @RefSecNum{The Context of Overload Resolution}).
218 @Defn{declare}
219 The declaration is said
220 to @i(declare) the name, the view, and in most cases, the
221 entity itself.
222
223 As an alternative to an @nt<identifier>,
224 an enumeration literal can be declared with a @nt<character_literal>
225 as its name (see @RefSecNum(Enumeration Types)),
226 and a function can be declared with an @nt<operator_symbol>
227 as its name (see @RefSecNum(Subprogram Declarations)).
228
229 @Defn{defining name}
230 The syntax rules use the terms @nt<defining_identifier>,
231 @nt<defining_@!character_@!literal>, and @nt<defining_@!operator_@!symbol>
232 for the defining occurrence of a name; these are collectively
233 called @i(defining names).
234 @Defn{usage name}
235 The terms @nt<direct_name> and
236 @nt<selector_name> are used for usage occurrences of @nt<identifier>s,
237 @nt<character_literal>s, and @nt<operator_symbol>s. These
238 are collectively called @i(usage names).
239 @begin(Honest)
240 The terms @nt<identifier>,
241 @nt<character_literal>, and @nt<operator_symbol> are used directly
242 in contexts where the normal visibility rules do not
243 apply (such as the @nt<identifier> that appears after the @key(end) of
244 a @nt<task_body>). Analogous conventions apply to the use of @nt<designator>,
245 which is the collective term for @nt<identifier> and @nt<operator_symbol>.
246 @end(Honest)
247
248 @end{StaticSem}
249
250 @begin{RunTime}
251 @RootDefn{execution}
252 The process by which a construct achieves its run-time effect is
253 called @i(execution).
254 @RootDefn{elaboration}
255 @RootDefn{evaluation}
256 This process is also called @i(elaboration) for declarations
257 and @i(evaluation) for expressions.
258 One of the terms execution, elaboration, or evaluation is defined
259 by this International Standard for each construct that has a run-time effect.
260 @ToGlossary{Term=<Execution>,
261 Text=<The process by which a construct achieves its run-time effect is
262 called @i(execution).
263 @Defn(elaboration)
264 @Defn(evaluation)
265 Execution of a declaration is also called @i(elaboration).
266 Execution of an expression is also called @i(evaluation).>}
267 @begin{Honest}
268 The term elaboration is also used for the execution of certain
269 constructs that are not declarations,
270 and the term evaluation is used for the execution of certain
271 constructs that are not expressions.
272 For example, @nt{subtype_indication}s are elaborated,
273 and @nt{range}s are evaluated.
274
275 For bodies, execution and elaboration are both explicitly defined.
276 When we refer specifically to the execution of a body,
277 we mean the explicit definition of execution for that kind of body,
278 not its elaboration.
279 @end{Honest}
280 @begin(Discussion)
281 Technically, "the execution of a declaration" and "the
282 elaboration of a declaration" are synonymous.
283 We use the term "elaboration" of a construct when we know the
284 construct is elaborable.
285 When we are talking about more arbitrary constructs,
286 we use the term "execution".
287 For example, we use the term "erroneous execution",
288 to refer to any erroneous execution, including
289 erroneous elaboration or evaluation.
290
291 When we explicitly define evaluation or elaboration for a construct,
292 we are implicitly defining execution of that construct.
293
294 We also use the term "execution" for things like @nt{statement}s,
295 which are executable, but neither elaborable nor evaluable.
296 We considered using the term "execution" only for nonelaborable,
297 nonevaluable constructs, and defining the term "action" to mean what
298 we have defined "execution" to mean.
299 We rejected this idea because we thought three terms that mean the
300 same thing was enough @em four would be overkill.
301 Thus, the term "action" is used only informally in the standard
302 (except where it is defined as part of a larger term,
303 such as "protected action").
304 @end(Discussion)
305 @ChgToGlossary{Version=[2],Kind=[Added],Term=<Elaboration>,
306 Text=<@ChgAdded{Version=[2],Text=[The process by which a declaration achieves
307 its run-time effect is called elaboration. Elaboration is one of the forms of
308 execution.]}>}
309 @ChgToGlossary{Version=[2],Kind=[Added],Term=<Evaluation>,
310 Text=<@ChgAdded{Version=[2],Text=[The process by which an expression achieves
311 its run-time effect is called evaluation. Evaluation is one of the forms of
312 execution.]}>}
313 @begin{Honest}
314 @Defn{elaborable}
315 A construct is @i(elaborable) if elaboration is defined for it.
316 @Defn{evaluable}
317 A construct is @i(evaluable) if evaluation is defined for it.
318 @Defn{executable}
319 A construct is @i(executable) if execution is defined for it.
320 @end{Honest}
321 @begin(Discussion)
322 Don't confuse @lquotes@;elaborable@rquotes@; with @lquotes@;preelaborable@rquotes@; (defined
323 in @RefSecNum(Elaboration Control)).
324
325 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00114-01]}
326 Evaluation of an evaluable construct produces a result that is
327 either a value, a denotation, or a range.
328 The following are evaluable:
329 expression; @nt{name}
330 @nt{prefix}; @nt{range};
331 @Chg{Version=[2],New=[@nt{entry_index_specification}],Old=[@ntf{entry_list_iterator}]};
332 and possibly @nt{discrete_range}.
333 The last one is curious @em RM83 uses the term @lquotes@;evaluation of a
334 @nt{discrete_range},@rquotes@; but never defines it.
335 One might presume that the evaluation of a @nt{discrete_range}
336 consists of the evaluation of the @nt{range} or the
337 @nt{subtype_indication}, depending on what it is.
338 But @nt{subtype_indication}s are not evaluated; they are elaborated.
339
340 Intuitively, an @i(executable) construct is one that has
341 a defined run-time effect (which may be null). Since execution
342 includes elaboration and evaluation as special cases, all
343 elaborable and all evaluable constructs
344 are also executable. Hence, most constructs in Ada are executable.
345 An important exception is that the constructs inside a generic unit are
346 not executable directly, but rather are used as a template for
347 (generally) executable constructs in instances of the generic.
348 @end(Discussion)
349 @end{RunTime}
350
351 @begin{Notes}
352 @Defn{declare}
353 At compile time, the declaration of an entity @i(declares) the entity.
354 @Defn{create}
355 At run time, the elaboration of the declaration @i(creates) the entity.
356 @begin{Ramification}
357 Syntactic categories for declarations are named either
358 @i(entity_)@ntf<declaration> (if they include a trailing semicolon)
359 or @i(entity_)@ntf<specification> (if not).
360
361 @Defn{entity}
362 The various kinds of named entities that can be declared are as
363 follows: an object (including components and parameters), a named number,
364 a type (the name always refers to its first subtype), a subtype,
365 a subprogram (including enumeration literals and operators), a single entry,
366 an entry family, a package, a protected or task unit (which corresponds
367 to either a type or a single object), an exception,
368 a generic unit, a label,
369 and the name of a statement.
370
371 Identifiers are also associated with names of pragmas, arguments to
372 pragmas, and with attributes, but these are not user-definable.
373 @end{Ramification}
374 @end{Notes}
375
376 @begin{DiffWord83}
377 The syntax rule for @nt{defining_identifier} is new.
378 It is used for the defining occurrence of an @nt{identifier}.
379 Usage occurrences use the @nt{direct_name} or @nt{selector_name}
380 syntactic categories.
381 @Leading@;Each occurrence of an @nt{identifier} (or @ntf{simple_name}), @nt{character_literal}, or
382 @nt{operator_symbol} in the Ada 83 syntax rules is handled as follows in Ada
383 95:
384 @begin{itemize}
385 It becomes a @nt{defining_identifier}, @nt{defining_character_literal}, or
386 @nt{defining_operator_symbol} (or some syntactic category composed of these),
387 to indicate a defining occurrence;
388
389 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0299-1]}
390 It becomes a @nt{direct_name}, in usage occurrences where
391 the usage is required (in @Chg{Version=[3],New=[Clause],Old=[Section]}
392 @RefSecNum{Visibility Rules}) to be directly visible;
393
394 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0299-1]}
395 It becomes a @nt{selector_name}, in usage occurrences
396 where the usage is required (in
397 @Chg{Version=[3],New=[Clause],Old=[Section]} @RefSecNum{Visibility Rules})
398 to be visible but not necessarily directly visible;
399
400 It remains an @nt{identifier}, @nt{character_literal}, or @nt{operator_symbol},
401 in cases where the visibility rules do not apply
402 (such as the @nt{designator} that appears after the
403 @key{end} of a @nt{subprogram_body}).
404 @end{itemize}
405
406 For declarations that come in @lquotes@;two parts@rquotes@;
407 (program unit declaration plus body, private or
408 incomplete type plus full type, deferred constant plus full constant),
409 we consider both to be defining occurrences.
410 Thus, for example, the syntax for @nt{package_body} uses
411 @nt{defining_identifier} after the reserved word @key{body},
412 as opposed to @nt{direct_name}.
413
414 The defining occurrence of a statement name is in
415 its implicit declaration, not where it appears in the program text.
416 Considering the statement name itself to be the defining occurrence would
417 complicate the visibility rules.
418
419 The phrase @lquotes@;visible by selection@rquotes@;
420 is not used in Ada 95. It is subsumed by simply @lquotes@;visible@rquotes@; and
421 the Name Resolution Rules for @nt<selector_name>s.
422
423 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0299-1]}
424 (Note that in Ada 95, a declaration is visible at all
425 places where one could have used a @nt{selector_name},
426 not just at places where a @nt{selector_name} was actually used.
427 Thus, the places where a declaration is directly visible are a
428 subset of the places where it is visible.
429 See @Chg{Version=[3],New=[Clause],Old=[Section]}
430 @RefSecNum{Visibility Rules} for details.)
431
432 We use the term @lquotes@;declaration@rquotes@; to cover @ntf<_specification>s that declare
433 (views of) objects, such as @nt<parameter_specification>s. In Ada 83,
434 these are referred to as a @lquotes@;form of declaration,@rquotes@; but it is not
435 entirely clear that they are considered simply @lquotes@;declarations.@rquotes@;
436
437 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0299-1]}
438 RM83 contains an incomplete definition of "elaborated" in this
439 @Chg{Version=[3],New=[subclause],Old=[clause]}:
440 it defines "elaborated" for declarations,
441 @nt{declarative_part}s, @nt{declarative_item}s
442 and @nt{compilation_unit}s,
443 but "elaboration" is defined elsewhere for various other constructs.
444 To make matters worse, Ada 95 has a different set of elaborable
445 constructs.
446 Instead of correcting the list, it is more maintainable to
447 refer to the term "elaborable," which is defined in a distributed
448 manner.
449
450 RM83 uses the term @lquotes@;has no other effect@rquotes@; to describe an elaboration that
451 doesn't do anything except change the state from not-yet-elaborated to
452 elaborated. This was a confusing wording, because the answer to @lquotes@;other than
453 what?@rquotes@; was to be found many pages away.
454 In Ada 95, we change this wording to @lquotes@;has no effect@rquotes@; (for things that truly
455 do nothing at run time), and @lquotes@;has no effect other than to establish that
456 so-and-so can happen without failing the
457 Elaboration_Check@rquotes@; (for things where it matters).
458
459 We make it clearer that the term "execution" covers elaboration and
460 evaluation as special cases.
461 This was implied in RM83.
462 For example, "erroneous execution" can include any execution,
463 and RM83-9.4(3) has,
464 "The task designated by any other task object depends on the master
465 whose execution creates the task object;"
466 the elaboration of the master's @nt{declarative_part} is doing
467 the task creation.
468 @end{DiffWord83}
469
470 @begin{DiffWord95}
471 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00318-02]}
472 @ChgAdded{Version=[2],Text=[Added @nt{extended_return_statement} to
473 the list of declarations.]}
474
475 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00348-01]}
476 @ChgAdded{Version=[2],Text=[Added null procedures
477 (see @RefSecNum{Null Procedures}) to the syntax.]}
478 @end{DiffWord95}
479
480 @begin{DiffWord2005}
481 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0177-1]}
482 @ChgAdded{Version=[3],Text=[Added expression functions
483 (see @RefSecNum{Expression Functions}) to the syntax.]}
484 @end{DiffWord2005}
485
486
487
488 @LabeledClause{Types and Subtypes}
489
490 @begin{StaticSem}
491 @Defn{type}
492 @PDefn{primitive operation}
493 A @i(type) is characterized by a set of values,
494 and a set of @i(primitive operations)
495 which implement the fundamental aspects of its semantics.
496 @PDefn{object}
497 An @i(object) of a given type is a run-time entity that contains (has)
498 a value of the type.
499 @ChgToGlossary{Version=[2],Kind=[Revised],Term=<Type>,
500 Text=<Each object has a type.
501 A @i(type) has an associated set of values, and a set of @i(primitive
502 operations) which implement the fundamental aspects of its semantics.
503 Types are grouped into @Chg{Version=[2],New=[@i(categories)],
504 Old=[@i(classes)]}.
505 @Chg{Version=[2],New=[Most language-defined
506 categories of types are also @i<classes> of types],Old=[The types of a
507 given class share a set of primitive operations.
508 @Defn(closed under derivation) Classes are closed under derivation;
509 that is, if a type is in a class, then all of its derivatives
510 are in that class]}.>}
511 @ChgToGlossary{Version=[3],Kind=[Revised],Term=<Subtype>,
512 Text=<A subtype is a type together with @Chg{Version=[3],New=[optional
513 constraints, null exclusions, and predicates],
514 Old=[a constraint@Chg{Version=[2],New=[ or null exclusion],Old=[]}]},
515 which @Chg{Version=[3],New=[constrain],Old=[constrains]}
516 the values of the subtype to satisfy @Chg{Version=[3],New=[],Old=[a ]}certain
517 @Chg{Version=[3],New=[conditions],Old=[condition]}. The values of a subtype
518 are a subset of the values of its type.>}
519
520 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00442-01]}
521 @Chg{Version=[2],New=[@Defn2{Term=[category], Sec=(of types)}],
522 Old=[]}@Defn2{Term=[class], Sec=(of types)}
523 Types are grouped into @Chg{Version=[2],New=[@i(categories)],
524 Old=[@i(classes)]} of types@Chg{Version=[2],New=[],Old=[, reflecting the
525 similarity of their values and primitive operations]}.
526 @Defn2{Term=[language-defined class], Sec=(of types)}
527 There exist several @i(language-defined @Chg{Version=[2],New=[categories],
528 Old=[classes]}) of types (see NOTES below)@Chg{Version=[2],New=[, reflecting
529 the similarity of their values and primitive operations],Old=[]}.@Chg{Version=[2],
530 New=[@Defn2{Term=[language-defined category], Sec=(of types)} @Redundant[Most
531 categories of types form @i(classes) of types.]],Old=[]}
532 @Defn{elementary type}
533 @i(Elementary) types are those whose values are logically indivisible;
534 @Defn{composite type}
535 @Defn{component}
536 @i(composite) types are those whose values are composed
537 of @i(component) values.
538 @IndexSeeAlso{Term={aggregate},See=(composite type)}
539 @begin{TheProof}
540 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00442-01]}
541 @ChgAdded{Version=[2],Text=[The formal definition of @i<category> and
542 @i<class> is found in @RefSecNum{Derived Types and Classes}.]}
543 @end{TheProof}
544 @ChgNote<The following ought to have the Term be:
545 Class@Chg{Version=[2],New=[ (of types)],Old=[]}
546 but that doesn't index properly and it is too much work to fix. See if
547 anyone complains.>
548 @ChgToGlossary{Version=[2],Kind=[Revised],Term=<Class (of types)>,
549 Text=<@Defn(closed under derivation)
550 A class is a set of types that is
551 closed under derivation,
552 which means that if a given type is in the class,
553 then all types derived from that type are also in the class.
554 The set of types of a class share common properties,
555 such as their primitive operations.>}
556 @ChgToGlossary{Version=[2],Kind=[Added],Term=<Category (of types)>,
557 Text=<@ChgAdded{Version=[2],Text=[A category of types is a set of types with
558 one or more common properties, such as primitive operations. A
559 category of types that is closed under derivation is also known as
560 a @i<class>.]}>}
561 @ToGlossary{Term=<Elementary type>,
562 Text=<An elementary type does not have components.>}
563 @ChgToGlossary{Version=[2],Kind=[Revised],Term=<Composite type>,
564 Text=<A composite type @Chg{Version=[2],New=[may have],Old=[has]} components.>}
565 @ToGlossary{Term=<Scalar type>,
566 Text=<A scalar type is either a discrete type or a real type.>}
567 @ToGlossary{Term=<Access type>,
568 Text=<An access type has values that designate aliased
569 objects.
570 Access types correspond to @lquotes@;pointer types@rquotes@;
571 or @lquotes@;reference types@rquotes@; in some other languages.>}
572 @ToGlossary{Term=<Discrete type>,
573 Text=<A discrete type is either an integer type or an enumeration
574 type.
575 Discrete types may be used, for example, in @nt(case_statement)s
576 and as array indices.>}
577 @ToGlossary{Term=<Real type>,
578 Text=<A real type has values that are approximations
579 of the real numbers.
580 Floating point and fixed point types are real types.>}
581 @ToGlossary{Term=<Integer type>,
582 Text=<Integer types comprise the signed integer types
583 and the modular types.
584 A signed integer type has a base range that includes both
585 positive and negative numbers,
586 and has operations that may raise an exception when the result
587 is outside the base range.
588 A modular type has a base range whose lower bound is zero,
589 and has operations with @lquotes@;wraparound@rquotes@; semantics.
590 Modular types subsume what are called @lquotes@;unsigned types@rquotes@;
591 in some other languages.>}
592 @ToGlossary{Term=<Enumeration type>,
593 Text=<An enumeration type is defined by an enumeration of its values,
594 which may be named by identifiers or character
595 literals.>}
596 @ToGlossary{Term=<Character type>,
597 Text=<A character type is an enumeration type whose values
598 include characters.>}
599 @ToGlossary{Term=<Record type>,
600 Text=<A record type is a composite type consisting of zero or more
601 named components, possibly of different types.>}
602 @ToGlossary{Term=<Record extension>,
603 Text=<A record extension is a type that extends another type by adding
604 additional components.>}
605 @ToGlossary{Term=<Array type>,
606 Text=<An array type is a composite type whose components are all of
607 the same type. Components are selected by indexing.>}
608 @ChgToGlossary{Version=[2],Kind=[Revised],Term=<Task type>,
609 Text=<A task type is a composite type @Chg{Version=[2],New=[used to
610 represent], Old=[whose values are tasks, which are]} active entities
611 @Chg{Version=[2],New=[which],Old=[that may]} execute concurrently
612 @Chg{Version=[2],New=[and which can communicate via queued task entries],
613 Old=[with other tasks]}.
614 The top-level task of a partition is called the environment task.>}
615 @ChgToGlossary{Version=[2],Kind=[Revised],Term=<Protected type>,
616 Text=<A protected type is a composite type whose components are
617 @Chg{Version=[2],New=[accessible only
618 through one of its protected operations which synchronize],
619 Old=[protected from]} concurrent access by multiple tasks.>}
620 @ChgToGlossary{Version=[2],Kind=[Revised],Term=<Private type>,
621 Text=<A private type @Chg{Version=[2],New=[gives a],Old=[is a partial]} view
622 of a type @Chg{Version=[2],New=[that reveals only some of its properties.
623 The remaining properties are provided by the],Old=[whose]} full view
624 @Chg{Version=[2],New=[given elsewhere. Private types can be used for
625 defining abstractions that hide unnecessary details],Old=[is hidden]} from
626 @Chg{Version=[2],New=[their],Old=[its]} clients.>}@ChgNote{This was changed
627 to parallel "incomplete type"}
628 @ChgToGlossary{Version=[2],Kind=[Revised],Term=<Private extension>,
629 Text=<A private extension is @Chg{Version=[2],New=[a type that extends
630 another type, with the additional properties],Old=[like a record extension,
631 except that the components of the extension part
632 are]} hidden from its clients.>}
633
634 @ChgToGlossary{Version=[2],Kind=[AddedNormal],Term=<Incomplete type>,
635 Text=<@ChgAdded{Version=[2],Text=[An incomplete type gives a view of a type
636 that reveals only some of its properties. The remaining properties are
637 provided by the full view given elsewhere. Incomplete types can be used
638 for defining recursive data structures.]}>}
639
640 @Defn{scalar type}
641 The elementary types are the @i(scalar) types (@i(discrete) and @i(real))
642 and the @i(access) types (whose values provide access to objects or
643 subprograms).
644 @Defn{discrete type}
645 @Defn{enumeration type}
646 Discrete types are either @i(integer) types or are defined by enumeration
647 of their values (@i(enumeration) types).
648 @Defn{real type}
649 Real types are either @i(floating point) types
650 or @i(fixed point) types.
651
652 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00251-01],ARef=[AI95-00326-01]}
653 The composite types are the @i(record) types, @i(record extensions),
654 @i(array) types, @Chg{Version=[2],New=[@i(interface) types, ],Old=[]}@i(task)
655 types, and @i(protected) types.@Chg{Version=[2], New=[],
656 Old=[@Defn{private type}
657 @Defn{private extension}
658 A @i(private) type or @i(private extension) represents a partial view
659 (see @RefSecNum{Private Types and Private Extensions})
660 of a type, providing support for data abstraction.
661 A partial view is a composite type.]}
662 @begin{Honest}
663 @ChgRef{Version=[2],Kind=[Deleted],ARef=[AI95-00442-01]}
664 @ChgDeleted{Version=[2],Text=[The set of all record types do not form a
665 class (because tagged record types can have private extensions), though
666 the set of untagged record types do.
667 In any case, what record types had in common in Ada 83 (component selection)
668 is now a property of the composite class, since all composite types
669 (other than array types) can have discriminants.
670 Similarly, the set of all private types do not form a class (because
671 tagged private types can have record extensions), though
672 the set of untagged private types do.
673 Nevertheless, the set of untagged private types is not particularly
674 @lquotes@;interesting@rquotes@; @em more interesting is the set of
675 all nonlimited
676 types, since that is what a generic formal (nonlimited) private
677 type matches.]}
678 @end{Honest}
679
680 @ChgRef{Version=[2],Kind=[Added],ARef=[AI95-00326-01]}
681 @ChgAdded{Version=[2],Text=[@Defn{incomplete type}
682 @Defn{private type}
683 @Defn{private extension}
684 There can be multiple views of a type with varying
685 sets of operations. @Redundant[An @i(incomplete) type represents an incomplete
686 view (see @RefSecNum{Incomplete Type Declarations}) of a type with a
687 very restricted usage, providing support for recursive data structures. A
688 @i(private) type or @i(private extension) represents a partial view
689 (see @RefSecNum{Private Types and Private Extensions}) of a
690 type, providing support for data abstraction. The full view
691 (see @RefSecNum{Type Declarations}) of a
692 type represents its complete definition.] An incomplete or partial view is
693 considered a composite type@Redundant[, even if the full view is not].]}
694 @begin{TheProof}
695 @ChgRef{Version=[2],Kind=[AddedNormal]}
696 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0299-1]}
697 @ChgAdded{Version=[2],Text=[The real definitions of the views are in the
698 referenced @Chg{Version=[3],New=[subclauses],Old=[clauses]}.]}
699 @end{TheProof}
700
701 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00326-01]}
702 @Defn{discriminant}
703 Certain composite types (and@Chg{Version=[2],New=[],Old=[ partial]} views
704 thereof) have special
705 components called @i(discriminants) whose values affect the
706 presence, constraints, or initialization of other components.
707 Discriminants can be thought of as parameters of the type.
708
709 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00366-01]}
710 @Defn{subcomponent}
711 The term @i(subcomponent) is used
712 in this International Standard in place of the term component
713 to indicate either a component, or a component of another
714 subcomponent. Where other subcomponents
715 are excluded, the term component is used instead.
716 @Defn2{Term=[part], Sec=(of an object or value)}
717 Similarly, a @i(part) of an object or value is used to mean
718 the whole object or value, or any set of its subcomponents.@Chg{Version=[2],
719 New=[ The terms component, subcomponent, and part are also applied to a type
720 meaning the component, subcomponent, or part of objects and values of the
721 type.@Defn2{Term=[part], Sec=(of a type)}@Defn2{Term=[component], Sec=(of a type)}],Old=[]}
722 @begin{Discussion}
723 The definition of @lquotes@;part@rquotes@; here is designed to simplify rules
724 elsewhere. By design, the intuitive meaning of
725 @lquotes@;part@rquotes@; will convey the correct result to the casual reader,
726 while this formalistic definition will answer the concern of
727 the compiler-writer.
728
729 We use the term @lquotes@;part@rquotes@; when talking about the parent part,
730 ancestor part, or extension part of a type extension.
731 In contexts such as these, the part might represent an empty
732 set of subcomponents (e.g. in a null record extension, or a
733 nonnull extension of a null record).
734 We also use @lquotes@;part@rquotes@; when specifying rules such as
735 those that apply to an object
736 with a @lquotes@;controlled part@rquotes@; meaning that it applies if the
737 object as a whole is controlled, or any subcomponent is.
738 @end{Discussion}
739
740 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00231-01]}
741 @PDefn{constraint}
742 The set of possible values for an object of a given type can be
743 subjected to a condition that is called a @i(constraint)
744 @Defn{null constraint}@Defn2{Term=[constraint],Sec=[null]}
745 (the case
746 of a @i(null constraint) that specifies no restriction is also
747 included)@Redundant[;
748 the rules for which values satisfy a given kind of constraint
749 are given in @RefSecNum(Scalar Types) for @nt<range_constraint>s,
750 @RefSecNum(Index Constraints and Discrete Ranges)
751 for @nt<index_constraint>s, and
752 @RefSecNum(Discriminant Constraints) for
753 @nt<discriminant_constraint>s].@Chg{Version=[2],New=[ The set of possible values
754 for an object of an access type can also be subjected to a condition that
755 excludes the null value (see @RefSecNum{Access Types}).],Old=[]}
756
757 @begin{Ramification}
758 @ChgRef{Version=[5],Kind=[AddedNormal],ARef=[AI12-0140-1]}
759 @ChgAdded{Version=[5],Text=[@ldquote@;Null constraint@rdquote includes the
760 cases of no explicit constraint, as well as unknown discriminants and
761 unconstrained array type declarations (which are explicit ways to declare
762 no constraint).]}
763 @end{Ramification}
764
765 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00231-01],ARef=[AI95-00415-01]}
766 @Defn{subtype}
767 A @i(subtype) of a given type is a combination of the type,
768 a constraint on values of the type, and certain
769 attributes specific to the subtype.
770 The given type is called the @Chg{Version=[2],New=[@i(type of the subtype)],
771 Old=[type @i(of) the subtype]}.@Chg{Version=[2],New=[@Defn2{Term=[type], Sec=(of a subtype)}
772 @Defn2{Term=[subtype], Sec=(type of)}],Old=[]}
773 Similarly, the associated constraint is
774 called the @Chg{Version=[2],New=[@i(constraint of the subtype)],
775 Old=[constraint @i(of) the subtype]}.@Chg{Version=[2],New=[@Defn2{Term=[constraint], Sec=(of a subtype)}
776 @Defn2{Term=[subtype], Sec=(constraint of)}],Old=[]} The set of
777 values of a subtype consists of the values of its type
778 that satisfy its constraint@Chg{Version=[2],New=[ and any exclusion of the
779 null value],
780 Old=[]}.
781 @Defn2{Term=[belong], Sec=(to a subtype)}
782 Such values @i(belong) to the subtype.@Chg{Version=[2],New=[@Defn2{Term=[values], Sec=(belonging to a subtype)}
783 @Defn2{Term=[subtype], Sec=(values belonging to)}],Old=[]}
784 @begin{Discussion}
785 We make a strong distinction between a type and its
786 subtypes.
787 In particular, a type is @i(not) a subtype of itself.
788 There is no constraint associated with a type (not even a null one),
789 and type-related attributes are distinct from subtype-specific attributes.
790 @end{Discussion}
791 @begin{Discussion}
792 We no longer use the term "base type."
793 All types were "base types" anyway in Ada 83, so the term was redundant,
794 and occasionally confusing. In the RM95 we
795 say simply "the type @i(of) the subtype" instead of "the base type
796 of the subtype."
797 @end{Discussion}
798 @begin{Ramification}
799 The value subset for a subtype might be empty, and need
800 not be a proper subset.
801 @end{Ramification}
802 @begin{Honest}
803 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00442-01]}
804 Any name of a @Chg{Version=[2],New=[category],Old=[class]} of types (such as
805 @lquotes@;discrete@rquotes@;@Chg{Version=[2],New=[, ],Old=[ or]}
806 @lquotes@;real@rquotes@;@Chg{Version=[2],New=[, or],Old=[), or other category of
807 types (such as]} @lquotes@;limited@rquotes@;@Chg{Version=[2],New=[],
808 Old=[ or @lquotes@;incomplete@rquotes@;]})
809 is also used to qualify its subtypes, as well as its objects, values,
810 declarations, and definitions, such as an @lquotes@;integer type
811 declaration@rquotes@; or an @lquotes@;integer value.@rquotes@; In addition, if
812 a term such as @lquotes@;parent subtype@rquotes@; or @lquotes@;index
813 subtype@rquotes@; is defined, then the corresponding term for the type of the
814 subtype is @lquotes@;parent type@rquotes@; or @lquotes@;index type.@rquotes@;
815 @end{Honest}
816 @begin{Discussion}
817 We use these corresponding terms without explicitly defining them,
818 when the meaning is obvious.
819 @end{Discussion}
820
821 @Defn{constrained}
822 @Defn{unconstrained}
823 @Defn2{Term=[constrained], Sec=(subtype)}
824 @Defn2{Term=[unconstrained], Sec=(subtype)}
825 A subtype is called an @i(unconstrained) subtype if its
826 type has unknown discriminants,
827 or if its type allows range, index, or discriminant constraints,
828 but the subtype does not impose such a constraint;
829 otherwise, the subtype is called a @i(constrained) subtype
830 (since it has no unconstrained characteristics).
831 @begin{Discussion}
832 In an earlier version of Ada 9X,
833 "constrained" meant "has a nonnull
834 constraint." However, we changed to this definition
835 since we kept having to special
836 case composite non-array/nondiscriminated types. It also corresponds
837 better to the (now obsolescent) attribute 'Constrained.
838
839 For scalar types, @lquotes@;constrained@rquotes@; means @lquotes@;has a nonnull
840 constraint@rquotes@;.
841 For composite types, in implementation terms, @lquotes@;constrained@rquotes@; means
842 that the size of all objects of the subtype is the same, assuming a
843 typical implementation model.
844
845 Class-wide subtypes are always unconstrained.
846 @end{Discussion}
847 @end{StaticSem}
848
849 @begin{Notes}
850 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00442-01]}
851 @Chg{Version=[2],New=[Any set of types can be called a
852 @lquotes@;category@rquotes@; of types, and any],Old=[Any]}
853 set of types that is closed under derivation
854 (see @RefSecNum(Derived Types and Classes)) can be called
855 a @lquotes@;class@rquotes@; of types. However, only certain
856 @Chg{Version=[2],New=[categories and ],Old=[]}classes are used in the
857 description of the rules of the language @em generally those
858 that have their own particular set of primitive operations
859 (see @RefSecNum(Classification of Operations)), or that
860 correspond to a set of types that are matched by a given
861 kind of generic formal type (see @RefSecNum(Formal Types)).
862 @PDefn{language-defined class}
863 The following are examples of @lquotes@;interesting@rquotes@; @i(language-defined classes):
864 elementary, scalar, discrete, enumeration, character, boolean,
865 integer, signed integer, modular, real, floating point,
866 fixed point, ordinary fixed point, decimal fixed point,
867 numeric, access, access-to-object, access-to-subprogram,
868 composite, array, string, (untagged) record, tagged, task, protected,
869 nonlimited. Special syntax is provided to define types in
870 each of these classes.@Chg{Version=[2],New=[ In addition to these
871 classes, the following are examples of @lquotes@;interesting@rquotes@;
872 @i(language-defined categories): @PDefn{language-defined categories}
873 abstract, incomplete, interface, limited, private, record.],Old=[]}
874 @begin{Discussion}
875 @Defn{value}
876 A @i(value) is a run-time entity with a given type which can be
877 assigned to an object of an appropriate subtype of the type.
878 @Defn{operation}
879 An @i(operation) is a program entity that operates on zero or more
880 operands to produce an effect, or yield a result, or both.
881 @end{Discussion}
882 @begin{Ramification}
883 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00442-01]}
884 Note that a type's @Chg{Version=[2],New=[category (and ],Old=[]}class@Chg{Version=[2],New=[)],Old=[]}
885 depends on the place of the reference @em a
886 private type is composite outside and possibly elementary inside.
887 It's really the @i{view} that is elementary or composite.
888 Note that although private types are composite,
889 there are some properties that
890 depend on the corresponding full view @em for example,
891 parameter passing modes, and
892 the constraint checks that apply in various places.
893
894 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00345-01],ARef=[AI95-00442-01]}
895 @Chg{Version=[2],New=[Every property of types forms a category, but not],
896 Old=[Not]} every property of types represents a class.
897 For example, the set of all abstract types does not form a class,
898 because this set is not closed under derivation.@Chg{Version=[2],New=[
899 Similarly, the set of all interface types does not form a class.],Old=[]}
900
901 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00442-01]}
902 The set of limited types @Chg{Version=[2],New=[does not form a class
903 (since nonlimited types can inherit from limited interfaces), but the
904 set of nonlimited types does. The set of tagged record types and the set
905 of tagged private types do not form a class (because each of them can
906 be extended to create a type of the other category); that implies that
907 the set of record types and the set of private types also do not form a
908 class (even though untagged record types and untagged private types do
909 form a class). In all of these cases, we can talk about the category
910 of the type; for instance, we can talk about the @lquotes@;category
911 of limited types@rquotes.],
912 Old=[forms a class in the sense that it is closed
913 under derivation, but the more interesting
914 class, from the point of generic formal type matching, is the
915 set of all types, limited and nonlimited, since that is what
916 matches a generic formal @lquotes@;limited@rquotes@; private type.
917 Note also that a limited type can @lquotes@;become nonlimited@rquotes@; under
918 certain circumstances, which
919 makes @lquotes@;limited@rquotes@; somewhat problematic as a class of types]}.
920
921 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00442-01]}
922 @ChgAdded{Version=[2],Text=[Normatively, the @i<language-defined classes>
923 are those that are defined to be inherited on derivation by
924 @RefSecNum{Derived Types and Classes}; other properties either aren't
925 interesting or form categories, not classes.]}
926 @end{Ramification}
927
928 @noprefix@;@ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00442-01]}
929 These language-defined @Chg{Version=[2],New=[categories],Old=[classes]} are
930 organized like this:
931 @begin{Display}
932 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00345-01]}
933 @TabClear{}
934 @TabSet{3, 6, 9, 12, 15, 18, 21}
935 all types
936 @\elementary
937 @\@\scalar
938 @\@\@\discrete
939 @\@\@\@\enumeration
940 @\@\@\@\@\character
941 @\@\@\@\@\boolean
942 @\@\@\@\@\other enumeration
943 @\@\@\@\integer
944 @\@\@\@\@\signed integer
945 @\@\@\@\@\modular integer
946 @\@\@\real
947 @\@\@\@\floating point
948 @\@\@\@\fixed point
949 @\@\@\@\@\ordinary fixed point
950 @\@\@\@\@\decimal fixed point
951 @\@\access
952 @\@\@\access-to-object
953 @\@\@\access-to-subprogram
954 @\composite@Chg{Version=[2],New=[
955 @\@\untagged],Old=[]}
956 @Chg{Version=[2],New=[@\],Old=[]}@\@\array
957 @Chg{Version=[2],New=[@\],Old=[]}@\@\@\string
958 @Chg{Version=[2],New=[@\],Old=[]}@\@\@\other array
959 @\@\@Chg{Version=[2],New=[@\],Old=[untagged ]}record@Chg{Version=[2],New=[],Old=[
960 @\@\tagged]}
961 @Chg{Version=[2],New=[@\],Old=[]}@\@\task
962 @Chg{Version=[2],New=[@\],Old=[]}@\@\protected@Chg{Version=[2],New=[
963 @\@\tagged (including interfaces)
964 @\@\@\nonlimited tagged record
965 @\@\@\limited tagged
966 @\@\@\@\limited tagged record
967 @\@\@\@\synchronized tagged
968 @\@\@\@\@\tagged task
969 @\@\@\@\@\tagged protected],Old=[]}
970 @end{Display}
971
972 @noprefix@ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00345-01],ARef=[AI95-00442-01]}
973 @Chg{Version=[2],New=[There are other categories, such as],Old=[The classes]}
974 @lquotes@;numeric@rquotes@; and
975 @lquotes@;@Chg{Version=[2],New=[discriminated],Old=[nonlimited]}@rquotes@;@Chg{Version=[2],
976 New=[, which],Old=[]}
977 represent other @Chg{Version=[2],New=[categorization],Old=[classification]}
978 dimensions@Chg{Version=[2],New=[, but],
979 Old=[ and]} do not fit into the above strictly hierarchical picture.
980 @begin{Discussion}
981 @ChgRef{Version=[2],Kind=[Added],ARef=[AI95-00345-01],ARef=[AI95-00442-01]}
982 @ChgAdded{Version=[2],Text=[Note that this is also true for some categories
983 mentioned in the chart. The category @lquotes@;task@rquotes@; includes both
984 untagged tasks and tagged tasks. Similarly for @lquotes@;protected@rquotes@;,
985 @lquotes@;limited@rquotes@;, and @lquotes@;nonlimited@rquotes@; (note that
986 limited and nonlimited are not shown for untagged composite types).]}
987 @end{Discussion}
988 @end{Notes}
989
990 @begin{DiffWord83}
991 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0299-1]}
992 This @Chg{Version=[3],New=[subclause],Old=[clause and its subclauses]}
993 now @Chg{Version=[3],New=[precedes],Old=[precede]} the
994 @Chg{Version=[3],New=[],Old=[clause and ]}subclauses on objects and
995 named numbers, to cut down on the number of forward references.
996
997 We have dropped the term "base type" in favor of simply "type" (all
998 types in Ada 83 were "base types" so it wasn't clear when it was
999 appropriate/necessary to say "base type"). Given a subtype S of
1000 a type T, we call T the "type of the subtype S."
1001 @end{DiffWord83}
1002
1003 @begin{DiffWord95}
1004 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00231-01]}
1005 @ChgAdded{Version=[2],Text=[Added a mention of null exclusions when we're
1006 talking about constraints (these are not constraints, but they are similar).]}
1007
1008 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00251-01]}
1009 @ChgAdded{Version=[2],Text=[Defined an interface type to be a composite
1010 type.]}
1011
1012 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00326-01]}
1013 @ChgAdded{Version=[2],Text=[Revised the wording so that it is clear
1014 that an incomplete view is similar to a partial view in terms of the
1015 language.]}
1016
1017 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00366-01]}
1018 @ChgAdded{Version=[2],Text=[Added a definition of component of a type,
1019 subcomponent of a type, and part of a type. These are commonly used in
1020 the standard, but they were not previously defined.]}
1021
1022 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00442-01]}
1023 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0299-1]}
1024 @ChgAdded{Version=[2],Text=[Reworded most of this
1025 @Chg{Version=[3],New=[subclause],Old=[clause]} to use
1026 category rather than class, since so many interesting properties are
1027 not, strictly speaking, classes. Moreover, there was no normative
1028 description of exactly which properties formed classes, and which did
1029 not. The real definition of class, along with a list of properties, is now
1030 in @RefSecNum{Derived Types and Classes}.]}
1031 @end{DiffWord95}
1032
1033
1034 @LabeledSubClause{Type Declarations}
1035
1036 @begin{Intro}
1037 A @nt<type_declaration> declares a type and its first subtype.
1038 @end{Intro}
1039
1040 @begin{Syntax}
1041 @Syn{lhs=<type_declaration>,rhs=" @Syn2{full_type_declaration}
1042 | @Syn2{incomplete_type_declaration}
1043 | @Syn2{private_type_declaration}
1044 | @Syn2{private_extension_declaration}"}
1045
1046
1047 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0183-1]}
1048 @Syn{lhs=<full_type_declaration>,rhs="
1049 @key{type} @Syn2{defining_identifier} [@Syn2{known_discriminant_part}] @key{is} @Syn2{type_definition}@Chg{Version=[3],New=<
1050 [@Syn2{aspect_specification}]>,Old=[]};
1051 | @Syn2{task_type_declaration}
1052 | @Syn2{protected_type_declaration}"}
1053
1054 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00251-01]}
1055 @Syn{tabs=[P29], lhs=<type_definition>,rhs="
1056 @Syn2{enumeration_type_definition}@\| @Syn2{integer_type_definition}
1057 | @Syn2{real_type_definition}@\| @Syn2{array_type_definition}
1058 | @Syn2{record_type_definition}@\| @Syn2{access_type_definition}
1059 | @Syn2{derived_type_definition}@Chg{Version=[2],New=[@\| @Syn2{interface_type_definition}],Old=[]}"}
1060 @end{Syntax}
1061
1062 @begin{Legality}
1063 A given type shall not have a subcomponent whose type is the given
1064 type itself.
1065 @end{Legality}
1066
1067 @begin{StaticSem}
1068 @Defn{first subtype}
1069 The @nt{defining_@!identifier} of a @nt{type_@!declaration} denotes
1070 the @i(first subtype) of the type.
1071 The @nt<known_@!discriminant_@!part>, if any,
1072 defines the discriminants of the type (see @RefSec(Discriminants)).
1073 The remainder of the @nt<type_@!declaration> defines the
1074 remaining characteristics of (the view of) the type.
1075
1076 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00230-01]}
1077 @Defn{named type}
1078 A type defined by a @nt<type_@!declaration> is a @i(named) type;
1079 such a type has one or more nameable subtypes.
1080 @Defn{anonymous type}
1081 Certain other forms of declaration also include type
1082 definitions as part of the declaration for an object@Chg{Version=[2],New=[],
1083 Old=[ (including a parameter or a discriminant)]}. The type defined by such
1084 a declaration is @i(anonymous) @em it has no nameable subtypes.
1085 @Defn2{Term=[italics],Sec=(pseudo-names of anonymous types)}
1086 For explanatory purposes, this International Standard sometimes refers to
1087 an anonymous type by a pseudo-name, written in italics, and
1088 uses such pseudo-names at places where the syntax normally requires
1089 an @nt<identifier>. For a named type whose first subtype is T,
1090 this International Standard sometimes refers to the type of T
1091 as simply @lquotes@;the type T@rquotes@;.
1092 @begin{Ramification}
1093 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00230-01]}
1094 The only user-defined types
1095 that can be anonymous in the above sense are array,
1096 access, task, and protected types.
1097 An anonymous array, task, or protected type
1098 can be defined as part of an @nt{object_declaration}.
1099 An anonymous access type can be defined as part of
1100 @Chg{Version=[2],New=[numerous other constructs],Old=[a parameter or
1101 discriminant specification]}.
1102 @end{Ramification}
1103
1104 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00230-01],ARef=[AI95-00326-01]}
1105 @Defn{full type}
1106 A named type that is declared by a @nt<full_type_@!declaration>,
1107 or an anonymous type that is defined @Chg{Version=[2],New=[by an
1108 @nt{access_definition} or ],Old=[]}as part of declaring an object of the type,
1109 is called a
1110 @i(full type).@Defn{full type definition} @Chg{Version=[2],New=[The
1111 declaration of a full type also declares the @i<full view> of the
1112 type.@Defn2{Term=[full view],Sec=(of a type)} ],Old=[]}The
1113 @nt<type_@!definition>, @nt<task_@!definition>, @nt<protected_@!definition>,
1114 or @nt<access_@!definition> that defines a full type is called
1115 a @i(full type definition).
1116 @redundant[Types declared by other forms of @nt<type_@!declaration> are
1117 not separate types; they are partial or incomplete views
1118 of some full type.]
1119 @begin{Honest}
1120 Class-wide, universal, and root numeric types are full types.
1121 @end{Honest}
1122 @begin{Reason}
1123 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00230-01]}
1124 @ChgAdded{Version=[2],Text=[We need to mention @nt{access_definition}
1125 separately, as it may occur in renames, which do not declare objects.]}
1126 @end{Reason}
1127
1128 @PDefn{predefined operator}
1129 The definition of a type implicitly declares
1130 certain @i(predefined operators) that operate on the type,
1131 according to what classes the type belongs,
1132 as specified in @RefSec(Operators and Expression Evaluation).
1133 @begin{Discussion}
1134 We no longer talk about the implicit declaration of basic operations.
1135 These are treated like an @nt{if_statement} @em they don't need
1136 to be declared, but are still applicable to only certain classes of types.
1137
1138 @end{Discussion}
1139
1140 @Defn{predefined type}
1141 The @i{predefined types}
1142 @Redundant[(for example the types
1143 Boolean, Wide_Character, Integer,
1144 @i{root_integer}, and @i{universal_integer})]
1145 are the types that are defined in
1146 @Redundant[a predefined library package called] Standard@Redundant[;
1147 this package also includes the @Redundant{(implicit)}
1148 declarations of their predefined operators].
1149 @Redundant[The package Standard is described in
1150 @RefSecNum{The Package Standard}.]
1151 @begin{Ramification}
1152 We use the term @lquotes@;predefined@rquotes@; to refer to entities declared in the
1153 visible part of Standard,
1154 to implicitly declared operators of a type whose semantics are defined
1155 by the language, to Standard itself,
1156 and to the @lquotes@;predefined environment@rquotes@;.
1157 We do not use this term to refer to library packages other than Standard.
1158 For example Text_IO is a language-defined package,
1159 not a predefined package,
1160 and Text_IO.Put_Line is not a predefined operation.
1161 @end{Ramification}
1162 @end{StaticSem}
1163
1164 @begin{RunTime}
1165 @PDefn2{Term=[elaboration], Sec=(full_type_declaration)}
1166 The elaboration of a @nt{full_type_declaration} consists of the
1167 elaboration of the full type definition.
1168 @PDefn2{Term=[elaboration], Sec=(full type definition)}
1169 Each elaboration of a full type definition
1170 creates a distinct type and its first subtype.
1171 @begin{Reason}
1172 The creation is associated with the type @i(definition), rather than
1173 the type @i(declaration), because there are types
1174 that are created by full type definitions that are
1175 not immediately contained within a type declaration (e.g.
1176 an array object declaration, a singleton task declaration, etc.).
1177 @end{Reason}
1178 @begin{Ramification}
1179 Any implicit declarations that occur immediately following the full
1180 type definition are elaborated where they (implicitly) occur.
1181 @end{Ramification}
1182 @end{RunTime}
1183
1184 @begin{Examples}
1185 @Leading@keepnext@i(Examples of type definitions:)
1186 @begin(Example)
1187 (White, Red, Yellow, Green, Blue, Brown, Black)
1188 @key(range) 1 .. 72
1189 @key(array)(1 .. 10) @key(of) Integer
1190 @end(Example)
1191
1192 @begin{WideAbove}
1193 @leading@keepnext@i(Examples of type declarations:)
1194 @end{WideAbove}
1195 @begin(Example)
1196 @key(type) Color @key(is) (White, Red, Yellow, Green, Blue, Brown, Black);
1197 @key(type) Column @key(is) @key(range) 1 .. 72;
1198 @key(type) Table @key(is) @key(array)(1 .. 10) @key(of) Integer;
1199 @end(Example)
1200 @end{Examples}
1201
1202 @begin{Notes}
1203 Each of the above examples declares a named type. The identifier
1204 given denotes the first subtype of the type. Other named subtypes of the
1205 type can be declared with @nt<subtype_declaration>s
1206 (see @RefSecNum{Subtype Declarations}). Although names do not directly
1207 denote types, a phrase like @lquotes@;the type Column@rquotes@; is sometimes used
1208 in this International Standard to refer to the type of Column, where Column denotes
1209 the first subtype of the type. For an example of the definition
1210 of an anonymous type, see the declaration
1211 of the array Color_Table in @RefSecNum{Object Declarations}; its type
1212 is anonymous @em it has no nameable subtypes.
1213 @end{Notes}
1214
1215 @begin{DiffWord83}
1216 The syntactic category @nt{full_type_declaration} now includes task and
1217 protected type declarations.
1218
1219 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0299-1]}
1220 We have generalized the concept of first-named subtype (now
1221 called simply @lquotes@;first subtype@rquotes@;) to cover all kinds of types, for uniformity
1222 of description elsewhere.
1223 RM83 defined first-named subtype in Section 13.
1224 We define first subtype here, because it is now a more fundamental concept.
1225 We renamed the term, because in Ada 95 some first subtypes have no
1226 name.
1227
1228 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00230-01]}
1229 We no longer elaborate @nt{discriminant_part}s, because
1230 there is nothing to do, and it was complex to say that you only wanted
1231 to elaborate it once for a private or incomplete type. This is also
1232 consistent with the fact that subprogram specifications are not
1233 elaborated (neither in Ada 83 nor in Ada 95). Note, however, that an
1234 @nt<access_definition> appearing in a @nt<discriminant_part> is
1235 elaborated@Chg{Version=[2],New=[ at the @nt{full_type_declaration} (for
1236 a nonlimited type) or],Old=[]} when an object with such a discriminant is
1237 created@Chg{Version=[2],New=[ (for a limited type)],Old=[]}.
1238 @end{DiffWord83}
1239
1240 @begin{DiffWord95}
1241 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00230-01]}
1242 @ChgAdded{Version=[2],Text=[Added wording so that anonymous access types
1243 are always full types, even if they appear in renames.]}
1244
1245 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00251-01]}
1246 @ChgAdded{Version=[2],Text=[Added interface types
1247 (see @RefSecNum{Interface Types}) to the syntax.]}
1248
1249 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00326-01]}
1250 @ChgAdded{Version=[2],Text=[Added a definition of full view, so that
1251 all types have a well-defined full view.]}
1252 @end{DiffWord95}
1253
1254 @begin{Extend2005}
1255 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0183-1]}
1256 @ChgAdded{Version=[3],Text=[@Defn{extensions to Ada 2005}
1257 An optional @nt{aspect_specification} can be used in a @nt{full_type_declaration}.
1258 This is described in @RefSecNum{Aspect Specifications}.]}
1259 @end{Extend2005}
1260
1261 @LabeledSubClause{Subtype Declarations}
1262
1263 @begin{Intro}
1264 A @nt<subtype_declaration> declares a subtype of some previously
1265 declared type, as defined by a @nt<subtype_indication>.
1266 @end{Intro}
1267
1268 @begin{Syntax}
1269 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0183-1]}
1270 @Syn{lhs=<subtype_declaration>,rhs="
1271 @key{subtype} @Syn2{defining_identifier} @key{is} @Syn2{subtype_indication}@Chg{Version=[3],New=<
1272 [@Syn2{aspect_specification}]>,Old=[]};"}
1273
1274 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00231-01]}
1275 @Syn{lhs=<subtype_indication>,rhs=" @Chg{Version=[2],New=<[@Syn2{null_exclusion}] >,Old=<>}@Syn2{subtype_mark} [@Syn2{constraint}]"}
1276
1277 @Syn{lhs=<subtype_mark>,rhs="@SynI{subtype_}@Syn2{name}"}
1278 @begin{Ramification}
1279 Note that @nt{name} includes @nt{attribute_reference};
1280 thus, S'Base can be used as a @nt{subtype_mark}.
1281 @end{Ramification}
1282 @begin{Reason}
1283 We considered changing @nt{subtype_mark} to @ntf{subtype_name}.
1284 However, existing users are used to the word "mark,"
1285 so we're keeping it.
1286 @end{Reason}
1287
1288 @Syn{lhs=<constraint>,rhs="@Syn2<scalar_constraint> | @Syn2<composite_constraint>"}
1289
1290 @Syn{lhs=<scalar_constraint>,rhs="
1291 @Syn2{range_constraint} | @Syn2{digits_constraint} | @Syn2{delta_constraint}"}
1292 @Syn{lhs=<composite_constraint>,rhs="
1293 @Syn2{index_constraint} | @Syn2{discriminant_constraint}"}
1294 @end{Syntax}
1295
1296 @begin{Resolution}
1297 A @nt{subtype_mark} shall resolve to denote a subtype.
1298 @Defn2{Term=[determines], Sec=(a type by a @nt{subtype_mark})}
1299 The type @i(determined by) a @nt<subtype_mark> is the
1300 type of the subtype denoted by the @nt{subtype_mark}.
1301 @begin{Ramification}
1302 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0005-1]}
1303 Types are never directly named; all @nt{subtype_mark}s denote
1304 subtypes @em possibly an unconstrained (base) subtype,
1305 but never the type.
1306 When we use the term @i(anonymous type) we really
1307 mean a type with no @Chg{Version=[3],New=[nameable],Old=[namable]}
1308 subtypes.
1309 @end{Ramification}
1310 @end{Resolution}
1311
1312 @begin{RunTime}
1313 @Leading@PDefn2{Term=[elaboration], Sec=(subtype_declaration)}
1314 The elaboration of a @nt{subtype_declaration} consists of the elaboration
1315 of the @nt{subtype_indication}.
1316 @PDefn2{Term=[elaboration], Sec=(subtype_indication)}
1317 The elaboration of a @nt{subtype_indication} creates a new subtype.
1318 If the @nt{subtype_indication} does not include a
1319 @nt<constraint>, the new subtype has the same (possibly null)
1320 constraint as that denoted by the @nt{subtype_mark}.
1321 The elaboration of a @nt{subtype_indication} that includes a
1322 @nt<constraint> proceeds as follows:
1323 @begin{itemize}
1324 The @nt<constraint> is first elaborated.
1325
1326 @IndexCheck{Range_Check}
1327 A check is then made that
1328 the @nt<constraint> is @i(compatible) with the
1329 subtype denoted by the @nt{subtype_mark}.
1330 @begin{Ramification}
1331 The checks associated with
1332 constraint compatibility are all Range_Checks.
1333 Discriminant_Checks and Index_Checks are associated only with
1334 checks that a value satisfies a constraint.
1335 @end{Ramification}
1336 @end{itemize}
1337
1338 The condition imposed by a @nt<constraint> is the condition obtained
1339 after elaboration of the @nt<constraint>.
1340 @RootDefn2{Term=[compatibility], Sec=(constraint with a subtype)}
1341 The rules defining compatibility are given for each form of @nt<constraint>
1342 in the appropriate subclause. These rules are such that if a
1343 @nt<constraint> is @i(compatible) with a subtype,
1344 then the condition imposed by the @nt<constraint> cannot
1345 contradict any condition already imposed by the subtype on its values.
1346 @Defn2{Term=(Constraint_Error),Sec=(raised by failure of runtime check)}
1347 The exception Constraint_Error is raised if any check of
1348 compatibility fails.
1349 @begin{Honest}
1350 The condition imposed by a @nt<constraint> is named after it @em
1351 a @nt<range_constraint> imposes a range constraint, etc.
1352 @end{Honest}
1353 @begin{Ramification}
1354 A @nt<range_constraint> causes freezing of its type.
1355 Other @nt<constraint>s do not.
1356 @end{Ramification}
1357 @end{RunTime}
1358
1359 @begin{Notes}
1360 A @nt<scalar_constraint> may be applied to a subtype of an appropriate
1361 scalar type (see @RefSecNum{Scalar Types}, @RefSecNum{Fixed Point Types},
1362 and @RefSecNum{Reduced Accuracy Subtypes}), even if the subtype
1363 is already constrained. On the other hand, a @nt<composite_constraint>
1364 may be applied to a composite subtype (or an access-to-composite subtype)
1365 only if the composite subtype is unconstrained
1366 (see @RefSecNum{Index Constraints and Discrete Ranges} and
1367 @RefSecNum{Discriminant Constraints}).
1368 @end{Notes}
1369
1370 @begin{Examples}
1371 @Leading@keepnext@i(Examples of subtype declarations:)
1372 @begin(Example)
1373 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00433-01]}
1374 @key(subtype) Rainbow @key(is) Color @key(range) Red .. Blue; --@RI[ see @RefSecNum(Type Declarations)]
1375 @key(subtype) Red_Blue @key(is) Rainbow;
1376 @key(subtype) Int @key(is) Integer;
1377 @key(subtype) Small_Int @key(is) Integer @key(range) -10 .. 10;
1378 @key(subtype) Up_To_K @key(is) Column @key(range) 1 .. K; --@RI[ see @RefSecNum(Type Declarations)]
1379 @key(subtype) Square @key(is) Matrix(1 .. 10, 1 .. 10); --@RI[ see @RefSecNum(Array Types)]
1380 @key(subtype) Male @key(is) Person(Sex => M); --@RI[ see @RefSecNum(Incomplete Type Declarations)]@Chg{Version=[2],New=[
1381 @key(subtype) Binop_Ref @key(is not null) Binop_Ptr; --@RI[ see @RefSecNum(Access Types)]],Old=[]}
1382 @end(Example)
1383
1384 @end{Examples}
1385
1386 @begin{Incompatible83}
1387 @Defn{incompatibilities with Ada 83}
1388 In Ada 95, all @nt<range_constraint>s cause freezing of their type.
1389 Hence, a type-related representation item for a scalar type has to
1390 precede any @nt<range_constraint>s whose type is the scalar type.
1391 @end{Incompatible83}
1392
1393 @begin{DiffWord83}
1394 @nt{Subtype_mark}s allow only subtype names now, since
1395 types are never directly named.
1396 There is no need for RM83-3.3.2(3), which says a
1397 @nt{subtype_mark} can denote both the type and the subtype;
1398 in Ada 95, you denote an unconstrained (base) subtype if you want,
1399 but never the type.
1400
1401 The syntactic category @ntf{type_mark} is now called @nt{subtype_mark},
1402 since it always denotes a subtype.
1403 @end{DiffWord83}
1404
1405 @begin{Extend95}
1406 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00231-01]}
1407 @ChgAdded{Version=[2],Text=[@Defn{extensions to Ada 95}
1408 An optional @nt{null_exclusion} can be used in a @nt{subtype_indication}.
1409 This is described in @RefSecNum{Access Types}.]}
1410 @end{Extend95}
1411
1412 @begin{Extend2005}
1413 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0183-1]}
1414 @ChgAdded{Version=[3],Text=[@Defn{extensions to Ada 2005}
1415 An optional @nt{aspect_specification} can be used in a @nt{subtype_declaration}.
1416 This is described in @RefSecNum{Aspect Specifications}.]}
1417 @end{Extend2005}
1418
1419
1420
1421
1422 @LabeledSubClause{Classification of Operations}
1423
1424 @begin{StaticSem}
1425 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00416-01]}
1426 @Defn{operates on a type}
1427 An operation @i(operates
1428 on a type) @i(T) if it yields a value of type @i(T), if it has an operand
1429 whose expected type
1430 (see @RefSecNum{The Context of Overload Resolution})
1431 is @i(T), or if it has an access parameter@Chg{Version=[2],New=[ or access result type],Old=[]}
1432 (see @RefSecNum(Subprogram Declarations))
1433 designating @i(T).
1434 @Defn2{Term=[predefined operation], Sec=(of a type)}
1435 A predefined operator, or
1436 other language-defined operation
1437 such as assignment or a membership test, that operates
1438 on a type, is called
1439 a @i(predefined operation) of the type.
1440 @Defn2{Term=[primitive operations], Sec=(of a type)}
1441 The @i(primitive operations) of a type are
1442 the predefined operations of the type, plus any user-defined
1443 primitive subprograms.
1444 @ToGlossary{Term=<Primitive operations>,
1445 Text=<The primitive operations of a type are the operations
1446 (such as subprograms) declared together with
1447 the type declaration.
1448 They are inherited by other types in the same class of types.
1449 For a tagged type,
1450 the primitive subprograms are dispatching subprograms,
1451 providing run-time polymorphism.
1452 A dispatching subprogram may be called with statically
1453 tagged operands, in which case the subprogram body invoked
1454 is determined at compile time.
1455 Alternatively, a dispatching subprogram may be called
1456 using a dispatching call,
1457 in which case the subprogram body invoked is determined
1458 at run time.>}
1459 @begin{Honest}
1460 Protected subprograms are not considered to be
1461 @lquotes@;primitive subprograms,@rquotes@; even though they are
1462 subprograms, and they are inherited by derived types.
1463 @end{Honest}
1464 @begin{Discussion}
1465 We use the term
1466 @lquotes@;primitive subprogram@rquotes@; in most of the rest of the manual.
1467 The term @lquotes@;primitive operation@rquotes@; is used mostly in conceptual
1468 discussions.
1469 @end{Discussion}
1470
1471 @Leading@Defn2{Term=[primitive subprograms], Sec=(of a type)}
1472 The @i(primitive subprograms) of a
1473 specific type are defined as follows:
1474 @begin{Itemize}
1475 The predefined operators of the
1476 type (see @RefSecNum{Operators and Expression Evaluation});
1477
1478 For a derived type, the inherited (see @RefSecNum{Derived Types and Classes})
1479 user-defined subprograms;
1480
1481 For an enumeration type, the enumeration literals (which are
1482 considered parameterless
1483 functions @em see @RefSecNum{Enumeration Types});
1484
1485 For a specific type declared immediately within
1486 a @nt<package_specification>,
1487 any subprograms (in addition to the enumeration literals)
1488 that are
1489 explicitly declared immediately within the same
1490 @nt<package_specification> and that operate on the type;
1491
1492 @ChgRef{Version=[3],Kind=[Added],ARef=[AI05-0128-1]}
1493 @ChgAdded{Version=[3],Text=[For a specific type with an
1494 explicitly declared primitive "=" operator whose result type
1495 is Boolean, the corresponding "/=" operator (see
1496 @RefSecNum{Overloading of Operators});]}
1497
1498 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00200-01]}
1499 @Defn2{Term=[override], Sec=(a primitive subprogram)}
1500 @Chg{Version=[2],New=[For a nonformal type, any],Old=[Any]}
1501 subprograms not covered above
1502 @Redundant[that are explicitly declared immediately within the same
1503 declarative region as the type] and that override (see @RefSecNum{Visibility})
1504 other implicitly declared primitive subprograms of the type.
1505 @end{Itemize}
1506 @begin{Discussion}
1507 In Ada 83, only subprograms
1508 declared in the visible part were @lquotes@;primitive@rquotes@; (i.e.
1509 derivable). In Ada 95, mostly because of child library units,
1510 we include all operations declared in the private part as well,
1511 and all operations that override implicit declarations.
1512 @end{Discussion}
1513 @begin{Ramification}
1514 It is possible for a subprogram
1515 to be primitive for more than one type, though it is illegal
1516 for a subprogram to be primitive for more than one tagged type.
1517 See @RefSecNum(Tagged Types and Type Extensions).
1518 @end{Ramification}
1519 @begin(Discussion)
1520 The order of the implicit declarations when there are both
1521 predefined operators and inherited subprograms is described in
1522 @RefSec(Derived Types and Classes).
1523 @end(Discussion)
1524 @begin{Ramification}
1525 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00200-01]}
1526 @ChgAdded{Version=[2],Text=[Subprograms declared in a generic package
1527 specification are never primitive for a formal type, even if they happen
1528 to override an operation of the formal type. This includes formal
1529 subprograms, which are never primitive operations (that's true even
1530 for an abstract formal subprogram).]}
1531 @end{Ramification}
1532
1533 @Defn2{Term=[primitive operator], Sec=(of a type)}
1534 A primitive subprogram whose designator is an @nt<operator_symbol>
1535 is called a @i(primitive operator).
1536
1537 @end{StaticSem}
1538
1539 @begin{Incompatible83}
1540 @Defn{incompatibilities with Ada 83}
1541 The attribute S'Base is no longer defined for
1542 nonscalar subtypes. Since this was only permitted
1543 as the prefix of another attribute, and there are no
1544 interesting nonscalar attributes defined for an unconstrained
1545 composite or access subtype, this should not affect any
1546 existing programs.
1547 @end{Incompatible83}
1548
1549 @begin{Extend83}
1550 @Defn{extensions to Ada 83}
1551 The primitive subprograms (derivable subprograms) include
1552 subprograms declared in the private part of a package
1553 specification as well, and those that override implicitly declared
1554 subprograms, even if declared in a body.
1555 @end{Extend83}
1556
1557 @begin{DiffWord83}
1558 We have dropped the confusing
1559 term @i<operation of a type> in favor of the more useful
1560 @i<primitive operation of a type> and the phrase
1561 @i<operates on a type>.
1562
1563 The description of S'Base has been moved to
1564 @RefSec{Scalar Types} because it is now defined only for scalar types.
1565 @end{DiffWord83}
1566
1567 @begin{DiffWord95}
1568 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00200-01]}
1569 @ChgAdded{Version=[2],Text=[Clarified that a formal subprogram that happens
1570 to override a primitive operation of a formal type is not a primitive
1571 operation (and thus not a dispatching operation) of the formal type.]}
1572
1573 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00416-01]}
1574 @ChgAdded{Version=[2],Text=[Added wording to include access result types
1575 in the kinds of operations that operate on a type T.]}
1576 @end{DiffWord95}
1577
1578 @begin{DiffWord2005}
1579 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0128-1]}
1580 @ChgAdded{Version=[3],Text=[@b<Correction:> The implicitly declared "/="
1581 for a primitive "=" operator is also primitive; this makes it eligible
1582 to be made visible by a @key[use type] clause.]}
1583 @end{DiffWord2005}
1584
1585
1586 @LabeledAddedSubClause{Version=[3],Name=[Subtype Predicates]}
1587
1588 @begin{Intro}
1589 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0153-3],ARef=[AI05-0269-1],ARef=[AI05-0299-1]}
1590 @ChgAdded{Version=[3],Text=[The language-defined @i{predicate aspects}
1591 Static_Predicate and Dynamic_Predicate may be used to define properties of
1592 subtypes. A @i{predicate specification} is an @nt{aspect_specification}
1593 for one of the two predicate
1594 aspects.@Defn{predicate aspect}@Defn{predicate specification}@PDefn2{Term=[aspect],Sec=(predicate)}@AspectDefn{Static_Predicate}@AspectDefn{Dynamic_Predicate}
1595 General rules for aspects and @nt{aspect_specification}s are found in
1596 @Chg{Version=[3],New=[Clause],Old=[Section]} @RefSecNum{Representation Issues} (@RefSecNum{Operational and Representation Aspects}
1597 and @RefSecNum{Aspect Specifications} respectively).]}
1598 @ChgAspectDesc{Version=[3],Kind=[AddedNormal],Aspect=[Static_Predicate],
1599 Text=[@ChgAdded{Version=[3],Text=[Condition that must hold true for objects of
1600 a given subtype; the subtype may be static.]}]}
1601
1602 @ChgAspectDesc{Version=[3],Kind=[AddedNormal],Aspect=[Dynamic_Predicate],
1603 Text=[@ChgAdded{Version=[3],Text=[Condition that must hold true for objects of
1604 a given subtype; the subtype is not static.]}]}
1605 @end{Intro}
1606
1607 @begin{Resolution}
1608 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0153-3]}
1609 @ChgAdded{Version=[3],Text=[The expected type for a predicate aspect
1610 @nt{expression} is any boolean
1611 type.@PDefn2{Term=[expected type],Sec=[@nt{expression} of a predicate aspect]}]}
1612
1613 @end{Resolution}
1614
1615 @begin{StaticSem}
1616
1617 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0153-3]}
1618 @ChgAdded{Version=[3],Type=[Leading],Text=[A predicate specification may be
1619 given on a @nt{type_declaration} or a @nt{subtype_declaration}, and applies
1620 to the declared subtype. In addition, predicate specifications apply to
1621 certain other subtypes:]}
1622 @begin{Itemize}
1623 @ChgRef{Version=[3],Kind=[AddedNormal]}
1624 @ChgRef{Version=[4],Kind=[Revised],ARef=[AI12-0071-1],ARef=[AI12-0099-1]}
1625 @ChgAdded{Version=[3],Text=[For a (first) subtype defined by a
1626 @Chg{Version=[4],New=[],Old=[derived ]}type declaration,
1627 @Chg{Version=[4],New=[any],Old=[the]}
1628 predicates of @Chg{Version=[4],New=[],Old=[the ]}parent
1629 @Chg{Version=[4],New=[or],Old=[subtype and the]} progenitor subtypes apply.]}
1630
1631 @ChgRef{Version=[3],Kind=[AddedNormal]}
1632 @ChgAdded{Version=[3],Text=[For a subtype created by a @nt{subtype_indication},
1633 the predicate of the subtype denoted by the @nt{subtype_mark} applies.]}
1634 @end{Itemize}
1635
1636 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0153-3]}
1637 @ChgRef{Version=[4],Kind=[Deleted],ARef=[AI12-0071-1]}
1638 @ChgAdded{Version=[3],Text=[@Chg{Version=[4],New=[],Old=[The @i<predicate>
1639 of a subtype consists of all
1640 predicate specifications that apply, and-ed together; if no predicate
1641 specifications apply, the predicate is True @Redundant[(in particular, the
1642 predicate of a base subtype is True)].@Defn2{Term=[Predicate],Sec=(of a subtype)}]}]}
1643
1644 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0290-1]}
1645 @ChgAdded{Version=[3],Type=[Leading],Text=[Predicate checks are defined to be
1646 @i<enabled> or @i<disabled> for a given subtype as
1647 follows:@Defn2{Term=[enabled],Sec=[predicate checks]}@Defn2{Term=[disabled],Sec=[predicate checks]}@Defn2{Term=[predicate check],Sec=[enabled]}]}
1648
1649 @begin{Itemize}
1650 @ChgRef{Version=[3],Kind=[AddedNormal]}
1651 @ChgAdded{Version=[3],Type=[Leading],Text=[If a subtype is declared by
1652 a @nt{type_declaration} or @nt{subtype_declaration}
1653 that includes a predicate specification, then:]}
1654 @begin{Itemize}
1655 @ChgRef{Version=[3],Kind=[AddedNormal]}
1656 @ChgAdded{Version=[3],Text=[if performing checks is required by the
1657 Static_Predicate assertion policy (see @RefSecNum{Pragmas Assert and Assertion_Policy})
1658 and the declaration includes a Static_Predicate specification, then
1659 predicate checks are enabled for the subtype;]}
1660
1661 @ChgRef{Version=[3],Kind=[AddedNormal]}
1662 @ChgAdded{Version=[3],Text=[if performing checks is required by the
1663 Dynamic_Predicate assertion policy (see @RefSecNum{Pragmas Assert and Assertion_Policy})
1664 and the declaration includes a Dynamic_Predicate specification, then
1665 predicate checks are enabled for the subtype;]}
1666
1667 @ChgRef{Version=[3],Kind=[AddedNormal]}
1668 @ChgAdded{Version=[3],Text=[otherwise, predicate checks are disabled for the
1669 subtype@Redundant[, regardless of whether predicate checking is enabled
1670 for any other subtypes mentioned in the declaration];]}
1671 @end{Itemize}
1672
1673 @ChgRef{Version=[3],Kind=[AddedNormal]}
1674 @ChgRef{Version=[4],Kind=[Revised],ARef=[AI12-0099-1]}
1675 @ChgAdded{Version=[3],Text=[If a subtype is defined by a
1676 @Chg{Version=[4],New=[],Old=[derived ]}type declaration
1677 that does not include a predicate specification, then predicate
1678 checks are enabled for the subtype if and only if
1679 @Chg{Version=[4],New=[any ],Old=[]}predicate checks are enabled
1680 for @Chg{Version=[4],New=[],Old=[at least one of the ]}parent
1681 @Chg{Version=[4],New=[or],Old=[subtype and the]} progenitor subtypes;]}
1682
1683 @ChgRef{Version=[3],Kind=[AddedNormal]}
1684 @ChgAdded{Version=[3],Text=[If a subtype is created by a
1685 @nt{subtype_indication} other than in one of the previous cases, then
1686 predicate checks are enabled for the subtype if and only if predicate checks
1687 are enabled for the subtype denoted by the @nt{subtype_mark};]}
1688
1689 @ChgRef{Version=[3],Kind=[AddedNormal]}
1690 @ChgAdded{Version=[3],Text=[Otherwise, predicate checks are disabled for the
1691 given subtype.]}
1692
1693 @begin{Discussion}
1694 @ChgRef{Version=[3],Kind=[AddedNormal]}
1695 @ChgAdded{Version=[3],Text=[In this case, no predicate specifications can
1696 apply to the subtype and so it doesn't typically matter whether predicate
1697 checks are enabled. This rule does make a difference, however, when
1698 determining whether predicate checks are enabled for another type when this
1699 type is one of multiple progenitors. See the @ldquote@;derived type declaration@rdquote
1700 wording above.]}
1701
1702 @ChgRef{Version=[3],Kind=[AddedNormal]}
1703 @ChgRef{Version=[4],Kind=[Revised],ARef=[AI12-0071-1]}
1704 @ChgAdded{Version=[3],Text=[Even when predicate checks are disabled,
1705 a predicate @Chg{Version=[4],New=[can],Old=[cam]} affect various
1706 @LegalityTitle, the results of membership
1707 tests, the items in a @key[for] loop, and the result of the Valid
1708 attribute.]}
1709 @end{Discussion}
1710
1711 @end{Itemize}
1712
1713 @ChgRef{Version=[4],Kind=[Added],ARef=[AI12-0054-2]}
1714 @ChgAdded{Version=[4],Text=[For a subtype with a directly-specified predicate
1715 aspect, the following additional language-defined aspect may be specified with
1716 an @nt{aspect_specification} (see @RefSecNum{Aspect Specifications}):]}
1717
1718 @begin{Description}
1719 @ChgRef{Version=[4],Kind=[Added]}
1720 @ChgAdded{Version=[4],Text=[Predicate_Failure@\
1721 This aspect shall be specified by an @nt{expression}, which
1722 determines the action to be performed when a predicate check fails because a
1723 directly-specified predicate aspect of the subtype evaluates to
1724 False, as explained below.@AspectDefn{Predicate_Failure}]}
1725 @end{Description}
1726 @ChgAspectDesc{Version=[4],Kind=[Added],Aspect=[Predicate_Failure],
1727 InitialVersion=[4],
1728 Text=[@ChgAdded{Version=[4],Text=[Action to be performed when a predicate
1729 check fails.]}]}
1730 @end{StaticSem}
1731
1732 @begin{Resolution}
1733 @ChgRef{Version=[4],Kind=[Added],ARef=[AI12-0054-2]}
1734 @ChgAdded{Version=[4],Text=[The expected type for the Predicate_Failure
1735 @nt{expression} is String.]}
1736 @end{Resolution}
1737
1738 @begin{Legality}
1739
1740 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0153-3],ARef=[AI05-0269-1]}
1741 @ChgAdded{Version=[3],Type=[Leading],Text=[The @nt{expression} of a
1742 Static_Predicate specification shall be @i<predicate-static>; that is, one of
1743 the following:@Defn{predicate-static}@Defn2{Term=[expression],Sec=[predicate-static]}]}
1744 @begin{Itemize}
1745 @ChgRef{Version=[3],Kind=[AddedNormal]}
1746 @ChgAdded{Version=[3],Text=[a static expression;]}
1747
1748 @ChgRef{Version=[3],Kind=[AddedNormal]}
1749 @ChgRef{Version=[4],Kind=[Revised],ARef=[AI12-0039-1]}
1750 @ChgAdded{Version=[3],Text=[a membership test whose
1751 @Chg{Version=[4],New=[@i<tested_>@nt{simple_expression}],Old=[@nt{simple_expression}]}
1752 is the current instance, and whose @nt{membership_choice_list} meets the
1753 requirements for a static membership test
1754 (see @RefSecNum{Static Expressions and Static Subtypes});]}
1755
1756 @ChgRef{Version=[3],Kind=[AddedNormal]}
1757 @ChgAdded{Version=[3],Text=[a @nt{case_expression} whose
1758 @SynI{selecting_}@nt{expression} is the current instance,
1759 and whose @SynI{dependent_}@nt{expression}s are static expressions;]}
1760
1761 @ChgRef{Version=[3],Kind=[AddedNormal]}
1762 @ChgAdded{Version=[3],Text=[a call to a predefined equality or ordering
1763 operator, where one operand is the current instance, and the other is a
1764 static expression;]}
1765
1766 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0262-1]}
1767 @ChgRef{Version=[4],Kind=[Revised],ARef=[AI12-0099-1]}
1768 @ChgAdded{Version=[3],Text=[a call to a predefined boolean
1769 @Chg{Version=[4],New=[],Old=[logical ]}operator@Chg{Version=[4],New=[
1770 @key[and], @key[or], @key[xor], or @key[not]],Old=[]},
1771 where each operand is predicate-static;]}
1772
1773 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0269-1]}
1774 @ChgAdded{Version=[3],Text=[a short-circuit control form where both operands
1775 are predicate-static; or]}
1776
1777 @ChgRef{Version=[3],Kind=[AddedNormal]}
1778 @ChgAdded{Version=[3],Text=[a parenthesized predicate-static @nt{expression}.]}
1779 @end{Itemize}
1780
1781 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0262-1]}
1782 @ChgAdded{Version=[3],Text=[A predicate shall not be specified for an incomplete
1783 subtype.]}
1784
1785 @begin{Reason}
1786 @ChgRef{Version=[3],Kind=[AddedNormal]}
1787 @ChgAdded{Version=[3],Text=[The expression of such a predicate could not
1788 depend on the properties of the value of the type (since it doesn't have
1789 any), so it is useless and we don't want to require the added complexity
1790 needed to support it.]}
1791 @end{Reason}
1792
1793 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0287-1]}
1794 @ChgAdded{Version=[3],Text=[If a predicate applies to a subtype, then that
1795 predicate shall not mention any other subtype to which the same predicate
1796 applies.]}
1797
1798 @begin{Reason}
1799 @ChgRef{Version=[3],Kind=[AddedNormal]}
1800 @ChgAdded{Version=[3],Type=[Leading],Text=[This is intended to prevent
1801 recursive predicates, which cause definitional problems for static predicates.
1802 Inside of the predicate, the subtype name refers to the current instance of
1803 the subtype, which is an object, so a direct use of the subtype name cannot be
1804 recursive. But other subtypes naming the same type might:]}
1805 @begin{Example}
1806 @ChgRef{Version=[3],Kind=[AddedNormal]}
1807 @ChgAdded{Version=[3],Text=[ @key[type] Really_Ugly @key[is private];
1808 @key[private]
1809 @key[subtype] Ugly @key[is] Really_Ugly;
1810 @key[type] Really_Ugly @key[is new] Integer
1811 @key[with] Static_Predicate => Really_Ugly @key[not in] Ugly; --@ExamCom{ Illegal!}]}
1812 @end{Example}
1813 @end{Reason}
1814
1815
1816 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0153-3]}
1817 @ChgAdded{Version=[3],Text=[An index subtype, @nt{discrete_range} of an
1818 @nt{index_constraint} or @nt{slice}, or a
1819 @nt{discrete_subtype_definition} of a @nt{constrained_array_definition},
1820 @nt{entry_declaration}, or @nt{entry_index_specification} shall not denote a
1821 subtype to which predicate specifications apply.]}
1822
1823 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0153-3]}
1824 @ChgAdded{Version=[3],Text=[The @nt{prefix} of an @nt{attribute_reference}
1825 whose @nt{attribute_designator} is First, Last, or Range shall not denote a
1826 scalar subtype to which predicate specifications apply.]}
1827
1828 @begin{Reason}
1829 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0297-1]}
1830 @ChgAdded{Version=[3],Text=[This is to prevent confusion about whether the
1831 First value is the lowest value of the subtype (which does not depend on the
1832 predicate) or the lowest value of the subtype which meets the predicate.
1833 (For a dynamic predicate, determining this latter value is expensive as it
1834 would usually require a loop.) For a static subtype that has a static
1835 predicate, the First_Valid and Last_Valid attributes (see
1836 @RefSecNum{Operations of Discrete Types}) can be used instead.]}
1837 @end{Reason}
1838
1839 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0153-3],ARef=[AI05-0262-1],ARef=[AI05-0287-1]}
1840 @ChgAdded{Version=[3],Text=[The @nt{discrete_subtype_definition} of a
1841 @nt{loop_parameter_specification} shall not denote a
1842 nonstatic subtype to which predicate specifications apply or any
1843 subtype to which Dynamic_Predicate specifications apply.]}
1844
1845 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0153-3],ARef=[AI05-0262-1]}
1846 @ChgAdded{Version=[3],Text=[The @nt{discrete_choice} of a
1847 @nt{named_array_aggregate} shall not denote a nonstatic subtype to which
1848 predicate specifications apply.]}
1849
1850 @begin{Reason}
1851 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0262-1]}
1852 @ChgAdded{Version=[3],Text=[This rule prevents noncontiguous
1853 dynamically bounded array aggregates, which could be expensive to check for.
1854 (Array aggregates have rules to prevent problems with static subtypes.) We
1855 define this rule here so that the runtime generic body check applies.]}
1856 @end{Reason}
1857
1858 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0262-1]}
1859 @ChgAdded{Version=[3],Text=[In addition to the places
1860 where @LegalityTitle normally apply (see @RefSecNum{Generic Instantiation}),
1861 these rules apply also in the private part of an instance of a generic
1862 unit.@PDefn{generic contract issue}]}
1863 @end{Legality}
1864
1865 @begin{Runtime}
1866 @ChgRef{Version=[4],Kind=[Added],ARef=[AI12-0071-1]}
1867 @ChgAdded{Version=[4],Text=[If any of the above @LegalityTitle is violated in an
1868 instance of a generic unit, Program_Error is raised at the point of the
1869 violation.@Defn2{Term=[Program_Error],Sec=(raised by failure of runtime check)}@Indexcheck{Program_Error_Check}]}
1870
1871 @begin{Discussion}
1872 @ChgRef{Version=[4],Kind=[AddedNormal]}
1873 @ChgAdded{Version=[4],Text=[This is the usual way around the contract model;
1874 this applies even in instance bodies. Note that errors in instance
1875 specifications will be detected at compile-time by the "re-check" of the
1876 specification, only errors in the body should raise Program_Error.]}
1877 @end{Discussion}
1878
1879 @ChgRef{Version=[4],Kind=[Added],ARef=[AI12-0071-1]}
1880 @ChgAdded{Version=[4],Type=[Leading],Text=[To determine whether a value
1881 @i<satisfies the predicates> of a subtype @i<S>,
1882 the following tests are performed in the following order, until one of
1883 the tests fails, in which case the predicates are not satisfied and no further
1884 tests are performed, or all of the tests succeed, in which case the
1885 predicates are
1886 satisfied:@Defn2{Term=[satisfies the predicates],Sec=(of a subtype)}@Defn{predicates satisfied}]}
1887
1888 @begin{Itemize}
1889 @ChgRef{Version=[4],Kind=[Added]}
1890 @ChgAdded{Version=[4],Text=[the value is first tested to determine whether it
1891 satisfies any constraints or any null exclusion of @i<S>;]}
1892
1893 @ChgRef{Version=[4],Kind=[Added]}
1894 @ChgAdded{Version=[4],Type=[Leading],Text=[then:]}
1895
1896 @begin{Itemize}
1897 @ChgRef{Version=[4],Kind=[Added]}
1898 @ChgAdded{Version=[4],Text=[if @i<S> is a first subtype, the value is
1899 tested to determine whether it satisfies the predicates of the parent
1900 and progenitor subtypes (if any) of @i<S> (in an arbitrary order);]}
1901
1902 @begin{Ramification}
1903 @ChgRef{Version=[4],Kind=[AddedNormal]}
1904 @ChgAdded{Version=[4],Text=[This rule has an effect for derived types
1905 (which have a parent subtype and may have progenitors) and for
1906 task and protected types (which may have progentitors). Other kinds
1907 of type declarations can have neither, and no test is required for
1908 other first subtypes.]}
1909 @end{Ramification}
1910
1911 @ChgRef{Version=[4],Kind=[Added]}
1912 @ChgAdded{Version=[4],Text=[if @i<S> is defined by a
1913 @nt{subtype_indication}, the value is tested to determine whether it
1914 satisfies the predicates of the subtype denoted by the @nt{subtype_mark}
1915 of the @nt{subtype_indication};]}
1916 @end{Itemize}
1917
1918 @ChgRef{Version=[4],Kind=[Added]}
1919 @ChgAdded{Version=[4],Text=[finally, if @i<S> is defined by a declaration to
1920 which one or more predicate specifications apply, the predicates are
1921 evaluated (in an arbitrary order) to test that all of them yield True for
1922 the given value.]}
1923 @end{Itemize}
1924
1925 @begin{Discussion}
1926 @ChgRef{Version=[4],Kind=[Added]}
1927 @ChgAdded{Version=[4],Text=[It is important to stop on the first of the above
1928 steps that fails, as later steps might presume that the earlier steps had
1929 succeeded.]}
1930 @end{Discussion}
1931
1932 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0153-3],ARef=[AI05-0290-1]}
1933 @ChgAdded{Version=[3],Type=[Leading],Text=[If predicate checks are enabled for a
1934 given subtype, then:]}
1935 @begin{DescribeCode}
1936 @ChgRef{Version=[3],Kind=[AddedNormal]}
1937 @ChgRef{Version=[4],Kind=[Revised],ARef=[AI12-0054-2],ARef=[AI12-0071-1]}
1938 @ChgRef{Version=[5],Kind=[Revised],ARef=[AI12-0301-1],ARef=[AI12-0333-1]}
1939 @ChgAdded{Version=[3],Text=[@Redundant[On @Chg{Version=[5],New=[a],Old=[every]}
1940 subtype conversion,
1941 @Chg{Version=[4],New=[],Old=[the predicate of the target subtype
1942 is evaluated, and ]}a check is performed that
1943 the @Chg{Version=[4],New=[operand satisfies the predicates of the target
1944 subtype], Old=[predicate is True]}@Chg{Version=[5],New=[, unless it is a
1945 conversion for an actual parameter of mode @key[out]
1946 (see @RefSecNum{Type Conversions})],Old=[]}.@Chg{Version=[5],New=[],Old=[ This
1947 includes all parameter passing,
1948 except for certain parameters passed by reference, which are covered by the
1949 following rule:]}] @Chg{Version=[5],New=[In addition, after],Old=[After]}
1950 normal completion and leaving of a subprogram,
1951 for each @key[in out] or @key[out] parameter that is passed by reference,
1952 @Chg{Version=[4],New=[],Old=[the predicate of the subtype of the actual is
1953 evaluated, and ]}a check is performed that the @Chg{Version=[4],New=[value of
1954 the parameter satisfies the predicates of the subtype of the
1955 actual],Old=[predicate is True]}. For an object created
1956 by an @nt{object_declaration} with no explicit initialization @nt{expression},
1957 or by an uninitialized @nt{allocator}, if @Chg{Version=[5],New=[the types of
1958 any parts have specified Default_Value or Default_Component_Value aspects,
1959 or ],Old=[]}any subcomponents have
1960 @nt{default_expression}s, @Chg{Version=[4],New=[],Old=[the predicate of the
1961 nominal subtype of the created object is evaluated, and ]}a check is performed
1962 that the @Chg{Version=[4],New=[value of
1963 the created object satisfies the predicates of the nominal subtype],
1964 Old=[predicate is True]}.@Chg{Version=[4],New=[],Old=[ Assertions.Assertion_Error
1965 is raised if any of these checks fail.]}@Defn2{Term=[predicate check],
1966 Sec=[@key[in out] parameters]}@Defn2{Term=[predicate check],
1967 Sec=[@nt{object_declaration}]}@Defn2{Term=[predicate check],
1968 Sec=[@nt{allocator}]}@Defn2{Term=[check, language-defined],
1969 Sec=[controlled by assertion policy]}@Chg{Version=[4],New=[],
1970 Old=[@Defn2{Term=(Assertion_Error), Sec=(raised by failure of runtime check)}]}]}
1971
1972 @begin{Ramification}
1973 @ChgRef{Version=[5],Kind=[Added],ARef=[AI12-0333-1]}
1974 @ChgAdded{Version=[5],Text=[Most parameter passing is covered by the subtype
1975 conversion rule: all inbound @key[in] and @key[in out] parameters are converted
1976 to the formal subtype, and the copy-back for by-copy @key[out] and @key[in out]
1977 parameters includes a conversion to the actual subtype. The remaining parameter
1978 passing cases are covered by special rules: by-reference @key[out] and
1979 @key[in out] parameters by the rule given above, and we don't want any
1980 predicate checks on inbound @key[out] parameters, accomplished in part
1981 by a special rule in @Refsecnum{Type Conversions}.]}
1982 @end{Ramification}
1983
1984 @ChgRef{Version=[4],Kind=[Added],ARef=[AI12-0054-2]}
1985 @ChgAdded{Version=[4],Text=[If any of the predicate checks fail,
1986 Assertion_Error is raised, unless the subtype whose directly-specified predicate
1987 aspect evaluated to False also has a directly-specified Predicate_Failure
1988 aspect. In that case, the specified Predicate_Failure @nt{expression} is
1989 evaluated; if the evaluation of the Predicate_Failure @nt{expression}
1990 propagates an exception occurrence, then this occurrence is propagated for the
1991 failure of the predicate check; otherwise, Assertion_Error is raised, with an
1992 associated message string defined by the value of the Predicate_Failure
1993 @nt{expression}. In the absence of such a Predicate_Failure aspect, an
1994 implementation-defined message string is associated with the Assertion_Error
1995 exception.@Defn2{Term=(Assertion_Error), Sec=(raised by failure of runtime check)}]}
1996
1997 @begin{Ramification}
1998 @ChgRef{Version=[3],Kind=[AddedNormal]}
1999 @ChgAdded{Version=[3],Text=<Predicates are not evaluated at the point of the
2000 (sub)type declaration.>}
2001 @end{Ramification}
2002
2003 @begin{ImplNote}
2004 @ChgRef{Version=[3],Kind=[AddedNormal]}
2005 @ChgAdded{Version=[3],Text=[Static_Predicate checks can be removed even in the
2006 presence of potentially invalid values, just as constraint checks can be
2007 removed.]}
2008 @end{ImplNote}
2009
2010 @ChgImplDef{Version=[4],Kind=[AddedNormal],Text=[@ChgAdded{Version=[4],
2011 Text=[The message string associated with the Assertion_Error exception
2012 raised by the failure of a predicate check if there is no applicable
2013 Predicate_Failure aspect.]}]}
2014 @end{DescribeCode}
2015
2016 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0262-1]}
2017 @ChgRef{Version=[4],Kind=[Deleted],ARef=[AI12-0071-1]}
2018 @ChgAdded{Version=[3],Text=[@Chg{Version=[4],New=[],Old=[A value @i<satisfies> a
2019 predicate if the predicate is True for that
2020 value.@PDefn2{Term=[satisfies], Sec=(a subtype predicate)}]}]}
2021
2022 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0153-3],ARef=[AI05-0276-1]}
2023 @ChgRef{Version=[4],Kind=[Deleted],ARef=[AI12-0071-1]}
2024 @ChgAdded{Version=[3],Text=[@Chg{Version=[4],New=[],Old=[If any of the above
2025 @LegalityTitle is violated in an instance of a generic unit, Program_Error is
2026 raised at the point of the violation.@Defn2{Term=[Program_Error],Sec=(raised by failure of runtime check)}]}]}
2027
2028 @begin{Discussion}
2029 @ChgRef{Version=[3],Kind=[AddedNormal]}
2030 @ChgRef{Version=[4],Kind=[Deleted]}
2031 @ChgAdded{Version=[3],Text=[@Chg{Version=[4],New=[],Old=[This is the usual
2032 way around the contract model; this applies even in instance bodies. Note
2033 that errors in instance specifications will be detected at compile-time
2034 by the "re-check" of the specification, only errors in the body should
2035 raise Program_Error.]}]}
2036 @end{Discussion}
2037
2038 @end{Runtime}
2039
2040 @begin{Notes}
2041 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0153-3]}
2042 @ChgAdded{Version=[3],Text=[A predicate specification does not cause a subtype
2043 to be considered constrained.]}
2044
2045 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0153-3]}
2046 @ChgAdded{Version=[3],Text=[A Static_Predicate, like a constraint, always
2047 remains True for all objects of the subtype, except in the case of uninitialized
2048 variables and other invalid values. A Dynamic_Predicate, on the other hand, is
2049 checked as specified above, but can become False at other times. For example,
2050 the predicate of a record subtype is not checked when a subcomponent is
2051 modified.]}
2052
2053 @ChgRef{Version=[4],Kind=[AddedNormal],ARef=[AI12-0071-1]}
2054 @ChgAdded{Version=[4],Text=[No predicates apply to the base subtype of a
2055 scalar type; every value of a scalar type @i<T> is considered to satisfy
2056 the predicates of @i<T>'Base.]}
2057
2058 @ChgRef{Version=[4],Kind=[AddedNormal],ARef=[AI12-0054-2]}
2059 @ChgAdded{Version=[4],Text=[Predicate_Failure @nt{expression}s are never
2060 evaluated during the evaluation of a membership test (see
2061 @RefSecNum{Relational Operators and Membership Tests}) or Valid attribute
2062 (see @RefSecNum{The Valid Attribute}).]}
2063
2064 @ChgRef{Version=[4],Kind=[AddedNormal],ARef=[AI12-0054-2]}
2065 @ChgAdded{Version=[4],Text=[A Predicate_Failure @nt{expression} can be a
2066 @nt{raise_expression} (see @RefSecNum{Raise Statements and Raise Expressions}).]}
2067 @end{Notes}
2068
2069 @begin{Examples}
2070 @begin(Example)
2071 @ChgRef{Version=[4],Kind=[AddedNormal],ARef=[AI12-0054-2]}
2072 @ChgAdded{Version=[4],Text=[@key[subtype] Basic_Letter @key[is] Character -- @examcom[See @RefSecNum{The Package Characters.Handling} for "basic letter".]
2073 @key[with] Static_Predicate => Basic_Letter @key[in] 'A'..'Z' | 'a'..'z' | '@latin1(198)' | '@latin1(230)' | '@latin1(208)' | '@latin1(240)' | '@latin1(222)' | '@latin1(254)' | '@latin1(223)';]}
2074
2075 @ChgRef{Version=[4],Kind=[AddedNormal],ARef=[AI12-0054-2]}
2076 @ChgAdded{Version=[4],Text=[@key[subtype] Even_Integer @key[is] Integer
2077 @key[with] Dynamic_Predicate => Even_Integer @key[mod] 2 = 0,
2078 Predicate_Failure => "Even_Integer must be a multiple of 2";]}
2079 @end(Example)
2080
2081 @ChgRef{Version=[4],Kind=[AddedNormal],ARef=[AI12-0054-2]}
2082 @ChgAdded{Version=[4],Type=[Leading],Text=[@i{Text_IO (see
2083 @RefSecNum{The Package Text_IO}) could have used predicates to describe some
2084 common exceptional conditions as follows:}]}
2085
2086 @begin(Example)
2087 @ChgRef{Version=[4],Kind=[AddedNormal]}
2088 @ChgAdded{Version=[4],Text=[@key[with] Ada.IO_Exceptions;
2089 @key[package] Ada.Text_IO @key[is]]}
2090
2091 @ChgRef{Version=[4],Kind=[AddedNormal]}
2092 @ChgAdded{Version=[4],Text=[ @key[type] File_Type @key[is limited private];]}
2093
2094 @ChgRef{Version=[4],Kind=[AddedNormal]}
2095 @ChgAdded{Version=[4],Text=[ @key[subtype] Open_File_Type @key[is] File_Type
2096 @key[with] Dynamic_Predicate => Is_Open (Open_File_Type),
2097 Predicate_Failure => @key[raise] Status_Error @key[with] "File not open";
2098 @key[subtype] Input_File_Type @key[is] Open_File_Type
2099 @key[with] Dynamic_Predicate => Mode (Input_File_Type) = In_File,
2100 Predicate_Failure => @key[raise] Mode_Error @key[with] "Cannot read file: " &
2101 Name (Input_File_Type);
2102 @key[subtype] Output_File_Type @key[is] Open_File_Type
2103 @key[with] Dynamic_Predicate => Mode (Output_File_Type) /= In_File,
2104 Predicate_Failure => @key[raise] Mode_Error @key[with] "Cannot write file: " &
2105 Name (Output_File_Type);]}
2106
2107 @ChgRef{Version=[4],Kind=[AddedNormal]}
2108 @ChgAdded{Version=[4],Text=[ ...]}
2109
2110 @ChgRef{Version=[4],Kind=[AddedNormal]}
2111 @ChgAdded{Version=[4],Text=[ @key[function] Mode (File : @key[in] Open_File_Type) @key[return] File_Mode;
2112 @key[function] Name (File : @key[in] Open_File_Type) @key[return] String;
2113 @key[function] Form (File : @key[in] Open_File_Type) @key[return] String;]}
2114
2115 @ChgRef{Version=[4],Kind=[AddedNormal]}
2116 @ChgAdded{Version=[4],Text=[ ...]}
2117
2118 @ChgRef{Version=[4],Kind=[AddedNormal]}
2119 @ChgAdded{Version=[4],Text=[ @key[procedure] Get (File : @key[in] Input_File_Type; Item : @key[out] Character);]}
2120
2121 @ChgRef{Version=[4],Kind=[AddedNormal]}
2122 @ChgAdded{Version=[4],Text=[ @key[procedure] Put (File : @key[in] Output_File_Type; Item : @key[in] Character);]}
2123
2124 @ChgRef{Version=[4],Kind=[AddedNormal]}
2125 @ChgAdded{Version=[4],Text=[ ...]}
2126
2127 @ChgRef{Version=[4],Kind=[AddedNormal]}
2128 @ChgAdded{Version=[4],Text=[ -- @examcom[Similarly for all of the other input and output subprograms.]]}
2129
2130 @begin{Discussion}
2131 @ChgRef{Version=[5],Kind=[AddedNormal]}
2132 @ChgAdded{Version=[5],Text=[We didn't change the language-defined Text_IO
2133 this way for Ada 202x as it would be incompatible in marginal cases: these
2134 subprogram specifications would not be subtype conformant with existing
2135 access-to-subprogram types, so Put_Line'Access (for instance) would become
2136 illegal in existing code. The gain would not be worth the disruption.]}
2137 @end{Discussion}
2138
2139 @end(Example)
2140 @end{Examples}
2141
2142 @begin{Extend2005}
2143 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0153-3],ARef=[AI05-0262-1],ARef=[AI05-0276-1],ARef=[AI05-0290-1]}
2144 @ChgAdded{Version=[3],Text=[@Defn{extensions to Ada 2005}
2145 Predicate aspects are new in Ada 2012.]}
2146 @end{Extend2005}
2147
2148 @begin{Inconsistent2012}
2149 @ChgRef{Version=[5],Kind=[AddedNormal],ARef=[AI12-0301-1]}
2150 @ChgAdded{Version=[5],Text=[@Defn{inconsistencies with Ada 2012}
2151 @b<Correction:> Predicate checks are now performed on default-initialized
2152 objects with parts that have Default_Value or Default_Component_Value
2153 specified. This is consistent with the handling of constraint checks for
2154 such objects; it is thought that the omission was unintended. However,
2155 a program that declares such an object and depends on there not being a
2156 predicate check in original Ada 2012 will fail in Ada 202x. As these
2157 attributes were new in Ada 2012, their use is uncommon, so we believe
2158 that this inconsistency will be rare and more likely to catch a bug than
2159 create one.]}
2160 @end{Inconsistent2012}
2161
2162 @begin{Extend2012}
2163 @ChgRef{Version=[4],Kind=[AddedNormal],ARef=[AI12-0054-2]}
2164 @ChgAdded{Version=[4],Text=[@Defn{extensions to Ada 2012}
2165 @b<Corrigendum:> The Predicate_Failure aspect is new. We can consider this
2166 a correction as it is always possible for implementers to add
2167 implementation-defined aspects, so the same is true for language-defined
2168 aspects.]}
2169 @end{Extend2012}
2170
2171 @begin{Diffword2012}
2172 @ChgRef{Version=[4],Kind=[AddedNormal],ARef=[AI12-0071-1]}
2173 @ChgAdded{Version=[4],Text=[@b<Corrigendum:> Specified the order of
2174 evaluation of most predicates, by defining the new term "satisfies the
2175 predicates of the subtype". This is not inconsistent, as the order
2176 previously was unspecified, so any code depending on the order was
2177 incorrect. The change is necessary so that the Predicate_Failure
2178 aspect has consistent results in cases where multiple predicates and
2179 aspects apply; see the Ada.Text_IO example above for such a case.]}
2180
2181 @ChgRef{Version=[4],Kind=[AddedNormal],ARef=[AI12-0099-1]}
2182 @ChgAdded{Version=[4],Text=[@b<Corrigendum:> Revised wording to ensure all
2183 kinds of types are covered, including the anonymous task associated with
2184 a @nt{single_task_declaration}, and generalized it.]}
2185
2186 @ChgRef{Version=[4],Kind=[AddedNormal],ARef=[AI12-0099-1]}
2187 @ChgAdded{Version=[4],Text=[@b<Corrigendum:> Revised wording to list the
2188 boolean operators that can be predicate-static, to eliminate confusion
2189 about whether @key[not] is included.]}
2190
2191 @ChgRef{Version=[5],Kind=[AddedNormal],ARef=[AI12-0333-1]}
2192 @ChgAdded{Version=[5],Text=[@b<Correction:> Predicate checks are no
2193 longer made for any inbound @key[out] parameters. The rule change for
2194 this is found in @RefSecNum{Type Conversions}, so the inconsistency is
2195 documented there.]}
2196 @end{Diffword2012}
2197
2198
2199
2200 @LabeledClause{Objects and Named Numbers}
2201
2202 @begin{Intro}
2203 @redundant[Objects are created at run time
2204 and contain a value of a given type.
2205 @Defn2{Term=[creation], Sec=(of an object)}
2206 An object can be created and
2207 initialized as part of elaborating a
2208 declaration, evaluating an @nt<allocator>, @nt<aggregate>,
2209 or @nt<function_call>, or passing a parameter by copy.
2210 Prior to reclaiming the storage for an object, it is finalized if
2211 necessary (see @RefSecNum(Completion and Finalization)).]
2212 @end{Intro}
2213
2214 @begin{StaticSem}
2215
2216 @Leading@keepnext@Defn{object}
2217 All of the following are objects:
2218 @ToGlossary{Term=<Object>,
2219 Text=<An object is either a constant or a variable.
2220 An object contains a value.
2221 An object is created by an @nt(object_declaration)
2222 or by an @nt(allocator).
2223 A formal parameter is (a view of) an object.
2224 A subcomponent of an object is an object.>}
2225 @begin(itemize)
2226 the entity declared by
2227 an @nt<object_declaration>;
2228
2229 a formal parameter of a subprogram, entry, or generic subprogram;
2230
2231 a generic formal object;
2232
2233 a loop parameter;
2234
2235 @ChgRef{Version=[5],Kind=[Added],ARef=[AI12-0061-1]}
2236 @ChgAdded{Version=[5],Text=[the index parameter of an @nt{iterated_component_association};]}
2237
2238 @ChgRef{Version=[5],Kind=[Added],ARef=[AI12-0308-1]}
2239 @ChgAdded{Version=[5],Text=[the chunk parameter of a @nt{chunk_specification};]}
2240
2241 a choice parameter of an @nt<exception_handler>;
2242
2243 an entry index of an @nt<entry_body>;
2244
2245 the result of dereferencing an
2246 access-to-object value (see @RefSecNum{Names});
2247
2248 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00416-01]}
2249 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0015-1]}
2250 the @Chg{Version=[2],New=[return object ],Old=[]}@Chg{Version=[3],
2251 New=[of a function],Old=[@Chg{Version=[2],New=[created as the ],Old=[]}result
2252 of evaluating a @nt<function_call> (or the equivalent
2253 operator invocation @em see @RefSecNum{Overloading of Operators})]};
2254
2255 the result of evaluating an @nt<aggregate>;
2256
2257 @ChgRef{Version=[3],Kind=[Added],ARef=[AI05-0003-1]}
2258 @ChgRef{Version=[5],Kind=[RevisedAdded],ARef=[AI12-0226-1]}
2259 @ChgAdded{Version=[3],Text=[a @Chg{Version=[5],New=[value conversion or ],
2260 Old=[]}@nt{qualified_expression} whose operand denotes an object;]}
2261
2262 a component, slice, or view conversion of another object.
2263 @end(itemize)
2264
2265 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0054-2]}
2266 @Defn{constant}
2267 @Defn{variable}
2268 @Defn{constant object}
2269 @Defn{variable object}
2270 @Defn{constant view}
2271 @Defn{variable view}
2272 An object is either a @i(constant) object or a @i(variable)
2273 object.@Chg{Version=[3],New=[],Old=[ The value of a constant object
2274 cannot be changed between its initialization
2275 and its finalization, whereas the value of a variable object can be
2276 changed.]}
2277 Similarly, a view of an object is either a @i(constant) or
2278 a @i(variable). All views of a constant
2279 @Chg{Version=[3],New=[elementary ],Old=[]}object are constant.
2280 @Chg{Version=[3],New=[All views of a constant composite object are
2281 constant, except for parts that are of controlled or immutably limited
2282 types; variable views of those parts and their subcomponents
2283 may exist. In this sense, objects of controlled and immutably
2284 limited types are @i<inherently mutable>@Defn{inherently mutable object}. ],Old=[]}A
2285 constant view of @Chg{Version=[3],New=[an],Old=[a variable]} object
2286 cannot be used to modify @Chg{Version=[3],New=[its value],Old=[the value
2287 of the variable]}. The terms constant and variable by themselves
2288 refer to constant and variable views of objects.
2289
2290 @Defn2{Term=[read], Sec=(the value of an object)}
2291 The value of an object
2292 is @i(read) when the value of any part of the object is evaluated,
2293 or when the value of an enclosing object is evaluated.
2294 @Defn2{Term=[update], Sec=(the value of an object)}
2295 The value of a variable
2296 is @i(updated) when an assignment is performed to any part of the
2297 variable, or when an assignment is performed to an enclosing object.
2298 @begin{Ramification}
2299 Reading and updating are intended to include read/write references of
2300 any kind, even if they are not associated with the evaluation of a
2301 particular construct. Consider, for example, the expression
2302 @lquotes@;X.@key[all](F)@rquotes@;,
2303 where X is an access-to-array object, and F is a function.
2304 The implementation is allowed to first evaluate @lquotes@;X.@key[all]@rquotes@;
2305 and then F.
2306 Finally, a read is performed to get the value of the F'th component of
2307 the array.
2308 Note that the array is not necessarily read as part of the evaluation of
2309 @lquotes@;X.@key[all]@rquotes@;.
2310 This is important, because if F were to free X using
2311 Unchecked_Deallocation, we want the execution of the final read to be
2312 erroneous.
2313 @end{Ramification}
2314
2315 @Leading@;Whether a view of an object is constant or variable is determined
2316 by the definition of the view.
2317 The following (and no others) represent constants:
2318 @begin(itemize)
2319 an object declared by an @nt<object_declaration> with the
2320 reserved word @key(constant);
2321
2322 @begin{Honest}
2323 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00385-01]}
2324 @ChgAdded{Version=[2],Type=[Leading],Text=[We mean the word @key{constant}
2325 as defined by the grammar for @nt{object_declaration}, not some random word
2326 @key{constant}. Thus,]}
2327 @begin{Example}
2328 @ChgRef{Version=[2],Kind=[AddedNormal]}
2329 @ChgAdded{Version=[2],Text=[X : @key{access constant} T;]}
2330 @end{Example}
2331 @ChgRef{Version=[2],Kind=[AddedNormal]}
2332 @ChgAdded{Version=[2],Text=[is not a constant.]}
2333 @end{Honest}
2334
2335 a formal parameter or generic formal object of mode @key(in);
2336
2337 a discriminant;
2338
2339 @ChgRef{Version=[3],Kind=[Added],ARef=[AI05-0262-1]}
2340 @ChgAdded{Version=[3],Text=[a loop parameter unless specified to be a variable
2341 for a generalized loop (see @RefSecNum{Generalized Loop Iteration});]}
2342
2343 @ChgRef{Version=[5],Kind=[Added],ARef=[AI12-0061-1]}
2344 @ChgAdded{Version=[5],Text=[the index parameter of an @nt{iterated_component_association};]}
2345
2346 @ChgRef{Version=[5],Kind=[Added],ARef=[AI12-0308-1]}
2347 @ChgAdded{Version=[5],Text=[the chunk parameter of a @nt{chunk_specification};]}
2348
2349 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0262-1]}
2350 a @Chg{Version=[3],New=[],Old=[loop parameter, ]}choice
2351 parameter@Chg{Version=[3],New=[],Old=[,]} or entry index;
2352
2353 the dereference of an access-to-constant value;
2354
2355 @ChgRef{Version=[3],Kind=[Added],ARef=[AI05-0015-1]}
2356 @ChgAdded{Version=[3],Text=[the return object declared by an
2357 @nt{extended_return_statement} with the reserved word @key[constant];]}
2358
2359 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0015-1]}
2360 the @Chg{Version=[3],New=[object denoted by],Old=[result of evaluating]}
2361 a @nt<function_call> or an @nt<aggregate>;
2362
2363 @ChgRef{Version=[3],Kind=[Added],ARef=[AI05-0003-1]}
2364 @ChgRef{Version=[5],Kind=[RevisedAdded],ARef=[AI12-0226-1]}
2365 @ChgAdded{Version=[3],Text=[the result of evaluating a
2366 @Chg{Version=[5],New=[value conversion
2367 or ],Old=[]}@nt{qualified_expression};]}
2368
2369 @ChgRef{Version=[5],Kind=[Added],ARef=[AI12-0125-3]}
2370 @ChgAdded{Version=[5],Text=[a @nt{target_name} of an
2371 @nt{assignment_statement} when used in the @nt{expression} of the assignment
2372 (see @RefSecNum{Target Name Symbols});]}
2373
2374 @ChgRef{Version=[3],Kind=[Added],ARef=[AI05-0120-1]}
2375 @ChgRef{Version=[5],Kind=[RevisedAdded],ARef=[AI12-0125-3]}@Comment{Just a paragraph number change.}
2376 @ChgAdded{Version=[3],Text=[within the body of a protected function (or a
2377 function declared immediately within a @nt{protected_body}), the current
2378 instance of the enclosing protected unit;]}
2379
2380 a @nt<selected_component>, @nt<indexed_component>,
2381 @nt<slice>, or view conversion of a constant.
2382 @begin{Honest}
2383 @ChgRef{Version=[2],Kind=[DeletedNoDelMsg],ARef=[AI95-00114-01]}
2384 @ChgNote{This is just wrong, even for Ada 95.}
2385 @ChgDeleted{Version=[2],Text=[A noninvertible view conversion to a
2386 general access type
2387 is also defined to be a constant @em see @RefSecNum(Type Conversions).]}
2388 @end{Honest}
2389
2390 @end(itemize)
2391
2392 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0264-1]}
2393 @ChgRef{Version=[5],Kind=[Revised],ARef=[AI12-0191-1],ARef=[AI12-0294-1]}
2394 @Defn{nominal subtype}
2395 At the place where a view of an
2396 object is defined, a @i(nominal subtype) is associated
2397 with the view.@Chg{Version=[5],New=[ The @i<nominal type>@Defn{nominal type}
2398 of a view is the type of the nominal subtype of the view.],Old=[]}
2399 @Defn{actual subtype}
2400 @IndexSee{Term=[subtype (of an object)],See=(actual subtype of an object)}
2401 The object's @i(actual subtype) (that is, its
2402 subtype) can be more restrictive than
2403 the nominal subtype of the view; it always is
2404 @Chg{Version=[5],New=[more restrictive ],Old=[]}if the nominal subtype
2405 is an @i(indefinite subtype).
2406 @Defn{indefinite subtype}
2407 @Defn{definite subtype}
2408 A subtype is an indefinite subtype if it is an unconstrained array
2409 subtype, or if it has unknown discriminants or unconstrained
2410 discriminants without defaults (see @RefSecNum(Discriminants));
2411 otherwise@Chg{Version=[3],New=[,],Old=[]} the subtype is a @i{definite}
2412 subtype @Redundant[(all elementary subtypes are definite subtypes)].
2413 @redundant[A class-wide subtype is defined to have unknown discriminants,
2414 and is therefore an indefinite subtype.
2415 An indefinite subtype does not by itself
2416 provide enough information to create an object;
2417 an additional @nt<constraint> or
2418 explicit initialization @nt<expression>
2419 is necessary (see @RefSecNum(Object Declarations)).
2420 A component cannot have an indefinite nominal subtype.]
2421
2422 @ChgRef{Version=[3],Kind=[Added],ARef=[AI05-0008-1]}
2423 @ChgAdded{Version=[3],Type=[Leading],Text=[A view of a composite object is
2424 @i<known to be constrained> if:@Defn{known to be constrained}@Defn2{Term=[constrained],Sec=[known to be]}]}
2425
2426 @begin{Itemize}
2427
2428 @ChgRef{Version=[3],Kind=[Added]}
2429 @ChgAdded{Version=[3],Text=[its nominal subtype is constrained, and is not an
2430 untagged partial view; or]}
2431
2432 @ChgRef{Version=[3],Kind=[Added]}
2433 @ChgAdded{Version=[3],Text=[its nominal subtype is indefinite; or]}
2434
2435 @ChgRef{Version=[3],Kind=[Added],ARef=[AI05-0008-1],ARef=[AI05-0093-1]}
2436 @ChgAdded{Version=[3],Text=[its type is immutably limited (see @RefSecNum{Limited Types}); or]}
2437
2438 @ChgRef{Version=[3],Kind=[Added]}
2439 @ChgAdded{Version=[3],Text=[it is part of a stand-alone constant (including a
2440 generic formal object of mode @key[in]); or]}
2441
2442 @ChgRef{Version=[3],Kind=[Added]}
2443 @ChgAdded{Version=[3],Text=[it is part of a formal parameter of mode @key[in]; or]}
2444
2445 @ChgRef{Version=[3],Kind=[Added]}
2446 @ChgAdded{Version=[3],Text=[it is part of the object denoted by a
2447 @nt{function_call} or @nt{aggregate}; or]}
2448
2449 @ChgRef{Version=[5],Kind=[Added],ARef=[AI12-0226-1],ARef=[AI12-0228-1]}
2450 @ChgAdded{Version=[5],Text=[it is a value conversion or
2451 @nt{qualified_expression} where the operand
2452 denotes a view of a composite object that is known to be constrained; or]}
2453
2454 @ChgRef{Version=[3],Kind=[Added]}
2455 @ChgRef{Version=[5],Kind=[RevisedAdded],ARef=[AI12-0228-1]}@Comment{Just the paragraph number}
2456 @ChgAdded{Version=[3],Text=[it is part of a constant return object of an
2457 @nt{extended_return_statement}; or]}
2458
2459 @ChgRef{Version=[3],Kind=[Added],ARef=[AI05-0008-1],ARef=[AI05-0041-1]}
2460 @ChgRef{Version=[5],Kind=[RevisedAdded],ARef=[AI12-0228-1]}@Comment{Just the paragraph number}
2461 @ChgAdded{Version=[3],Text=[it is a dereference of a pool-specific access type,
2462 and there is no ancestor of its type that has a constrained partial view.]}
2463
2464 @end{Itemize}
2465
2466 @begin{Discussion}
2467 @ChgRef{Version=[3],Kind=[AddedNormal]}
2468 @ChgAdded{Version=[3],Text=[We do not include dereferences of general access
2469 types because they might denote stand-alone aliased unconstrained variables.
2470 That's true even for access-to-constant types (the denoted object does not
2471 have to be a constant).]}
2472
2473 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0005-1],ARef=[AI05-0008-1]}
2474 @ChgRef{Version=[5],Kind=[Revised],ARef=[AI12-0228-1]}
2475 @ChgAdded{Version=[3],Text=[@Chg{Version=[5],New=[We don't mention view
2476 conversions as there are no mutable tagged types
2477 (discriminant defaults are allowed only if the type is immutably limited),
2478 so all tagged view conversions are either of an indefinite type (if it has
2479 discriminants without defaults), an immutably limited type (if the
2480 discriminants do have defaults), or constrained (if there are no discriminants).
2481 This matches the first three bullets here, so all tagged view conversions are
2482 known to be constrained without needing to mention them explicitly. Untagged
2483 view conversions only can occur in parameter passing (as actuals to @key[in out]
2484 or @key[out] parameters), and "known to be constrained" is not used there.],Old=[There are other
2485 cases that could have been included in this definition (view conversions,
2486 the current instance of
2487 a type, objects of a formal discriminated
2488 private type), but these are not relevant to the places this term is
2489 used, so they were not included. If this term is used in additional places,
2490 the definition should be checked to see if any of these additional cases
2491 are relevant and appropriate wording added if necessary.]}]}
2492
2493 @ChgRef{Version=[5],Kind=[AddedNormal],ARef=[AI12-0228-1]}
2494 @ChgAdded{Version=[5],Text=[We don't need to mention the current instance
2495 of a (sub)type, either. If a current instance of a type or subtype
2496 appears in an aspect specification, it represents a value, so whether or not
2497 it is known to be constrained is irrelevant (the term is only defined for
2498 composite objects). Otherwise, the current instance of a type can only be used
2499 in an immutably limited type, so all such instances are known to be
2500 constrained by the third bullet.]}
2501 @end{Discussion}
2502
2503 @ChgRef{Version=[3],Kind=[Added],ARef=[AI05-0008-1],ARef=[AI05-0041-1]}
2504 @ChgRef{Version=[5],Kind=[RevisedAdded],ARef=[AI12-0228-1]}@Comment{Just the paragraph number}
2505 @ChgAdded{Version=[3],Type=[Leading],Keepnext=[T],Text=[For the purposes of
2506 determining within a generic body whether an object is known
2507 to be constrained:]}
2508 @begin{Itemize}
2509 @ChgRef{Version=[3],Kind=[Added]}
2510 @ChgRef{Version=[5],Kind=[RevisedAdded]}@Comment{Just the paragraph number}
2511 @ChgAdded{Version=[3],Text=[if a subtype is a descendant of an untagged generic
2512 formal private or derived type, and the subtype is not an unconstrained array
2513 subtype, it is not considered indefinite and is considered to have a
2514 constrained partial view;]}
2515
2516 @ChgRef{Version=[3],Kind=[Added]}
2517 @ChgRef{Version=[5],Kind=[RevisedAdded]}@Comment{Just the paragraph number}
2518 @ChgAdded{Version=[3],Text=[if a subtype is a descendant of a formal access type, it is not
2519 considered pool-specific.]}
2520
2521 @end{Itemize}
2522
2523
2524 @Defn{named number}
2525 A @i(named number) provides a name for a numeric value known
2526 at compile time. It is declared by a @nt<number_declaration>.
2527 @end{StaticSem}
2528
2529 @begin{Notes}
2530 A constant cannot be the target of an assignment operation, nor be
2531 passed as an @key(in) @key(out) or @key(out)
2532 parameter, between its initialization and finalization, if any.
2533
2534 @ChgRef{Version=[3],Kind=[Added],ARef=[AI05-0054-2]}
2535 @ChgAdded{Version=[3],Text=[The value of a constant object cannot be
2536 changed after its initialization, except in some cases where the
2537 object has a controlled or immutably limited part (see
2538 @RefSecNum{Limited Types}, @RefSecNum{Assignment and Finalization},
2539 and @RefSecNum{Data Validity}).]}
2540
2541 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0264-1]}
2542 The nominal and actual subtypes of an elementary object are
2543 always the same. For a discriminated or array object,
2544 if the nominal subtype is constrained@Chg{Version=[3],New=[,],Old=[]} then so is
2545 the actual subtype.
2546 @end{Notes}
2547
2548 @begin{Extend83}
2549 @Defn{extensions to Ada 83}
2550 There are additional kinds of objects (choice parameters and
2551 entry indices of entry bodies).
2552
2553 The result of a function and of evaluating an aggregate
2554 are considered (constant) objects. This is necessary to explain
2555 the action of finalization on such things.
2556 Because a @nt<function_call> is also syntactically a @nt<name>
2557 (see @RefSecNum(Names)), the result of a @nt{function_call} can be renamed,
2558 thereby allowing repeated use of the result without calling
2559 the function again.
2560 @end{Extend83}
2561
2562 @begin{DiffWord83}
2563 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0299-1]}
2564 This @Chg{Version=[3],New=[subclause],Old=[clause and its subclauses]}
2565 now @Chg{Version=[3],New=[follows],Old=[follow]} the
2566 @Chg{Version=[3],New=[],Old=[clause and ]}subclauses on types and subtypes,
2567 to cut down on the number of forward references.
2568
2569 The term nominal subtype is new. It is used to distinguish
2570 what is known at compile time about an object's constraint, versus what
2571 its "true" run-time constraint is.
2572
2573 The terms definite and indefinite (which apply to
2574 subtypes) are new.
2575 They are used to aid in the description of generic formal
2576 type matching,
2577 and to specify when an explicit initial value is required
2578 in an @nt<object_declaration>.
2579
2580 We have moved the syntax for @nt<object_declaration> and
2581 @nt<number_declaration> down into their respective subclauses, to
2582 keep the syntax close to the description of the associated semantics.
2583
2584 We talk about variables and constants here, since the discussion is
2585 not specific to @nt<object_declaration>s, and it seems
2586 better to have the list of the kinds of constants juxtaposed
2587 with the kinds of objects.
2588
2589 We no longer talk about indirect updating due to parameter passing.
2590 Parameter passing is handled in 6.2 and 6.4.1 in a way that there
2591 is no need to mention it here in the definition of read and update.
2592 Reading and updating now includes the case of evaluating or
2593 assigning to an enclosing object.
2594 @end{DiffWord83}
2595
2596 @begin{DiffWord95}
2597 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00416-01]}
2598 @ChgAdded{Version=[2],Text=[Clarified that the return object is the object
2599 created by a function call.]}
2600 @end{DiffWord95}
2601
2602 @begin{Extend2005}
2603 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0015-1]}
2604 @ChgAdded{Version=[3],Text=[@Defn{extensions to Ada 2005}
2605 Added wording to allow
2606 return objects to be declared as constants, and corrected the definition
2607 of return objects as objects.]}
2608 @end{Extend2005}
2609
2610 @begin{DiffWord2005}
2611 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0008-1],ARef=[AI05-0041-1],ARef=[AI05-0093-1]}
2612 @ChgAdded{Version=[3],Text=[@b<Correction:> Added a definition of
2613 @i<known to be constrained>, for use in other rules.]}
2614
2615 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0054-2]}
2616 @ChgAdded{Version=[3],Text=[@b<Correction:> We now recognize the fact
2617 that not all declared constant objects are immutable; for those that
2618 a variable view can be constructed, they can be changed via that view.]}
2619
2620 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0120-1]}
2621 @ChgAdded{Version=[3],Text=[@b<Correction:> Added the current instance of
2622 a protected object to the list of constant views; since the list
2623 claims to include all possibilities, it had better include that one.]}
2624
2625 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0003-1]}
2626 @ChgAdded{Version=[3],Text=[The result of a
2627 @nt{qualified_expression} is defined to be a constant view and is defined
2628 to be an object if the operand of the @nt{qualified_expression} is an object.
2629 These definitions, combined with some grammar changes, allow
2630 @nt{qualified_expression}s to be used in more places. See
2631 @RefSecNum{Names} for details.]}@ChgNote{This is defined an extension in @RefSecNum{Names}.}
2632 @end{DiffWord2005}
2633
2634 @begin{Extend2012}
2635 @ChgRef{Version=[5],Kind=[AddedNormal],ARef=[AI12-0228-1]}
2636 @ChgAdded{Version=[5],Text=[@Defn{extensions to Ada 2012}@b<Correction:>
2637 A @nt{qualified_expression} of an object that is known to be constrained
2638 is now also known to be constrained. This allows qualification to be used
2639 to disambiguate a function call used as a prefix in a rename without making
2640 the rename illegal.]}
2641
2642 @ChgRef{Version=[5],Kind=[AddedNormal],ARef=[AI12-0226-1]}
2643 @ChgAdded{Version=[5],Text=[A value conversion of an object is an
2644 object; this makes value conversions consistent with qualified expressions.]}
2645 @end{Extend2012}
2646
2647 @begin{DiffWord2012}
2648 @ChgRef{Version=[5],Kind=[AddedNormal],ARef=[AI12-0125-3]}
2649 @ChgAdded{Version=[5],Text=[Added a rule defining a @nt{target_name} as
2650 a constant (see @RefSecNum{Target Name Symbols}).]}
2651 @end{DiffWord2012}
2652
2653
2654 @LabeledSubClause{Object Declarations}
2655
2656 @begin{Intro}
2657 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0262-1]}
2658 @RootDefn{stand-alone object}
2659 @Defn{explicit initial value}
2660 @Defn{initialization expression}
2661 An @nt<object_declaration> declares a @i(stand-alone) object with a given
2662 nominal subtype and, optionally, an explicit initial
2663 value given by an initialization expression.
2664 @Defn{anonymous array type}
2665 @Defn{anonymous task type}
2666 @Defn{anonymous protected type}
2667 For an array, @Chg{Version=[3],New=[access, ],Old=[]}task, or protected object,
2668 the @nt<object_declaration> may include the definition
2669 of the (anonymous) type of the object.
2670 @end{Intro}
2671
2672 @begin{Syntax}
2673 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00385-01],ARef=[AI95-00406-01]}
2674 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0183-1]}
2675 @Syn{lhs=<object_declaration>,rhs="
2676 @Syn2{defining_identifier_list} : [@key{aliased}] [@key{constant}] @Syn2{subtype_indication} [:= @Syn2{expression}]@Chg{Version=[3],New=<
2677 [@Syn2{aspect_specification}]>,Old=[]};@Chg{Version=[2],New=<
2678 | @Syn2{defining_identifier_list} : [@key{aliased}] [@key{constant}] @Syn2{access_definition} [:= @Syn2{expression}]@Chg{Version=[3],New=<
2679 [@Syn2{aspect_specification}]>,Old=[]};>,Old=<>}
2680 | @Syn2{defining_identifier_list} : [@key{aliased}] [@key{constant}] @Syn2{array_type_definition} [:= @Syn2{expression}]@Chg{Version=[3],New=<
2681 [@Syn2{aspect_specification}]>,Old=[]};
2682 | @Syn2{single_task_declaration}
2683 | @Syn2{single_protected_declaration}"}
2684
2685 @Syn{lhs=<defining_identifier_list>,rhs="
2686 @Syn2{defining_identifier} {, @Syn2{defining_identifier}}"}
2687 @end{Syntax}
2688
2689 @begin{Resolution}
2690 @PDefn2{Term=[expected type],
2691 Sec=(object_declaration initialization expression)}
2692 For an @nt<object_declaration> with an @nt<expression> following
2693 the compound delimiter :=,
2694 the type expected for
2695 the @nt<expression> is that of the object.
2696 @Defn{initialization expression}
2697 This @nt<expression> is called the @i(initialization expression).
2698 @IndexSee{Term=[constructor],See=[initialization expression]}
2699 @end{Resolution}
2700
2701 @begin{Legality}
2702 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00287-01]}
2703 An @nt<object_declaration> without the reserved word @key(constant)
2704 declares a variable object. If it has a @nt<subtype_indication> or
2705 an @nt<array_type_definition> that defines an indefinite subtype,
2706 then there shall be an initialization expression.@Chg{Version=[2],New=[],Old=[
2707 An initialization expression shall not be given if the object is
2708 of a limited type.]}
2709 @end{Legality}
2710
2711 @begin{StaticSem}
2712 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0264-1],ARef=[AI05-0299-1]}
2713 An @nt<object_declaration> with the reserved word @key(constant)
2714 declares a constant object.
2715 @Defn{full constant declaration}
2716 If it has an initialization expression,
2717 then it is called a @i(full constant declaration).
2718 @Defn{deferred constant declaration}
2719 Otherwise@Chg{Version=[3],New=[,],Old=[]} it is called
2720 a @i(deferred constant declaration).
2721 The rules for deferred constant declarations are given in @Chg{Version=[3],New=[subclause],Old=[clause]}
2722 @RefSecNum(Deferred Constants). The rules for full constant declarations
2723 are given in this subclause.
2724
2725 Any declaration that includes a @nt{defining_identifier_list}
2726 with more than one @nt{defining_identifier}
2727 is equivalent to a series of declarations each containing one
2728 @nt{defining_identifier} from the list,
2729 with the rest of the text of the declaration copied for each
2730 declaration in the series, in the same order as the list.
2731 The remainder of this International Standard relies
2732 on this equivalence;
2733 explanations are given for
2734 declarations with a single @nt<defining_identifier>.
2735
2736 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00385-01]}
2737 @Defn{nominal subtype}
2738 The @nt<subtype_indication>@Chg{Version=[2],New=[, @nt{access_definition},],Old=[]}
2739 or full type definition of an
2740 @nt<object_declaration> defines the nominal subtype of the object.
2741 The @nt<object_declaration> declares an object of the type
2742 of the nominal subtype.
2743 @begin{Discussion}
2744 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00385-01]}
2745 The phrase @lquotes@;full type definition@rquotes@; here includes the
2746 case of an anonymous array, @Chg{Version=[2],New=[access, ],Old=[]}task, or
2747 protected type.
2748 @end{Discussion}
2749
2750 @ChgRef{Version=[2],Kind=[Added],ARef=[AI95-00373-01]}
2751 @ChgRef{Version=[5],Kind=[RevisedAdded],ARef=[AI12-0192-1]}
2752 @ChgAdded{Version=[5],Type=[Leading],Text=[]}@Comment{Just to get conditional Leading here.}
2753 @ChgAdded{Version=[2],Text=[@Defn{requires late initialization}
2754 A component of an object is said to
2755 @i{require late initialization} if@Chg{Version=[5],New=[:],Old=[ it has an
2756 access discriminant value constrained by a per-object expression, or if it has
2757 an initialization expression that includes a name denoting the current instance
2758 of the type or denoting an access discriminant.]}]}
2759 @begin{Itemize}
2760 @ChgRef{Version=[5],Kind=[Added],ARef=[AI12-0192-1]}
2761 @ChgAdded{Version=[5],Text=[it has an access discriminant value constrained by a
2762 per-object expression;]}
2763
2764 @ChgRef{Version=[5],Kind=[Added],ARef=[AI12-0192-1]}
2765 @ChgAdded{Version=[5],Text=[it has an initialization expression that includes a
2766 name denoting an access discriminant; or]}
2767
2768 @ChgRef{Version=[5],Kind=[Added],ARef=[AI12-0192-1]}
2769 @ChgAdded{Version=[5],Text=[it has an initialization expression that includes
2770 a reference to the current instance of the type either by name or implicitly
2771 as the target object of a call.]}
2772 @end{Itemize}
2773
2774 @begin{Reason}
2775 @ChgRef{Version=[2],Kind=[AddedNormal]}
2776 @ChgAdded{Version=[2],Text=[Such components can depend on the values of
2777 other components of the object. We want to initialize them as late and as
2778 reproducibly as possible.]}
2779 @end{Reason}
2780 @end{StaticSem}
2781
2782 @begin{RunTime}
2783 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00363-01]}
2784 @Defn2{Term=[constraint], Sec=(of an object)}
2785 If a composite object declared by an
2786 @nt{object_declaration} has an unconstrained nominal subtype,
2787 then if this subtype is indefinite
2788 or the object is constant @Chg{Version=[2],New=[],
2789 Old=[or aliased (see @RefSecNum(Access Types)) ]}the
2790 actual subtype of this object is constrained.
2791 The constraint is determined
2792 by the bounds or discriminants (if any) of its initial value;
2793 @Defn{constrained by its initial value}
2794 the object is said to be @i(constrained by its initial value).
2795 @Defn2{Term=[actual subtype], Sec=(of an object)}
2796 @IndexSee{Term=[subtype (of an object)],See=(actual subtype of an object)}
2797 @Chg{Version=[2],New=[],
2798 Old=[@Redundant[In the case of an aliased object,
2799 this initial value may be either explicit or implicit;
2800 in the other cases, an explicit initial value is required.] ]}When
2801 not constrained by its initial value, the actual and nominal
2802 subtypes of the object are the same.
2803 @Defn2{Term=[constrained], Sec=(object)}
2804 @Defn2{Term=[unconstrained], Sec=(object)}
2805 If its actual subtype is constrained, the object
2806 is called a @i(constrained object).
2807
2808 @Leading@Defn2{Term=[implicit initial values], Sec=(for a subtype)}
2809 For an @nt<object_declaration> without an initialization expression,
2810 any initial values for the object or its subcomponents
2811 are determined by the @i(implicit initial values) defined for
2812 its nominal subtype, as follows:
2813 @begin(itemize)
2814 The implicit initial value for an access subtype is the
2815 null value of the access type.
2816
2817 @ChgRef{Version=[3],Kind=[Added],ARef=[AI05-0228-1]}
2818 @ChgAdded{Version=[3],Text=[The implicit initial value for a scalar subtype
2819 that has the Default_Value aspect specified is the value of that aspect
2820 converted to the nominal subtype (which might raise Constraint_Error @em see
2821 @RefSec{Type Conversions});@PDefn2{Term=[implicit subtype conversion],
2822 Sec=(default value of a scalar)}]}
2823
2824 @begin{Ramification}
2825 @ChgRef{Version=[3],Kind=[Added]}
2826 @ChgAdded{Version=[3],Text=[This is a @RuntimeTitle rule, so the
2827 visibility of the @nt{aspect_specification} is not relevant @em if the full
2828 type for a private type has the Default_Value aspect specified, partial
2829 views of the type also have this implicit initial value.]}
2830 @end{Ramification}
2831
2832 The implicit initial (and only) value for each discriminant
2833 of a constrained discriminated subtype is defined by the subtype.
2834
2835 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0228-1]}
2836 For a (definite) composite subtype,
2837 the implicit initial value of each component
2838 with a @nt<default_expression> is obtained by
2839 evaluation of this expression and conversion to the
2840 component's nominal subtype (which might raise
2841 Constraint_Error@Chg{Version=[3],New=[],Old=[ @em see
2842 @RefSec{Type Conversions}]}), unless the component is a
2843 discriminant of a constrained subtype (the previous case),
2844 or is in an excluded @nt<variant>
2845 (see @RefSecNum(Variant Parts and Discrete Choices)).
2846 @PDefn2{Term=[implicit subtype conversion],Sec=(component defaults)}
2847 For each component that does not have a @nt<default_expression>,
2848 @Chg{Version=[3],New=[if the composite subtype has the Default_Component_Value
2849 aspect specified, the implicit initial value is the value of that aspect
2850 converted to the component's nominal subtype; otherwise, ],Old=[]}any
2851 implicit initial values are those determined by the component's
2852 nominal subtype.
2853
2854 For a protected or task subtype, there is an implicit component
2855 (an entry queue) corresponding to each entry, with its implicit
2856 initial value being an empty queue.
2857 @begin(ImplNote)
2858 The implementation may add implicit components for its own use,
2859 which might have implicit initial values.
2860 For a task subtype, such components might represent the state
2861 of the associated thread of control. For a type with dynamic-sized
2862 components, such implicit components might be used to hold the offset to
2863 some explicit component.
2864 @end(ImplNote)
2865 @end(itemize)
2866
2867 @Leading@PDefn2{Term=[elaboration], Sec=(object_declaration)}
2868 The elaboration of an @nt{object_declaration} proceeds in the following
2869 sequence of steps:
2870 @begin(enumerate)
2871 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00385-01]}
2872 The @nt{subtype_@!indication},@Chg{Version=[2],New=[ @nt{access_@!definition},],Old=[]}
2873 @nt<array_@!type_@!definition>, @nt{single_@!task_@!declaration},
2874 or @nt{single_@!protected_@!declaration} is first elaborated.
2875 This creates the nominal subtype (and the anonymous type in the
2876 @Chg{Version=[2],New=[last four],Old=[latter three]} cases).
2877
2878 If the @nt<object_declaration> includes an initialization expression,
2879 the (explicit) initial value is obtained by evaluating the
2880 expression and converting it to the nominal subtype (which might
2881 raise Constraint_Error @em see @RefSecNum(Type Conversions)).
2882 @PDefn2{Term=[implicit subtype conversion],Sec=(initialization expression)}
2883
2884 @ChgRef{Version=[1],Kind=[Revised],Ref=[8652/0002],ARef=[AI95-00171-01]}
2885 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00373-01]}
2886 The object is created, and, if there is not an initialization expression,
2887 @Chg{Version=[2],New=[the object is @i{initialized by default}.
2888 @Defn{initialized by default}When an object is initialized by
2889 default, ],Old=[]}any per-object @Chg{New=[constraints],Old=[expressions]}
2890 (see @RefSecNum(Record Types)) are
2891 @Chg{New=[elaborated], Old=[evaluated]} and any implicit initial values for
2892 the object or for its subcomponents are obtained as determined by
2893 the nominal subtype.@Chg{Version=[2],New=[
2894 @Defn2{Term=[initialization], Sec=(of an object)}
2895 @Defn2{Term=[assignment operation], Sec=(during elaboration of an @nt{object_declaration})}
2896 Any initial values (whether explicit or implicit) are assigned
2897 to the object or to the corresponding subcomponents.
2898 As described in @RefSecNum{Assignment Statements}
2899 and @RefSecNum{Assignment and Finalization},
2900 Initialize and Adjust procedures can be called.
2901 @IndexSee{Term=[constructor],See=[initialization]}],Old=[]}
2902 @begin(Discussion)
2903 For a per-object constraint that contains some per-object
2904 expressions and some non-per-object expressions,
2905 the values used for the constraint consist of the values
2906 of the non-per-object expressions evaluated at the point
2907 of the @nt{type_declaration}, and the values of the per-object
2908 expressions evaluated at the point of the creation of the
2909 object.
2910
2911 The elaboration of per-object constraints was presumably performed
2912 as part of the dependent compatibility check in Ada 83.
2913 If the object is of a limited type
2914 with an access discriminant, the @nt<access_definition> is elaborated
2915 at this time (see @RefSecNum(Discriminants)).
2916 @end(Discussion)
2917 @begin{Reason}
2918 The reason we say that evaluating an explicit initialization
2919 expression happens before creating the object is that in some cases
2920 it is impossible to know the size of the object being created until
2921 its initial value is known, as in
2922 @lquotes@;X: String := Func_Call(...);@rquotes@;.
2923 The implementation can create the object early in the
2924 common case where the size can be known early,
2925 since this optimization is semantically neutral.
2926 @end{Reason}
2927
2928 @ChgRef{Version=[2],Kind=[Deleted],ARef=[AI95-00373-01]}
2929 @ChgDeleted{Version=[2],Text=[@Defn2{Term=[initialization], Sec=(of an object)}
2930 @Defn2{Term=[assignment operation], Sec=(during elaboration of an @nt{object_declaration})}
2931 Any initial values (whether explicit or implicit) are assigned
2932 to the object or to the corresponding subcomponents.
2933 As described in @RefSecNum{Assignment Statements}
2934 and @RefSecNum{Assignment and Finalization},
2935 Initialize and Adjust procedures can be called.
2936 @IndexSee{Term=[constructor],See=[initialization]}]}
2937 @begin(Ramification)
2938 Since the initial values have already been converted to the appropriate
2939 nominal subtype, the only Constraint_Errors that might
2940 occur as part of these assignments are for values outside their
2941 base range that are used to initialize unconstrained numeric
2942 subcomponents. See @RefSecNum{Scalar Types}.
2943 @end(Ramification)
2944 @end(enumerate)
2945
2946 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00373-01]}
2947 @ChgAdded{Version=[2],Type=[Leading],Text=[]}@Comment{Just to get conditional Leading here.}
2948 For the third step above, @Chg{Version=[2],New=[],Old=[the object creation and
2949 any elaborations and ]}evaluations @Chg{Version=[2],New=[and assignments ],Old=[]}are
2950 performed in an arbitrary
2951 order@Chg{Version=[2],New=[ subject to the following restrictions:],Old=[,
2952 except that if the @nt<default_expression> for a discriminant is
2953 evaluated to obtain its initial value, then this evaluation
2954 is performed before that of
2955 the @nt<default_expression> for any component that depends on the
2956 discriminant,
2957 and also before that of any @nt<default_expression> that
2958 includes the name of the discriminant.
2959 The evaluations of the third step and the assignments of the fourth step
2960 are performed in an arbitrary order,
2961 except that each evaluation is performed before the resulting value is
2962 assigned.]}@PDefn2{Term=[arbitrary order],Sec=[allowed]}
2963 @begin(Itemize)
2964
2965 @ChgRef{Version=[2],Kind=[Added],ARef=[AI95-00373-01]}
2966 @ChgAdded{Version=[2],Text=[Assignment to any part of the object
2967 is preceded by the evaluation of the value that is to be assigned.]}
2968 @begin{Reason}
2969 @ChgRef{Version=[2],Kind=[Added]}
2970 @ChgAdded{Version=[2],Text=[Duh. But we ought to say it. Note that, like
2971 any rule in the International Standard, it doesn't prevent
2972 an @lquotes@;as-if@rquotes optimization; as long as the semantics as observed
2973 from the program are correct, the compiler can generate any code it wants.]}
2974 @end{Reason}
2975 @ChgRef{Version=[2],Kind=[Added],ARef=[AI95-00373-01]}
2976 @ChgAdded{Version=[2],Text=[The evaluation of a @nt{default_expression} that
2977 includes the name of a discriminant is preceded by the assignment to that
2978 discriminant.]}
2979 @begin{Reason}
2980 @ChgRef{Version=[2],Kind=[Added]}
2981 @ChgAdded{Version=[2],Text=[Duh again. But we have to say this, too. It's
2982 odd that Ada 95 only required the default expressions to be evaluated before
2983 the discriminant is used; it says nothing about discriminant values that
2984 come from @nt{subtype_indication}s.]}
2985 @end{Reason}
2986 @ChgRef{Version=[2],Kind=[Added],ARef=[AI95-00373-01]}
2987 @ChgAdded{Version=[2],Text=[The evaluation of the @nt{default_expression}
2988 for any component that depends on a discriminant is preceded by the assignment
2989 to that discriminant.]}
2990 @begin{Reason}
2991 @Leading@keepnext@;For example:
2992 @begin{Example}
2993 @key[type] R(D : Integer := F) @key[is]
2994 @key[record]
2995 S : String(1..D) := (@key[others] => G);
2996 @key[end] @key[record];
2997
2998 X : R;
2999 @end{Example}
3000
3001 For the elaboration of the declaration of X,
3002 it is important that F be evaluated before the aggregate.
3003 @end{Reason}
3004
3005 @ChgRef{Version=[2],Kind=[Added],ARef=[AI95-00373-01]}
3006 @ChgRef{Version=[3],Kind=[RevisedAdded],ARef=[AI05-0092-1]}
3007 @ChgAdded{Version=[2],Text=[The assignments to any components, including
3008 implicit components, not requiring late initialization
3009 @Chg{Version=[3],New=[],Old=[must ]}precede the
3010 initial value evaluations for any components requiring late initialization;
3011 if two components both require late initialization, then assignments to parts
3012 of the component occurring earlier in the order of the component declarations
3013 @Chg{Version=[3],New=[],Old=[must ]}precede the
3014 initial value evaluations of the component occurring later.]}
3015 @begin{Reason}
3016 @ChgRef{Version=[2],Kind=[AddedNormal]}
3017 @ChgAdded{Version=[2],Type=[Leading],Text=[Components that require late
3018 initialization can refer to the entire object during their initialization.
3019 We want them to be initialized as late as possible to reduce the chance
3020 that their initialization depends on uninitialized components. For instance:]}
3021 @begin{Example}
3022 @ChgRef{Version=[2],Kind=[AddedNormal]}
3023 @ChgAdded{Version=[2],Text=[@key{type} T (D : Natural) @key{is}
3024 @key{limited record}
3025 C1 : T1 (T'Access);
3026 C2 : Natural := F (D);
3027 C3 : String (1 .. D) := (others => ' ');
3028 @key{end record};]}
3029 @end{Example}
3030 @ChgRef{Version=[2],Kind=[AddedNormal]}
3031 @ChgAdded{Version=[2],Text=[Component C1 requires late initialization. The
3032 initialization could depend on the values of any component of T, including D,
3033 C2, or C3. Therefore, we want to it to be initialized last. Note that C2 and
3034 C3 do not require late initialization; they only have to be initialized after
3035 D.]}
3036
3037 @ChgRef{Version=[2],Kind=[AddedNormal]}
3038 @ChgAdded{Version=[2],Text=[It is possible for there to be more than one
3039 component that requires late initialization. In this case, the language can't
3040 prevent problems, because all of the components can't be the last one
3041 initialized. In this case, we specify the order of initialization for
3042 components requiring late initialization; by doing so, programmers can
3043 arrange their code to avoid accessing uninitialized components, and such
3044 arrangements are portable. Note that if the program accesses an uninitialized
3045 component, @RefSecNum{Data Validity} defines the execution to be erroneous.]}
3046 @end{Reason}
3047 @end{Itemize}
3048
3049 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0228-1]}
3050 @Redundant[There is no implicit initial
3051 value defined for a scalar subtype@Chg{Version=[3],New=[ unless the
3052 Default_Value aspect has been specified for the type],Old=[]}.]
3053 @PDefn{uninitialized variables}
3054 In the absence of an explicit initialization@Chg{Version=[3],New=[ or the
3055 specification of the Default_Value aspect],Old=[]}, a newly created
3056 scalar object might have a value that does not belong to its subtype
3057 (see @RefSecNum{Data Validity} and @RefSecNum{Pragma Normalize_Scalars}).
3058 @begin{Honest}
3059 It could even be represented by a bit pattern that doesn't
3060 actually represent any value of the type at all,
3061 such as an invalid internal code for an enumeration type,
3062 or a NaN for a floating point type.
3063 It is a generally a bounded error to reference scalar objects with
3064 such @lquotes@;invalid representations@rquotes@;, as explained in
3065 @RefSec{Data Validity}.
3066 @end{Honest}
3067 @begin{Ramification}
3068 There is no requirement that two objects of the same scalar subtype have
3069 the same implicit initial @lquotes@;value@rquotes@; (or representation).
3070 It might even be the case that two elaborations of the same
3071 @nt{object_declaration} produce two different initial values.
3072 However, any particular uninitialized object is default-initialized to a
3073 single value (or invalid representation).
3074 Thus, multiple reads of such an uninitialized object will produce the
3075 same value each time
3076 (if the implementation chooses not to detect the error).
3077 @end{Ramification}
3078 @end{RunTime}
3079
3080 @begin{Notes}
3081 Implicit initial values are not defined
3082 for an indefinite subtype,
3083 because if an object's nominal subtype is indefinite,
3084 an explicit initial value is required.
3085
3086 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0092-1],ARef=[AI05-0255-1]}
3087 @ChgRef{Version=[5],Kind=[Revised],ARef=[AI12-0061-1],ARef=[AI12-0308-1]}
3088 @Defn{stand-alone constant}
3089 @Defn{stand-alone variable}
3090 As indicated above,
3091 a stand-alone object is an object declared by an @nt<object_declaration>.
3092 Similar definitions apply to
3093 @lquotes@;stand-alone constant@rquotes@; and @lquotes@;stand-alone variable.@rquotes@;
3094 A subcomponent of an object is not a stand-alone object,
3095 nor is an object that is created by an @nt<allocator>.
3096 An object declared by a
3097 @nt<loop_parameter_specification>,
3098 @Chg{Version=[3],New=[@nt{iterator_specification},
3099 ],Old=[]}@Chg{Version=[5],New=[@nt{iterated_component_association},
3100 @nt{chunk_specification},
3101 ],Old=[]}@nt<parameter_specification>,
3102 @nt<entry_index_specification>, @nt<choice_parameter_specification>,
3103 @Chg{Version=[3],New=[@nt{extended_return_statement}, ],Old=[]}or
3104 a @nt{formal_object_declaration} @Chg{Version=[3],New=[of mode @key[in out] ],Old=[]}is
3105 not @Chg{Version=[3],New=[considered],Old=[called]} a stand-alone object.
3106
3107 The type of a stand-alone object cannot
3108 be abstract (see @RefSecNum{Abstract Types and Subprograms}).
3109 @end{Notes}
3110
3111 @begin{Examples}
3112 @Leading@keepnext@i(Example of a multiple object declaration:)
3113 @begin(Example)
3114 --@RI[ the multiple object declaration ]
3115
3116 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00433-01]}
3117 John, Paul : @Chg{Version=[2],New=[@key{not null} ],Old=[]}Person_Name := @key(new) Person(Sex => M); --@RI[ see @RefSecNum(Incomplete Type Declarations)]
3118
3119 --@RI[ is equivalent to the two single object declarations in the order given]
3120
3121 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00433-01]}
3122 John : @Chg{Version=[2],New=[@key{not null} ],Old=[]}Person_Name := @key(new) Person(Sex => M);
3123 Paul : @Chg{Version=[2],New=[@key{not null} ],Old=[]}Person_Name := @key(new) Person(Sex => M);
3124 @end(Example)
3125
3126 @begin{WideAbove}
3127 @leading@keepnext@i(Examples of variable declarations:)
3128 @end{WideAbove}
3129 @begin(Example)
3130 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00433-01]}
3131 Count, Sum : Integer;
3132 Size : Integer @key(range) 0 .. 10_000 := 0;
3133 Sorted : Boolean := False;
3134 Color_Table : @key(array)(1 .. Max) @key(of) Color;
3135 Option : Bit_Vector(1 .. 10) := (@key(others) => True);
3136 Hello : @Chg{Version=[2],New=[@key(aliased)],Old=[@key(constant)]} String := "Hi, world.";@Chg{Version=[2],New=[
3137 @unicode(952), @unicode(966) : Float @b<range> -@pi .. +@pi;],Old=[]}
3138 @end(Example)
3139
3140 @begin{WideAbove}
3141 @leading@keepnext@i(Examples of constant declarations:)
3142 @end{WideAbove}
3143 @begin(Example)
3144 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00433-01]}
3145 Limit : @key(constant) Integer := 10_000;
3146 Low_Limit : @key(constant) Integer := Limit/10;
3147 Tolerance : @key(constant) Real := Dispersion(1.15);@Chg{Version=[2],New=[
3148 Hello_Msg : @key(constant access) String := Hello'Access; --@RI[ see @RefSecNum{Operations of Access Types}]],Old=[]}
3149 @end(Example)
3150 @end{Examples}
3151
3152 @begin{Extend83}
3153 @Defn{extensions to Ada 83}
3154 The syntax rule for @nt{object_declaration} is modified to allow the
3155 @key{aliased} reserved word.
3156
3157 A variable declared by an @nt<object_declaration> can be constrained
3158 by its initial value; that is, a variable of a nominally unconstrained
3159 array subtype, or discriminated type without defaults, can
3160 be declared so long as it has an explicit initial value.
3161 In Ada 83, this was permitted for constants, and for variables
3162 created by allocators, but not for variables declared by
3163 @nt<object_declaration>s. This is particularly important
3164 for tagged class-wide types, since there is no way to constrain
3165 them explicitly, and so an initial value is the only way
3166 to provide a constraint. It is also important for generic formal
3167 private types with unknown discriminants.
3168
3169 We now allow an @nt{unconstrained_array_definition}
3170 in an @nt{object_declaration}.
3171 This allows an object of an anonymous array type to have its
3172 bounds determined by its initial value.
3173 This is for uniformity: If one can write @lquotes@;X: @key[constant]
3174 @key[array](Integer @key[range] 1..10) @key[of] Integer := ...;@rquotes@; then
3175 it makes sense to also allow
3176 @lquotes@;X: @key[constant] @key[array](Integer @key[range] <>) @key[of] Integer := ...;@rquotes@;.
3177 (Note that if anonymous array types are
3178 ever sensible, a common situation is for a table implemented as an array.
3179 Tables are often constant, and for constants, there's usually no point in
3180 forcing the user to count the number of elements in the value.)
3181 @end{Extend83}
3182
3183 @begin{DiffWord83}
3184 We have moved the syntax for @nt{object_declaration}s into this subclause.
3185
3186 Deferred constants no longer have a separate syntax rule, but rather
3187 are incorporated in @nt<object_declaration> as constants declared
3188 without an initialization expression.
3189 @end{DiffWord83}
3190
3191 @begin{Inconsistent95}
3192 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00363-01]}
3193 @ChgAdded{Version=[2],Text=[@Defn{inconsistencies with Ada 95}
3194 Unconstrained aliased objects of types
3195 with discriminants with defaults are no longer
3196 constrained by their initial values. This means that a program that
3197 raised Constraint_Error from an attempt to change the discriminants
3198 will no longer do so. The change only affects programs that depended
3199 on the raising of Constraint_Error in this case, so the inconsistency
3200 is unlikely to occur outside of the ACATS. This change may however cause
3201 compilers to implement these objects differently, possibly taking additional
3202 memory or time. This is unlikely to be worse than the differences caused by
3203 any major compiler upgrade.]}
3204 @end{Inconsistent95}
3205
3206 @begin{Extend95}
3207 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00287-01]}
3208 @ChgAdded{Version=[2],Text=[@Defn{extensions to Ada 95}
3209 A constant may have a limited type; the initialization @nt{expression}
3210 has to be built-in-place (see @RefSecNum{Limited Types}).]}
3211
3212 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00385-01],ARef=[AI95-00406-01]}
3213 @ChgAdded{Version=[2],Text=[@Defn{extensions to Ada 95}
3214 A stand-alone object may have an anonymous access type.]}
3215 @end{Extend95}
3216
3217 @begin{DiffWord95}
3218 @ChgRef{Version=[2],Kind=[AddedNormal],Ref=[8652/0002],ARef=[AI95-00171-01]}
3219 @ChgAdded{Version=[2],Text=[@b<Corrigendum:> Corrected wording to say that
3220 per-object constraints are elaborated (not evaluated).]}
3221
3222 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00373-01]}
3223 @ChgAdded{Version=[2],Text=[The rules for evaluating default initialization
3224 have been tightened. In particular, components whose default initialization
3225 can refer to the rest of the object are required to be initialized last.]}
3226
3227 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00433-01]}
3228 @ChgAdded{Version=[2],Text=[Added examples of various new constructs.]}
3229 @end{DiffWord95}
3230
3231 @begin{Extend2005}
3232 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0183-1]}
3233 @ChgAdded{Version=[3],Text=[@Defn{extensions to Ada 2005}
3234 An optional @nt{aspect_specification} can be used in an @nt{object_declaration}.
3235 This is described in @RefSecNum{Aspect Specifications}.]}
3236 @end{Extend2005}
3237
3238 @begin{DiffWord2005}
3239 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0228-1]}
3240 @ChgAdded{Version=[3],Text=[Implicit initial values can now be given
3241 for scalar types and for scalar array components, using the Default_Value
3242 (see @RefSecNum{Scalar Types}) and Default_Component_Value
3243 (see @RefSecNum{Array Types}) aspects; the extension is documented there.]}
3244 @end{DiffWord2005}
3245
3246 @begin{Inconsistent2012}
3247 @ChgRef{Version=[5],Kind=[AddedNormal],ARef=[AI12-0192-1]}
3248 @ChgAdded{Version=[5],Text=[@Defn{inconsistencies with Ada 2012}
3249 @b<Correction:> Components of a protected type require late initialization if
3250 their initialization includes (implicitly) the current instance of the type.
3251 This means that the components could end up being initialized in a different
3252 order. In most cases, this will have no visible effect, or even fix bugs.
3253 Most code for which this is an issue depends on the (unspecified) order of
3254 initialization, so it is at risk of failing with a new compiler version
3255 regardless of Ada rule changes. However, there do exist very unlikely
3256 cases where legal, portable Ada 2012 code would become erroneous. (See
3257 the discussion section of @AILink{AI=[AI12-0192-1],Text=[AI12-0192-1]}
3258 for an example.) These are so unlikely that it is expected that they
3259 only exist in the minds of Ada lawyers.]}
3260 @end{Inconsistent2012}
3261
3262
3263
3264 @ISOOnlyRMNewPageVer{Version=[3]}@Comment{For ISO version of Ada 2012 Standard}
3265 @LabeledSubClause{Number Declarations}
3266
3267 @begin{Intro}
3268 A @nt<number_declaration> declares a named number.
3269 @begin{Discussion}
3270 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0299-1]}
3271 @Defn{static}
3272 If a value or other property of a construct is required to be
3273 @i(static) that means it is required to be determined prior
3274 to execution. A @i(static) expression is an expression
3275 whose value is computed
3276 at compile time and is usable in contexts where the actual value
3277 might affect the legality of the construct.
3278 This is fully defined in @Chg{Version=[3],New=[subclause],Old=[clause]}
3279 @RefSecNum(Static Expressions and Static Subtypes).
3280 @end{Discussion}
3281 @end{Intro}
3282
3283 @begin{Syntax}
3284 @Syn{lhs=<number_declaration>,rhs="
3285 @Syn2{defining_identifier_list} : @key{constant} := @SynI{static_}@Syn2{expression};"}
3286 @end{Syntax}
3287
3288 @begin{Resolution}
3289 @PDefn2{Term=[expected type],
3290 Sec=(number_declaration expression)}
3291 The @SynI(static_)@nt{expression} given for
3292 a @nt{number_declaration} is expected to be of any numeric type.
3293 @end{Resolution}
3294
3295 @begin{Legality}
3296 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0299-1]}
3297 The @i(static_)@nt{expression} given for a number declaration
3298 shall be a static expression, as defined by @Chg{Version=[3],New=[subclause],Old=[clause]}
3299 @RefSecNum(Static Expressions and Static Subtypes).
3300 @end{Legality}
3301
3302 @begin{StaticSem}
3303 The named number denotes a value of type @i(universal_integer) if
3304 the type of the @i(static_)@!@nt{expression} is an integer type.
3305 The named number denotes a value of type @i(universal_real) if
3306 the type of the @i(static_)@!@nt{expression} is a real type.
3307
3308 The value denoted by the named number is the value of the
3309 @i(static_)@nt{expression}, converted to the corresponding
3310 universal type.
3311 @PDefn2{Term=[implicit subtype conversion],Sec=(named number value)}
3312 @end{StaticSem}
3313
3314 @begin{RunTime}
3315 @PDefn2{Term=[elaboration], Sec=(number_declaration)}
3316 The elaboration of a @nt<number_declaration> has no effect.
3317 @begin(TheProof)
3318 Since the @i(static_)@nt<expression> was evaluated at compile time.
3319 @end(TheProof)
3320 @end{RunTime}
3321
3322 @begin{Examples}
3323 @Leading@keepnext@i(Examples of number declarations:)
3324 @begin(Example)
3325 Two_Pi : @key(constant) := 2.0*Ada.Numerics.Pi; --@RI[ a real number (see @RefSecNum{The Numerics Packages})]
3326
3327 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00433-01]}
3328 Max : @key(constant) := 500; --@RI[ an integer number]
3329 Max_Line_Size : @key(constant) := Max/6@Chg{Version=[2],New=[;],Old=[ ]} --@RI[ the integer 83]
3330 Power_16 : @key(constant) := 2**16; --@RI[ the integer 65_536]
3331 One, Un, Eins : @key(constant) := 1; --@RI[ three different names for 1]
3332 @end(Example)
3333 @end{Examples}
3334
3335 @begin{Extend83}
3336 @Defn{extensions to Ada 83}
3337 We now allow a static expression of any numeric type
3338 to initialize a named
3339 number. For integer types, it was possible in Ada 83
3340 to use 'Pos to define a named number, but there was
3341 no way to use a static expression of some nonuniversal
3342 real type to define a named number. This change is
3343 upward compatible because of the preference rule for
3344 the operators of the root numeric types.
3345 @end{Extend83}
3346
3347 @begin{DiffWord83}
3348 We have moved the syntax rule into this subclause.
3349
3350 AI83-00263 describes the elaboration of a number declaration
3351 in words similar to that of an @nt{object_declaration}. However, since
3352 there is no expression to be evaluated and no object to be created,
3353 it seems simpler to say that the elaboration has no effect.
3354 @end{DiffWord83}
3355
3356
3357 @LabeledClause{Derived Types and Classes}
3358
3359 @begin{Intro}
3360 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00401-01],ARef=[AI95-00419-01]}
3361 @Defn{derived type}
3362 A @nt<derived_type_definition> defines a @Chg{Version=[2],
3363 New=[@i{derived type}],Old=[new type]} (and its first subtype)
3364 whose characteristics are @i(derived) from those of a
3365 @Chg{Version=[2],New=[parent type, and possibly from progenitor types],
3366 Old=[@i(parent type)]}.
3367 @IndexSee{Term=[inheritance],See=[derived types and classes]}
3368 @ChgToGlossary{Version=[2],Kind=[Revised],Term=<Derived type>,
3369 Text=<A derived type is a type defined in terms of @Chg{Version=[2],
3370 New=[one or more other types given in a derived type definition. The
3371 first of those types],Old=[another type, which]}
3372 is the parent type of the derived type@Chg{Version=[2],New=[ and
3373 any others are progenitor types],Old=[]}.
3374 Each class containing the parent type @Chg{Version=[2],New=[or a progenitor
3375 type ],Old=[]}also contains the derived type.
3376 The derived type inherits properties such as components and
3377 primitive operations from the parent@Chg{Version=[2],New=[ and progenitors],Old=[]}.
3378 A type together with the types derived from it
3379 (directly or indirectly) form a derivation class.>}
3380
3381 @ChgRef{Version=[2],Kind=[Added],ARef=[AI95-00442-01]}
3382 @ChgAdded{Version=[2],Text=[@Defn2{Term=[class],Sec=[of types]}
3383 @Defn2{Term=[category],Sec=[of types]}
3384 A @i<class of types> is a set of types that is closed under
3385 derivation; that is, if the parent or a progenitor type of a
3386 derived type belongs to a class, then so does the derived type.
3387 By saying that a particular group of types forms a class,
3388 we are saying that all derivatives of a type in the set inherit
3389 the characteristics that define that set. The
3390 more general term @i<category of types> is used for a set of types
3391 whose defining characteristics are not necessarily inherited by
3392 derivatives; for example, limited, abstract, and interface are all
3393 categories of types, but not classes of types.]}
3394
3395 @begin{Ramification}
3396 @ChgRef{Version=[2],Kind=[AddedNormal]}
3397 @ChgAdded{Version=[2],Text=[A class of types is also a category of types.]}
3398 @end{Ramification}
3399
3400 @end{Intro}
3401
3402 @begin{Syntax}
3403 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00251-01],ARef=[AI95-00419-01]}
3404 @Syn{lhs=<derived_type_definition>,rhs="@Chg{Version=[2],New=<
3405 >,Old=<>}[@key{abstract}] @Chg{Version=[2],New=<[@key{limited}] >,Old=<>}@key{new} @SynI{parent_}@Syn2{subtype_indication} [@Chg{Version=[2],New=<[@key{and} @Syn2{interface_list}] >,Old=<>}@Syn2{record_extension_part}]"}
3406 @end{Syntax}
3407
3408 @begin{Legality}
3409 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00251-01],ARef=[AI95-00401-01],ARef=[AI95-00419-01]}
3410 @Defn{parent subtype}
3411 @Defn{parent type}
3412 The @Syni(parent_)@nt<subtype_indication> defines the @i(parent subtype);
3413 its type is the @Chg{Version=[2],New=[@i(parent type)],Old=[parent type]}.
3414 @Chg{Version=[2],New=[The @nt{interface_list} defines the progenitor types
3415 (see @RefSecNum{Interface Types}). A derived type
3416 has one parent type and zero or more progenitor types.],Old=[]}
3417
3418 @ChgToGlossary{Version=[2],Kind=[AddedNormal],Term=<Parent>,
3419 Text=<@ChgAdded{Version=[2],Text=[The parent of a derived type is the
3420 first type given in the definition of the derived type. The parent
3421 can be almost any kind of type, including an interface type.]}>}
3422
3423
3424 A type shall be completely defined
3425 (see @RefSecNum(Completions of Declarations))
3426 prior to being specified as the parent type
3427 in a @nt<derived_type_definition> @em @Redundant[the
3428 @nt<full_type_declaration>s for the parent
3429 type and any of its subcomponents have to
3430 precede the @nt<derived_type_definition>.]
3431 @begin{Discussion}
3432 This restriction does not apply to the ancestor type of a private
3433 extension @em see @RefSecNum(Private Types and Private Extensions);
3434 such a type need not be completely defined prior to the
3435 @nt<private_extension_declaration>. However, the restriction
3436 does apply to record extensions, so the ancestor type will
3437 have to be completely defined prior to the @nt<full_type_declaration>
3438 corresponding to the @nt<private_extension_declaration>.
3439 @end{Discussion}
3440 @begin{Reason}
3441 We originally hoped we could relax this restriction.
3442 However, we found it too complex to specify the rules for
3443 a type derived from an incompletely defined limited type that
3444 subsequently became nonlimited.
3445 @end{Reason}
3446
3447 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00401-01]}
3448 @Defn{record extension}
3449 If there is a @nt<record_extension_part>, the derived type is
3450 called a @i(record extension) of the parent type.
3451 A @nt<record_extension_part> shall be provided if and only if
3452 the parent type is a tagged type.@Chg{Version=[2],New=[ @Redundant[An
3453 @nt{interface_list} shall be provided only if
3454 the parent type is a tagged type.]],Old=[]}
3455 @begin(TheProof)
3456 @ChgRef{Version=[2],Kind=[Added],ARef=[AI95-00401-01]}
3457 @ChgAdded{Version=[2],Text=[The syntax only allows an @nt{interface_list}
3458 to appear with a @nt{record_extension_part}, and a @nt{record_extension_part}
3459 can only be provided if the parent type is a tagged type. We give the last
3460 sentence anyway for completeness.]}
3461 @end(TheProof)
3462 @begin(ImplNote)
3463 We allow a record extension to inherit discriminants;
3464 an early version of Ada 9X did not.
3465 If the parent subtype is unconstrained, it can be implemented
3466 as though its discriminants were repeated in a new
3467 @nt{known_discriminant_part} and then used to constrain the old ones
3468 one-for-one.
3469 However, in an extension aggregate, the discriminants in this case
3470 do not appear in the component association list.
3471 @end(ImplNote)
3472 @begin{Ramification}
3473 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00114-01]}
3474 @ChgAdded{Version=[2],Type=[Leading],Text=[]}@Comment{Conditional leading}
3475 This rule needs to be rechecked in the visible
3476 part of an instance of a generic unit@Chg{Version=[2],New=[ because of the
3477 @lquotes@;only if@rquotes@; part of the rule. For example:],Old=[]}
3478 @begin{Example}
3479 @ChgRef{Version=[2],Kind=[AddedNormal]}
3480 @ChgAdded{Version=[2],Text=[@key{generic}
3481 @key{type} T @key{is private};
3482 @key{package} P @key{is}
3483 @key{type} Der @key{is new} T;
3484 @key{end} P;]}
3485
3486 @ChgRef{Version=[2],Kind=[AddedNormal]}
3487 @ChgAdded{Version=[2],Text=[@key{package} I @key{is new} P (Some_Tagged_Type); -- @RI[illegal]]}
3488 @end{Example}
3489 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00114-01]}
3490 @ChgAdded{Version=[2],Text=[The instantiation is illegal because a tagged
3491 type is being extended in the visible part without a
3492 @nt{record_extension_part}. Note that this is legal in the private part or
3493 body of an instance, both to avoid a contract model violation, and because
3494 no code that can see that the type is actually tagged can also see the
3495 derived type declaration.]}
3496
3497 @ChgRef{Version=[2],Kind=[AddedNormal]}
3498 @ChgAdded{Version=[2],Text=[No recheck is needed for derived types with
3499 a @nt{record_extension_part}, as that has to be derived from something that
3500 is known to be tagged (otherwise the template is illegal).]}
3501 @end{Ramification}
3502
3503 @ChgRef{Version=[2],Kind=[Added],ARef=[AI95-00419-01]}
3504 @ChgRef{Version=[3],Kind=[RevisedAdded],ARef=[AI05-0096-1]}
3505 @ChgAdded{Version=[2],Text=[If the reserved word @key{limited} appears in a
3506 @nt{derived_type_definition}, the parent type shall be a limited
3507 type.@Chg{Version=[3],New=[ If the parent type is a tagged formal type,
3508 then in addition to the places where @LegalityTitle normally apply
3509 (see @RefSecNum{Generic Instantiation}), this rule applies also in
3510 the private part of an instance of a
3511 generic unit.@PDefn{generic contract issue}],Old=[]}]}
3512 @begin{Reason}
3513 @ChgRef{Version=[2],Kind=[AddedNormal]}
3514 @ChgAdded{Version=[2],Text=[We allow @key{limited} because we don't inherit
3515 limitedness from interfaces, so we must have a way to derive a limited type
3516 from interfaces. The word @key{limited} has to be legal when the parent
3517 @i{could be} an interface, and that includes generic formal abstract types.
3518 Since we have to allow it in this case, we might as well allow it everywhere
3519 as documentation, to make it explicit that the type is limited.]}
3520
3521 @ChgRef{Version=[2],Kind=[AddedNormal]}
3522 @ChgAdded{Version=[2],Text=[However, we do not want to allow @key{limited}
3523 when the parent is nonlimited: limitedness cannot change in a derivation
3524 tree.]}
3525
3526 @ChgRef{Version=[3],Kind=[AddedNormal]}
3527 @ChgAdded{Version=[3],Text=[If the parent type is an untagged limited formal
3528 type with an actual type that is nonlimited, we allow derivation as a limited
3529 type in the private part or body as no place could have visibility on the
3530 resulting type where it was known to be nonlimited (outside of the instance).
3531 (See the previous paragraph's annotations for an explanation of this.)
3532 However, if the parent type is a tagged limited formal type with an actual
3533 type that is nonlimited, it would be possible to pass a value of the limited
3534 type extension to a class-wide type of the parent, which would be nonlimited.
3535 That's too weird to allow (even though all of the extension components would
3536 have to be nonlimited because the rules of @RefSecNum{Type Extensions} are
3537 rechecked), so we have a special rule to prevent that in the private part
3538 (type extension from a formal type is illegal in a generic package body).]}
3539 @end{Reason}
3540 @end{Legality}
3541
3542 @begin{StaticSem}
3543 @Defn2{Term=[constrained], Sec=(subtype)}
3544 @Defn2{Term=[unconstrained], Sec=(subtype)}
3545 The first subtype of the derived type is
3546 unconstrained if a @nt{known_discriminant_part}
3547 is provided in the declaration of the derived type, or if the
3548 parent subtype is unconstrained.
3549 @Defn{corresponding constraint}
3550 Otherwise, the constraint
3551 of the first subtype @i(corresponds) to that of the parent subtype
3552 in the following sense: it is the same as that of the parent subtype
3553 except that for a range constraint (implicit or explicit), the value of
3554 each bound of its range is replaced by the corresponding value
3555 of the derived type.
3556 @begin(Discussion)
3557 A @nt<digits_constraint> in a @nt<subtype_indication> for
3558 a decimal fixed point subtype always imposes a range constraint,
3559 implicitly if there is no explicit one given.
3560 See @RefSec(Fixed Point Types).
3561 @end(Discussion)
3562
3563 @ChgRef{Version=[2],Kind=[Added],ARef=[AI95-00231-01]}
3564 @ChgAdded{Version=[2],Text=[The first subtype of the derived type excludes null
3565 (see @RefSecNum{Access Types}) if and only if the parent subtype excludes null.]}
3566
3567 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0110-1]}
3568 @Leading@keepnext@;The @Chg{Version=[3],New=[@i{characteristics}@PDefn{characteristics}
3569 and implicitly declared primitive subprograms],Old=[characteristics]} of the
3570 derived type are defined as follows:
3571 @begin{Ramification}
3572 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0110-1]}
3573 @ChgAdded{Version=[3],Text=[The characteristics of a type do not include its
3574 primitive subprograms (primitive subprograms include predefined operators).
3575 The rules governing availability/visibility and inheritance of characteristics
3576 are separate from those for primitive subprograms.]}
3577 @end{Ramification}
3578
3579 @begin(itemize)
3580 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00251-01],ARef=[AI95-00401-01],ARef=[AI95-00442-01]}
3581 @Chg{Version=[2],New=[@Redundant[If the parent type or a progenitor type
3582 belongs to a class of types, then the derived type also belongs to that class.]
3583 The following sets of types, as well as any higher-level sets composed from
3584 them, are classes in this sense@Redundant[, and hence the characteristics
3585 defining these classes are inherited by derived types from their parent or
3586 progenitor types]: signed integer, modular integer, ordinary fixed, decimal
3587 fixed, floating point, enumeration, boolean, character, access-to-constant,
3588 general access-to-variable, pool-specific access-to-variable,
3589 access-to-subprogram, array, string, non-array composite, nonlimited, untagged
3590 record, tagged, task, protected, and synchronized tagged],
3591 Old=[Each class of types that includes the parent type also includes
3592 the derived type]}.
3593 @begin{Discussion}
3594 This is inherent in our notion
3595 of a @lquotes@;class@rquotes@; of types. It is not mentioned in the
3596 initial definition of @lquotes@;class@rquotes@; since at that point
3597 type derivation has not been defined. In any case, this rule
3598 ensures that every class of types is closed under
3599 derivation.
3600 @end{Discussion}
3601
3602 If the parent type is an elementary type or an array type, then the
3603 set of possible values of the derived type
3604 is a copy of the set of possible values of the parent type.
3605 For a scalar type, the base range of the derived type is the same
3606 as that of the parent type.
3607 @begin{Discussion}
3608 The base range of a type defined by an @nt<integer_type_definition>
3609 or a @nt<real_type_definition> is determined by the @ntf<_definition>,
3610 and is not necessarily the same as that of the corresponding
3611 root numeric type from which the newly defined type is implicitly
3612 derived. Treating numerics types as implicitly derived from one of
3613 the two root numeric types is simply to link them into a type hierarchy;
3614 such an implicit derivation does not follow all the rules given here
3615 for an explicit @nt<derived_type_definition>.
3616 @end{Discussion}
3617
3618 If the parent type is a composite type other than an array type,
3619 then the components,
3620 protected subprograms, and entries
3621 that are declared for the derived type are as follows:
3622 @begin(inneritemize)
3623 The discriminants specified by a new @nt{known_discriminant_part},
3624 if there is one;
3625 otherwise, each discriminant of the parent type
3626 (implicitly declared in the same order with the same specifications) @em
3627 @Defn{inherited discriminant}
3628 @Defn{inherited component}
3629 in the latter case, the discriminants are said to be @i(inherited),
3630 or if unknown in the parent, are also unknown in the derived type;
3631
3632 Each nondiscriminant component, entry, and protected subprogram
3633 of the parent type, implicitly declared in the same order
3634 with the same declarations;
3635 @Defn{inherited component}
3636 @Defn{inherited protected subprogram}
3637 @Defn{inherited entry}
3638 these components, entries, and protected subprograms are said to be @i(inherited);
3639 @begin{Ramification}
3640
3641 The profiles of entries and protected subprograms do
3642 not change upon type derivation, although the type of the
3643 @lquotes@;implicit@rquotes@; parameter identified by the @nt<prefix> of
3644 the @nt<name> in a call does.@end{ramification}
3645 @begin{Honest}
3646
3647 Any name in the parent @nt{type_declaration} that denotes the
3648 current instance of the type is replaced with a name denoting the
3649 current instance of the derived type, converted to the parent type.
3650
3651 @end{Honest}
3652
3653 Each component declared in a
3654 @nt<record_extension_part>, if any.
3655 @end(inneritemize)
3656
3657 @noprefix@;Declarations of components, protected subprograms,
3658 and entries, whether implicit or explicit,
3659 occur immediately within the declarative region of
3660 the type, in the order indicated above,
3661 following the parent @nt<subtype_indication>.
3662 @begin(Discussion)
3663 The order of declarations within the region matters
3664 for @nt{record_aggregate}s and @nt<extension_aggregate>s.
3665 @end(Discussion)
3666 @begin{Ramification}
3667 In most cases, these things are implicitly declared
3668 @i{immediately} following the parent @nt<subtype_indication>.
3669 However, @RefSec{Private Operations} defines some cases in which
3670 they are implicitly declared later, and some cases in which
3671 the are not declared at all.
3672 @end{Ramification}
3673 @begin{Discussion}
3674 The place of the implicit declarations of inherited components matters
3675 for visibility @em they are not visible in the
3676 @nt<known_discriminant_part> nor in the parent @nt<subtype_indication>,
3677 but are usually visible within the
3678 @nt<record_extension_part>, if any
3679 (although there are restrictions on their use).
3680 Note that a discriminant specified in a new
3681 @nt<known_discriminant_part> is
3682 not considered @lquotes@;inherited@rquotes@; even if it has the same name
3683 and subtype as a discriminant of the parent type.
3684 @end{Discussion}
3685
3686 @ChgRef{Version=[2],Kind=[Deleted],ARef=[AI95-00419-01]}
3687 @ChgDeleted{Version=[2],Text=[The derived type is limited if and
3688 only if the parent type is limited.]}
3689 @ChgNote{This rule is normatively in @RefSecNum{Limited Types}, and we don't
3690 want it scattered everywhere.}
3691 @begin{Honest}
3692 @ChgRef{Version=[2],Kind=[DeletedNoDelMsg],ARef=[AI95-00419-01]}
3693 @ChgDeleted{Version=[2],Text=[The derived type can become nonlimited if
3694 the derivation takes place in the visible part of a child package,
3695 and the parent type is nonlimited as viewed from the
3696 private part of the child package @em see @RefSecNum(Limited Types).]}
3697 @end{Honest}
3698
3699 @Redundant[For each predefined operator of the parent type,
3700 there is a corresponding predefined operator of the derived type.]
3701 @begin(TheProof)
3702 This is a ramification of the fact that each class that includes
3703 the parent type also includes the derived type,
3704 and the fact that the set of predefined operators that is defined for
3705 a type, as described in
3706 @RefSecNum(Operators and Expression Evaluation), is determined by
3707 the classes to which it belongs.
3708 @end(TheProof)
3709 @begin(Reason)
3710 Predefined operators are handled separately because
3711 they follow a slightly different rule
3712 than user-defined primitive subprograms. In particular
3713 the systematic replacement described below does not apply fully to the
3714 relational operators for Boolean and the exponentiation
3715 operator for Integer. The relational operators for a type
3716 derived from Boolean still return Standard.Boolean. The
3717 exponentiation operator for a type derived from Integer
3718 still expects Standard.Integer for the right operand.
3719 In addition, predefined operators "reemerge" when a type
3720 is the actual type corresponding to a generic formal type,
3721 so they need to be well defined even if hidden by user-defined
3722 primitive subprograms.
3723 @end(Reason)
3724
3725 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00401-01]}
3726 @Defn{inherited subprogram}
3727 For each user-defined primitive subprogram (other than a user-defined
3728 equality operator @em see below) of the parent type@Chg{Version=[2],New=[ or of a
3729 progenitor type],Old=[]} that already exists at the place of the
3730 @nt{derived_type_definition}, there exists a corresponding @i(inherited)
3731 primitive subprogram of the derived type
3732 with the same defining name.
3733 @Defn2{Term=[equality operator],Sec=(special inheritance rule for tagged types)}
3734 Primitive user-defined equality operators of the parent
3735 type@Chg{Version=[2],New=[ and any progenitor types],Old=[]} are also
3736 inherited by the derived type, except when
3737 the derived type is a nonlimited record extension, and
3738 the inherited operator would have a profile that is type
3739 conformant with the profile of the corresponding
3740 predefined equality operator; in this case, the user-defined
3741 equality operator is not inherited, but is rather incorporated into
3742 the implementation of the predefined equality operator of the record extension
3743 (see @RefSecNum(Relational Operators and Membership Tests)).
3744 @PDefn{type conformance}
3745 @begin{Ramification}
3746 We say @lquotes@;...already exists...@rquotes@; rather than @lquotes@;is visible@rquotes@; or @lquotes@;has
3747 been declared@rquotes@; because there are certain operations that are declared
3748 later, but still exist at the place of the
3749 @nt{derived_type_definition},
3750 and there are operations that are never declared, but still exist.
3751 These cases are explained in @RefSecNum{Private Operations}.
3752
3753 Note that nonprivate extensions can appear only after the last
3754 primitive subprogram of the parent @em the freezing rules ensure this.
3755 @end{Ramification}
3756 @begin{Reason}
3757 A special case is made for the equality operators on nonlimited
3758 record extensions
3759 because their predefined equality operators are already defined in terms
3760 of the primitive equality operator of their parent type (and of the
3761 tagged components of the extension part). Inheriting the parent's
3762 equality operator as is would be undesirable, because it would ignore
3763 any components of the extension part.
3764 On the other hand, if the parent type is limited, then any user-defined
3765 equality operator is inherited as is, since there is no predefined
3766 equality operator to take its place.
3767 @end{Reason}
3768 @begin{Ramification}
3769 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00114-01]}
3770 Because user-defined equality operators are not inherited
3771 by @Chg{Version=[2],New=[nonlimited ],Old=[]}record extensions, the
3772 formal parameter names of = and /=
3773 revert to Left and Right, even if different formal parameter names
3774 were used in the user-defined equality operators of the parent type.
3775 @end{Ramification}
3776 @begin{Discussion}
3777 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00401-01]}
3778 @ChgAdded{Version=[2],Text=[This rule only describes what operations
3779 are inherited; the rules that describe what happens when there are
3780 conflicting inherited subprograms are found in @RefSecNum{Visibility}.]}
3781 @end{Discussion}
3782
3783 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00401-01]}
3784 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0164-1],ARef=[AI05-0240-1]}
3785 @noprefix@;The profile of an inherited subprogram
3786 (including an inherited enumeration literal) is obtained
3787 from the profile of the corresponding
3788 (user-defined) primitive subprogram of the parent@Chg{Version=[2],New=[ or progenitor],Old=[]}
3789 type, after systematic replacement of each
3790 subtype of its profile (see
3791 @RefSecNum{Subprogram Declarations})
3792 that is of the parent@Chg{Version=[2],New=[ or progenitor],Old=[]}
3793 type@Chg{Version=[3],New=[, other than those subtypes
3794 found in the designated profile of an @nt{access_definition},],Old=[]}
3795 with a @i(corresponding subtype) of the derived type.
3796 @Defn{corresponding subtype}
3797 For a given subtype of the parent@Chg{Version=[2],New=[ or progenitor],Old=[]} type,
3798 the corresponding subtype of the derived type is defined as follows:
3799 @begin(inneritemize)
3800 If the declaration of the derived type has neither a
3801 @nt<known_discriminant_part> nor a @nt<record_extension_part>,
3802 then the corresponding subtype
3803 has a constraint that corresponds (as defined above for the first
3804 subtype of the derived type) to that of the given subtype.
3805
3806 If the derived type is a record extension, then the
3807 corresponding subtype is the first subtype of the derived type.
3808
3809 If the derived type has a new @nt<known_discriminant_part>
3810 but is not a record extension,
3811 then the corresponding subtype is constrained
3812 to those values that when converted to the parent type belong to
3813 the given subtype (see @RefSecNum(Type Conversions)).
3814 @PDefn2{Term=[implicit subtype conversion],Sec=(derived type discriminants)}
3815 @begin{Reason}
3816 An inherited subprogram of an untagged type has an Intrinsic
3817 calling convention, which precludes the use of the Access
3818 attribute.
3819 We preclude 'Access because correctly performing
3820 all required constraint checks on an indirect call to such
3821 an inherited subprogram was felt to impose an undesirable
3822 implementation burden.
3823
3824 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0164-1]}
3825 @ChgAdded{Version=[3],Text=[Note that the exception to substitution of the
3826 parent or progenitor type applies only in the profiles of anonymous
3827 access-to-subprogram types. The exception is necessary to avoid calling
3828 an access-to-subprogram with types and/or constraints different than
3829 expected by the actual routine.]}
3830 @end{Reason}
3831 @end(inneritemize)
3832
3833 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00401-01]}
3834 @noprefix@;The same formal parameters have @nt<default_expression>s in
3835 the profile of the inherited subprogram. @Redundant[Any type mismatch due
3836 to the systematic replacement of the parent@Chg{Version=[2],New=[ or progenitor],Old=[]}
3837 type by the derived type is handled as part of the normal
3838 type conversion associated with parameter
3839 passing @em see @RefSecNum(Parameter Associations).]
3840 @begin(Reason)
3841 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00401-01]}
3842 We don't introduce the type conversion explicitly here
3843 since conversions to record extensions or on access parameters
3844 are not generally legal. Furthermore, any type conversion would
3845 just be "undone" since the @Chg{Version=[2],New=[],Old=[parent's ]}subprogram
3846 @Chg{Version=[2],New=[of the parent or progenitor ],Old=[]}is ultimately being
3847 called anyway.@Chg{Version=[2],New=[ (Null procedures can be inherited from
3848 a progenitor without being overridden, so it is possible to call subprograms
3849 of an interface.)],Old=[]}
3850 @end(Reason)
3851
3852 @end(itemize) @Comment{end of characteristics of derived type}
3853
3854 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00401-01]}
3855 If a primitive subprogram of the parent@Chg{Version=[2],New=[ or progenitor],
3856 Old=[]} type is visible at the
3857 place of the @nt{derived_type_definition},
3858 then the corresponding inherited subprogram is implicitly declared
3859 immediately after the @nt{derived_type_definition}.
3860 Otherwise, the inherited subprogram is implicitly declared later
3861 or not at all,
3862 as explained in @RefSecNum{Private Operations}.
3863
3864 @PDefn{derived type}
3865 A derived type can also be defined by a @nt<private_@!extension_@!declaration>
3866 (see @RefSecNum(Private Types and Private Extensions))
3867 or a @nt<formal_@!derived_@!type_@!definition>
3868 (see @RefSecNum(Formal Private and Derived Types)).
3869 Such a derived type is a partial
3870 view of the corresponding full or actual type.
3871
3872 All numeric types are derived types, in that
3873 they are implicitly derived from a corresponding
3874 root numeric type (see @RefSecNum(Integer Types) and @RefSecNum(Real Types)).
3875
3876 @end{StaticSem}
3877
3878 @begin{RunTime}
3879 @PDefn2{Term=[elaboration], Sec=(derived_type_definition)}
3880 The elaboration of a @nt<derived_type_definition>
3881 creates the derived type and its first subtype,
3882 and consists of the elaboration of the @nt<subtype_@!indication>
3883 and the @nt<record_@!extension_@!part>, if any.
3884 If the @nt{subtype_@!indication} depends on a discriminant,
3885 then only those expressions that do not depend on a discriminant
3886 are evaluated.
3887 @begin{Discussion}
3888 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00251-01]}
3889 @ChgAdded{Version=[2],Text=[We don't mention the @nt{interface_list}, because
3890 it does not need elaboration (see @RefSecNum{Interface Types}). This is
3891 consistent with the handling of @nt{discriminant_part}s, which aren't
3892 elaborated either.]}
3893 @end{Discussion}
3894 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00391-01],ARef=[AI95-00401-01]}
3895 @PDefn2{Term=[execution], Sec=(call on an inherited subprogram)}
3896 For the execution of a call on an inherited subprogram,
3897 a call on the corresponding primitive subprogram of the
3898 parent@Chg{Version=[2],New=[ or progenitor],Old=[]} type is
3899 performed; the normal conversion of each actual parameter
3900 to the subtype of the corresponding formal parameter
3901 (see @RefSecNum(Parameter Associations))
3902 performs any necessary type conversion as well.
3903 If the result type of the inherited subprogram
3904 is the derived type, the result of calling the
3905 @Chg{Version=[2],New=[],Old=[parent's ]}subprogram@Chg{Version=[2],
3906 New=[ of the parent or progenitor],Old=[]} is converted to the
3907 derived type@Chg{Version=[2],New=[, or in the case of a
3908 null extension, extended to the derived type using the equivalent of an
3909 @nt{extension_aggregate} with the original result as the @nt{ancestor_part}
3910 and @key{null record} as the @nt{record_component_association_list}],Old=[]}.
3911 @PDefn2{Term=[implicit subtype conversion],Sec=(result of inherited function)}
3912 @begin(Discussion)
3913 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00391-01]}
3914 If an inherited function returns the derived type, and the type
3915 is a @Chg{Version=[2],New=[nonnull ],Old=[]}record extension, then the
3916 inherited function @Chg{Version=[2],New=[shall be overridden, unless
3917 the type is abstract (in which case the function ],Old=[]}is abstract,
3918 and (unless overridden) cannot be called except via
3919 a dispatching call@Chg{Version=[2],New=[)],Old=[]}.
3920 See @RefSecNum(Abstract Types and Subprograms).
3921 @end(Discussion)
3922 @end{RunTime}
3923
3924 @begin{Notes}
3925 @Defn{closed under derivation}
3926 Classes are closed under derivation @em
3927 any class that contains a type also contains its derivatives.
3928 Operations available for a given class of types
3929 are available for the derived types in that class.
3930
3931 Evaluating an inherited enumeration literal
3932 is equivalent to evaluating the corresponding enumeration literal
3933 of the parent type, and then converting the result to
3934 the derived type. This follows from their equivalence to
3935 parameterless functions.
3936 @PDefn2{Term=[implicit subtype conversion],Sec=(inherited enumeration literal)}
3937
3938 A generic subprogram is not a subprogram,
3939 and hence cannot be a primitive subprogram and
3940 cannot be inherited by a derived type. On the other hand,
3941 an instance of a generic subprogram can be a primitive subprogram,
3942 and hence can be inherited.
3943
3944 If the parent type is an access type, then the parent
3945 and the derived type share the same storage pool;
3946 there is a @key{null} access value for the derived type
3947 and it is the implicit initial value for the type.
3948 See @RefSecNum(Access Types).
3949
3950 If the parent type is a boolean type, the predefined relational operators
3951 of the derived type deliver a result of the predefined type Boolean
3952 (see @RefSecNum(Relational Operators and Membership Tests)).
3953 If the parent type is an integer type, the right operand of the
3954 predefined exponentiation operator is of the predefined type Integer
3955 (see @RefSecNum(Highest Precedence Operators)).
3956
3957 Any discriminants of the parent type are either all inherited, or
3958 completely replaced with a new set of discriminants.
3959
3960 For an inherited subprogram, the subtype of a formal parameter
3961 of the derived type need not have any value in common with the first
3962 subtype of the derived type.
3963 @begin(TheProof)
3964 @Leading@;This happens when the parent subtype is constrained to a range
3965 that does not overlap with the range of a subtype of the parent
3966 type that appears in the profile of
3967 some primitive subprogram of the parent type.
3968 For example:
3969 @begin(example)
3970 @key(type) T1 @key(is range) 1..100;
3971 @key(subtype) S1 @key(is) T1 @key(range) 1..10;
3972 @key(procedure) P(X : @key[in] S1); @RI{-- P is a primitive subprogram}
3973 @key(type) T2 @key(is new) T1 @key(range) 11..20;
3974 @RI(-- implicitly declared:)
3975 @RI{-- @key(procedure) P(X : @key[in] T2'Base @key(range) 1..10);}
3976 @RI{-- X cannot be in T2'First .. T2'Last}
3977 @end(example)
3978 @end(TheProof)
3979
3980 If the reserved word @key{abstract} is given in the declaration of a
3981 type, the type is abstract (see @RefSecNum{Abstract Types and Subprograms}).
3982
3983 @ChgRef{Version=[2],Kind=[Added],ARef=[AI95-00251-01],ARef=[AI95-00401-01]}
3984 @ChgAdded{Version=[2],Text=[An interface type that has a progenitor type
3985 @lquotes@;is derived from@rquotes@; that type.
3986 A @nt{derived_type_definition}, however, never defines an interface type.]}
3987
3988 @ChgRef{Version=[2],Kind=[Added],ARef=[AI95-00345-01]}
3989 @ChgAdded{Version=[2],Text=[It is illegal for the parent type of a
3990 @nt{derived_type_definition} to be a synchronized tagged type.]}
3991 @begin{TheProof}
3992 @ChgRef{Version=[2],Kind=[AddedNormal]}
3993 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0299-1]}
3994 @ChgAdded{Version=[2],Text=[@RefSecNum{Type extensions} prohibits record
3995 extensions whose parent type is a synchronized tagged type, and this
3996 @Chg{Version=[3],New=[subclause],Old=[clause]}
3997 requires tagged types to have a record extension. Thus there are no legal
3998 derivations. Note that a synchronized interface can be used as a progenitor
3999 in an @nt{interface_type_definition} as well as in task and protected types,
4000 but we do not allow concrete extensions of any synchronized tagged type.]}
4001 @end{TheProof}
4002
4003 @end{Notes}
4004
4005 @begin{Examples}
4006 @Leading@keepnext@i(Examples of derived type declarations:)
4007 @begin(Example)
4008 @key(type) Local_Coordinate @key(is) @key(new) Coordinate; --@RI[ two different types]
4009 @key(type) Midweek @key(is) @key(new) Day @key(range) Tue .. Thu; --@RI[ see @RefSecNum(Enumeration Types)]
4010 @key(type) Counter @key(is) @key(new) Positive; --@RI[ same range as Positive ]
4011
4012 @key(type) Special_Key @key(is) @key(new) Key_Manager.Key; --@RI[ see @RefSecNum(Private Operations)]
4013 --@RI[ the inherited subprograms have the following specifications: ]
4014 --@RI[ procedure Get_Key(K : out Special_Key);]
4015 --@RI[ function "<"(X,Y : Special_Key) return Boolean;]
4016 @end(Example)
4017 @end{Examples}
4018
4019 @begin{Inconsistent83}
4020 @Defn{inconsistencies with Ada 83}
4021 When deriving from a (nonprivate, nonderived) type in the same
4022 visible part in which it is defined, if a predefined
4023 operator had been overridden prior to the derivation,
4024 the derived type will inherit the user-defined operator rather
4025 than the predefined operator. The work-around (if the new behavior
4026 is not the desired behavior) is to move the definition of the
4027 derived type prior to the overriding of any predefined operators.
4028
4029 @end{Inconsistent83}
4030
4031 @begin{Incompatible83}
4032 @Defn{incompatibilities with Ada 83}
4033 @Leading@;When deriving from a (nonprivate, nonderived) type in the same
4034 visible part in which it is defined, a primitive subprogram of the
4035 parent type declared before the derived type will be inherited by the
4036 derived type. This can cause upward incompatibilities in cases like
4037 this:
4038 @begin{Example}
4039 @key[package] P @key[is]
4040 @key[type] T @key[is] (A, B, C, D);
4041 @key[function] F( X : T := A ) @key[return] Integer;
4042 @key[type] NT @key[is] @key[new] T;
4043 --@RI{ inherits F as}
4044 --@RI{ function F( X : NT := A ) return Integer;}
4045 --@RI{ in Ada 95 only}
4046 ...
4047 @key[end] P;
4048 ...
4049 @key[use] P; --@RI{ Only one declaration of F from P is use-visible in}
4050 --@RI{ Ada 83; two declarations of F are use-visible in}
4051 --@RI{ Ada 95.}
4052 @key[begin]
4053 ...
4054 @key[if] F > 1 @key[then] ... --@RI{ legal in Ada 83, ambiguous in Ada 95}
4055 @end{Example}
4056 @end{Incompatible83}
4057
4058 @begin{Extend83}
4059 @Defn{extensions to Ada 83}
4060 The syntax for a @nt{derived_type_definition} is amended to
4061 include an optional @nt{record_extension_part}
4062 (see @RefSecNum(Type Extensions)).
4063
4064 A derived type may override the discriminants of the parent by giving a
4065 new @nt{discriminant_part}.
4066
4067 The parent type in a @nt<derived_type_definition>
4068 may be a derived type defined
4069 in the same visible part.
4070
4071 When deriving from a type in the same visible part in which it is defined,
4072 the primitive subprograms declared prior to the derivation
4073 are inherited as primitive subprograms of the derived type.
4074 See @RefSecNum(Classification of Operations).
4075 @end{Extend83}
4076
4077 @begin{DiffWord83}
4078 We now talk about the classes to which a type belongs, rather than
4079 a single class.
4080
4081 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0190-1]}@ChgNote{Irrelevant here,
4082 and broken since 7.6.1 defined "collection"}
4083 @ChgDeleted{Version=[3],Text=[As explained in Section 13, the concept of
4084 "storage pool" replaces the Ada 83 concept of "collection." These concepts are
4085 similar, but not the same.]}
4086 @end{DiffWord83}
4087
4088 @begin{Extend95}
4089 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00251-01],ARef=[AI95-00401-01]}
4090 @ChgAdded{Version=[2],Text=[@Defn{extensions to Ada 95}
4091 A derived type may inherit from multiple (interface) progenitors,
4092 as well as the parent type @em see @RefSec{Interface Types}.]}
4093
4094 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00419-01]}
4095 @ChgAdded{Version=[2],Text=[A derived type may specify that it is a limited
4096 type. This is required for interface ancestors (from which limitedness is
4097 not inherited), but it is generally useful as documentation of limitedness.]}
4098 @end{Extend95}
4099
4100 @begin{DiffWord95}
4101 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00391-01]}
4102 @ChgAdded{Version=[2],Text=[Defined the result of functions for
4103 null extensions (which we no longer require to be overridden - see
4104 @RefSecNum{Abstract Types and Subprograms}).]}
4105
4106 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00442-01]}
4107 @ChgAdded{Version=[2],Text=[Defined the term @lquotes@;category of
4108 types@rquotes and used it in wording elsewhere; also specified the
4109 language-defined categories that form classes of types (this was never
4110 normatively specified in Ada 95).]}
4111 @end{DiffWord95}
4112
4113 @begin{Incompatible2005}
4114 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0096-1]}
4115 @ChgAdded{Version=[3],Text=[@Defn{incompatibilities with Ada 2005}@b<Correction:>
4116 Added a (re)check that limited type extensions never are derived from
4117 nonlimited types in generic private parts. This is disallowed as it would
4118 make it possible to pass a limited object to a nonlimited class-wide type,
4119 which could then be copied. This is only possible using Ada 2005 syntax,
4120 so examples in existing programs should be rare.]}
4121 @end{Incompatible2005}
4122
4123 @begin{DiffWord2005}
4124 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0110-1]}
4125 @ChgAdded{Version=[3],Text=[@b<Correction:> Added wording to clarify that
4126 the characteristics of derived types are formally defined here. (This is the
4127 only place in the Standard that actually spells out what sorts of things
4128 are actually characteristics, which is rather important.)]}
4129
4130 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0164-1]}
4131 @ChgAdded{Version=[3],Text=[@b<Correction:> Added wording to ensure that
4132 anonymous access-to-subprogram types don't get modified on derivation.]}
4133 @end{DiffWord2005}
4134
4135
4136 @LabeledSubClause{Derivation Classes}
4137
4138 @begin{Intro}
4139 In addition to the various language-defined classes of types,
4140 types can be grouped into @i(derivation classes).
4141 @end{Intro}
4142
4143 @begin{StaticSem}
4144 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00251-01],ARef=[AI95-00401-01]}
4145 @Defn2{Term=[derived from], Sec=(directly or indirectly)}
4146 A derived type is @i(derived from) its parent type @i(directly);
4147 it is derived
4148 @i(indirectly) from any type from which its parent type is derived.@Chg{Version=[2],
4149 New=[ A derived type, interface type, type extension, task type, protected type,
4150 or formal derived type is also derived from every ancestor of each of its
4151 progenitor types, if any.],Old=[]}
4152 @Defn2{Term=[derivation class], Sec=(for a type)}
4153 @Defn2{Term=[root type], Sec=(of a class)}
4154 @Defn{rooted at a type}
4155 The derivation class of types for a type @i(T) (also called
4156 the class @i(rooted) at @i(T)) is
4157 the set consisting of @i(T) (the @i(root type) of the class)
4158 and all types derived from @i(T) (directly or indirectly) plus
4159 any associated universal or class-wide types (defined below).
4160 @begin{Discussion}
4161 Note that the definition of @lquotes@;derived from@rquotes@; is a recursive
4162 definition.
4163 We don't define a root type for all interesting
4164 language-defined classes, though presumably we could.
4165 @end{Discussion}
4166 @begin{Honest}
4167 By the class-wide type @lquotes@;associated@rquotes@; with a type @i(T),
4168 we mean the type @i(T)'Class.
4169 Similarly, the universal type associated with
4170 @i{root_integer}, @i{root_real}, and @i{root_fixed} are
4171 @i{universal_integer}, @i{universal_real}, and @i{universal_fixed},
4172 respectively.
4173 @end{Honest}
4174
4175 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00230-01]}
4176 Every type is either a @i(specific) type, a @i(class-wide) type,
4177 or a @i(universal) type.
4178 @Defn{specific type}
4179 A specific type is
4180 one defined by a @nt<type_declaration>,
4181 a @nt<formal_type_declaration>, or a full type definition
4182 embedded in @Chg{Version=[2],New=[another construct],Old=[a declaration
4183 for an object]}.
4184 Class-wide and universal types are implicitly defined, to act
4185 as representatives for an entire class of types, as follows:
4186 @begin(Honest)
4187 The root types @i(root_integer), @i(root_real), and
4188 @i(root_fixed) are also specific
4189 types. They are declared in the specification of package Standard.
4190 @end(Honest)
4191 @begin(Description)
4192 @Defn{class-wide type}Class-wide types
4193 @\Class-wide types are defined for @Redundant[(and belong to)]
4194 each derivation class rooted
4195 at a tagged type (see @RefSecNum(Tagged Types and Type Extensions)).
4196 Given a subtype S of a tagged type @i(T),
4197 S'Class is the @nt<subtype_mark> for a corresponding
4198 subtype of the tagged class-wide
4199 type @i(T)'Class. Such types are called
4200 @lquotes@;class-wide@rquotes@; because when a formal parameter is defined
4201 to be of a class-wide type @i(T)'Class, an actual parameter
4202 of any type in the derivation class rooted at @i(T) is acceptable
4203 (see @RefSecNum(The Context of Overload Resolution)).
4204
4205 @NoPrefix@Defn{first subtype}
4206 The set of values for a class-wide type @i(T)'Class is the discriminated
4207 union of the set of values of each specific type in the
4208 derivation class rooted at @i(T) (the tag acts as the implicit discriminant
4209 @em see @RefSecNum(Tagged Types and Type Extensions)).
4210 Class-wide types have no primitive subprograms of their own.
4211 However, as explained in @RefSecNum(Dispatching Operations of Tagged Types),
4212 operands of a class-wide type @i(T)'Class can be used as part
4213 of a dispatching call on a primitive subprogram of the type @i(T).
4214 The only components @Redundant[(including discriminants)] of
4215 @i(T)'Class that are visible are those of @i(T).
4216 If S is a first subtype,
4217 then S'Class is a first subtype.
4218 @begin{Reason}
4219 We want S'Class to be a first subtype when S is,
4220 so that an @nt{attribute_@!definition_@!clause} like
4221 @lquotes@key[for] S'Class'Output @key[use] ...;@rquotes@;
4222 will be legal.
4223 @end{Reason}
4224
4225 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00230-01]}
4226 @Defn{universal type}Universal types
4227 @\Universal types
4228 are defined for @Redundant[(and belong to)] the integer,
4229 real, @Chg{Version=[2],New=[],Old=[and ]}fixed point@Chg{Version=[2],
4230 New=[, and access],Old=[]} classes,
4231 and are referred to in this standard as respectively,
4232 @i(universal_integer), @i(universal_real), @Chg{Version=[2],New=[],
4233 Old=[and ]}@i(universal_fixed)@Chg{Version=[2],
4234 New=[, and @i(universal_access)@Chg{Version=[3],
4235 New=[@PDefn{universal_integer}@PDefn{universal_real}@PDefn{universal_fixed}@PDefn{universal_access}],Old=[]}],Old=[]}.
4236 These are analogous to class-wide types for these language-defined
4237 @Chg{Version=[2],New=[elementary],Old=[numeric]} classes.
4238 As with class-wide types, if a formal parameter is of a universal type,
4239 then an actual parameter of any type in the corresponding class
4240 is acceptable. In addition, a value of a universal type
4241 (including an integer or real @nt<numeric_literal>@Chg{Version=[2],New=[, or
4242 the literal @key{null}],Old=[]}) is @lquotes@;universal@rquotes@;
4243 in that it is acceptable where some particular type in the
4244 class is expected
4245 (see @RefSecNum(The Context of Overload Resolution)).
4246
4247 @NoPrefix@;The set of values of a universal type is the undiscriminated union
4248 of the set of values possible for any definable type in the associated class.
4249 Like class-wide types, universal types have no
4250 primitive subprograms of their own. However, their @lquotes@;universality@rquotes@; allows
4251 them to be used as operands with the primitive subprograms of any
4252 type in the corresponding class.
4253 @begin(Discussion)
4254 A class-wide type is only class-wide in one direction,
4255 from specific to class-wide, whereas
4256 a universal type is class-wide (universal) in both directions,
4257 from specific to universal and back.
4258
4259 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00230-01]}
4260 We considered defining class-wide or perhaps universal types for
4261 all derivation classes, not just tagged classes and these @Chg{Version=[2],
4262 New=[four elementary],Old=[three numeric]} classes. However, this was felt
4263 to overly weaken the strong-typing model in some situations. Tagged types
4264 preserve strong type distinctions thanks to the run-time tag. Class-wide
4265 or universal types for untagged types would weaken the compile-time
4266 type distinctions without providing a compensating run-time-checkable
4267 distinction.
4268
4269 We considered defining standard names for the universal
4270 numeric types so they could be used in formal parameter specifications.
4271 However, this was felt to impose an undue implementation burden for
4272 some implementations.
4273 @end(Discussion)
4274 @begin(Honest)
4275 Formally, the set of values of a universal type is actually a @i(copy) of
4276 the undiscriminated union of the values of the types in its
4277 class. This is because we
4278 want each value to have exactly one type, with explicit or implicit
4279 conversion needed to go between types. An alternative,
4280 consistent model would be to associate a class, rather than
4281 a particular type, with a value,
4282 even though any given expression would have a particular type.
4283 In that case, implicit type conversions would not generally need to
4284 change the value, although an associated subtype conversion might
4285 need to.
4286 @end(Honest)
4287 @end(Description)
4288
4289 @PDefn{root_integer}
4290 @PDefn{root_real}
4291 The integer and real numeric classes each have a specific root type in
4292 addition to their universal type, named respectively @i(root_integer)
4293 and @i(root_real).
4294
4295 @ChgRef{Version=[5],Kind=[Revised],ARef=[AI12-0325-1]}
4296 @Defn2{Term=[cover], Sec=(a type)}
4297 A class-wide or universal type is said to @i(cover) all of the types
4298 in its class.@Chg{Version=[5],New=[ In addition, @i{universal_integer} covers
4299 a type that has a specified Integer_Literal aspect, while @i{universal_real}
4300 covers a type that has a specified Real_Literal aspect (see
4301 @RefSecNum{User-Defined Literals}).],Old=[]} A specific type covers only
4302 itself.
4303
4304 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00230-01],ARef=[AI95-00251-01]}
4305 @Defn2{Term=[descendant], Sec=(of a type)}
4306 A specific type @i(T2) is defined to be a @i(descendant) of a
4307 type @i(T1) if @i(T2) is the same as @i(T1), or if @i(T2) is derived
4308 (directly or indirectly) from @i(T1). A class-wide type @i(T2)'Class is
4309 defined to be a descendant of type @i(T1) if @i(T2) is a descendant of @i(T1).
4310 Similarly, the @Chg{Version=[2],New=[numeric ],Old=[]}universal types are
4311 defined to be descendants of the root types of their classes.
4312 @Defn2{Term=[ancestor], Sec=(of a type)}
4313 If a type @i(T2) is a descendant of a type @i(T1),
4314 then @i(T1) is called an @i(ancestor) of @i(T2).
4315 @Defn2{Term=[ultimate ancestor], Sec=(of a type)}
4316 @Defn2{Term=[ancestor], Sec=(ultimate)}
4317 @Chg{Version=[2],New=[An],Old=[The]} @i(ultimate ancestor) of a type
4318 is @Chg{Version=[2],New=[an],Old=[the]} ancestor of
4319 @Chg{Version=[2],New=[that],Old=[the]} type that is not
4320 @Chg{Version=[2],New=[itself ],Old=[]}a descendant of any other
4321 type.@Chg{Version=[2],New=[ Every untagged type
4322 has a unique ultimate ancestor.],Old=[]}
4323 @begin{Ramification}
4324 A specific type is a descendant of itself.
4325 Class-wide types are considered descendants of the corresponding
4326 specific type, and do not have any descendants of their own.
4327
4328 A specific type is an ancestor of itself.
4329 The root of a derivation class is an ancestor of all types in the
4330 class, including any class-wide types in the class.
4331 @end{Ramification}
4332 @begin(Discussion)
4333 @Leading@keepnext@;The terms root, parent, ancestor, and ultimate ancestor
4334 are all related. For example:
4335 @begin(Itemize)
4336 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00251-01]}
4337 Each type has at most one parent, and one
4338 or more ancestor types; each @Chg{Version=[2],New=[untagged ],Old=[]}type
4339 has exactly one ultimate ancestor.
4340 In Ada 83, the term @lquotes@;parent type@rquotes@; was sometimes used
4341 more generally to include any ancestor type
4342 (e.g. RM83-9.4(14)). In Ada 95, we restrict
4343 parent to mean the immediate ancestor.
4344
4345 A class of types has at most one root type; a derivation class
4346 has exactly one root type.
4347
4348 The root of a class is an ancestor of all of the types in the class
4349 (including itself).
4350
4351 The type @i(root_integer) is the root of the integer class,
4352 and is the ultimate ancestor of all integer types.
4353 A similar statement applies to @i(root_real).
4354 @end(Itemize)
4355 @end(Discussion)
4356
4357 @ChgToGlossary{Version=[2],Kind=[AddedNormal],Term=<Ancestor>,
4358 Text=<@ChgAdded{Version=[2],Text=[An ancestor of a type is the type itself
4359 or, in the case of a type derived from other types, its parent type or one
4360 of its progenitor types or one of their ancestors. Note that ancestor and
4361 descendant are inverse relationships.]}>}
4362
4363 @ChgToGlossary{Version=[2],Kind=[AddedNormal],Term=<Descendant>,
4364 Text=<@ChgAdded{Version=[2],Text=[A type is a descendant of itself, its
4365 parent and progenitor types, and their ancestors. Note that descendant and
4366 ancestor are inverse relationships.]}>}
4367
4368 @Defn2{Term=[inherited], Sec=(from an ancestor type)}
4369 An inherited component @Redundant[(including an inherited discriminant)] of a
4370 derived type is inherited @i(from) a given
4371 ancestor of the type
4372 if the corresponding component was inherited by each derived type in the
4373 chain of derivations going back to the given ancestor.
4374
4375 @end{StaticSem}
4376
4377 @begin{Notes}
4378 Because operands of a universal type are acceptable to the
4379 predefined operators of any type in their class, ambiguity can
4380 result. For @i(universal_integer) and @i(universal_real), this
4381 potential ambiguity is resolved by giving a preference
4382 (see @RefSecNum{The Context of Overload Resolution})
4383 to the predefined operators
4384 of the corresponding root types (@i(root_integer)
4385 and @i(root_real), respectively).
4386 Hence, in an apparently ambiguous expression like
4387 @begin(Display)
4388 1 + 4 < 7
4389 @end(Display)
4390
4391 @NoPrefix@;where each of the literals is of type @i(universal_integer),
4392 the predefined operators of @i(root_integer) will be preferred over those
4393 of other specific integer types, thereby resolving the ambiguity.
4394 @begin(Ramification)
4395 Except for this preference, a root numeric type
4396 is essentially like any other specific type in the
4397 associated numeric class. In particular, the result of a
4398 predefined operator of a root numeric type is not @lquotes@;universal@rquotes@;
4399 (implicitly convertible) even if both operands were.
4400 @end(Ramification)
4401 @end{Notes}
4402
4403 @begin{DiffWord95}
4404 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00230-01]}
4405 @ChgAdded{Version=[2],Text=[Updated the wording to define the
4406 @i{universal_access} type. This was defined to make @key{null} for
4407 anonymous access types sensible.]}
4408
4409 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00251-01],ARef=[AI95-00401-01]}
4410 @ChgAdded{Version=[2],Text=[The definitions of ancestors and descendants
4411 were updated to allow multiple ancestors (necessary to support interfaces).]}
4412 @end{DiffWord95}
4413
4414 @begin{DiffWord2012}
4415 @ChgRef{Version=[5],Kind=[AddedNormal],ARef=[AI12-0325-1]}
4416 @ChgAdded{Version=[5],Text=[Updated the wording to say that
4417 universal types cover the types with the appropriate user-defined
4418 literal.]}
4419 @end{DiffWord2012}
4420
4421
4422 @LabeledClause{Scalar Types}
4423
4424 @begin{Intro}
4425 @Defn{scalar type}
4426 @i(Scalar) types comprise enumeration types, integer types, and real types.
4427 @Defn{discrete type}
4428 Enumeration types and integer types are called @i(discrete) types;
4429 @Defn{position number}
4430 each value of a discrete type has a @i(position number) which is an integer
4431 value.
4432 @Defn{numeric type}
4433 Integer types and real types are called @i(numeric) types.
4434 @Redundant[All scalar types are ordered, that is, all
4435 relational operators are predefined for their values.]
4436
4437 @end{Intro}
4438
4439 @begin{Syntax}
4440 @Syn{lhs=<range_constraint>,rhs=" @key{range} @Syn2{range}"}
4441
4442
4443 @Syn{lhs=<range>,rhs=" @Syn2{range_attribute_reference}
4444 | @Syn2{simple_expression} .. @Syn2{simple_expression}"}
4445 @end{Syntax}
4446 @begin(Discussion)
4447 These need to be @nt<simple_expression>s rather than
4448 more general @nt<expression>s because ranges appear in
4449 membership tests and other contexts where
4450 @nt<expression> .. @nt<expression> would
4451 be ambiguous.
4452 @end(Discussion)
4453
4454 @begin{Intro}
4455 @Defn{range}
4456 @Defn2{Term=[lower bound], Sec=(of a range)}
4457 @Defn2{Term=[upper bound], Sec=(of a range)}
4458 @Defn{type of a range}
4459 A @i(range) has a @i(lower bound) and an @i(upper bound) and
4460 specifies a subset of the values of some scalar type
4461 (the @i(type of the range)).
4462 A range with lower bound L and upper bound R is described by @lquotes@;L .. R@rquotes@;.
4463 @Defn{null range}
4464 If R is less than L, then
4465 the range is a @i(null range), and specifies an
4466 empty set of values.
4467 Otherwise, the range specifies the values of the type from
4468 the lower bound to the upper bound, inclusive.
4469 @Defn2{Term=[belong], Sec=(to a range)}
4470 A value @i(belongs) to a range if it is of the type of the
4471 range, and is in the subset of values specified by the range.
4472 @PDefn2{Term=[satisfies], Sec=(a range constraint)}
4473 A value @i(satisfies) a range constraint if it belongs to
4474 the associated range.
4475 @Defn2{Term=[included], Sec=(one range in another)}
4476 One range is @i(included) in another if all values that
4477 belong to the first range also belong to the second.
4478 @end{Intro}
4479
4480 @begin{Resolution}
4481 @PDefn2{Term=[expected type], Sec=(range_constraint range)}
4482 For a @nt<subtype_indication> containing a @nt<range_constraint>, either
4483 directly or as part of some other @nt<scalar_constraint>,
4484 the type of the @nt<range> shall resolve to that of the type determined by
4485 the @nt<subtype_mark> of the @nt<subtype_indication>.
4486 @PDefn2{Term=[expected type], Sec=(range simple_expressions)}
4487 For a @nt<range> of a given type,
4488 the @nt<simple_expression>s of the @nt<range> (likewise, the
4489 @nt<simple_expression>s of the equivalent @nt<range> for a
4490 @nt<range_attribute_reference>)
4491 are expected to be of the type of the @nt<range>.
4492 @begin(Discussion)
4493 In Ada 95, @nt<constraint>s
4494 only appear within @nt<subtype_indication>s; things that look
4495 like constraints that appear in type declarations are called
4496 something else like @nt<real_range_specification>s.
4497
4498 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0299-1]}
4499 We say "the expected type is ..." or "the type is expected to be ..."
4500 depending on which reads better. They are fundamentally equivalent,
4501 and both feed into the type resolution rules of @Chg{Version=[3],New=[subclause],Old=[clause]}
4502 @RefSecNum(The Context of Overload Resolution).
4503
4504 In some cases, it doesn't work to use expected types.
4505 For example, in the above rule, we say that
4506 the @lquotes@;type of the @nt<range> shall resolve to ...@rquotes@;
4507 rather than @lquotes@;the expected type for the @nt<range> is ...@rquotes@;.
4508 We then use @lquotes@;expected type@rquotes@; for the bounds.
4509 If we used @lquotes@;expected@rquotes@; at both points, there
4510 would be an ambiguity, since one could apply the rules of
4511 @RefSecNum{The Context of Overload Resolution}
4512 either on determining the type of the range, or on determining the
4513 types of the individual bounds. It is clearly important
4514 to allow one bound to be of a universal type, and the other of
4515 a specific type, so we need to use @lquotes@;expected type@rquotes@; for the bounds.
4516 Hence, we used @lquotes@;shall resolve to@rquotes@; for the type of the range as a
4517 whole.
4518 There are other situations where @lquotes@;expected type@rquotes@; is not quite
4519 right, and we use @lquotes@;shall resolve to@rquotes@; instead.
4520 @end(Discussion)
4521 @end{Resolution}
4522
4523 @begin{StaticSem}
4524 @RootDefn2{Term=[base range], Sec=(of a scalar type)}
4525 The @i(base range) of a scalar type is the range of
4526 finite values of the type that can be represented
4527 in every unconstrained object of the type;
4528 it is also the range supported at a minimum for
4529 intermediate values during the evaluation of expressions involving
4530 predefined operators of the type.
4531 @begin{ImplNote}
4532 Note that in some machine architectures intermediates
4533 in an expression (particularly if static),
4534 and register-resident variables might accommodate
4535 a wider range. The base range does not include the values
4536 of this wider range that are not assignable without overflow to
4537 memory-resident objects.@end{implnote}
4538 @begin(Ramification)
4539 @PDefn2{Term=[base range], Sec=(of an enumeration type)}
4540 The base range of an enumeration type is the range of values
4541 of the enumeration type.
4542 @end(Ramification)
4543 @begin{Reason}
4544
4545 If the representation supports infinities,
4546 the base range is nevertheless restricted
4547 to include only the representable finite values,
4548 so that 'Base'First and 'Base'Last are always guaranteed to be finite.@end{reason}
4549 @begin(Honest)
4550 By a "value that can be assigned without overflow" we don't mean
4551 to restrict ourselves to values that can be represented exactly.
4552 Values between machine representable values can be assigned,
4553 but on subsequent reading, a slightly different value might
4554 be retrieved, as (partially) determined by the number of digits of
4555 precision of the type.
4556 @end(Honest)
4557
4558 @Defn2{Term=[constrained], Sec=(subtype)}
4559 @Defn2{Term=[unconstrained], Sec=(subtype)}
4560 @Redundant[A constrained scalar subtype is one to which a range constraint
4561 applies.]
4562 @Defn2{Term=[range], Sec=(of a scalar subtype)}
4563 The @i(range) of a constrained scalar subtype
4564 is the range associated with the range constraint of the subtype.
4565 The @i(range) of an unconstrained scalar subtype is the base range of
4566 its type.
4567 @end{StaticSem}
4568
4569 @begin{RunTime}
4570 @PDefn2{Term=[compatibility], Sec=(range with a scalar subtype)}
4571 A range is @i(compatible) with a scalar subtype if and only
4572 if it is either a null range
4573 or each bound of the range belongs to the range of the subtype.
4574 @PDefn2{Term=[compatibility], Sec=(range_constraint with a scalar subtype)}
4575 A @nt<range_constraint> is @i(compatible) with a scalar subtype if and only if
4576 its range is compatible with the subtype.
4577 @begin(Ramification)
4578 Only @nt<range_constraint>s (explicit or implicit) impose conditions
4579 on the values of a scalar subtype. The other @nt<scalar_constraint>s,
4580 @nt<digits_constraint>s and @nt<delta_constraint>s impose conditions
4581 on the subtype denoted by the @nt<subtype_mark> in a @nt<subtype_indication>,
4582 but don't impose a condition on the values of the subtype being
4583 defined. Therefore, a scalar subtype is not called @i(constrained)
4584 if all that applies to it is a @nt<digits_constraint>.
4585 Decimal subtypes are subtle, because a @nt<digits_constraint> without
4586 a @nt<range_constraint> nevertheless includes an implicit
4587 @nt<range_constraint>.
4588 @end(Ramification)
4589
4590 @PDefn2{Term=[elaboration], Sec=(range_constraint)}
4591 The elaboration of a @nt{range_constraint} consists of the
4592 evaluation of the @nt{range}.
4593 @PDefn2{Term=[evaluation], Sec=(range)}
4594 The evaluation of a @nt{range} determines a lower bound and an upper bound.
4595 If @nt<simple_expression>s are given to specify bounds, the evaluation of
4596 the @nt<range> evaluates these @nt<simple_expression>s in an arbitrary order,
4597 and converts them to the type of the @nt<range>.@PDefn2{Term=[arbitrary order],Sec=[allowed]}
4598 @PDefn2{Term=[implicit subtype conversion],Sec=(bounds of a range)}
4599 If a @nt<range_attribute_reference> is given, the evaluation
4600 of the @nt<range>
4601 consists of the evaluation of the @nt<range_attribute_reference>.
4602
4603 @keepnext@i(Attributes)
4604
4605 @Leading@keepnext@;For @PrefixType{every scalar subtype S},
4606 the following attributes are defined:
4607 @begin(description)
4608 @Attribute{Prefix=<S>, AttrName=<First>,
4609 Text=[S'First denotes the lower bound of
4610 the range of S. The value of this attribute is of the type
4611 of S.]}
4612 @begin{Ramification}
4613 Evaluating S'First never raises Constraint_Error.@end{ramification}
4614
4615 @Attribute{Prefix=<S>, AttrName=<Last>,
4616 Text=[S'Last denotes the upper bound of
4617 the range of S. The value of this attribute is of the type
4618 of S.]}
4619 @begin{Ramification}
4620 Evaluating S'Last never raises Constraint_Error.@end{ramification}
4621
4622 @Attribute{Prefix=<S>, AttrName=<Range>,
4623 Text=[S'Range is equivalent to the @nt<range> S'First .. S'Last.]}
4624
4625 @Attribute{Prefix=<S>, AttrName=<Base>,
4626 Text=[S'Base denotes an
4627 unconstrained subtype of the type of S.
4628 This unconstrained subtype is called the @i(base subtype) of the type.
4629 ]}@Defn2{Term=(base subtype), Sec=(of a type)}
4630
4631 @AttributeLeading{Prefix=<S>, AttrName=<Min>,
4632 Text=[S'Min denotes a function with the following specification:
4633 @begin(Descexample)
4634 @b(function) S'Min(@RI(Left), @RI(Right) : S'Base)
4635 @b(return) S'Base
4636 @end(Descexample)
4637
4638 @NoPrefix@;The function returns the lesser of the values
4639 of the two parameters.]}
4640 @begin{Discussion}
4641 @Defn2{Term=[italics],Sec=(formal parameters of attribute functions)}
4642 The formal parameter names are italicized because they cannot be
4643 used in calls @em
4644 see @RefSecNum{Subprogram Calls}.
4645 Such a specification
4646 cannot be written by the user because an @nt<attribute_reference>
4647 is not permitted as the designator of a user-defined function, nor
4648 can its formal parameters be anonymous.
4649 @end{Discussion}
4650
4651 @AttributeLeading{Prefix=<S>, AttrName=<Max>,
4652 Text=[S'Max denotes a function with the following specification:
4653 @begin(Descexample)
4654 @b(function) S'Max(@RI(Left), @RI(Right) : S'Base)
4655 @b(return) S'Base
4656 @end(Descexample)
4657
4658 @NoPrefix@;The function returns the greater of the values of the two parameters.]}
4659
4660 @AttributeLeading{Prefix=<S>, AttrName=<Succ>,
4661 Text=[S'Succ denotes a function with the following specification:
4662 @begin(Descexample)
4663 @b(function) S'Succ(@RI(Arg) : S'Base)
4664 @b(return) S'Base
4665 @end(Descexample)
4666
4667 @NoPrefix@Defn2{Term=(Constraint_Error),Sec=(raised by failure of runtime check)}
4668 For an enumeration type, the function returns the value
4669 whose position number is one more than that of the value of @i(Arg);
4670 @IndexCheck{Range_Check}
4671 Constraint_Error is raised if there is no such value of the type.
4672 For an integer type, the function returns the result of
4673 adding one to the value of @i(Arg).
4674 For a fixed point type, the function returns the result of
4675 adding @i(small) to the value of @i(Arg).
4676 For a floating point type, the
4677 function returns the machine number (as defined
4678 in @RefSecNum(Floating Point Types))
4679 immediately above the value of @i(Arg);
4680 @IndexCheck{Range_Check}
4681 Constraint_Error is raised if there is no such machine number.]}
4682 @begin{Ramification}
4683 S'Succ for a modular integer subtype wraps around
4684 if the value of @i(Arg) is S'Base'Last. S'Succ for a signed integer
4685 subtype might raise Constraint_Error if the value of @i(Arg) is
4686 S'Base'Last, or it might return the out-of-base-range value
4687 S'Base'Last+1, as is permitted for all predefined numeric operations.@end{ramification}
4688
4689 @AttributeLeading{Prefix=<S>, AttrName=<Pred>,
4690 Text=[S'Pred denotes a function with
4691 the following specification:
4692 @begin(Descexample)
4693 @b(function) S'Pred(@RI(Arg) : S'Base)
4694 @b(return) S'Base
4695 @end(Descexample)
4696
4697 @NoPrefix@Defn2{Term=(Constraint_Error),Sec=(raised by failure of runtime check)}
4698 For an enumeration type, the function returns the value
4699 whose position number is one less than that of the value of @i(Arg);
4700 @IndexCheck{Range_Check}
4701 Constraint_Error is raised if there is no such value of the type.
4702 For an integer type, the function returns the result of
4703 subtracting one from the value of @i(Arg).
4704 For a fixed point type, the function returns the result of
4705 subtracting @i(small) from the value of @i(Arg).
4706 For a floating point type, the
4707 function returns the machine number (as defined
4708 in @RefSecNum(Floating Point Types))
4709 immediately below the value of @i(Arg);
4710 @IndexCheck{Range_Check}
4711 Constraint_Error is raised if there is no such machine number.]}
4712 @begin{Ramification}
4713 S'Pred for a modular integer subtype wraps around
4714 if the value of @i(Arg) is S'Base'First. S'Pred for a signed integer
4715 subtype might raise Constraint_Error if the value of @i(Arg) is
4716 S'Base'First, or it might return the out-of-base-range value
4717 S'Base'First@en@;1, as is permitted for all predefined numeric operations.@end{ramification}
4718
4719 @ChgAttribute{Version=[5],Kind=[DeletedAddedNoDelMsg],ChginAnnex=[T],
4720 Leading=<T>, Prefix=<S>, AttrName=<Wide_Wide_Image>, ARef=[AI12-0020-1],
4721 InitialVersion=[2], OmitAnnex=[T],
4722 Text=[@Chg{Version=[2],New=[@Chg{Version=[5],New=[],Old=[S'Wide_Wide_Image denotes a function
4723 with the following specification:]}],Old=[]}
4724
4725 @begin(Descexample)
4726 @ChgRef{Version=[2],Kind=[Added]}
4727 @ChgRef{Version=[5],Kind=[DeletedAddedNoDelMsg]}
4728 @ChgAdded{Version=[2],Text=[@Chg{Version=[5],New=[],Old=[@b(function) S'Wide_Wide_Image(@RI(Arg) : S'Base)
4729 @b(return) Wide_Wide_String]}]}
4730 @end(Descexample)
4731
4732 @ChgRef{Version=[2],Kind=[Added]}
4733 @ChgRef{Version=[5],Kind=[DeletedAddedNoDelMsg],ARef=[AI12-0020-1]}
4734 @ChgAdded{Version=[2],NoPrefix=[T],Text=[@Chg{Version=[5],New=[],Old=[The
4735 @Defn2{Term=[image], Sec=(of a value)}function returns an @i(image)
4736 of the value of @i(Arg),
4737 that is, a sequence of characters representing the value in display
4738 form.]}]}]}@Comment{End of Annex text here.}
4739 @ChgAdded{Version=[2],NoPrefix=[T],Text=[@Chg{Version=[5],New=[],Old=[The
4740 lower bound of the result is one.]}]}
4741
4742 @ChgRef{Version=[2],Kind=[Added]}
4743 @ChgRef{Version=[5],Kind=[DeletedAddedNoDelMsg]}
4744 @ChgAdded{Version=[2],NoPrefix=[T],Text=[@Chg{Version=[5],New=[],Old=[The
4745 image of an integer value is
4746 the corresponding decimal literal,
4747 without underlines, leading zeros, exponent, or trailing spaces, but
4748 with a single leading character that is either a minus sign or
4749 a space.]}]}
4750 @begin{ImplNote}
4751 @ChgRef{Version=[2],Kind=[AddedNormal]}
4752 @ChgRef{Version=[5],Kind=[DeletedNoDelMsg]}
4753 @ChgAdded{Version=[2],Text=[@Chg{Version=[5],New=[],Old=[If
4754 the machine supports negative zeros for signed integer types,
4755 it is not specified whether "@ 0" or "@en@;0" should be returned
4756 for negative zero. We don't have enough experience with
4757 such machines to know what is appropriate, and what other
4758 languages do. In any case, the implementation should be
4759 consistent.]}]}
4760 @end{implnote}
4761
4762 @ChgRef{Version=[2],Kind=[Added]}
4763 @ChgRef{Version=[5],Kind=[DeletedAddedNoDelMsg]}
4764 @ChgAdded{Version=[2],NoPrefix=[T],Text=[@Chg{Version=[5],New=[],Old=[The
4765 @Defn{nongraphic character}image of an enumeration value is either the
4766 corresponding identifier in upper case or the corresponding
4767 character literal (including the two apostrophes); neither leading
4768 nor trailing spaces are included.
4769 For a @i(nongraphic character) (a value of
4770 a character type that has no
4771 enumeration literal associated with it), the
4772 result is a corresponding language-defined
4773 name in upper case (for example, the image
4774 of the nongraphic character identified as @i(nul) is @lquotes@;NUL@rquotes@; @em the
4775 quotes are not part of the image).]}]}
4776 @begin{ImplNote}
4777 @ChgRef{Version=[2],Kind=[AddedNormal]}
4778 @ChgRef{Version=[5],Kind=[DeletedNoDelMsg]}
4779 @ChgAdded{Version=[2],Text=[@Chg{Version=[5],New=[],Old=[For
4780 an enumeration type T that has @lquotes@;holes@rquotes@;
4781 (caused by an @nt{enumeration_@!representation_@!clause}),
4782 T'Wide_Image should raise Program_Error if the value
4783 is one of the holes (which is a bounded error anyway,
4784 since holes can be generated only via uninitialized variables and
4785 similar things).]}]}
4786 @end{ImplNote}
4787
4788 @ChgRef{Version=[2],Kind=[Added]}
4789 @ChgRef{Version=[5],Kind=[DeletedAddedNoDelMsg]}
4790 @ChgAdded{Version=[2],NoPrefix=[T],Text=[@Chg{Version=[5],New=[],Old=[The
4791 image of a floating point value is a decimal real literal
4792 best approximating the value (rounded away from zero if halfway between)
4793 with a single leading character that is either a minus sign
4794 or a space, a single digit (that is nonzero unless the value is zero),
4795 a decimal point, S'Digits@en@;1
4796 (see @RefSecNum(Operations of Floating Point Types)) digits
4797 after the decimal point (but one if S'Digits is one),
4798 an upper case E, the sign of the
4799 exponent (either + or @en), and two or more digits
4800 (with leading zeros if necessary)
4801 representing the exponent.
4802 If S'Signed_Zeros is True, then the leading character is a minus
4803 sign for a negatively signed zero.]}]}
4804 @begin{Honest}
4805 @ChgRef{Version=[2],Kind=[AddedNormal]}
4806 @ChgRef{Version=[5],Kind=[DeletedNoDelMsg]}
4807 @ChgAdded{Version=[2],Text=[@Chg{Version=[5],New=[],Old=[Leading
4808 zeros are present in the exponent only if necessary to make
4809 the exponent at least two digits.]}]}
4810 @end{Honest}
4811 @begin{Reason}
4812 @ChgRef{Version=[2],Kind=[AddedNormal]}
4813 @ChgRef{Version=[5],Kind=[DeletedNoDelMsg]}
4814 @ChgAdded{Version=[2],Text=[@Chg{Version=[5],New=[],Old=[This
4815 image is intended to conform to that produced by
4816 Text_IO.Float_IO.Put in its default format.]}]}
4817 @end{reason}
4818 @begin{ImplNote}
4819 @ChgRef{Version=[2],Kind=[AddedNormal]}
4820 @ChgRef{Version=[5],Kind=[DeletedNoDelMsg]}
4821 @ChgAdded{Version=[2],Text=[@Chg{Version=[5],New=[],Old=[The
4822 rounding direction is specified here
4823 to ensure portability of output results.]}]}
4824 @end{implnote}
4825
4826 @ChgRef{Version=[2],Kind=[Added]}
4827 @ChgRef{Version=[5],Kind=[DeletedAddedNoDelMsg]}
4828 @ChgAdded{Version=[2],NoPrefix=[T],Text=[@Chg{Version=[5],New=[],Old=[The
4829 image of a fixed point value
4830 is a decimal real literal
4831 best approximating the value (rounded away from zero if halfway between)
4832 with a single leading character that is either a minus sign
4833 or a space, one or more digits before the decimal point
4834 (with no redundant leading zeros),
4835 a decimal point, and S'Aft (see @RefSecNum(Operations of Fixed Point Types))
4836 digits after the decimal point.]}]}
4837 @begin{Reason}
4838 @ChgRef{Version=[2],Kind=[AddedNormal]}
4839 @ChgRef{Version=[5],Kind=[DeletedNoDelMsg]}
4840 @ChgAdded{Version=[2],Text=[@Chg{Version=[5],New=[],Old=[This
4841 image is intended to conform to
4842 that produced by Text_IO.Fixed_IO.Put.]}]}
4843 @end{reason}
4844 @begin{ImplNote}
4845 @ChgRef{Version=[2],Kind=[AddedNormal]}
4846 @ChgRef{Version=[5],Kind=[DeletedNoDelMsg]}
4847 @ChgAdded{Version=[2],Text=[@Chg{Version=[5],New=[],Old=[The
4848 rounding direction is specified here
4849 to ensure portability of output results.]}]}
4850 @end{implnote}
4851 @begin{ImplNote}
4852 @ChgRef{Version=[2],Kind=[AddedNormal]}
4853 @ChgRef{Version=[5],Kind=[DeletedNoDelMsg]}
4854 @ChgAdded{Version=[2],Text=[@Chg{Version=[5],New=[],Old=[For a machine
4855 that supports negative zeros,
4856 it is not specified whether "@ 0.000" or "@en@;0.000" is returned.
4857 See corresponding comment above about integer types with
4858 signed zeros.]}]}
4859 @end{implnote}
4860
4861 @ChgAttribute{Version=[5],Kind=[DeletedNoDelMsg],ChginAnnex=[T],
4862 Leading=<T>, Prefix=<S>, AttrName=<Wide_Image>, ARef=[AI12-0020-1],
4863 InitialVersion=[0], OmitAnnex=[T],
4864 Text=[@Chg{Version=[5],New=[],Old=[S'Wide_Image denotes a function with
4865 the following specification:]}
4866
4867 @begin(Descexample)
4868 @ChgRef{Version=[5],Kind=[DeletedNoDelMsg]}
4869 @ChgDeleted{Version=[5],Text=[@b(function) S'Wide_Image(@RI(Arg) : S'Base)
4870 @b(return) Wide_String]}
4871 @end(Descexample)
4872
4873 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00285-01]}
4874 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0262-1],ARef=[AI05-0264-1]}
4875 @ChgRef{Version=[5],Kind=[DeletedNoDelMsg],ARef=[AI12-0020-1]}
4876 @ChgDeleted{Version=[5],NoPrefix=[T],Text=[@Defn2{Term=[image], Sec=(of a value)}
4877 The function returns an @Chg{Version=[2],New=[image],Old=[@i(image)]} of
4878 the value of @i(Arg)@Chg{Version=[2],New=[ as a Wide_String],Old=[,
4879 that is, a sequence of characters representing the value in display
4880 form]}.]}]}@Comment{End of Attribute Annex text}
4881 @ChgDeleted{Version=[5],Text=[The lower bound of the result is
4882 one.@Chg{Version=[2],
4883 New=[ The image has the same sequence of @Chg{Version=[3],New=[graphic
4884 characters],Old=[character]} as
4885 defined for S'Wide_Wide_Image if all the graphic characters are defined in
4886 Wide_Character; otherwise@Chg{Version=[3],New=[,],Old=[]}
4887 the sequence of characters is
4888 implementation defined (but no shorter than that of S'Wide_Wide_Image for
4889 the same value of Arg).],Old=[]}]}
4890
4891 @ChgImplDef{Version=[5],Kind=[DeletedNoDelMsg],
4892 InitialVersion=[2],Text=[@ChgAdded{Version=[2],
4893 Text=[@Chg{Version=[5],New=[],Old=[The
4894 sequence of characters of the value returned by
4895 S'Image when some of the graphic characters of
4896 S'Wide_Wide_Image are not defined in Character.]}]}]}
4897
4898
4899 @begin{NotIso}
4900 @ChgAdded{Version=[2],Noprefix=[T],Noparanum=[T],Text=[@Shrink{@i<Paragraphs
4901 @Chg{Version=[5],New=[28],Old=[31]} through @Chg{Version=[5],New=[37],Old=[34]}
4902 were moved to
4903 @Chg{Version=[5],New=[@RefSec{Image Attributes}],Old=[Wide_Wide_Image]}.>}]}@Comment{This
4904 message should be deleted if the paragraphs are ever renumbered.}
4905 @end{NotIso}
4906
4907 @ChgRef{Version=[2],Kind=[DeletedNoDelMsg],ARef=[AI95-00285-01]}
4908 @ChgDeleted{Version=[2],NoPrefix=[T],Text=[The image of an integer value is
4909 the corresponding decimal literal,
4910 without underlines, leading zeros, exponent, or trailing spaces, but
4911 with a single leading character that is either a minus sign or
4912 a space.]}
4913 @begin{ImplNote}
4914 @ChgRef{Version=[2],Kind=[DeletedNoDelMsg]}
4915 @ChgDeleted{Version=[2],Text=[
4916 If the machine supports negative zeros for signed integer types,
4917 it is not specified whether "@en@;0" or " 0" should be returned
4918 for negative zero. We don't have enough experience with
4919 such machines to know what is appropriate, and what other
4920 languages do. In any case, the implementation should be
4921 consistent.]}
4922 @end{implnote}
4923
4924 @ChgRef{Version=[2],Kind=[DeletedNoDelMsg],ARef=[AI95-00285-01]}
4925 @ChgDeleted{Version=[2],NoPrefix=[T],Text=[@Defn{nongraphic character}
4926 The image of an enumeration value is either the corresponding
4927 identifier in upper case or the corresponding character literal
4928 (including the two apostrophes); neither leading nor trailing
4929 spaces are included.
4930 For a @i(nongraphic character) (a value of
4931 a character type that has no
4932 enumeration literal associated with it), the
4933 result is a corresponding language-defined or implementation-defined
4934 name in upper case (for example, the image
4935 of the nongraphic character identified as @i(nul) is @lquotes@;NUL@rquotes@; @em the
4936 quotes are not part of the image).]}
4937 @begin{ImplNote}
4938 @ChgRef{Version=[2],Kind=[DeletedNoDelMsg]}
4939 @ChgDeleted{Version=[2],Text=[For an enumeration type T
4940 that has @lquotes@;holes@rquotes@;
4941 (caused by an @nt{enumeration_representation_clause}),
4942 T'Wide_Image should raise Program_Error if the value
4943 is one of the holes (which is a bounded error anyway,
4944 since holes can be generated only via uninitialized variables and
4945 similar things).]}
4946 @end{ImplNote}
4947
4948 @ChgRef{Version=[2],Kind=[DeletedNoDelMsg],ARef=[AI95-00285-01]}
4949 @ChgDeleted{Version=[2],NoPrefix=[T],Text=[The image of a
4950 floating point value is a decimal real literal
4951 best approximating the value (rounded away from zero if halfway
4952 between)
4953 with a single leading character that is either a minus sign
4954 or a space, a single digit (that is nonzero unless the value is zero),
4955 a decimal point, S'Digits@en@;1
4956 (see @RefSecNum(Operations of Floating Point Types)) digits
4957 after the decimal point (but one if S'Digits is one),
4958 an upper case E, the sign of the
4959 exponent (either + or @en), and two or more digits
4960 (with leading zeros if necessary)
4961 representing the exponent.
4962 If S'Signed_Zeros is True, then the leading character is a minus
4963 sign for a negatively signed zero.]}
4964 @begin{Honest}
4965 @ChgRef{Version=[2],Kind=[DeletedNoDelMsg]}
4966 @ChgDeleted{Version=[2],Text=[Leading zeros are present in the
4967 exponent only if necessary to make the exponent at least two digits.]}
4968 @end{Honest}
4969 @begin{Reason}
4970 @ChgRef{Version=[2],Kind=[DeletedNoDelMsg]}
4971 @ChgDeleted{Version=[2],Text=[This image is intended to conform to
4972 that produced by
4973 Text_IO.Float_IO.Put in its default format.]}
4974 @end{reason}
4975 @begin{ImplNote}
4976 @ChgRef{Version=[2],Kind=[DeletedNoDelMsg]}
4977 @ChgDeleted{Version=[2],Text=[The rounding direction is specified here
4978 to ensure portability of output results.]}
4979 @end{implnote}
4980
4981 @ChgRef{Version=[2],Kind=[DeletedNoDelMsg],ARef=[AI95-00285-01]}
4982 @ChgDeleted{Version=[2],NoPrefix=[T],Text=[The image of a
4983 fixed point value is a decimal real literal
4984 best approximating the value (rounded away from zero if halfway between)
4985 with a single leading character that is either a minus sign
4986 or a space, one or more digits before the decimal point
4987 (with no redundant leading zeros),
4988 a decimal point, and S'Aft (see @RefSecNum(Operations of Fixed Point Types))
4989 digits after the decimal point.]}
4990 @begin{Reason}
4991 @ChgRef{Version=[2],Kind=[DeletedNoDelMsg]}
4992 @ChgDeleted{Version=[2],Text=[This image is intended to conform to
4993 that produced by Text_IO.Fixed_IO.Put.]}
4994 @end{reason}
4995 @begin{ImplNote}
4996 @ChgRef{Version=[2],Kind=[DeletedNoDelMsg]}
4997 @ChgDeleted{Version=[2],Text=[The rounding direction is specified here
4998 to ensure portability of output results.]}
4999 @end{implnote}
5000 @begin{ImplNote}
5001 @ChgRef{Version=[2],Kind=[DeletedNoDelMsg]}
5002 @ChgDeleted{Version=[2],Text=[For a machine that supports negative zeros,
5003 it is not specified whether "@en@;0.000" or " 0.000" is returned.
5004 See corresponding comment above about integer types with
5005 signed zeros.]}
5006 @end{implnote}
5007
5008 @ChgAttribute{Version=[5],Kind=[DeletedNoDelMsg],ChginAnnex=[T],
5009 Leading=<T>, Prefix=<S>, AttrName=<Image>, ARef=[AI12-0020-1],
5010 InitialVersion=[0], OmitAnnex=[T],
5011 Text=[@Chg{Version=[5],New=[],Old=[S'Image denotes a function with
5012 the following specification:]}
5013
5014 @begin(Descexample)
5015 @ChgRef{Version=[5],Kind=[DeletedNoDelMsg]}
5016 @ChgDeleted{Version=[5],Text=[@b(function) S'Image(@RI(Arg) : S'Base)
5017 @b(return) String]}
5018 @end(Descexample)
5019
5020 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00285-01]}
5021 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0264-1]}
5022 @ChgRef{Version=[5],Kind=[DeletedNoDelMsg],ARef=[AI12-0020-1]}
5023 @ChgDeleted{Version=[5],NoPrefix=[T],Text=[The function returns an image of the value of @i(Arg)
5024 as a String.]}]}@Comment{End of Attribute Annex text.}
5025 @ChgDeleted{Version=[5],Text=[The lower bound of the result is one. The
5026 image has the same sequence of graphic characters as that defined
5027 for S'@Chg{Version=[2],New=[Wide_Wide_Image],Old=[Wide_Image]} if all
5028 the graphic characters are defined in Character;
5029 otherwise@Chg{Version=[3],New=[,],Old=[]}
5030 the sequence of characters is implementation defined (but
5031 no shorter than that of S'@Chg{Version=[2],New=[Wide_Wide_Image],
5032 Old=[Wide_Image]} for the same value of @i(Arg)).]}
5033
5034 @ChgImplDef{Version=[5],Kind=[DeletedNoDelMsg],
5035 InitialVersion=[0],Text=[@Chg{Version=[5],New=[],Old=[The
5036 sequence of characters of the value returned by
5037 S'Image when some of the graphic characters of
5038 S'@Chg{Version=[2],New=[Wide_Wide_Image],Old=[Wide_Image]} are not
5039 defined in Character.]}]}
5040
5041 @ChgAttribute{Version=[5],Kind=[RevisedAdded],ChginAnnex=[T],
5042 Leading=<F>, Prefix=<S>, AttrName=<Wide_Wide_Width>, ARef=[AI95-00285-01], ARef=[AI12-0020-1],
5043 InitialVersion=[2], Text=[@Chg{Version=[2],New=[S'Wide_Wide_Width denotes the
5044 maximum length of a Wide_Wide_String
5045 returned by S'Wide_Wide_Image over all values of the
5046 subtype S@Chg{Version=[5],New=[, assuming a default implementation of
5047 S'Put_Image],Old=[]}. It denotes zero for a subtype that has
5048 a null range. Its type is @i(universal_integer).],Old=[]}]}
5049
5050 @ChgAttribute{Version=[5],Kind=[Revised],ChginAnnex=[T],
5051 Leading=<F>, Prefix=<S>, AttrName=<Wide_Width>, ARef=[AI12-0020-1],
5052 InitialVersion=[0], Text=[S'Wide_Width denotes the maximum length
5053 of a Wide_String
5054 returned by S'Wide_Image over all values of the
5055 subtype S@Chg{Version=[5],New=[, assuming a default implementation of
5056 S'Put_Image],Old=[]}. It denotes zero for a subtype that has
5057 a null range. Its type is @i(universal_integer).]}
5058
5059 @ChgAttribute{Version=[5],Kind=[Revised],ChginAnnex=[T],
5060 Leading=<F>, Prefix=<S>, AttrName=<Width>, ARef=[AI12-0020-1],
5061 InitialVersion=[0], Text=[S'Width denotes the maximum length
5062 of a String returned by S'Image over all values of the
5063 subtype S@Chg{Version=[5],New=[, assuming a default implementation of
5064 S'Put_Image],Old=[]}. It denotes zero for a subtype that has
5065 a null range. Its type is @i(universal_integer).]}
5066
5067 @ChgAttribute{Version=[2],Kind=[Added],ChginAnnex=[T],
5068 Leading=<T>, Prefix=<S>, AttrName=<Wide_Wide_Value>, ARef=[AI95-00285-01],
5069 Text=[@Chg{Version=[2],New=[S'Wide_Wide_Value denotes a function
5070 with the following specification:],Old=[]}
5071 @begin(Descexample)
5072 @ChgRef{Version=[2],Kind=[Added]}
5073 @ChgAdded{Version=[2],Text=[@b(function) S'Wide_Wide_Value(@RI(Arg) : Wide_Wide_String)
5074 @b(return) S'Base]}
5075 @end(Descexample)
5076 @ChgRef{Version=[2],Kind=[Added]}
5077 @ChgAdded{Version=[2],NoPrefix=[T],Text=[This function returns
5078 a value given an image of the value
5079 as a Wide_Wide_String, ignoring any leading or trailing spaces.]}]}
5080
5081 @ChgRef{Version=[2],Kind=[Added]}
5082 @ChgRef{Version=[3],Kind=[RevisedAdded],ARef=[AI05-0264-1]}
5083 @ChgAdded{Version=[2],NoPrefix=[T],Text=[@PDefn2{Term=[evaluation], Sec=(Wide_Wide_Value)}
5084 @Defn2{Term=(Constraint_Error),Sec=(raised by failure of runtime check)}
5085 For the evaluation of a call on S'Wide_Wide_Value
5086 for an enumeration subtype S,
5087 if the sequence of characters of the parameter (ignoring
5088 leading and trailing spaces) has the syntax
5089 of an enumeration literal and if it corresponds to a literal of the
5090 type of S (or corresponds to the result of S'Wide_Wide_Image
5091 for a nongraphic character of the type),
5092 the result is the corresponding enumeration value;
5093 @IndexCheck{Range_Check}
5094 otherwise@Chg{Version=[3],New=[,],Old=[]}
5095 Constraint_Error is raised.]}
5096 @begin{Discussion}
5097 @ChgRef{Version=[2],Kind=[Added]}
5098 @ChgAdded{Version=[2],Text=[It's not crystal clear that Range_Check
5099 is appropriate here,
5100 but it doesn't seem worthwhile to invent a whole new check name
5101 just for this weird case, so we decided to lump it in with
5102 Range_Check.]}
5103 @end{discussion}
5104 @begin{Honest}
5105 @ChgRef{Version=[2],Kind=[Added],Ref=[8652/0096],ARef=[AI95-00053-01]}
5106 @ChgAdded{Version=[2],Text=[A sequence of
5107 characters corresponds to the result of
5108 S'Wide_Wide_Image if it is the same ignoring case. Thus, the case of an
5109 image of a nongraphic character does not matter. For example,
5110 Character'Wide_Wide_Value("nul") does not raise Constraint_Error, even though
5111 Character'Wide_Wide_Image returns "NUL" for the nul character.]}
5112 @end{Honest}
5113
5114 @ChgRef{Version=[2],Kind=[Added]}
5115 @ChgRef{Version=[3],Kind=[RevisedAdded],ARef=[AI05-0264-1]}
5116 @ChgAdded{Version=[2],NoPrefix=[T],Text=[@Defn2{Term=(Constraint_Error),
5117 Sec=(raised by failure of runtime check)}
5118 For the evaluation of a call on S'Wide_Wide_Value for an integer
5119 subtype S, if the sequence of characters of the
5120 parameter (ignoring leading and trailing spaces)
5121 has the syntax of an integer literal,
5122 with an optional leading sign character
5123 (plus or minus for a signed type;
5124 only plus for a modular type), and the
5125 corresponding numeric value belongs to the base range of the
5126 type of S, then that value is the result;
5127 @IndexCheck{Range_Check}
5128 otherwise@Chg{Version=[3],New=[,],Old=[]}
5129 Constraint_Error is raised.]}
5130
5131 @begin(Discussion)
5132 @ChgRef{Version=[2],Kind=[Added]}
5133 @ChgAdded{Version=[2],Text=[We considered allowing 'Value
5134 to return a representable but out-of-range
5135 value without a Constraint_Error. However, we currently require
5136 (see @RefSecNum(Static Expressions and Static Subtypes))
5137 in an @nt{assignment_statement} like "X := <numeric_literal>;" that
5138 the value of the
5139 numeric-literal be in X's base range (at compile time), so it seems
5140 unfriendly and confusing to have a different range allowed for 'Value.
5141 Furthermore, for modular types, without the requirement for being
5142 in the base range, 'Value would have to handle arbitrarily long
5143 literals (since overflow never occurs for modular types).]}
5144 @end(Discussion)
5145
5146 @ChgRef{Version=[2],Kind=[Added]}
5147 @ChgAdded{Version=[2],NoPrefix=[T],Type=[Leading],Text=[For the
5148 evaluation of a call on S'Wide_Wide_Value for a
5149 real subtype S, if the sequence of characters of the
5150 parameter (ignoring leading and trailing spaces)
5151 has the syntax of one of the following:]}
5152 @begin[itemize]
5153 @ChgRef{Version=[2],Kind=[Added]}
5154 @ChgAdded{Version=[2],Text=[@nt[numeric_literal]]}
5155
5156 @ChgRef{Version=[2],Kind=[Added]}
5157 @ChgAdded{Version=[2],Text=<@nt[numeral].[@nt[exponent]]>}
5158
5159 @ChgRef{Version=[2],Kind=[Added]}
5160 @ChgAdded{Version=[2],Text=<.@nt[numeral][@nt[exponent]]>}
5161
5162 @ChgRef{Version=[2],Kind=[Added]}
5163 @ChgAdded{Version=[2],Text=<@nt[base]#@nt[based_numeral].#[@nt[exponent]]>}
5164
5165 @ChgRef{Version=[2],Kind=[Added]}
5166 @ChgAdded{Version=[2],Text=<@nt[base]#.@nt[based_numeral]#[@nt[exponent]]>}
5167 @end{Itemize}
5168
5169 @ChgRef{Version=[2],Kind=[Added]}
5170 @ChgRef{Version=[3],Kind=[RevisedAdded],ARef=[AI05-0264-1]}
5171 @ChgAdded{Version=[2],NoPrefix=[T],Text=[@Defn2{Term=(Constraint_Error),
5172 Sec=(raised by failure of runtime check)}
5173 with an optional leading sign character (plus or minus), and if the
5174 corresponding numeric value belongs to the base range of the
5175 type of S, then that value is the result;
5176 @IndexCheck{Range_Check}
5177 otherwise@Chg{Version=[3],New=[,],Old=[]}
5178 Constraint_Error is raised.
5179 The sign of a zero value is preserved
5180 (positive if none has been specified)
5181 if S'Signed_Zeros is True.]}
5182
5183
5184 @AttributeLeading{Prefix=<S>, AttrName=<Wide_Value>,
5185 Text=[S'Wide_Value denotes a function with
5186 the following specification:
5187 @begin(Descexample)
5188 @b(function) S'Wide_Value(@RI(Arg) : Wide_String)
5189 @b(return) S'Base
5190 @end(Descexample)
5191
5192 @NoPrefix@;This function returns a value given an image of the value
5193 as a Wide_String, ignoring any leading or trailing
5194 spaces.]}@Comment{This marks the end of the Annex text.}
5195
5196 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00285-01]}
5197 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0264-1]}
5198 @ChgRef{Version=[5],Kind=[Revised],ARef=[AI12-0020-1]}
5199 @NoPrefix@PDefn2{Term=[evaluation], Sec=(Wide_Value)}
5200 @Defn2{Term=(Constraint_Error),Sec=(raised by failure of runtime check)}
5201 For the evaluation of a call on S'Wide_Value
5202 for an enumeration subtype S,
5203 if the sequence of characters of the parameter (ignoring
5204 leading and trailing spaces) has the syntax
5205 of an enumeration literal and if it corresponds to a literal of the
5206 type of S (or corresponds to the result of S'Wide_Image
5207 for a @Chg{Version=[2],New=[value],Old=[nongraphic character]} of the
5208 type@Chg{Version=[5],New=[, assuming a default implementation
5209 of S'Put_Image],Old=[]}), the result is the corresponding enumeration value;
5210 @IndexCheck{Range_Check}
5211 otherwise@Chg{Version=[3],New=[,],Old=[]} Constraint_Error is raised.
5212 @Chg{Version=[2],New=[For a numeric subtype S,
5213 the evaluation of a call on S'Wide_Value with @i(Arg) of type Wide_String
5214 is equivalent to a call on S'Wide_Wide_Value for a corresponding
5215 @i(Arg) of type Wide_Wide_String.],Old=[]}
5216 @begin{Discussion}
5217 @ChgRef{Version=[2],Kind=[Deleted]}
5218 @ChgDeleted{Version=[2],Text=[It's not crystal clear that Range_Check
5219 is appropriate here,
5220 but it doesn't seem worthwhile to invent a whole new check name
5221 just for this weird case, so we decided to lump it in with
5222 Range_Check.]}
5223 @end{discussion}
5224 @begin{Honest}
5225 @ChgRef{Version=[1],Kind=[Added],Ref=[8652/0096],ARef=[AI95-00053-01]}
5226 @ChgRef{Version=[2],Kind=[DeletedAdded]}
5227 @ChgDeleted{Version=[2],Text=[
5228 @Chg{Version=[1],New=[A sequence of characters corresponds to the result of
5229 S'Wide_Image if it is the same ignoring case. Thus, the case of an
5230 image of a nongraphic character does not matter. For example,
5231 Character'Wide_Value("nul") does not raise Constraint_Error, even though
5232 Character'Wide_Image returns "NUL" for the nul character.],Old=[]}]}
5233 @end{Honest}
5234 @begin(Reason)
5235 @ChgRef{Version=[2],Kind=[AddedNormal]}
5236 @ChgAdded{Version=[2],Text=[S'Wide_Value is subtly different from
5237 S'Wide_Wide_Value for enumeration
5238 subtypes since S'Wide_Image might produce a different sequence of
5239 characters than S'Wide_Wide_Image if the enumeration literal
5240 uses characters outside of the predefined type Wide_Character.
5241 That is why we don't just define S'Wide_Value in terms of
5242 S'Wide_Wide_Value for enumeration subtypes.
5243 S'Wide_Value and S'Wide_Wide_Value for numeric subtypes yield
5244 the same result given the same sequence of characters.]}
5245 @end(Reason)
5246
5247 @begin{NotIso}
5248 @ChgAdded{Version=[2],Noprefix=[T],Noparanum=[T],Text=[@Shrink{@i<Paragraphs 44
5249 through 51 were moved to Wide_Wide_Value.>}]}@Comment{This message should be deleted if the
5250 paragraphs are ever renumbered.}
5251 @end{NotIso}
5252
5253 @ChgRef{Version=[2],Kind=[DeletedNoDelMsg],ARef=[AI95-00285-01]}
5254 @ChgDeleted{Version=[2],NoPrefix=[T],Text=[@Defn2{Term=(Constraint_Error),
5255 Sec=(raised by failure of runtime check)}
5256 For the evaluation of a call on S'Wide_Value (or S'Value) for an integer
5257 subtype S, if the sequence of characters of the
5258 parameter (ignoring leading and trailing spaces)
5259 has the syntax of an integer literal,
5260 with an optional leading sign character
5261 (plus or minus for a signed type;
5262 only plus for a modular type), and the
5263 corresponding numeric value belongs to the base range of the
5264 type of S, then that value is the result;
5265 @IndexCheck{Range_Check}
5266 otherwise Constraint_Error is raised.]}
5267
5268 @begin(Discussion)
5269 @ChgRef{Version=[2],Kind=[DeletedNoDelMsg]}
5270 @ChgDeleted{Version=[2],Text=[We considered allowing 'Value
5271 to return a representable but out-of-range
5272 value without a Constraint_Error. However, we currently require
5273 (see @RefSecNum(Static Expressions and Static Subtypes))
5274 in an @nt{assignment_statement} like "X := <numeric_literal>;" that
5275 the value of the
5276 numeric-literal be in X's base range (at compile time), so it seems
5277 unfriendly and confusing to have a different range allowed for 'Value.
5278 Furthermore, for modular types, without the requirement for being
5279 in the base range, 'Value would have to handle arbitrarily long
5280 literals (since overflow never occurs for modular types).]}
5281 @end(Discussion)
5282
5283 @ChgRef{Version=[2],Kind=[DeletedNoDelMsg]}
5284 @ChgDeleted{Version=[2],NoPrefix=[T],Type=[Leading],Text=[For the
5285 evaluation of a call on S'Wide_Value (or S'Value) for a
5286 real subtype S, if the sequence of characters of the
5287 parameter (ignoring leading and trailing spaces)
5288 has the syntax of one of the following:]}
5289 @begin[itemize]
5290 @ChgRef{Version=[2],Kind=[DeletedNoDelMsg]}
5291 @ChgDeleted{Version=[2],Text=<@nt[numeric_literal]>}
5292
5293 @ChgRef{Version=[2],Kind=[DeletedNoDelMsg]}
5294 @ChgDeleted{Version=[2],Text=<@nt[numeral].[@nt[exponent]]>}
5295
5296 @ChgRef{Version=[2],Kind=[DeletedNoDelMsg]}
5297 @ChgDeleted{Version=[2],Text=<.@nt[numeral][@nt[exponent]]>}
5298
5299 @ChgRef{Version=[2],Kind=[DeletedNoDelMsg]}
5300 @ChgDeleted{Version=[2],Text=<@nt[base]#@nt[based_numeral].#[@nt[exponent]]>}
5301
5302 @ChgRef{Version=[2],Kind=[DeletedNoDelMsg]}
5303 @ChgDeleted{Version=[2],Text=[@nt[base]#.@nt[based_numeral]#[@nt[exponent]]]}
5304 @end{Itemize}
5305
5306 @ChgRef{Version=[2],Kind=[DeletedNoDelMsg]}
5307 @ChgDeleted{Version=[2],NoPrefix=[T],Text=[@Defn2{Term=(Constraint_Error),
5308 Sec=(raised by failure of runtime check)}
5309 with an optional leading sign character (plus or minus), and if the
5310 corresponding numeric value belongs to the base range of the
5311 type of S, then that value is the result;
5312 @IndexCheck{Range_Check}
5313 otherwise Constraint_Error is raised.
5314 The sign of a zero value is preserved
5315 (positive if none has been specified)
5316 if S'Signed_Zeros is True.]}
5317
5318 @AttributeLeading{Prefix=<S>, AttrName=<Value>,
5319 Text=[S'Value denotes a function with
5320 the following specification:
5321 @begin(Descexample)
5322 @b(function) S'Value(@RI(Arg) : String)
5323 @b(return) S'Base
5324 @end(Descexample)
5325
5326 @NoPrefix@;This function returns a value given an image of the value
5327 as a String, ignoring any leading or trailing spaces.]}
5328
5329 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00285-01]}
5330 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0264-1]}
5331 @ChgRef{Version=[5],Kind=[Revised],ARef=[AI12-0020-1]}
5332 @NoPrefix@PDefn2{Term=[evaluation], Sec=(Value)}
5333 @Defn2{Term=(Constraint_Error),Sec=(raised by failure of runtime check)}
5334 For the evaluation of a call on S'Value
5335 for an enumeration subtype S,
5336 if the sequence of characters of the parameter (ignoring
5337 leading and trailing spaces) has the syntax
5338 of an enumeration literal and if it corresponds to a literal of the
5339 type of S (or corresponds to the result of S'Image
5340 for a value of the type@Chg{Version=[5],New=[, assuming a
5341 default implementation of S'Put_Image],Old=[]}),
5342 the result is the corresponding enumeration value;
5343 @IndexCheck{Range_Check}
5344 otherwise@Chg{Version=[3],New=[,],Old=[]} Constraint_Error is raised.
5345 For a numeric subtype S,
5346 the evaluation of a call on S'Value with @i(Arg) of type String
5347 is equivalent to a call on S'@Chg{Version=[2],New=[Wide_Wide_Value],Old=[Wide_Value]} for a corresponding
5348 @i(Arg) of type @Chg{Version=[2],New=[Wide_Wide_String],Old=[Wide_String]}.
5349 @begin(Reason)
5350 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00285-01]}
5351 S'Value is subtly different from S'@Chg{Version=[2],New=[Wide_Wide_Value],Old=[Wide_Value]} for enumeration
5352 subtypes@Chg{Version=[2],New=[; see the discussion under S'Wide_Value],
5353 Old=[since S'Image might produce a different sequence of
5354 characters than S'Wide_Image if the enumeration literal
5355 uses characters outside of the predefined type Character.
5356 That is why we don't just define S'Value in terms of S'Wide_Value
5357 for enumeration subtypes.
5358 S'Value and S'Wide_Value for numeric subtypes yield
5359 the same result given the same sequence of characters]}.
5360 @end(Reason)
5361
5362 @EndPrefixType{}
5363 @end(description)
5364
5365 @ChgRef{Version=[4],Kind=[Added],ARef=[AI12-0124-1]}
5366 @ChgRef{Version=[5],Kind=[DeletedAddedNoDelMsg],ARef=[AI12-0020-1],ARef=[AI12-0225-1]}
5367 @ChgAdded{Version=[4],Type=[Leading],Keepnext=[T],Text=[@Chg{Version=[5],New=[],Old=[For
5368 @PrefixType{a
5369 @nt{prefix} X that denotes an object of a scalar
5370 type@Redundant[ (after
5371 any implicit dereference)]}, the following attributes are defined:]}]}
5372
5373 @begin(description)
5374 @ChgAttribute{Version=[5],Kind=[DeletedAddedNoDelMsg],ChginAnnex=[T],
5375 Leading=<F>, Prefix=<X>, AttrName=<Wide_Wide_Image>,
5376 InitialVersion=[4], OmitAnnex=[T], ARef=[AI12-0124-1], ARef=[AI12-0020-1],
5377 Text=[@Chg{Version=[4],New=[@Chg{Version=[5],New=[],Old=[X'Wide_Wide_Image
5378 denotes the result of
5379 calling function S'Wide_Wide_Image with @i<Arg> being X, where S is the
5380 nominal subtype of X.]}],Old=[]}]}
5381
5382 @ChgAttribute{Version=[5],Kind=[DeletedAddedNoDelMsg],ChginAnnex=[T],
5383 Leading=<F>, Prefix=<X>, AttrName=<Wide_Image>,
5384 InitialVersion=[4], OmitAnnex=[T], ARef=[AI12-0124-1], ARef=[AI12-0020-1],
5385 Text=[@Chg{Version=[4],New=[@Chg{Version=[5],New=[],Old=[X'Wide_Image
5386 denotes the result of
5387 calling function S'Wide_Image with @i<Arg> being X, where S is the
5388 nominal subtype of X.]}],Old=[]}]}
5389
5390 @ChgAttribute{Version=[5],Kind=[DeletedAddedNoDelMsg],ChginAnnex=[T],
5391 Leading=<F>, Prefix=<X>, AttrName=<Image>,
5392 InitialVersion=[4], OmitAnnex=[T], ARef=[AI12-0124-1], ARef=[AI12-0020-1],
5393 Text=[@Chg{Version=[4],New=[@Chg{Version=[5],New=[],Old=[X'Image
5394 denotes the result of
5395 calling function S'Image with @i<Arg> being X, where S is the
5396 nominal subtype of X.]}],Old=[]}]}
5397
5398 @EndPrefixType{}
5399 @end(description)
5400 @end{RunTime}
5401
5402 @begin{ImplPerm}
5403
5404 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00285-01]}
5405 An implementation may extend the @Chg{Version=[2],New=[Wide_Wide_Value, ],
5406 Old=[Wide_Value, ]}
5407 @Redundant[@Chg{Version=[2],New=[Wide_Value, ],Old=[]}Value,
5408 @Chg{Version=[2],New=[Wide_Wide_Image, ],
5409 Old=[]}Wide_Image, and Image] attributes
5410 of a floating point type
5411 to support special values such as infinities and NaNs.
5412
5413 @begin{TheProof}
5414 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00285-01]}
5415 The permission is really only necessary for @Chg{Version=[2],New=[Wide_Wide_Value],
5416 Old=[Wide_Value]},
5417 because Value @Chg{Version=[2],New=[and Wide_Value are],Old=[is]} defined in
5418 terms of @Chg{Version=[2],New=[Wide_Wide_Value],
5419 Old=[Wide_Value]},
5420 and because the behavior of @Chg{Version=[2],New=[Wide_Wide_Image, ],
5421 Old=[]}Wide_Image@Chg{Version=[2],New=[,],Old=[]} and Image is already
5422 unspecified for things like infinities and NaNs.
5423 @end{TheProof}
5424 @begin{Reason}
5425 This is to allow implementations to define full support for IEEE
5426 arithmetic.
5427 See also the similar permission for Get in
5428 @RefSecNum{Input-Output for Real Types}.
5429 @end{Reason}
5430
5431 @ChgRef{Version=[3],Kind=[Added],ARef=[AI05-0182-1],ARef=[AI05-0262-1],ARef=[AI05-0269-1]}
5432 @ChgAdded{Version=[3],Text=[An implementation may extend the Wide_Wide_Value,
5433 Wide_Value, and Value attributes of a character type to accept
5434 strings of the form @ldquote@;Hex_@i<hhhhhhhh>@rdquote (ignoring case) for any
5435 character (not just the ones for which Wide_Wide_Image would produce that form
5436 @em see @RefSecNum{Character Types}), as well as three-character strings of
5437 the form @ldquote@;'@i<X>'@rdquote, where @i<X> is any character, including
5438 nongraphic characters.]}
5439 @end{ImplPerm}
5440
5441 @begin{StaticSem}
5442 @ChgRef{Version=[3],Kind=[Added],ARef=[AI05-0228-1]}
5443 @ChgAdded{Version=[3],Type=[Leading],Text=[For a scalar type,
5444 the following language-defined representation aspect
5445 may be specified with an @nt{aspect_specification} (see
5446 @RefSecNum{Aspect Specifications}):]}
5447 @begin{Description}
5448 @ChgRef{Version=[3],Kind=[Added]}
5449 @ChgAdded{Version=[3],Text=[Default_Value@\This aspect
5450 shall be specified by a static expression, and that
5451 expression shall be explicit, even if the aspect has a boolean type.
5452 Default_Value shall be specified only on a
5453 @nt{full_type_declaration}.@AspectDefn{Default_Value}]}
5454 @begin{Reason}
5455 @ChgRef{Version=[3],Kind=[AddedNormal]}
5456 @ChgAdded{Version=[3],Text=[The part about requiring an explicit expression is
5457 to disallow omitting the value for this aspect, which would otherwise be
5458 allowed by the rules of @RefSecNum{Aspect Specifications}.]}
5459
5460 @ChgRef{Version=[3],Kind=[AddedNormal]}
5461 @ChgAdded{Version=[3],Text=[This is a representation aspect in order to
5462 disallow specifying it on a derived type that has inherited primitive
5463 subprograms; that is necessary as the sizes of @key[out] parameters could be
5464 different whether or not a Default_Value is specified (see @RefSecNum{Parameter Associations}).]}
5465 @end{Reason}
5466 @ChgAspectDesc{Version=[3],Kind=[AddedNormal],Aspect=[Default_Value],
5467 Text=[@ChgAdded{Version=[3],Text=[Default value for a scalar subtype.]}]}
5468 @end{Description}
5469
5470 @ChgRef{Version=[3],Kind=[Added],ARef=[AI05-0228-1]}
5471 @ChgAdded{Version=[3],Text=[If a derived type with no primitive subprograms
5472 inherits a boolean Default_Value aspect, the aspect may be specified to have any
5473 value for the derived type.]}
5474 @begin{Reason}
5475 @ChgRef{Version=[3],Kind=[AddedNormal]}
5476 @ChgAdded{Version=[3],Text=[This overrides the
5477 @RefSecNum{Aspect Specifications} rule that says that a boolean aspect
5478 with a value True cannot be changed.]}
5479 @end{Reason}
5480 @end{StaticSem}
5481
5482 @begin{Resolution}
5483 @ChgRef{Version=[3],Kind=[Added],ARef=[AI05-0228-1]}
5484 @ChgAdded{Version=[3],Text=[The expected type for the @nt{expression}
5485 specified for the Default_Value aspect is the type defined by the
5486 @nt{full_type_declaration} on which it
5487 appears.@PDefn2{Term=[expected type],Sec=[@nt{expression} of a Default_Value aspect]}]}
5488 @end{Resolution}
5489
5490 @begin{Notes}
5491 The evaluation of S'First or S'Last never raises an exception.
5492 If a scalar subtype S has a nonnull range, S'First and S'Last
5493 belong to this range. These values can, for example, always be
5494 assigned to a variable of subtype S.
5495 @begin(Discussion)
5496 This paragraph addresses an issue that came up with Ada 83,
5497 where for fixed point types, the end points of the range
5498 specified in the type definition were not necessarily within
5499 the base range of the type. However, it was later clarified (and
5500 we reconfirm it in @RefSec(Fixed Point Types)) that the First and
5501 Last attributes reflect the true bounds chosen for the type, not the
5502 bounds specified in the type definition (which might be outside
5503 the ultimately chosen base range).
5504 @end(Discussion)
5505
5506 For a subtype of a scalar type, the result delivered by the attributes
5507 Succ, Pred, and Value might not belong to the subtype; similarly,
5508 the actual parameters
5509 of the attributes Succ, Pred, and Image need not belong to the subtype.
5510
5511 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00285-01]}
5512 @ChgRef{Version=[5],Kind=[Revised],ARef=[AI12-0020-1]}
5513 For any value V (including any nongraphic character) of an
5514 enumeration subtype S@Chg{Version=[5],New=[ without a specified Put_Image
5515 (see @RefSecNum{Image Attributes})],Old=[]}, S'Value(S'Image(V)) equals V,
5516 as @Chg{Version=[2],New=[do],Old=[does]} S'Wide_Value(S'Wide_Image(V))@Chg{Version=[2],
5517 New=[ and S'Wide_Wide_Value(S'Wide_Wide_Image(V))],Old=[]}.
5518 @Chg{Version=[2],New=[None of these
5519 expressions],Old=[Neither expression]} ever @Chg{Version=[2],New=[raise],Old=[raises]}
5520 Constraint_Error.
5521 @end{Notes}
5522
5523 @begin{Examples}
5524 @Leading@keepnext@i(Examples of ranges:)
5525 @begin{Example}
5526 -10 .. 10
5527 X .. X + 1
5528 0.0 .. 2.0*Pi
5529 Red .. Green --@RI[ see @RefSecNum{Enumeration Types}]
5530 1 .. 0 --@RI[ a null range]
5531 Table'Range --@RI[ a range attribute reference (see @RefSecNum{Array Types})]
5532
5533 @end{Example}
5534 @Leading@keepnext@i(Examples of range constraints:)
5535 @begin{Example}
5536 @key(range) -999.0 .. +999.0
5537 @key(range) S'First+1 .. S'Last-1
5538 @end{Example}
5539 @end{Examples}
5540
5541 @begin{Incompatible83}
5542 @ChgRef{Version=[1],Kind=[Revised]}@ChgNote{To be consistent with 8652/0006}
5543 @Defn{incompatibilities with Ada 83}
5544 S'Base is no longer defined for nonscalar types.
5545 One conceivable existing use of S'Base for nonscalar types is
5546 S'Base'Size where S is a generic formal private type.
5547 However, that is not generally useful because the actual
5548 subtype corresponding to S might be a constrained array
5549 or discriminated type, which would mean that S'Base'Size might
5550 very well overflow (for example, S'Base'Size where S is
5551 a constrained subtype of String will generally be 8 * (Integer'Last + 1)).
5552 For derived discriminated types that are packed, S'Base'Size might not even
5553 be well defined if the first subtype is constrained, thereby allowing
5554 some amount of normally required @lquotes@;dope@rquotes@; to have been squeezed out
5555 in the packing. Hence our conclusion is that S'Base'Size is
5556 not generally useful in a generic, and does not justify keeping
5557 the attribute Base for nonscalar types just so it can be used
5558 as a @Chg{New=[@nt{prefix}],Old=[prefix]}.
5559
5560 @end{Incompatible83}
5561
5562 @begin{Extend83}
5563 @Defn{extensions to Ada 83}
5564 The attribute S'Base for a scalar subtype is now permitted
5565 anywhere a @nt{subtype_mark} is permitted.
5566 S'Base'First .. S'Base'Last
5567 is the base range of the type.
5568 Using an @nt{attribute_@!definition_@!clause},
5569 one cannot specify any subtype-specific attributes
5570 for the subtype denoted by S'Base
5571 (the base subtype).
5572
5573 The attribute S'Range is now allowed for scalar subtypes.
5574
5575 The attributes S'Min and S'Max are now defined, and made available for all
5576 scalar types.
5577
5578 The attributes S'Succ, S'Pred, S'Image, S'Value, and S'Width are
5579 now defined for real types as well as discrete types.
5580
5581 Wide_String versions of S'Image and S'Value are defined.
5582 These are called S'Wide_Image and S'Wide_Value to avoid
5583 introducing ambiguities involving uses of these attributes
5584 with string literals.
5585 @end{Extend83}
5586
5587 @begin{DiffWord83}
5588 We now use the syntactic category @nt<range_attribute_reference> since
5589 it is now syntactically distinguished from other attribute references.
5590
5591 The definition of S'Base has been moved here from
5592 3.3.3 since it now applies only to scalar types.
5593
5594 More explicit rules are provided for nongraphic characters.
5595 @end{DiffWord83}
5596
5597 @begin{Extend95}
5598 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00285-01]}
5599 @ChgAdded{Version=[2],Text=[@Defn{extensions to Ada 95}
5600 The attributes Wide_Wide_Image, Wide_Wide_Value, and Wide_Wide_Width are new.
5601 Note that Wide_Image and Wide_Value are now defined in terms of
5602 Wide_Wide_Image and Wide_Wide_Value, but the image of types other than
5603 characters have not changed.]}
5604 @end{Extend95}
5605
5606 @begin{DiffWord95}
5607 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00285-01]}
5608 @ChgAdded{Version=[2],Text=[
5609 The Wide_Image and Wide_Value attributes are now defined in terms of
5610 Wide_Wide_Image and Wide_Wide_Value, but the images of numeric types
5611 have not changed.]}
5612 @end{DiffWord95}
5613
5614 @begin{Inconsistent2005}
5615 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0181-1]}
5616 @ChgAdded{Version=[3],Text=[@Defn{inconsistencies with Ada 2005}@b<Correction:>
5617 Soft hyphen (code point 173) is nongraphic in ISO/IEC 10646:2011 (and also
5618 in the 2003 version of that standard). Thus, we
5619 have given it the language-defined name @i{soft_hyphen}. This changes the
5620 result of Character'Image (and all of the related types and Image attributes)
5621 for this character, and changes the behavior of Character'Value (and all of
5622 the related types and Value attributes) for this character, and
5623 (in unusual circumstances), changes the result for Character'Width (and all
5624 of the related types and Width attributes). The vast majority of programs
5625 won't see any difference, as they are already prepared to handle nongraphic
5626 characters.]}
5627
5628 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0182-1]}
5629 @ChgAdded{Version=[3],Text=[@b<Correction:>
5630 Added an @ImplPermTitle to let Wide_Wide_Value, Wide_Value, and Value accept
5631 strings in the form of literals containing nongraphic characters and
5632 "Hex_hhhhhhhh" for Latin-1 and graphic characters. These were required to
5633 raise Constraint_Error in Ada 2005. Since these attributes aren't very
5634 useful, implementations were inconsistent as to whether these were accepted,
5635 and since code that would care why the attribute failed seems unlikely,
5636 this should not be a problem in practice.]}
5637 @end{Inconsistent2005}
5638
5639 @begin{Extend2005}
5640 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0228-1]}
5641 @ChgAdded{Version=[3],Text=[@Defn{extensions to Ada 2005}
5642 The new aspect Default_Value allows defining implicit initial values (see
5643 @RefSecNum{Object Declarations}) for scalar types.]}
5644 @end{Extend2005}
5645
5646 @begin{Extend2012}
5647 @ChgRef{Version=[4],Kind=[AddedNormal],ARef=[AI12-0124-1]}
5648 @ChgAdded{Version=[4],Text=[@Defn{extensions to Ada 2012}
5649 @b<Corrigendum:> An object can be now used as the prefix of the Image
5650 attribute (as well as Wide_Image and Wide_Wide_Image), a
5651 convenience feature already present in some implementations.]}
5652
5653 @ChgRef{Version=[5],Kind=[AddedNormal],ARef=[AI12-0020-1]}
5654 @ChgAdded{Version=[5],Text=[All of the Image-family attributes have
5655 been moved to @RefSecNum{Image Attributes}.]}
5656 @end{Extend2012}
5657
5658
5659
5660 @LabeledSubClause{Enumeration Types}
5661
5662 @begin{Intro}
5663 @Redundant[@Defn{enumeration type}
5664 An @nt<enumeration_type_definition> defines an enumeration type.]
5665 @end{Intro}
5666
5667 @begin{Syntax}
5668 @Syn{lhs=<enumeration_type_definition>,rhs="
5669 (@Syn2{enumeration_literal_specification} {, @Syn2{enumeration_literal_specification}})"}
5670
5671
5672 @Syn{lhs=<enumeration_literal_specification>,
5673 rhs=" @Syn2{defining_identifier} | @Syn2{defining_character_literal}"}
5674
5675 @Syn{lhs=<defining_character_literal>,rhs="@Syn2{character_literal}"}
5676 @end{Syntax}
5677
5678 @begin{Legality}
5679 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0227-1],ARef=[AI05-0299-1]}
5680 The @nt<defining_identifier>s@Chg{Version=[3],New=[ in upper case],Old=[]}
5681 @Redundant[and@Chg{Version=[3],New=[ the],Old=[]}
5682 @nt<defining_character_literal>s] listed in an
5683 @nt<enumeration_type_definition> shall be distinct.
5684 @begin{TheProof}
5685 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0227-1]}
5686 @Chg{Version=[3],New=[For character literals, this],Old=[This]}
5687 is a ramification of the normal disallowance
5688 of homographs explicitly declared immediately in the same
5689 declarative region.
5690 @end{TheProof}
5691 @begin{Reason}
5692 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0227-1]}
5693 @ChgAdded{Version=[3],Text=[To ease implementation of the attribute
5694 Wide_Wide_Value, we require that all enumeration literals have distinct
5695 images.]}
5696 @end{Reason}
5697 @end{Legality}
5698
5699 @begin{StaticSem}
5700 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0006-1]}
5701 @Defn{enumeration literal}
5702 Each @nt<enumeration_literal_specification> is the explicit declaration
5703 of the corresponding @i(enumeration literal): it declares
5704 a parameterless function,
5705 whose defining name is the @nt<defining_@!identifier>
5706 or @nt<defining_@!character_@!literal>, and whose result
5707 @Chg{Version=[3],New=[subtype is the base subtype of],Old=[type
5708 is]} the enumeration type.
5709 @begin{Reason}
5710 This rule defines the profile of the enumeration literal,
5711 which is used in the various types of conformance.
5712 @end{Reason}
5713 @begin{Ramification}
5714 The parameterless function associated with an enumeration literal
5715 is fully defined by the @nt<enumeration_type_definition>;
5716 a body is not permitted for it,
5717 and it never fails the Elaboration_Check when called.
5718 @end{Ramification}
5719 @begin{Discussion}
5720 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0006-1]}
5721 @ChgAdded{Version=[3],Text=[The result subtype is primarily a concern
5722 when an enumeration literal is used as the @nt{expression} of a
5723 case statement, due to the full coverage requirement based on the
5724 nominal subtype.]}
5725 @end{Discussion}
5726
5727 Each enumeration literal corresponds to a distinct value
5728 of the enumeration type, and to a distinct position number.
5729 @PDefn2{Term=[position number], Sec=(of an enumeration value)}
5730 The position number of the value of
5731 the first listed enumeration literal
5732 is zero; the position number of the value of each
5733 subsequent enumeration literal
5734 is one more than that of its predecessor in the list.
5735
5736 @redundant[The predefined order relations between values of
5737 the enumeration type follow the
5738 order of corresponding position numbers.]
5739
5740 @redundant[@PDefn2{Term=[overloaded], Sec=(enumeration literal)}
5741 If the same @nt<defining_identifier> or
5742 @nt<defining_character_literal> is specified in more than one
5743 @nt<enumeration_@!type_@!definition>, the corresponding enumeration literals
5744 are said to be @i(overloaded). At any place where an overloaded
5745 enumeration literal occurs in the text of a program, the type
5746 of the enumeration literal has to be determinable from the context
5747 (see @RefSecNum(The Context of Overload Resolution)).]
5748 @end{StaticSem}
5749
5750 @begin{RunTime}
5751 @PDefn2{Term=[elaboration], Sec=(enumeration_type_definition)}
5752 @Defn2{Term=[constrained], Sec=(subtype)}
5753 @Defn2{Term=[unconstrained], Sec=(subtype)}
5754 The elaboration of an @nt<enumeration_type_definition> creates
5755 the enumeration type and its first subtype,
5756 which is constrained to the base range of the type.
5757 @begin{Ramification}
5758 The first subtype of a discrete type is always constrained,
5759 except in the case of a derived type whose parent subtype
5760 is Whatever'Base.
5761 @end{Ramification}
5762
5763 When called, the parameterless function associated with an enumeration literal
5764 returns the corresponding value of the enumeration type.
5765 @end{RunTime}
5766
5767 @begin{Notes}
5768 If an enumeration literal occurs in a context that does not
5769 otherwise suffice to determine the type of the literal, then qualification
5770 by the name of the enumeration type is one way to resolve
5771 the ambiguity (see @RefSecNum(Qualified Expressions)).
5772 @end{Notes}
5773
5774 @begin{Examples}
5775 @Leading@keepnext@i(Examples of enumeration types and subtypes: )
5776 @begin(Example)
5777 @key(type) Day @key(is) (Mon, Tue, Wed, Thu, Fri, Sat, Sun);
5778 @key(type) Suit @key(is) (Clubs, Diamonds, Hearts, Spades);
5779 @key(type) Gender @key(is) (M, F);
5780 @key(type) Level @key(is) (Low, Medium, Urgent);
5781 @key(type) Color @key(is) (White, Red, Yellow, Green, Blue, Brown, Black);
5782 @key(type) Light @key(is) (Red, Amber, Green); --@RI[ Red and Green are overloaded]
5783
5784 @key(type) Hexa @key(is) ('A', 'B', 'C', 'D', 'E', 'F');
5785 @key(type) Mixed @key(is) ('A', 'B', '*', B, None, '?', '%');
5786
5787 @key(subtype) Weekday @key(is) Day @key(range) Mon .. Fri;
5788 @key(subtype) Major @key(is) Suit @key(range) Hearts .. Spades;
5789 @key(subtype) Rainbow @key(is) Color @key(range) Red .. Blue; --@RI[ the Color Red, not the Light]
5790 @end(Example)
5791 @end{Examples}
5792
5793 @begin{DiffWord83}
5794 The syntax rule for @nt{defining_character_literal} is new.
5795 It is used for the defining occurrence of a @nt{character_literal},
5796 analogously to @nt{defining_identifier}.
5797 Usage occurrences use the @nt{name} or @nt{selector_name}
5798 syntactic categories.
5799
5800 We emphasize the fact that an enumeration literal denotes
5801 a function, which is called to produce a value.
5802 @end{DiffWord83}
5803
5804 @begin{Incompatible2005}
5805 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0227-1]}
5806 @ChgAdded{Version=[3],Text=[@Defn{incompatibilities with Ada 2005}@b<Correction:>
5807 Required that all enumeration
5808 literals in a type have distinct images; this might not be the case since
5809 upper case conversion can map distinct characters to the same upper case
5810 character. This can only happen for identifiers using Unicode characters first
5811 allowed by Ada 2005; moreover, the original definition of Ada 2005 was
5812 confused and appeared to require inconsistent results from the Image
5813 attribute, so implementations that allowed problematic cases are rare; the
5814 problematic cases are very rare; so it is expected that this change would
5815 only affect test programs.]}
5816 @end{Incompatible2005}
5817
5818 @begin{DiffWord2005}
5819 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0006-1]}
5820 @ChgAdded{Version=[3],Text=[@b<Correction:> Defined the result
5821 subtype of an enumeration literal to close a minor language hole.]}
5822 @end{DiffWord2005}
5823
5824
5825 @LabeledSubClause{Character Types}
5826
5827 @begin{StaticSem}
5828 @Defn{character type}
5829 An enumeration type is said to be a @i(character type) if at least
5830 one of its enumeration literals is a @nt<character_literal>.
5831
5832 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00285-01]}
5833 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0181-1],ARef=[AI05-0262-1],ARef=[AI05-0266-1]}
5834 @ChgRef{Version=[5],Kind=[Revised],ARef=[AI12-0263-1]}
5835 @Defn{Latin-1}
5836 @Defn{BMP}
5837 @Chg{Version=[2],New=[@Chg{Version=[3],New=[@Chg{Version=[5],New=[@Defn{ISO/IEC 10646:2017}],
5838 Old=[@Defn{ISO/IEC 10646:2011}]}],
5839 Old=[@Defn{ISO/IEC 10646:2003}]}],Old=[@Defn{ISO 10646}]}
5840 @Defn{Character}
5841 The predefined type Character is a character type whose values
5842 correspond to the 256 code @Chg{Version=[3],New=[points],Old=[positions]}
5843 of Row 00 (also known as Latin-1) of the
5844 @Chg{Version=[2],New=[ISO/IEC 10646:@Chg{Version=[3],New=[@Chg{Version=[5],New=[2017],Old=[2011]}],
5845 Old=[2003]}],Old=[ISO 10646]} Basic Multilingual Plane (BMP).
5846 Each of the graphic characters of Row 00 of the BMP has
5847 a corresponding @nt<character_literal> in Character.
5848 Each of the nongraphic @Chg{Version=[3],New=[characters],Old=[positions]}
5849 of Row 00@Chg{Version=[3],New=[],Old=[ (0000-001F and 007F-009F)]}
5850 has a corresponding language-defined name, which is not usable as an
5851 enumeration literal,
5852 but which is usable with the attributes @Chg{Version=[2],New=[Image,
5853 Wide_Image, Wide_Wide_Image, Value, Wide_Value, and Wide_Wide_Value],
5854 Old=[(Wide_)Image and (Wide_)Value]};
5855 these names are given in the definition of type Character
5856 in @RefSec{The Package Standard}, but are set in @i{italics}.
5857 @Defn2{Term=[italics],Sec=(nongraphic characters)}
5858 @Chg{Version=[3],New=[@PDefn2{Term=[code point],Sec=[for characters]}],Old=[]}
5859
5860 @begin{Discussion}
5861 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0262-1]}
5862 @ChgRef{Version=[5],Kind=[Revised],ARef=[AI12-0263-1]}
5863 @ChgAdded{Version=[3],Text=[@i{Code point} is defined in ISO/IEC 10646:@Chg{Version=[5],New=[2017],Old=[2011]}.]}
5864 @end{Discussion}
5865
5866 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00285-01]}
5867 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0262-1]}
5868 @ChgRef{Version=[5],Kind=[Revised],ARef=[AI12-0263-1]}
5869 @Defn{Wide_Character}
5870 @Defn{BMP}
5871 @Chg{Version=[2],New=[@Chg{Version=[3],New=[@Chg{Version=[5],New=[@Defn{ISO/IEC 10646:2017}],
5872 Old=[@Defn{ISO/IEC 10646:2011}]}],
5873 Old=[@Defn{ISO/IEC 10646:2003}]}],Old=[@Defn{ISO 10646}]}
5874 The predefined type Wide_Character is a character type whose
5875 values correspond to the 65536 code
5876 @Chg{Version=[3],New=[points],Old=[positions]} of the @Chg{Version=[2],
5877 New=[ISO/IEC 10646:@Chg{Version=[3],New=[@Chg{Version=[5],New=[2017],
5878 Old=[2011]}],Old=[2003]}],Old=[ISO 10646]} Basic Multilingual Plane (BMP).
5879 Each of the graphic characters of the BMP has
5880 a corresponding @nt<character_literal> in Wide_Character.
5881 The first 256 values of Wide_Character
5882 have the same @nt<character_literal> or language-defined
5883 name as defined for Character. @Chg{Version=[2],New=[Each of the
5884 @ntf{graphic_character}s has],Old=[The last 2 values
5885 of Wide_Character correspond to the nongraphic
5886 positions FFFE and FFFF of the BMP,
5887 and are assigned
5888 the language-defined names @i(FFFE) and @i(FFFF). As with the other
5889 language-defined names for nongraphic characters,
5890 the names @i(FFFE) and @i(FFFF) are usable only with the attributes
5891 (Wide_)Image and (Wide_)Value; they are not usable as enumeration
5892 literals.
5893 All other values of Wide_Character are considered graphic characters,
5894 and have]} a corresponding @nt<character_literal>.
5895
5896 @ChgRef{Version=[2],Kind=[Added],ARef=[AI95-00285-01]}
5897 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0262-1]}@Comment{This changes the paragraph number! I didn't catch this until 2018, so it stays.}
5898 @ChgRef{Version=[5],Kind=[Revised],ARef=[AI12-0263-1]}
5899 @ChgAdded{Version=[2],Text=[@Defn{Wide_Wide_Character}
5900 @Chg{Version=[2],New=[@Chg{Version=[3],New=[@Chg{Version=[5],New=[@Defn{ISO/IEC 10646:2017}],
5901 Old=[@Defn{ISO/IEC 10646:2011}]}],
5902 Old=[@Defn{ISO/IEC 10646:2003}]}],Old=[@Defn{ISO 10646}]}
5903 The predefined type Wide_Wide_Character is a character type whose values
5904 correspond to the 2147483648 code @Chg{Version=[3],New=[points],Old=[positions]}
5905 of the ISO/IEC 10646:@Chg{Version=[3],New=[@Chg{Version=[5],New=[2017],
5906 Old=[2011]}],Old=[2003]} character set.
5907 Each of the @ntf{graphic_character}s
5908 has a corresponding @nt{character_literal} in
5909 Wide_Wide_Character. The first 65536 values of Wide_Wide_Character have the
5910 same @nt{character_literal} or language-defined name as defined for
5911 Wide_Character.]}
5912
5913 @ChgRef{Version=[2],Kind=[Added],ARef=[AI95-00285-01]}
5914 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0262-1]}@Comment{This changes the paragraph number! I didn't catch this until 2018, so it stays.}
5915 @ChgAdded{Version=[2],Text=[The characters whose code
5916 @Chg{Version=[3],New=[point],Old=[position]} is larger
5917 than 16#FF# and which are not @ntf{graphic_character}s have language-defined
5918 names which are formed by appending to the string "Hex_" the
5919 representation of their code @Chg{Version=[3],New=[point],Old=[position]}
5920 in hexadecimal as eight extended digits.
5921 As with other language-defined names, these names are usable only with the
5922 attributes (Wide_)Wide_Image and (Wide_)Wide_Value; they are not usable as
5923 enumeration literals.]}
5924
5925 @begin{Reason}
5926 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00285-01]}
5927 The language-defined names are not usable as
5928 enumeration literals to avoid "polluting" the name space. Since
5929 Wide_Character @Chg{Version=[2],New=[and Wide_Wide_Character ],Old=[]}are
5930 defined in Standard, if the @Chg{Version=[2],New=[language-defined ],
5931 Old=[]}names @Chg{Version=[2],New=[],Old=[FFFE and FFFF ]}were usable
5932 as enumeration literals, they would hide other nonoverloadable declarations
5933 with the same names in @key[use]-d packages.]}
5934
5935 @ChgRef{Version=[2],Kind=[DeletedNoDelMsg],ARef=[AI95-00285-01]}
5936 @ChgDeleted{Version=[2],Text=[ISO 10646 has not defined the meaning of
5937 all of the code positions
5938 from 0100 through FFFD, but they are all considered graphic characters by
5939 Ada to simplify the implementation, and to allow for revisions to ISO 10646.
5940 In ISO 10646, FFFE and FFFF are special, and will never be associated
5941 with graphic characters in any revision.]}
5942 @end{Reason}
5943 @end{StaticSem}
5944
5945 @begin{ImplPerm}
5946 @ChgRef{Version=[2],Kind=[DeletedNoDelMsg],ARef=[AI95-00285-01]}
5947 @ChgDeleted{Version=[2],Text=[@Defn{localization}
5948 In a nonstandard mode, an implementation may provide
5949 other interpretations for the predefined types Character and
5950 Wide_Character@Redundant[, to conform to local conventions].]}
5951 @end{ImplPerm}
5952 @begin{NotIso}
5953 @ChgAdded{Version=[2],Noparanum=[T],Text=[@Shrink{@i<Original Paragraphs 4 and 5
5954 were deleted.>}]}@Comment{This message should be deleted if the paragraphs
5955 are ever renumbered.}
5956 @end{NotIso}
5957
5958 @begin{ImplAdvice}
5959 @ChgRef{Version=[2],Kind=[DeletedNoDelMsg],ARef=[AI95-00285-01]}
5960 @ChgDeleted{Version=[2],Text=[@Defn{localization}
5961 If an implementation supports a mode with alternative interpretations
5962 for Character and Wide_Character, the set of graphic characters
5963 of Character should nevertheless remain
5964 a proper subset of the set of graphic characters of Wide_Character.
5965 Any character set @lquotes@;localizations@rquotes@; should be reflected in the results of
5966 the subprograms defined in the language-defined package Characters.Handling
5967 (see @RefSecNum{Character Handling}) available in such a mode.
5968 In a mode with an alternative interpretation of Character, the
5969 implementation should also support a corresponding change in what is
5970 a legal @ntf<identifier_letter>.]}
5971 @ChgNote{We won't add an ChgImplAdvice here, because we would need to add
5972 and remove it in the same command.}
5973 @end{ImplAdvice}
5974
5975 @begin{Notes}
5976 The language-defined library package Characters.Latin_1
5977 (see @RefSecNum(The Package Characters.Latin_1))
5978 includes the declaration of constants
5979 denoting control characters, lower case characters, and special characters
5980 of the predefined type Character.
5981 @begin{Honest}
5982 The package ASCII does the same, but only for the first
5983 128 characters of Character. Hence, it is an obsolescent
5984 package, and we no longer mention it here.
5985 @end{Honest}
5986
5987 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0299-1]}
5988 A conventional character set such as @i(EBCDIC) can be declared as
5989 a character type; the internal codes of the characters can be specified
5990 by an @nt<enumeration_representation_clause> as explained in
5991 @Chg{Version=[3],New=[subclause],Old=[clause]} @RefSecNum(Enumeration Representation Clauses).
5992 @end{Notes}
5993
5994 @begin{Examples}
5995 @Leading@keepnext@i(Example of a character type: )
5996 @begin(Example)
5997 @key(type) Roman_Digit @key(is) ('I', 'V', 'X', 'L', 'C', 'D', 'M');
5998 @end(Example)
5999 @end{Examples}
6000
6001 @begin{Inconsistent83}
6002 @Defn{inconsistencies with Ada 83}
6003 The declaration of Wide_Character in package Standard hides
6004 use-visible declarations with the same defining identifier.
6005 In the unlikely event that an Ada 83 program had depended on
6006 such a use-visible declaration, and the program remains
6007 legal after the substitution of Standard.Wide_Character,
6008 the meaning of the program will be different.
6009 @end{Inconsistent83}
6010
6011 @begin{Incompatible83}
6012 @Defn{incompatibilities with Ada 83}
6013 The presence of Wide_Character in package Standard means that
6014 an expression such as
6015 @begin(Example)
6016 'a' = 'b'
6017 @end(Example)
6018
6019 is ambiguous in Ada 95, whereas in Ada 83 both
6020 literals could be resolved to be of type Character.
6021
6022 The change in visibility rules (see @RefSecNum(Literals))
6023 for character literals means
6024 that additional qualification might be necessary to resolve
6025 expressions involving overloaded subprograms and
6026 character literals.
6027 @end{Incompatible83}
6028
6029 @begin{Extend83}
6030 @Defn{extensions to Ada 83}
6031 The type Character has been extended to have 256 positions,
6032 and the type Wide_Character has been added.
6033 Note that this change was already approved by the ARG
6034 for Ada 83 conforming compilers.
6035
6036 The rules for referencing character literals are changed
6037 (see @RefSecNum(Literals)),
6038 so that the declaration of the character type need
6039 not be directly visible to use its literals,
6040 similar to @b(null) and string literals.
6041 Context is used to resolve their type.
6042 @end{Extend83}
6043
6044 @begin{Inconsistent95}
6045 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00285-01]}
6046 @ChgAdded{Version=[2],Text=[@Defn{inconsistencies with Ada 95}
6047 Ada 95 defined most characters in Wide_Character to be graphic characters,
6048 while Ada 2005 uses the categorizations from ISO-10646:2003. It also
6049 provides language-defined names for all nongraphic characters. That
6050 means that in Ada 2005, Wide_Character'Wide_Value will raise Constraint_Error
6051 for a string representing a @nt{character_literal} of a nongraphic character,
6052 while Ada 95 would have accepted it. Similarly, the result of
6053 Wide_Character'Wide_Image will change for such nongraphic characters.]}
6054
6055 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00395-01]}
6056 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0005-1],ARef=[AI05-0262-1]}
6057 @ChgAdded{Version=[2],Text=[The language-defined names FFFE and FFFF were
6058 replaced by a consistent set of language-defined names for all nongraphic
6059 characters with @Chg{Version=[3],New=[code points],Old=[positions]}
6060 greater than 16#FF#. That means that
6061 in Ada 2005, Wide_Character'Wide_Value("FFFE") will raise Constraint_Error
6062 while Ada 95 would have accepted it. Similarly, the result of
6063 Wide_Character'Wide_Image will change for the position numbers 16#FFFE#
6064 and 16#FFFF#. It is very unlikely that this will matter in practice,
6065 as these names do not represent @Chg{Version=[3],New=[usable],Old=[useable]}
6066 characters.]}
6067
6068 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00285-01],ARef=[AI95-00395-01]}
6069 @ChgAdded{Version=[2],Text=[Because of the previously mentioned changes to
6070 the Wide_Character'Wide_Image of various character values, the value of
6071 attribute Wide_Width will change for some subtypes of Wide_Character.
6072 However, the new language-defined names were chosen so that the value of
6073 Wide_Character'Wide_Width itself does not change.]}
6074
6075 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00285-01]}
6076 @ChgAdded{Version=[2],Text=[The declaration of Wide_Wide_Character in
6077 package Standard hides use-visible declarations with the same defining
6078 identifier. In the (very) unlikely event that an Ada 95 program had
6079 depended on such a use-visible declaration, and the program remains
6080 legal after the substitution of Standard.Wide_Wide_Character,
6081 the meaning of the program will be different.]}
6082 @end{Inconsistent95}
6083
6084 @begin{Extend95}
6085 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00285-01]}
6086 @ChgAdded{Version=[2],Text=[@Defn{extensions to Ada 95}
6087 The type Wide_Wide_Character is new.]}
6088 @end{Extend95}
6089
6090 @begin{DiffWord95}
6091 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00285-01]}
6092 @ChgAdded{Version=[2],Text=[Characters are now defined in terms of
6093 the entire ISO/IEC 10646:2003 character set.]}
6094
6095 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00285-01]}
6096 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0248-1]}
6097 @ChgAdded{Version=[2],Text=[We dropped the @ImplAdviceTitle for
6098 @Chg{Version=[3],New=[nonstandard],Old=[non-standard]} interpretation of
6099 character sets; an implementation can do what it wants in a
6100 @Chg{Version=[3],New=[nonstandard],Old=[non-standard]} mode, so there isn't
6101 much point to any advice.]}
6102 @end{DiffWord95}
6103
6104 @begin{DiffWord2005}
6105 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0181-1]}
6106 @ChgAdded{Version=[3],Text=[@b<Correction:> Removed the position numbers
6107 of nongraphic characters from the text, as it is wrong and thus
6108 misleading.]}
6109
6110 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0262-1]}
6111 @ChgAdded{Version=[3],Text=[Changed "code position" to "code point"
6112 consistently throughout the standard, as ISO/IEC 10646:2011 prefers
6113 "code point" and we are referring to the definition in that Standard.
6114 This change also reduces confusion between "code point"
6115 and "position number"; while these have the same values for the predefined
6116 character types, there is no required relationship for other character
6117 types.@PDefn2{Term=[code point],Sec=[for characters]}]}
6118 @end{DiffWord2005}
6119
6120
6121 @LabeledSubClause{Boolean Types}
6122
6123 @begin{StaticSem}
6124 @Defn{Boolean}
6125 There is a predefined enumeration type named Boolean,
6126 @Redundant[declared in the visible part of package Standard].
6127 @Defn{False}
6128 @Defn{True}
6129 It has the two enumeration literals False and True ordered
6130 with the relation False < True.
6131 @Defn{boolean type}
6132 Any descendant of the predefined type Boolean is called
6133 a @i(boolean) type.
6134 @begin{ImplNote}
6135 An implementation is not required to support
6136 enumeration representation clauses on boolean types that
6137 impose an unacceptable implementation burden.
6138 See @RefSec(Enumeration Representation Clauses).
6139 However, it is generally straightforward to support representations
6140 where False is zero and True is 2**n @en@; 1 for some n.
6141 @end{ImplNote}
6142 @end{StaticSem}
6143
6144 @LabeledSubClause{Integer Types}
6145
6146 @begin{Intro}
6147 @Defn{integer type}
6148 @Defn{signed integer type}
6149 @Defn{modular type}
6150 An @nt<integer_type_definition> defines an integer type;
6151 it defines either a @i(signed)
6152 integer type, or a @i(modular) integer type.
6153 The base range
6154 of a signed integer type includes at
6155 least the values of the specified
6156 range.
6157 A modular type is an integer type with all arithmetic modulo
6158 a specified positive @i(modulus);
6159 such a type corresponds to an unsigned
6160 type with wrap-around semantics.
6161 @IndexSee{Term=[unsigned type],See=(modular type)}
6162 @end{Intro}
6163
6164 @begin{Syntax}
6165 @Syn{lhs=<integer_type_definition>,
6166 rhs="@Syn2{signed_integer_type_definition} | @Syn2{modular_type_definition}"}
6167
6168 @Syn{lhs=<signed_integer_type_definition>,
6169 rhs="@key(range) @SynI{static_}@Syn2{simple_expression} .. @SynI{static_}@Syn2{simple_expression}"}
6170 @begin{Discussion}
6171 We don't call this a @nt<range_constraint>,
6172 because it is rather different @em not only is
6173 it required to be static, but the associated overload resolution rules are
6174 different than for normal range constraints. A similar comment applies to
6175 @nt{real_range_specification}.
6176 This used to be @ntf<integer_range_specification> but when we
6177 added support for modular types, it seemed overkill to have three levels
6178 of syntax rules, and just calling these
6179 @ntf<signed_integer_range_specification>
6180 and @ntf<modular_range_specification> loses the fact that they
6181 are defining different classes of types, which is important for
6182 the generic type matching rules.
6183 @end{Discussion}
6184
6185 @Syn{lhs=<modular_type_definition>,
6186 rhs="@key(mod) @SynI{static_}@Syn2{expression}"}
6187 @end{Syntax}
6188
6189 @begin{Resolution}
6190 @PDefn2{Term=[expected type],
6191 Sec=(signed_integer_type_definition simple_expression)}
6192 Each @nt<simple_expression> in a
6193 @nt<signed_integer_type_definition> is expected to be of any integer type;
6194 they need not be of the same type.
6195 @PDefn2{Term=[expected type],
6196 Sec=(modular_type_definition expression)}
6197 The @nt<expression> in a
6198 @nt<modular_type_definition> is likewise expected to be of any integer type.
6199 @end{Resolution}
6200
6201 @begin{Legality}
6202 The @nt<simple_expression>s of a
6203 @nt<signed_integer_type_definition>
6204 shall be static, and their values shall be in the
6205 range System.Min_Int .. System.Max_Int.
6206
6207 @Defn2{Term=[modulus], Sec=(of a modular type)}
6208 @Defn{Max_Binary_Modulus}
6209 @Defn{Max_Nonbinary_Modulus}
6210 The @nt<expression> of a @nt<modular_type_definition> shall be static,
6211 and its value (the @i(modulus)) shall be positive,
6212 and shall be no greater than System.Max_Binary_Modulus if a power of 2,
6213 or no greater than System.Max_Nonbinary_Modulus if not.
6214 @begin(Reason)
6215 For a 2's-complement machine, supporting nonbinary moduli greater
6216 than System.Max_Int can be quite difficult, whereas essentially any
6217 binary moduli are straightforward to support, up to 2*System.Max_Int+2,
6218 so this justifies having two separate limits.
6219 @end(Reason)
6220 @end{Legality}
6221
6222 @begin{StaticSem}
6223 The set of values for a signed integer type is the (infinite)
6224 set of mathematical
6225 integers@Redundant[, though only values of the base range of the type
6226 are fully supported for run-time operations].
6227 The set of values for a modular integer type are the values from
6228 0 to one less than the modulus,
6229 inclusive.
6230
6231 @PDefn2{Term=[base range], Sec=(of a signed integer type)}
6232 A @nt<signed_integer_type_definition> defines an integer type whose
6233 base range
6234 includes at least the values of the @nt<simple_expression>s and
6235 is symmetric about zero, excepting possibly an extra negative value.
6236 @Defn2{Term=[constrained], Sec=(subtype)}
6237 @Defn2{Term=[unconstrained], Sec=(subtype)}
6238 A @nt<signed_integer_type_definition> also defines a constrained first
6239 subtype of the type, with a range whose bounds are given by
6240 the values of the @nt<simple_expression>s, converted to the type being defined.
6241 @begin{ImplNote}
6242 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00114-01]}
6243 The base range of a signed integer type might be much larger than is
6244 necessary to satisfy the @Chg{Version=[2],New=[above],Old=[aboved]}
6245 requirements.
6246 @end{ImplNote}
6247 @begin{Honest}
6248 @ChgRef{Version=[1],Kind=[Added]}@ChgNote{This is discussed in AC-00002, which we can't reference here}
6249 @ChgAdded{Version=[1],Text=[The conversion mentioned above is not
6250 an @i{implicit subtype conversion} (which is something that happens at
6251 overload resolution, see
6252 @RefSecNum{Type Conversions}), although it happens implicitly. Therefore,
6253 the freezing rules are not invoked on the type (which is important so that
6254 representation items can be given for the type).
6255 @PDefn2{Term=[subtype conversion],Sec=(bounds of signed integer type)}]}
6256 @end{Honest}
6257
6258 @PDefn2{Term=[base range], Sec=(of a modular type)}
6259 A @nt<modular_type_definition> defines a modular type whose base range
6260 is from zero to one less than the given modulus.
6261 @Defn2{Term=[constrained], Sec=(subtype)}
6262 @Defn2{Term=[unconstrained], Sec=(subtype)}
6263 A @nt<modular_type_definition> also defines a constrained first
6264 subtype of the type with a range that is the same as the base range of
6265 the type.
6266
6267 @Defn{Integer}
6268 There is a predefined signed integer subtype named
6269 Integer@Redundant[,
6270 declared in the visible part of
6271 package Standard].
6272 It is constrained to the base range of its type.
6273 @begin{Reason}
6274 Integer is a constrained subtype, rather than an unconstrained
6275 subtype. This means that on assignment to an object of subtype Integer,
6276 a range check is required. On the other hand, an object of subtype
6277 Integer'Base is unconstrained, and no range check (only overflow check)
6278 is required on assignment. For example, if the object is held in an
6279 extended-length register, its value might be outside of
6280 Integer'First .. Integer'Last. All parameter and result subtypes
6281 of the predefined integer operators are of such unconstrained subtypes,
6282 allowing extended-length registers to be used as operands or
6283 for the result.
6284 In an earlier version of Ada 95, Integer was unconstrained. However,
6285 the fact that certain Constraint_Errors might be omitted or appear
6286 elsewhere was felt to be an undesirable upward inconsistency in this case.
6287 Note that for Float, the opposite conclusion was reached, partly because
6288 of the high cost of performing range checks when not actually necessary.
6289 Objects of subtype Float are unconstrained, and no range checks, only
6290 overflow checks, are performed for them.
6291 @end{Reason}
6292
6293 @Leading@Defn{Natural}
6294 @Defn{Positive}
6295 Integer has two predefined subtypes,
6296 @Redundant[declared in the visible part of package Standard:]
6297 @begin{Example}
6298 @key[subtype] Natural @key[is] Integer @key[range] 0 .. Integer'Last;
6299 @key[subtype] Positive @key[is] Integer @key[range] 1 .. Integer'Last;
6300 @end{Example}
6301
6302 @Defn{root_integer}
6303 @Defn{Min_Int}
6304 @Defn{Max_Int}
6305 A type defined by an @nt<integer_type_definition> is implicitly
6306 derived from @i(root_integer), an anonymous
6307 predefined (specific) integer type, whose base
6308 range is System.Min_Int .. System.Max_Int.
6309 However, the base range of the new type is not inherited from
6310 @i{root_integer}, but is instead determined by the range or modulus
6311 specified by the @nt{integer_type_definition}.
6312 @PDefn{universal_integer}
6313 @Defn{integer literals}
6314 @Redundant[Integer literals are all of the type @i(universal_integer),
6315 the universal type (see @RefSecNum(Derivation Classes)) for the
6316 class rooted at @i(root_integer), allowing their use with
6317 the operations of any integer type.]
6318 @begin{Discussion}
6319 This implicit derivation is not considered exactly equivalent to
6320 explicit derivation via a @nt<derived_type_definition>. In particular,
6321 integer types defined via a @nt<derived_type_definition> inherit their
6322 base range from their parent type. A type defined by
6323 an @nt<integer_type_definition> does not necessarily inherit
6324 its base range from @i(root_integer).
6325 It is not specified whether the implicit derivation from
6326 @i(root_integer) is direct or indirect, not that it really matters.
6327 All we want is for all integer types to be descendants of @i(root_integer).
6328
6329 @ChgRef{Version=[1],Kind=[Added],Ref=[8652/0099],ARef=[AI95-00152-01]}
6330 @Chg{New=[Note that this derivation does not imply any inheritance of
6331 subprograms. Subprograms are inherited only for types derived by a
6332 @nt{derived_@!type_@!definition} (see @RefSecNum{Derived Types and Classes}),
6333 or a @nt{private_@!extension_@!declaration} (see
6334 @RefSecNum{Private Types and Private Extensions}, @RefSecNum{Private Operations},
6335 and @RefSecNum{Formal Private and Derived Types}).],Old=[]}
6336 @end{Discussion}
6337 @begin{ImplNote}
6338 It is the intent that even nonstandard integer
6339 types (see below) will be descendants of @i(root_integer), even though they
6340 might have a base range that exceeds that of @i(root_integer).
6341 This causes no problem for static calculations, which
6342 are performed without range restrictions
6343 (see @RefSecNum(Static Expressions and Static Subtypes)). However
6344 for run-time calculations, it is possible that Constraint_Error
6345 might be raised when using an operator of @i(root_integer)
6346 on the result of 'Val applied to a value of a nonstandard integer type.
6347 @end{ImplNote}
6348
6349 @PDefn2{Term=[position number], Sec=(of an integer value)}
6350 The @i(position number) of an integer value is equal to the value.
6351
6352 @begin{WideAbove}
6353 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00340-01]}
6354 @Leading@keepnext@;For @PrefixType{every modular subtype S},
6355 the following @Chg{Version=[2],New=[attributes are],Old=[attribute is]} defined:
6356 @end{WideAbove}
6357 @begin(description)
6358 @ChgAttribute{Version=[2],Kind=[Added],ChginAnnex=[T],
6359 Leading=<T>, Prefix=<S>, AttrName=<Mod>, ARef=[AI95-00340-01],
6360 Text=[@Chg{Version=[2],New=[S'Mod denotes a function with the following specification:],Old=[]}
6361
6362 @begin(Descexample)
6363 @ChgRef{Version=[2],Kind=[Added]}
6364 @ChgAdded{Version=[2],Text=[@key{function} S'Mod (@RI{Arg} : @RI{universal_integer})
6365 @key{return} S'Base]}
6366 @end(Descexample)
6367
6368 @ChgRef{Version=[2],Kind=[Added]}
6369 @ChgAdded{Version=[2],NoPrefix=[T],Text=[This function returns @i{Arg}
6370 @key{mod} S'Modulus, as a value of the type of S.]}]}@Comment{end attribute Mod}
6371
6372 @Attribute{Prefix=<S>, AttrName=<Modulus>,
6373 Text=[S'Modulus yields the modulus of the type of S, as a value of the
6374 type @i(universal_integer).]}
6375 @end(description)
6376
6377 @end{StaticSem}
6378
6379 @begin{RunTime}
6380 @PDefn2{Term=[elaboration], Sec=(integer_type_definition)}
6381 The elaboration of an @nt<integer_type_definition> creates the
6382 integer type and its first subtype.
6383
6384 For a modular type, if the result of the execution of a
6385 predefined operator (see @RefSecNum(Operators and Expression Evaluation))
6386 is outside the base range of the type, the result is reduced
6387 modulo the modulus of the type to a value that is within the
6388 base range of the type.
6389
6390 @IndexCheck{Overflow_Check}
6391 @Defn2{Term=(Constraint_Error),Sec=(raised by failure of runtime check)}
6392 For a signed integer type,
6393 the exception Constraint_Error is raised by the execution of
6394 an operation that cannot deliver the correct result because
6395 it is outside the base range of the type.
6396 @redundant[@IndexCheck{Division_Check}
6397 @Defn2{Term=(Constraint_Error),Sec=(raised by failure of runtime check)}
6398 For any integer type, Constraint_Error is raised by the operators
6399 "/", "@key(rem)", and "@key(mod)" if the right operand is zero.]
6400
6401 @end{RunTime}
6402
6403 @begin{ImplReq}
6404 @Defn{Integer}
6405 In an implementation, the range of Integer shall include the range
6406 @en@;2**15+1 .. +2**15@en@;1.
6407
6408 @Defn{Long_Integer}
6409 If Long_Integer is predefined for an implementation, then its
6410 range shall include the range @en@;2**31+1 .. +2**31@en@;1.
6411
6412 System.Max_Binary_Modulus shall be at least 2**16.
6413 @end{ImplReq}
6414
6415 @begin{ImplPerm}
6416 For the execution of a predefined operation of a signed integer type,
6417 the implementation need not raise Constraint_Error if the result is
6418 outside the base range of the type, so long as the correct result
6419 is produced.
6420 @begin{Discussion}
6421 Constraint_Error is never raised for operations on modular types,
6422 except for divide-by-zero (and @key[rem]/@key[mod]-by-zero).
6423 @end{Discussion}
6424
6425 @Defn{Long_Integer}
6426 @Defn{Short_Integer}
6427 An implementation may provide additional predefined signed integer
6428 types@Redundant[, declared in the visible part of Standard], whose first
6429 subtypes have names of the form Short_Integer,
6430 Long_Integer, Short_Short_Integer, Long_Long_Integer, etc.
6431 Different predefined integer types are allowed to have the same base range.
6432 However, the range of Integer should be no wider than that of Long_Integer.
6433 Similarly, the range of Short_Integer (if provided) should be no wider
6434 than Integer.
6435 Corresponding recommendations apply to any other predefined integer types.
6436 There need not be a named integer type corresponding to each
6437 distinct base range supported by an implementation.
6438 The range of each first subtype should be the base range of its type.
6439 @ImplDef{The predefined integer types declared in Standard.}
6440
6441 @Defn{nonstandard integer type}
6442 An implementation may provide @i(nonstandard integer types),
6443 descendants of @i(root_integer) that are
6444 declared outside of the specification of package Standard,
6445 which need not have all the standard characteristics
6446 of a type defined by an @nt<integer_type_definition>.
6447 For example, a nonstandard integer type
6448 might have an asymmetric base range
6449 or it might not be allowed as
6450 an array or loop index (a very long integer).
6451 Any type descended from a nonstandard integer type is also nonstandard.
6452 An implementation may place arbitrary restrictions on the use of such types;
6453 it is implementation defined whether operators that are predefined
6454 for @lquotes@;any integer type@rquotes@; are defined for a particular
6455 nonstandard integer type.
6456 @Redundant[In any case, such types are not permitted as
6457 @nt{explicit_generic_actual_parameter}s for formal scalar types @em
6458 see @RefSecNum(Formal Scalar Types).]
6459 @ImplDef{Any nonstandard integer types and the operators defined for them.}
6460
6461 @PDefn2{Term=[one's complement], Sec=(modular types)}
6462 For a one's complement machine, the high bound of the base range
6463 of a modular type whose modulus is one less than a power of 2
6464 may be equal to the modulus, rather than one less than the modulus.
6465 It is implementation defined for which powers of 2, if any, this
6466 permission is exercised.
6467
6468 @ChgRef{Version=[1],Kind=[Added],Ref=[8652/0003],ARef=[AI95-00095-01]}
6469 @Chg{New=[For a one's complement machine, implementations may support nonbinary
6470 modulus values greater than System.Max_Nonbinary_Modulus. It is implementation
6471 defined which specific values greater than System.Max_Nonbinary_Modulus, if
6472 any, are supported.],Old=[]}
6473 @begin{Reason}
6474 @ChgRef{Version=[1],Kind=[Added]}
6475 @ChgAdded{Version=[1],Text=[On a one's complement machine, the natural full word
6476 type would have
6477 a modulus of 2**Word_Size@en@;1. However, we would want to allow the all-ones
6478 bit pattern (which represents negative zero as a number) in logical operations.
6479 These permissions are intended to allow that and the natural modulus value
6480 without burdening implementations with supporting expensive modulus values.]}
6481 @end{Reason}
6482 @end{ImplPerm}
6483
6484 @begin{ImplAdvice}
6485 @Defn{Long_Integer}
6486 An implementation should support Long_Integer in addition to
6487 Integer if the target machine supports 32-bit (or longer) arithmetic.
6488 No other named integer subtypes are recommended for package Standard.
6489 Instead, appropriate named integer subtypes should be provided in
6490 the library package Interfaces
6491 (see @RefSecNum{The Package Interfaces}).
6492 @ChgImplAdvice{Version=[2],Kind=[Added],Text=[@ChgAdded{Version=[2],
6493 Text=[Long_Integer should be declared in Standard if the target supports
6494 32-bit arithmetic. No other named integer subtypes should be declared in
6495 Standard.]}]}
6496 @begin{ImplNote}
6497 To promote portability, implementations should explicitly declare the integer
6498 (sub)types Integer and Long_Integer in Standard, and leave other
6499 predefined integer types anonymous.
6500 For implementations
6501 that already support Byte_Integer, etc., upward compatibility
6502 argues for keeping such declarations in Standard during the
6503 transition period, but perhaps generating a warning on use.
6504 A separate package Interfaces in the predefined environment
6505 is available for pre-declaring types such as Integer_8, Integer_16, etc.
6506 See @RefSecNum(The Package Interfaces).
6507 In any case, if the user declares a subtype (first or not)
6508 whose range fits in, for example, a byte, the implementation can
6509 store variables of the subtype in a single byte, even if the
6510 base range of the type is wider.
6511 @end{ImplNote}
6512
6513 @PDefn2{Term=[two's complement],Sec=(modular types)}
6514 An implementation for a two's complement machine should support
6515 modular types with a binary modulus
6516 up to System.Max_Int*2+2.
6517 An implementation should support a nonbinary modulus up to Integer'Last.
6518 @ChgImplAdvice{Version=[2],Kind=[Added],Text=[@ChgAdded{Version=[2],
6519 Text=[For a two's complement target, modular types with a binary modulus
6520 up to System.Max_Int*2+2 should be supported. A nonbinary modulus up
6521 to Integer'Last should be supported.]}]}
6522 @begin{Reason}
6523 Modular types provide bit-wise "@key{and}", "@key{or}", "@key{xor}",
6524 and "@key{not}" operations.
6525 It is important for systems programming that these be available for all
6526 integer types of the target hardware.
6527 @end{Reason}
6528 @begin{Ramification}
6529 Note that on a one's complement machine,
6530 the largest supported modular type would normally have a nonbinary
6531 modulus. On a two's complement machine, the largest supported
6532 modular type would normally have a binary modulus.
6533 @end{Ramification}
6534 @begin{ImplNote}
6535 Supporting a nonbinary modulus greater than Integer'Last can
6536 impose an undesirable implementation burden on some machines.
6537 @end{ImplNote}
6538 @end{ImplAdvice}
6539
6540 @begin{Notes}
6541 @PDefn{universal_integer}
6542 @Defn{integer literals}
6543 Integer literals are of the anonymous predefined
6544 integer type @i(universal_integer). Other integer types
6545 have no literals. However, the overload resolution rules
6546 (see @RefSec(The Context of Overload Resolution))
6547 allow expressions of the type @i(universal_integer)
6548 whenever an integer type is expected.
6549
6550 The same arithmetic operators are predefined for all signed integer types
6551 defined by a @nt<signed_integer_type_definition>
6552 (see @RefSec(Operators and Expression Evaluation)).
6553 For modular types, these same operators are predefined, plus
6554 bit-wise logical operators (@key(and), @key(or), @key(xor), and @key(not)).
6555 In addition, for the unsigned types declared in the language-defined
6556 package Interfaces (see @RefSecNum(The Package Interfaces)),
6557 functions are defined that provide
6558 bit-wise shifting and rotating.
6559
6560 Modular types match a @nt{generic_formal_parameter_declaration} of the
6561 form "@key(type) T @key(is mod) <>;";
6562 signed integer types match "@key(type) T @key(is range) <>;"
6563 (see @RefSecNum{Formal Scalar Types}).
6564 @end{Notes}
6565
6566 @begin{Examples}
6567 @Leading@keepnext@i(Examples of integer types and subtypes: )
6568 @begin(Example)
6569 @key(type) Page_Num @key(is) @key(range) 1 .. 2_000;
6570 @key(type) Line_Size @key(is) @key(range) 1 .. Max_Line_Size;
6571
6572 @key(subtype) Small_Int @key(is) Integer @key(range) -10 .. 10;
6573 @key(subtype) Column_Ptr @key(is) Line_Size @key(range) 1 .. 10;
6574 @key(subtype) Buffer_Size @key(is) Integer @key(range) 0 .. Max;
6575
6576 @key(type) Byte @key(is) @key(mod) 256; --@RI[ an unsigned byte]
6577 @key(type) Hash_Index @key(is) @key(mod) 97; --@RI[ modulus is prime]
6578 @end(Example)
6579 @end{Examples}
6580
6581 @begin{Extend83}
6582 @Defn{extensions to Ada 83}
6583 An implementation is allowed to support any number of distinct
6584 base ranges for integer types, even if fewer
6585 integer types are explicitly declared in Standard.
6586
6587 Modular (unsigned, wrap-around) types are new.
6588 @end{Extend83}
6589
6590 @begin{DiffWord83}
6591 Ada 83's integer types are now called "signed" integer types,
6592 to contrast them with "modular" integer types.
6593
6594 Standard.Integer, Standard.Long_Integer, etc., denote
6595 constrained subtypes of predefined integer types, consistent
6596 with the Ada 95 model that only subtypes have names.
6597
6598 We now impose minimum requirements on the base range of
6599 Integer and Long_Integer.
6600
6601 We no longer explain integer type definition in terms
6602 of an equivalence to a normal type derivation, except to say that all
6603 integer types are by definition implicitly derived from @i(root_integer).
6604 This is for various reasons.
6605
6606 First of all, the equivalence with a type derivation and a subtype
6607 declaration was not perfect, and was the source of various AIs (for example,
6608 is the conversion of the bounds static? Is a numeric type a derived
6609 type with respect to other rules of the language?)
6610
6611 Secondly, we don't want to require that every integer size supported
6612 shall have a corresponding named type in Standard. Adding named
6613 types to Standard creates nonportabilities.
6614
6615 Thirdly, we don't want the set of types that match
6616 a formal derived type "type T is new Integer;" to
6617 depend on the particular underlying integer representation chosen
6618 to implement a given user-defined integer type. Hence, we
6619 would have needed anonymous integer types as parent types for
6620 the implicit derivation anyway. We have simply chosen to identify
6621 only one anonymous integer type @em @i(root_integer), and stated
6622 that every integer type is derived from it.
6623
6624 Finally, the @lquotes@;fiction@rquotes@; that there were distinct
6625 preexisting predefined types
6626 for every supported representation breaks down for fixed point
6627 with arbitrary smalls, and was never exploited for enumeration
6628 types, array types, etc. Hence, there seems little benefit
6629 to pushing an explicit equivalence between integer type
6630 definition and normal type derivation.
6631 @end{DiffWord83}
6632
6633 @begin{Extend95}
6634 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00340-01]}
6635 @ChgAdded{Version=[2],Text=[@Defn{extensions to Ada 95}
6636 The Mod attribute is new. It eases mixing of signed and unsigned values in
6637 an expression, which can be difficult as there may be no type which
6638 can contain all of the values of both of the types involved.]}
6639 @end{Extend95}
6640
6641 @begin{DiffWord95}
6642 @ChgRef{Version=[2],Kind=[AddedNormal],Ref=[8652/0003],ARef=[AI95-00095-01]}
6643 @Chg{Version=[2],New=[@b<Corrigendum:> Added additional permissions for
6644 modular types on one's complement machines.],Old=[]}
6645 @end{DiffWord95}
6646
6647
6648 @NotISORMNewPageVer{Version=[3]}@Comment{For printed version of Ada 2012 RM}
6649 @LabeledSubClause{Operations of Discrete Types}
6650
6651 @begin{StaticSem}
6652 @Leading@;For @PrefixType{every discrete subtype S},
6653 the following attributes are defined:
6654 @begin(description)
6655 @AttributeLeading{Prefix=<S>, AttrName=<Pos>,
6656 Text=[S'Pos denotes a function with the following specification:
6657 @begin(Descexample)
6658 @b(function) S'Pos(@RI(Arg) : S'Base)
6659 @b(return) @RI(universal_integer)
6660 @end(Descexample)
6661
6662 @NoPrefix@;This function returns the position number of the value
6663 of @i(Arg), as a value of type @i(universal_integer).]}
6664
6665 @AttributeLeading{Prefix=<S>, AttrName=<Val>,
6666 Text=[S'Val denotes a function with the following specification:
6667 @begin(Descexample)
6668 @b(function) S'Val(@RI(Arg) : @RI(universal_integer))
6669 @b(return) S'Base
6670 @end(Descexample)
6671
6672 @NoPrefix@PDefn2{Term=(evaluation), Sec=(Val)}
6673 @Defn2{Term=(Constraint_Error),Sec=(raised by failure of runtime check)}
6674 This function returns a value of the type of S
6675 whose position number equals the value of @i(Arg).]}
6676 @IndexCheck{Range_Check}
6677 For the evaluation of a call on S'Val, if there
6678 is no value in the base range of its type with the given
6679 position number, Constraint_Error is raised.
6680 @begin{Ramification}
6681
6682 By the overload resolution rules, a formal parameter of type
6683 @i(universal_integer) allows an actual parameter of any
6684 integer type.@end{ramification}
6685 @begin{Reason}
6686 We considered allowing
6687 S'Val for a signed integer subtype S to return an out-of-range value,
6688 but since checks were required for enumeration and modular types
6689 anyway, the allowance didn't seem worth the complexity of the rule.@end{reason}
6690 @end(description)
6691 @EndPrefixType{}
6692
6693 @ChgRef{Version=[3],Kind=[Added],ARef=[AI05-0297-1]}
6694 @ChgRef{Version=[4],Kind=[RevisedAdded],ARef=[AI12-0071-1]}
6695 @ChgAdded{Version=[3],Type=[Leading],Text=[For @ChgPrefixType{Version=[4],
6696 Kind=[Revised],Text=[every static discrete subtype S for which there exists
6697 at least one value belonging to S that satisfies
6698 @Chg<Version=[4],New=[the predicates],Old=[any predicate]> of S]},
6699 the following attributes are defined:]}
6700
6701 @begin(Description)
6702 @ChgNote{Original: @ChgAttribute{Version=[3],Kind=[Added],ChginAnnex=[T],
6703 Leading=<F>, Prefix=<S>, AttrName=<First_Valid>, ARef=[AI05-0297-1],
6704 We don't have a way to change multiple versions for attributes.}}
6705 @ChgAttribute{Version=[4],Kind=[RevisedAdded],ChginAnnex=[T],
6706 Leading=<F>, Prefix=<S>, AttrName=<First_Valid>,
6707 InitialVersion=[3], ARef=[AI05-0297-1], ARef=[AI12-0071-1],
6708 Text=[@Chg{Version=[3],New=[S'First_Valid denotes the smallest value
6709 that belongs to S and satisfies the
6710 @Chg{Version=[4],New=[predicates],Old=[predicate]} of S.
6711 The value of this attribute is of the type of S.],Old=[]}]}
6712
6713 @ChgNote{Original: @ChgAttribute{Version=[3],Kind=[Added],ChginAnnex=[T],
6714 Leading=<F>, Prefix=<S>, AttrName=<Last_Valid>, ARef=[AI05-0297-1],
6715 We don't have a way to change multiple versions for attributes.}}
6716 @ChgAttribute{Version=[4],Kind=[RevisedAdded],ChginAnnex=[T],
6717 Leading=<F>, Prefix=<S>, AttrName=<Last_Valid>,
6718 InitialVersion=[3], ARef=[AI05-0297-1], ARef=[AI12-0071-1],
6719 Text=[@Chg{Version=[3],New=[S'Last_Valid denotes the largest value
6720 that belongs to S and satisfies the
6721 @Chg{Version=[4],New=[predicates],Old=[predicate]} of S. The value of
6722 this attribute is of the type of S.],Old=[]}]}
6723 @end(Description)
6724 @EndPrefixType{}
6725
6726 @ChgRef{Version=[3],Kind=[Added],ARef=[AI05-0297-1]}
6727 @ChgAdded{Version=[3],Text=[@Redundant[First_Valid and Last_Valid
6728 @nt{attribute_reference}s are always static expressions. Any explicit predicate
6729 of S can only have been specified by a Static_Predicate aspect.]]}
6730
6731 @begin{TheProof}
6732 @ChgRef{Version=[3],Kind=[AddedNormal]}
6733 @ChgAdded{Version=[3],Text=[An @nt{attribute_reference} is static if the
6734 prefix is a static subtype (see @RefSecNum{Static Expressions and Static Subtypes}),
6735 (true by definition) and any arguments are static (there are none). Similarly,
6736 a dynamic predicate always makes a subtype nonstatic. QED.]}
6737 @end{TheProof}
6738 @begin{Reason}
6739 @ChgRef{Version=[3],Kind=[AddedNormal]}
6740 @ChgAdded{Version=[3],Text=[We require there to be at least one value so that
6741 these are always values of the subtype. (This sidesteps the question of what
6742 to return for a subtype with no values.)]}
6743 @end{Reason}
6744 @begin{Discussion}
6745 @ChgRef{Version=[3],Kind=[AddedNormal]}
6746 @ChgAdded{Version=[3],Text=[These attributes are intended primarily for use in
6747 the case where the Static_Predicate aspect of S has been specified; First and
6748 Last are equivalent if these are allowed and there is no predicate.]}
6749 @end{Discussion}
6750 @end{StaticSem}
6751
6752 @begin{ImplAdvice}
6753 For the evaluation of a call on S'Pos for an enumeration
6754 subtype, if the value of the operand does not correspond
6755 to the internal code for any enumeration literal of its
6756 type
6757 @Redundant[(perhaps due to an uninitialized variable)],
6758 then the implementation should raise Program_Error.
6759 This is particularly important for enumeration types with
6760 noncontiguous internal codes specified by an
6761 @nt<enumeration_@!representation_@!clause>.
6762 @ChgImplAdvice{Version=[2],Kind=[Added],Text=[@ChgAdded{Version=[2],
6763 Text=[Program_Error should be raised for the evaluation of S'Pos for an
6764 enumeration type, if the value of the operand does not correspond
6765 to the internal code for any enumeration literal of the type.]}]}
6766 @begin{Reason}
6767 We say Program_Error here, rather than Constraint_Error,
6768 because the main reason for such values is uninitialized variables,
6769 and the normal way to indicate such a use (if detected) is to raise
6770 Program_Error.
6771 (Other reasons would involve the misuse of low-level features such as
6772 Unchecked_Conversion.)
6773 @end{Reason}
6774 @end{ImplAdvice}
6775
6776 @begin{Notes}
6777 Indexing and loop iteration use values of discrete types.
6778
6779 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0299-1]}
6780 @PDefn2{Term=[predefined operations],Sec=(of a discrete type)}
6781 The predefined operations of a discrete type include the assignment
6782 operation, qualification, the membership tests, and the
6783 relational operators; for a boolean type
6784 they include the short-circuit control forms and the
6785 logical operators; for an integer
6786 type they include type conversion to and from other numeric types,
6787 as well as the binary and unary adding operators @en@; and +, the multiplying
6788 operators, the unary operator @key(abs),
6789 and the exponentiation operator.
6790 The assignment operation is described in @RefSecNum(Assignment Statements).
6791 The other predefined operations are described in
6792 @Chg{Version=[3],New=[Clause],Old=[Section]} @RefSecNum{Names and Expressions}.
6793
6794 As for all types, objects of a discrete type
6795 have Size and Address attributes (see @RefSecNum(Operational and Representation Attributes)).
6796
6797 @Leading@;For a subtype of a discrete type, the result delivered by the
6798 attribute Val might not belong to the subtype; similarly, the actual parameter
6799 of the attribute Pos need not belong to the subtype. The following relations
6800 are satisfied (in the absence of an exception) by these attributes:
6801 @begin(Example)
6802 S'Val(S'Pos(X)) = X
6803 S'Pos(S'Val(N)) = N
6804 @end(Example)
6805 @end{Notes}
6806
6807 @begin{Examples}
6808 @Leading@keepnext@i(Examples of attributes of discrete subtypes: )
6809 @begin(Example)
6810 --@RI[ For the types and subtypes declared in subclause @RefSecNum(Enumeration Types) the following hold: ]
6811
6812 -- Color'First = White, Color'Last = Black
6813 -- Rainbow'First = Red, Rainbow'Last = Blue
6814
6815 -- Color'Succ(Blue) = Rainbow'Succ(Blue) = Brown
6816 -- Color'Pos(Blue) = Rainbow'Pos(Blue) = 4
6817 -- Color'Val(0) = Rainbow'Val(0) = White
6818 @end(Example)
6819 @end{Examples}
6820
6821 @begin{Extend83}
6822 @Defn{extensions to Ada 83}
6823 The attributes S'Succ, S'Pred, S'Width, S'Image, and S'Value have
6824 been generalized to apply to real types as well
6825 (see @RefSec{Scalar Types}).
6826 @end{Extend83}
6827
6828 @begin{Extend2005}
6829 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0297-1]}
6830 @ChgAdded{Version=[3],Text=[@Defn{extensions to Ada 2005}
6831 The attributes S'First_Valid and S'Last_Valid are new.]}
6832 @end{Extend2005}
6833
6834 @begin{DiffWord2012}
6835 @ChgRef{Version=[4],Kind=[AddedNormal],ARef=[AI12-0071-1]}
6836 @ChgAdded{Version=[4],Text=[@b<Corrigendum:> Updated wording of the
6837 attributes S'First_Valid and S'Last_Valid to use the new term
6838 "satisfies the predicates" (see @RefSecNum{Subtype Predicates}).]}
6839 @end{DiffWord2012}
6840
6841
6842 @LabeledSubClause{Real Types}
6843
6844 @begin{Intro}
6845 @Defn{real type}
6846 Real types provide approximations to the real numbers, with relative bounds
6847 on errors for floating point types, and with absolute bounds for fixed
6848 point types.
6849 @end{Intro}
6850
6851 @begin{Syntax}
6852 @Syn{lhs=<real_type_definition>,rhs="
6853 @Syn2{floating_point_definition} | @Syn2{fixed_point_definition}"}
6854 @end{Syntax}
6855
6856 @begin{StaticSem}
6857 @Defn{root_real}
6858 A type defined by a @nt<real_type_definition> is implicitly
6859 derived from @i(root_real), an anonymous
6860 predefined (specific) real type.
6861 @Redundant[Hence, all real types, whether floating point or fixed point,
6862 are in the derivation class rooted at @i(root_real).]
6863 @begin{Ramification}
6864 It is not specified whether the derivation from @i(root_real) is
6865 direct or indirect, not that it really matters.
6866 All we want is for all real types to be descendants of @i(root_real).
6867
6868 @ChgRef{Version=[1],Kind=[Added],Ref=[8652/0099],ARef=[AI95-00152-01]}
6869 @Chg{New=[Note that this derivation does not imply any inheritance of
6870 subprograms. Subprograms are inherited only for types derived by a
6871 @nt{derived_@!type_@!definition} (see @RefSecNum{Derived Types and Classes}),
6872 or a @nt{private_@!extension_@!declaration} (see
6873 @RefSecNum{Private Types and Private Extensions}, @RefSecNum{Private Operations},
6874 and @RefSecNum{Formal Private and Derived Types}).],Old=[]}
6875
6876 @end{Ramification}
6877
6878 @redundant[@PDefn{universal_real}
6879 @Defn{real literals}
6880 Real literals are all of the type @i(universal_real),
6881 the universal type (see @RefSecNum(Derivation Classes)) for the
6882 class rooted at @i(root_real), allowing their use with
6883 the operations of any real type.
6884 @PDefn{universal_fixed}
6885 Certain multiplying operators have a result type of @i(universal_fixed)
6886 (see @RefSecNum{Multiplying Operators}),
6887 the universal type for the class of fixed point types, allowing
6888 the result of the multiplication or division to be used where any
6889 specific fixed point type is expected.]
6890 @end{StaticSem}
6891
6892 @begin{RunTime}
6893 @PDefn2{Term=[elaboration], Sec=(real_type_definition)}
6894 The elaboration of a @nt<real_type_definition> consists of the
6895 elaboration of the @nt<floating_point_definition> or the
6896 @nt<fixed_point_definition>.
6897 @end{RunTime}
6898
6899 @begin{ImplReq}
6900 An implementation shall perform the run-time evaluation
6901 of a use of a predefined operator of @i(root_real)
6902 with an accuracy at least as great as that of any floating point
6903 type definable by a @nt<floating_point_definition>.
6904 @begin{Ramification}
6905 Static calculations using the operators of @i(root_real) are
6906 exact, as for all static calculations.
6907 See @RefSecNum(Static Expressions and Static Subtypes).
6908 @end{Ramification}
6909 @begin(ImplNote)
6910 The Digits attribute of the type used to represent @i(root_real)
6911 at run time is at least as great as that of any other floating
6912 point type defined by a @nt<floating_point_definition>,
6913 and its safe range includes that of any such floating point type
6914 with the same Digits attribute.
6915 On some machines, there might be real types with less accuracy but
6916 a wider range, and hence run-time calculations with @i(root_real)
6917 might not be able to accommodate all values that can be represented
6918 at run time in such floating point or fixed point types.
6919 @end(ImplNote)
6920 @end{ImplReq}
6921
6922 @begin{ImplPerm}
6923 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00114-01]}
6924 @Redundant[For the execution of a predefined operation of a real type,
6925 the implementation need not raise Constraint_Error if the result is
6926 outside the base range of the type, so long as the correct result
6927 is produced, or the Machine_Overflows attribute of the type is @Chg{Version=[2],
6928 New=[False],Old=[false]}
6929 (see @RefSecNum{Numeric Performance Requirements}).]
6930
6931 @Defn{nonstandard real type}
6932 An implementation may provide @i(nonstandard real types),
6933 descendants of @i(root_real) that are
6934 declared outside of the specification of package Standard,
6935 which need not have all the standard characteristics
6936 of a type defined by a @nt<real_type_definition>. For
6937 example, a nonstandard real type
6938 might have an asymmetric or unsigned base range,
6939 or its predefined operations might wrap around or @lquotes@;saturate@rquotes@; rather
6940 than overflow (modular or saturating arithmetic), or it might not
6941 conform to the accuracy
6942 model (see @RefSecNum{Numeric Performance Requirements}).
6943 Any type descended from a nonstandard real type is also nonstandard.
6944 An implementation may place arbitrary restrictions on the use of such types;
6945 it is implementation defined whether operators that are predefined
6946 for @lquotes@;any real type@rquotes@; are defined for a particular nonstandard real type.
6947 @Redundant[In any case, such types are not permitted as @nt{explicit_generic_actual_parameter}s for formal scalar types @em see @RefSecNum(Formal Scalar Types).]
6948 @ImplDef{Any nonstandard real types and the operators defined for them.}
6949 @end{ImplPerm}
6950
6951 @begin{Notes}
6952 As stated, real literals are of the anonymous predefined
6953 real type @i(universal_real). Other real types
6954 have no literals. However, the overload resolution rules
6955 (see @RefSecNum(The Context of Overload Resolution))
6956 allow expressions of the type @i(universal_real)
6957 whenever a real type is expected.
6958
6959 @end{Notes}
6960
6961 @begin{DiffWord83}
6962 The syntax rule for @nt{real_type_definition} is modified to use
6963 the new syntactic categories
6964 @nt{floating_point_definition} and @nt{fixed_point_definition},
6965 instead of @ntf{floating_point_constraint} and
6966 @ntf{fixed_point_constraint}, because the semantics of a type
6967 definition are significantly different than the semantics of a
6968 constraint.
6969
6970 All discussion of model numbers, safe ranges, and machine numbers
6971 is moved to @RefSecNum{Floating Point Types},
6972 @RefSecNum{Operations of Floating Point Types}, and
6973 @RefSecNum{Numeric Performance Requirements}.
6974 Values of a fixed point type are now described as being multiples of
6975 the @i(small) of the fixed point type, and we have no need for model
6976 numbers, safe ranges, etc. for fixed point types.
6977
6978 @end{DiffWord83}
6979
6980 @LabeledSubClause{Floating Point Types}
6981
6982 @begin{Intro}
6983 @Defn{floating point type}
6984 For floating point types, the error bound is specified as a relative
6985 precision by giving the required minimum number of significant decimal
6986 digits.
6987 @end{Intro}
6988
6989 @begin{Syntax}
6990 @Syn{lhs=<floating_point_definition>,rhs="
6991 @key{digits} @SynI{static_}@Syn2{expression} [@Syn2{real_range_specification}]"}
6992
6993 @Syn{lhs=<real_range_specification>,rhs="
6994 @key{range} @SynI{static_}@Syn2{simple_expression} .. @SynI{static_}@Syn2{simple_expression}"}
6995 @end{Syntax}
6996
6997 @begin{Resolution}
6998 @Defn2{Term=[requested decimal precision], Sec=(of a floating point type)}
6999 The @i(requested decimal precision), which is the minimum
7000 number of significant decimal digits required for the floating point type,
7001 is specified by the
7002 value of the @nt<expression> given after
7003 the reserved word @key(digits).
7004 @PDefn2{Term=[expected type], Sec=(requested decimal precision)}
7005 This @nt<expression>
7006 is expected to be of any integer type.
7007
7008 @PDefn2{Term=[expected type], Sec=(real_range_specification bounds)}
7009 Each @nt<simple_expression> of a
7010 @nt<real_range_specification> is expected to be of any real
7011 type@Redundant[; the types need not be the same].
7012 @end{Resolution}
7013
7014 @begin{Legality}
7015 @Defn{Max_Base_Digits}
7016 The requested decimal precision shall be specified by a static @nt<expression>
7017 whose value is positive and no greater than
7018 System.Max_Base_Digits.
7019 Each @nt<simple_expression> of a @nt<real_range_specification>
7020 shall also be static.
7021 @Defn{Max_Digits}
7022 If the @nt<real_range_specification> is omitted,
7023 the requested decimal precision shall be no greater than System.Max_Digits.
7024 @begin(Reason)
7025 We have added Max_Base_Digits to package System. It corresponds
7026 to the requested decimal precision of
7027 @i(root_real). System.Max_Digits
7028 corresponds to the maximum value for Digits that may be specified
7029 in the absence of a @nt<real_range_specification>, for upward
7030 compatibility. These might not be the same if @i<root_real>
7031 has a base range that does not include @PorM 10.0**(4*Max_Base_Digits).
7032 @end(Reason)
7033
7034 A @nt<floating_point_definition> is illegal if the
7035 implementation does not support a floating point type that
7036 satisfies the requested decimal precision and range.
7037 @ImplDef{What combinations of requested decimal precision and range
7038 are supported for floating point types.}
7039 @end{Legality}
7040
7041 @begin{StaticSem}
7042 The set of values for a floating point type is the (infinite) set of rational
7043 numbers.
7044 @Defn2{Term=[machine numbers], Sec=(of a floating point type)}
7045 The @i(machine numbers) of a floating point type are the values
7046 of the type that can be represented exactly in every
7047 unconstrained variable of the type.
7048 @PDefn2{Term=[base range], Sec=(of a floating point type)}
7049 The base range (see @RefSecNum{Scalar Types})
7050 of a floating point type is symmetric around zero,
7051 except that it can include some extra negative values
7052 in some implementations.@begin{ImplNote}
7053 For example, if a 2's complement
7054 representation is used for the mantissa rather than a sign-mantissa or
7055 1's complement representation, then there is usually one extra
7056 negative machine number.@end{implnote}
7057 @begin{Honest}
7058
7059 If the Signed_Zeros attribute is True,
7060 then minus zero could in a sense be considered a value of the type.
7061 However, for most purposes, minus zero behaves the same as plus zero.
7062
7063 @end{Honest}
7064
7065 @Defn2{Term=[base decimal precision], Sec=(of a floating point type)}
7066 The @i(base decimal precision) of a floating point type is the number
7067 of decimal digits of precision representable in objects
7068 of the type.
7069 @Defn2{Term=[safe range], Sec=(of a floating point type)}
7070 The @i(safe range) of a floating point type is that part of its
7071 base range for which the accuracy corresponding to the base decimal precision
7072 is preserved by all predefined operations.
7073 @begin{ImplNote}
7074 In most cases,
7075 the safe range and base range are the same.
7076 However, for some hardware, values near the boundaries of
7077 the base range might result in excessive
7078 inaccuracies or spurious overflows when used with
7079 certain predefined operations. For such hardware, the safe
7080 range would omit such values.@end{implnote}
7081
7082 @PDefn2{Term=[base decimal precision], Sec=(of a floating point type)}
7083 A @nt<floating_point_definition> defines a floating point type
7084 whose base decimal precision is no less than the requested
7085 decimal precision.
7086 @PDefn2{Term=[safe range], Sec=(of a floating point type)}
7087 @PDefn2{Term=[base range], Sec=(of a floating point type)}
7088 If a @nt<real_range_specification> is given,
7089 the safe range of the floating point type (and hence, also its base range)
7090 includes at least the
7091 values of the simple expressions
7092 given in the @nt<real_range_specification>.
7093 If a @nt<real_range_specification> is not given,
7094 the safe (and base) range of the type includes at least the values of the range
7095 @en@;10.0**(4*D) .. +10.0**(4*D) where D is the requested decimal precision.
7096 @Redundant[The safe range might include
7097 other values as well. The attributes Safe_First and Safe_Last
7098 give the actual bounds of the safe range.]
7099
7100 A @nt<floating_point_definition> also defines a first
7101 subtype of the type.
7102 @Defn2{Term=[constrained], Sec=(subtype)}
7103 @Defn2{Term=[unconstrained], Sec=(subtype)}
7104 If a @nt<real_range_specification> is given, then
7105 the subtype is constrained to a range whose bounds are
7106 given by a conversion of the values of the @nt<simple_expression>s
7107 of the @nt<real_range_specification> to the type being defined.
7108 Otherwise, the subtype is unconstrained.
7109
7110 @begin{Honest}
7111 @ChgRef{Version=[1],Kind=[Added]}@ChgNote{This is discussed in AC-00002, which we can't reference here}
7112 @ChgAdded{Version=[1],Text=[The conversion mentioned above is not an @i{implicit subtype
7113 conversion} (which is something that happens at overload resolution, see
7114 @RefSecNum{Type Conversions}), although it happens implicitly. Therefore,
7115 the freezing rules are not invoked on the type (which is important so that
7116 representation items can be given for the type).
7117 @PDefn2{Term=[subtype conversion],Sec=(bounds of a floating point type)}]}
7118 @end{Honest}
7119
7120 @Defn{Float}
7121 There is a predefined, unconstrained, floating point subtype
7122 named Float@Redundant[, declared in the visible part of
7123 package Standard].
7124 @end{StaticSem}
7125
7126 @begin{RunTime}
7127 @PDefn2{Term=[elaboration], Sec=(floating_point_definition)}
7128 @Redundant[The elaboration of a @nt<floating_point_definition> creates
7129 the floating point type and its first subtype.]
7130 @end{RunTime}
7131
7132 @begin{ImplReq}
7133 @Defn{Float}
7134 In an implementation that supports floating point types with
7135 6 or more digits of precision, the requested
7136 decimal precision for Float shall be at least 6.
7137
7138 @Defn{Long_Float}
7139 If Long_Float is predefined for an implementation, then its
7140 requested decimal precision shall be at least 11.
7141 @end{ImplReq}
7142
7143 @begin{ImplPerm}
7144 @Defn{Short_Float}
7145 @Defn{Long_Float}
7146 An implementation is
7147 allowed to provide additional predefined floating point
7148 types@Redundant[, declared in the visible part of Standard], whose
7149 (unconstrained) first subtypes have names of the form Short_Float,
7150 Long_Float, Short_Short_Float, Long_Long_Float, etc.
7151 Different predefined floating point types are allowed to
7152 have the same base decimal precision.
7153 However, the precision of Float should be no greater than that of Long_Float.
7154 Similarly, the precision of Short_Float (if provided) should be no greater
7155 than Float.
7156 Corresponding recommendations apply to any other predefined floating point
7157 types.
7158 There need not be a named floating point type corresponding to each
7159 distinct base decimal precision supported by an implementation.
7160 @ImplDef{The predefined floating point types declared in Standard.}
7161 @end{ImplPerm}
7162
7163 @begin{ImplAdvice}
7164 @Defn{Long_Float}
7165 An implementation should support Long_Float in addition to
7166 Float if the target machine supports 11 or more digits of precision.
7167 No other named floating point subtypes are recommended for package Standard.
7168 Instead, appropriate named floating point subtypes should be provided in
7169 the library package Interfaces
7170 (see @RefSecNum(The Package Interfaces)).
7171 @ChgImplAdvice{Version=[2],Kind=[Added],Text=[@ChgAdded{Version=[2],
7172 Text=[Long_Float should be declared in Standard if the target supports
7173 11 or more digits of precision. No other named float subtypes should be
7174 declared in Standard.]}]}
7175 @begin{ImplNote}
7176 To promote portability, implementations should explicitly declare the floating
7177 point (sub)types Float and Long_Float in Standard, and leave other
7178 predefined float types anonymous.
7179 For implementations
7180 that already support Short_Float, etc., upward compatibility
7181 argues for keeping such declarations in Standard during the
7182 transition period, but perhaps generating a warning on use.
7183 A separate package Interfaces in the predefined environment
7184 is available for pre-declaring types such as Float_32, IEEE_Float_64, etc.
7185 See @RefSecNum(The Package Interfaces).
7186 @end{ImplNote}
7187 @end{ImplAdvice}
7188
7189 @begin{Notes}
7190 If a floating point subtype is unconstrained,
7191 then assignments to variables of the subtype involve only
7192 Overflow_Checks, never Range_Checks.
7193 @end{Notes}
7194
7195 @begin{Examples}
7196 @Leading@keepnext@i(Examples of floating point types and subtypes:)
7197 @begin(Example)
7198 @key(type) Coefficient @key(is) @key(digits) 10 @key(range) -1.0 .. 1.0;
7199
7200 @key(type) Real @key(is) @key(digits) 8;
7201 @key(type) Mass @key(is) @key(digits) 7 @key(range) 0.0 .. 1.0E35;
7202
7203 @key(subtype) Probability @key(is) Real @key(range) 0.0 .. 1.0; --@RI[ a subtype with a smaller range]
7204 @end(Example)
7205 @end{Examples}
7206
7207 @begin{Inconsistent83}
7208 @Defn{inconsistencies with Ada 83}
7209 No Range_Checks, only Overflow_Checks, are performed on
7210 variables (or parameters) of an
7211 unconstrained floating point subtype. This is upward
7212 compatible for programs that do not raise Constraint_Error.
7213 For those that do raise Constraint_Error, it is possible
7214 that the exception will be raised at a later point, or
7215 not at all, if extended range floating point registers are used to hold
7216 the value of the variable (or parameter).
7217 @begin(Reason)
7218 This change was felt to be justified by the possibility
7219 of improved performance on machines with extended-range
7220 floating point registers. An implementation need not
7221 take advantage of this relaxation in the range checking; it
7222 can hide completely the use of extended range registers if desired,
7223 presumably at some run-time expense.
7224 @end(Reason)
7225 @end{Inconsistent83}
7226
7227 @begin{DiffWord83}
7228 The syntax rules for @ntf{floating_point_constraint} and
7229 @ntf{floating_accuracy_definition} are removed. The syntax rules for
7230 @nt{floating_point_definition} and
7231 @nt{real_range_specification} are new.
7232
7233 A syntax rule for @nt<digits_constraint> is given in
7234 @RefSec{Fixed Point Types}. In @RefSecNum{Reduced Accuracy Subtypes}
7235 we indicate that a @nt<digits_constraint>
7236 may be applied to a floating point @nt<subtype_mark> as well
7237 (to be compatible with Ada 83's @ntf<floating_point_constraint>).
7238
7239 Discussion of model numbers is postponed to
7240 @RefSecNum{Operations of Floating Point Types} and
7241 @RefSecNum{Numeric Performance Requirements}.
7242 The concept of safe numbers has been replaced by the concept
7243 of the safe range of values. The bounds of the safe range are
7244 given by T'Safe_First .. T'Safe_Last, rather than -T'Safe_Large ..
7245 T'Safe_Large, since on some machines the safe range is not
7246 perfectly symmetric.
7247 The concept of machine numbers is new, and is relevant to
7248 the definition of Succ and Pred for floating point numbers.
7249 @end{DiffWord83}
7250
7251
7252 @NotISORMNewPageVer{Version=[3]}@Comment{For printed version of Ada 2012 RM}
7253 @LabeledSubClause{Operations of Floating Point Types}
7254
7255 @begin{StaticSem}
7256 @Leading@;The following attribute is defined for
7257 @PrefixType{every floating point subtype S}:
7258
7259 @begin(description)
7260 @ChgAttribute{Version=[1], Kind=[Revised], ChginAnnex=[F], Leading=[F],
7261 Prefix=<S>, AttrName=<Digits>, Ref=[8652/0004], ARef=[AI95-00203-01],
7262 Text=[S'Digits denotes the requested decimal precision
7263 for the subtype S. The value of this attribute
7264 is of the type @i(universal_integer).]}
7265 The requested decimal precision of the base subtype of a floating
7266 point type @i{T} is defined to be the largest value of @i{d} for which
7267 @chg{New=[@*],Old=[]}
7268 ceiling(@i{d} * log(10) / log(T'Machine_Radix)) + @Chg{New=[@i{g}],Old=[1]}
7269 <= T'Model_Mantissa@Chg{New=[@*
7270 where g is 0 if Machine_Radix is a positive power of 10 and 1 otherwise],Old=[]}.
7271 @end(description)
7272 @EndPrefixType{}
7273 @end{StaticSem}
7274
7275 @begin{Notes}
7276 @PDefn2{Term=[predefined operations],Sec=(of a floating point type)}
7277 The predefined operations of a floating point type include the assignment
7278 operation, qualification, the membership tests, and
7279 explicit conversion to and from other numeric types. They also
7280 include the relational operators and the following predefined
7281 arithmetic operators:
7282 the binary and unary adding operators @en@; and +,
7283 certain multiplying
7284 operators, the unary operator @key(abs),
7285 and the exponentiation operator.
7286
7287 As for all types, objects of a floating point type
7288 have Size and Address attributes
7289 (see @RefSecNum(Operational and Representation Attributes)).
7290 Other attributes of floating point types are defined in
7291 @RefSecNum{Attributes of Floating Point Types}.
7292 @end{Notes}
7293
7294 @begin{DiffWord95}
7295 @ChgRef{Version=[2],Kind=[AddedNormal],Ref=[8652/0004],ARef=[AI95-00203-01]}
7296 @ChgAdded{Version=[2],Text=[@b<Corrigendum:> Corrected the formula for Digits when
7297 the Machine_Radix is 10.]}
7298 @end{DiffWord95}
7299
7300
7301 @LabeledSubClause{Fixed Point Types}
7302
7303 @begin{Intro}
7304 @Defn{fixed point type}
7305 @Defn{ordinary fixed point type}
7306 @Defn{decimal fixed point type}
7307 A fixed point type is either an ordinary fixed point type,
7308 or a decimal fixed point type.
7309 @Defn2{Term=[delta], Sec=(of a fixed point type)}
7310 The error bound of a fixed point type is specified as an
7311 absolute value, called the @i(delta) of the fixed point type.
7312 @end{Intro}
7313
7314 @begin{Syntax}
7315 @Syn{lhs=<fixed_point_definition>,rhs="@Syn2{ordinary_fixed_point_definition} | @Syn2{decimal_fixed_point_definition}"}
7316
7317
7318 @Syn{lhs=<ordinary_fixed_point_definition>,rhs="
7319 @key{delta} @SynI{static_}@Syn2{expression} @Syn2{real_range_specification}"}
7320
7321 @Syn{lhs=<decimal_fixed_point_definition>,rhs="
7322 @key{delta} @SynI{static_}@Syn2{expression} @key{digits} @SynI{static_}@Syn2{expression} [@Syn2{real_range_specification}]"}
7323
7324 @ChgRef{Version=[4],Kind=[Revised],ARef=[AI12-0152-1]}
7325 @Syn{lhs=<digits_constraint>,rhs="
7326 @key{digits} @SynI{static_}@Chg{Version=[4],New=[@Syn2{simple_expression}],Old=[@Syn2{expression}]} [@Syn2{range_constraint}]"}
7327 @end{Syntax}
7328
7329 @begin{Resolution}
7330 @PDefn2{Term=[expected type], Sec=(fixed point type delta)}
7331 For a type defined by a @nt<fixed_point_definition>,
7332 the @i(delta) of the type is specified by the value of
7333 the @nt<expression> given after the
7334 reserved word @key(delta); this @nt<expression> is expected
7335 to be of any real type.
7336 @PDefn2{Term=[expected type], Sec=(decimal fixed point type digits)}
7337 @Defn2{Term=[digits], Sec=(of a decimal fixed point subtype)}
7338 @Defn{decimal fixed point type}
7339 For a type defined by a @nt<decimal_fixed_point_definition>
7340 (a @i(decimal) fixed point type),
7341 the number of significant decimal digits
7342 for its first subtype (the @i(digits) of the first subtype)
7343 is specified by the @nt<expression> given
7344 after the reserved word @key(digits); this @nt<expression>
7345 is expected to be of any integer type.
7346
7347 @ChgRef{Version=[4],Kind=[Added],ARef=[AI12-0159-1]}
7348 @ChgAdded{Version=[4],Text=[The @nt{simple_expression} of a
7349 @nt{digits_constraint} is expected to be of any integer type.]}
7350 @end{Resolution}
7351
7352 @begin{Legality}
7353 In a @nt<fixed_point_definition> or @nt<digits_constraint>,
7354 the @nt<expression>s given after the
7355 reserved words @key(delta) and @key(digits) shall be static; their
7356 values shall be positive.
7357
7358 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00100-01]}
7359 @Defn2{Term=[small], Sec=(of a fixed point type)}
7360 The set of values of a fixed point type comprise the integral multiples
7361 of a number called the @i(small) of the
7362 type.@Chg{Version=[2],New=[@PDefn2{Term=[machine numbers],Sec=[of a fixed point type]}
7363 The @i{machine numbers} of a fixed point type are the values of the type that
7364 can be represented exactly in every unconstrained variable of the type.],Old=[]}
7365 @Defn{ordinary fixed point type}
7366 For a type defined by an @nt<ordinary_fixed_point_definition>
7367 (an @i(ordinary) fixed point type), the @i(small) may be specified
7368 by an @nt<attribute_@!definition_@!clause>
7369 (see @RefSecNum{Operational and Representation Attributes});
7370 if so specified, it shall be no greater than the @i(delta) of the type.
7371 If not specified, the @i(small) of an ordinary fixed
7372 point type is an implementation-defined
7373 power of two less than or equal to the @i(delta).
7374 @ImplDef{The @i(small) of an ordinary fixed point type.}
7375
7376 For a decimal fixed point type,
7377 the @i(small) equals the @i(delta);
7378 the @i(delta)
7379 shall be a power of 10.
7380 If a @nt<real_range_specification> is given,
7381 both bounds of the range shall be in
7382 the range @en@;(10**@i(digits)@en@;1)*@i(delta) .. +(10**@i(digits)@en@;1)*@i(delta).
7383
7384 A @nt<fixed_point_definition> is illegal if the implementation
7385 does not support a fixed point type with the given @i(small) and
7386 specified range or @i(digits).
7387 @ImplDef{What combinations of @i(small), range, and @i(digits)
7388 are supported for fixed point types.}
7389
7390 For a @nt<subtype_indication> with a @nt<digits_constraint>, the
7391 @nt<subtype_mark> shall denote a decimal fixed point subtype.
7392 @begin(Honest)
7393 Or, as an obsolescent feature, a floating point subtype is permitted
7394 @em see @RefSecNum(Reduced Accuracy Subtypes).
7395 @end(Honest)
7396 @end{Legality}
7397
7398 @begin{StaticSem}
7399 @PDefn2{Term=[base range], Sec=(of a fixed point type)}
7400 The base range (see @RefSecNum{Scalar Types}) of a fixed point type
7401 is symmetric around zero, except possibly for an extra negative
7402 value in some implementations.
7403
7404 @Leading@PDefn2{Term=[base range], Sec=(of an ordinary fixed point type)}
7405 An @nt<ordinary_fixed_point_definition> defines an
7406 ordinary fixed point type whose base range
7407 includes at least all multiples of @i(small) that are between the
7408 bounds specified
7409 in the @nt<real_range_specification>. The base range of the
7410 type does not necessarily include the specified bounds themselves.
7411 @Defn2{Term=[constrained], Sec=(subtype)}
7412 @Defn2{Term=[unconstrained], Sec=(subtype)}
7413 An @nt<ordinary_@!fixed_@!point_@!definition> also defines a constrained first
7414 subtype of the type, with each bound of its range
7415 given by the closer to zero of:
7416 @begin(itemize)
7417 the value of the conversion to the fixed point type
7418 of the corresponding @nt<expression> of the
7419 @nt<real_range_specification>;
7420 @PDefn2{Term=[implicit subtype conversion],Sec=(bounds of a fixed point type)}
7421
7422 @begin{Honest}
7423 @ChgRef{Version=[1],Kind=[Added]}@ChgNote{This is discussed in AC-00002, which we can't reference here}
7424 @ChgAdded{Version=[1],Text=[The conversion mentioned above is not an @i{implicit subtype
7425 conversion} (which is something that happens at overload resolution, see
7426 @RefSecNum{Type Conversions}), although it happens implicitly. Therefore,
7427 the freezing rules are not invoked on the type (which is important so that
7428 representation items can be given for the type).
7429 @PDefn2{Term=[subtype conversion],Sec=(bounds of a fixed point type)}]}
7430 @end{Honest}
7431
7432 the corresponding bound of the base range.
7433 @end(itemize)
7434
7435 @PDefn2{Term=[base range], Sec=(of a decimal fixed point type)}
7436 A @nt<decimal_fixed_point_definition> defines a decimal fixed point
7437 type whose base range includes at least
7438 the range @en@;(10**@i(digits)@en@;1)*@i(delta) .. +(10**@i(digits)@en@;1)*@i(delta).
7439 @Defn2{Term=[constrained], Sec=(subtype)}
7440 @Defn2{Term=[unconstrained], Sec=(subtype)}
7441 A @nt<decimal_fixed_point_definition> also defines a constrained first
7442 subtype of the type. If a @nt<real_range_specification> is given,
7443 the bounds of the first subtype are given by a conversion
7444 of the values of the @nt<expression>s of the
7445 @nt<real_range_specification>.
7446 @PDefn2{Term=[implicit subtype conversion],Sec=(bounds of a decimal fixed point type)}
7447 Otherwise, the range of the first subtype is
7448 @en@;(10**@i(digits)@en@;1)*@i(delta) .. +(10**@i(digits)@en@;1)*@i(delta).
7449
7450 @begin{Honest}
7451 @ChgRef{Version=[1],Kind=[Added]}@ChgNote{This is discussed in AC-00002, which we can't reference here}
7452 @ChgAdded{Version=[1],Text=[The conversion mentioned above is not an @i{implicit subtype
7453 conversion} (which is something that happens at overload resolution, see
7454 @RefSecNum{Type Conversions}), although it happens implicitly. Therefore,
7455 the freezing rules are not invoked on the type (which is important so that
7456 representation items can be given for the type).
7457 @PDefn2{Term=[subtype conversion],Sec=(bounds of a decimal fixed point type)}]}
7458 @end{Honest}
7459
7460 @end{StaticSem}
7461
7462 @begin{RunTime}
7463 @PDefn2{Term=[elaboration], Sec=(fixed_point_definition)}
7464 The elaboration of a @nt<fixed_point_definition>
7465 creates the fixed point type and its first subtype.
7466
7467 @ChgRef{Version=[4],Kind=[Revised],ARef=[AI12-0152-1]}
7468 For a @nt<digits_constraint> on a decimal fixed point subtype with
7469 a given @i(delta), if it does not have a @nt<range_constraint>,
7470 then it specifies an implicit range
7471 @en@;(10**@i(D)@en@;1)*@i(delta) .. +(10**@i(D)@en@;1)*@i(delta),
7472 where @i(D) is the value of the
7473 @Chg{Version=[4],New=[@nt<simple_expression>],Old=[@nt<expression>]}.
7474 @Defn2{Term=[compatibility],
7475 Sec=(digits_constraint with a decimal fixed point subtype)}
7476 A @nt<digits_constraint> is @i(compatible) with a decimal
7477 fixed point subtype if the value of the
7478 @Chg{Version=[4],New=[@nt<simple_expression>],Old=[@nt<expression>]}
7479 is no greater than the @i(digits) of the subtype,
7480 and if it specifies (explicitly
7481 or implicitly) a range that is compatible with the subtype.
7482 @begin(Discussion)
7483 Except for the requirement that the @i(digits) specified be
7484 no greater than the @i(digits) of the subtype being
7485 constrained, a @nt<digits_constraint> is essentially
7486 equivalent to a @nt<range_constraint>.
7487
7488 @Leading@keepnext@;Consider the following example:
7489 @begin{Example}
7490 @key[type] D @key[is] @key[delta] 0.01 @key[digits] 7 @key[range] -0.00 .. 9999.99;
7491 @end{Example}
7492
7493 @ChgRef{Version=[1],Kind=[Revised]}@ChgNote{Presentation AI-00008}
7494 The compatibility rule implies that the @nt{digits_constraint}
7495 "@key[digits] 6" specifies an implicit range of
7496 "@en@;@Chg{New=[9999.99],Old=[99.9999]} .. @Chg{New=[9999.99],Old=[99.9999]}".
7497 Thus, "@key[digits] 6" is not compatible with the constraint of D, but
7498 "@key[digits] 6 range 0.00 .. 9999.99" is compatible.
7499
7500 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00114-01]}
7501 A value of a scalar type
7502 belongs to a constrained subtype of the type if it belongs to the
7503 range of the subtype. Attributes like Digits and Delta have no
7504 @Chg{Version=[2],New=[effect],Old=[affect]} on this fundamental rule.
7505 So the obsolescent forms of
7506 @nt<digits_constraint>s and @nt<delta_constraint>s that are
7507 called @lquotes@;accuracy constraints@rquotes@; in RM83 don't really
7508 represent constraints on the values of the subtype, but rather primarily
7509 affect compatibility of the @lquotes@;constraint@rquotes@; with the subtype
7510 being @lquotes@;constrained.@rquotes@; In this sense, they might better
7511 be called @lquotes@;subtype assertions@rquotes@; rather than @lquotes@;constraints.@rquotes@;
7512
7513 Note that the @nt<digits_constraint> on a decimal fixed point subtype
7514 is a combination of an assertion about the @i(digits) of the
7515 subtype being further constrained, and a constraint on the range of
7516 the subtype being defined, either explicit or implicit.
7517 @end(Discussion)
7518
7519 @ChgRef{Version=[4],Kind=[Revised],ARef=[AI12-0152-1]}
7520 @PDefn2{Term=[elaboration], Sec=(digits_constraint)}
7521 The elaboration of a @nt<digits_constraint> consists of the
7522 elaboration of the @nt<range_constraint>, if any.
7523 @IndexCheck{Range_Check}
7524 If a @nt<range_constraint> is given, a check is made that
7525 the bounds of the range are both in the range
7526 @en@;(10**@i(D)@en@;1)*@i(delta) .. +(10**@i(D)@en@;1)*@i(delta),
7527 where @i(D) is the value of the (static)
7528 @Chg{Version=[4],New=[@nt<simple_expression>],Old=[@nt<expression>]}
7529 given after the reserved word @key(digits).
7530 @Defn2{Term=(Constraint_Error),Sec=(raised by failure of runtime check)}
7531 If this check fails, Constraint_Error is raised.
7532 @end{RunTime}
7533
7534 @begin{ImplReq}
7535 The implementation shall support at least 24 bits of precision
7536 (including the sign bit) for fixed point types.
7537 @begin{Reason}
7538 This is sufficient to represent Standard.Duration with a @i(small)
7539 no more than 50 milliseconds.
7540 @end{Reason}
7541 @end{ImplReq}
7542
7543 @begin{ImplPerm}
7544 Implementations are permitted to support only
7545 @i(small)s that are a power of two. In particular,
7546 all decimal fixed point type declarations can be disallowed.
7547 Note however that conformance with the Information Systems Annex
7548 requires support for decimal @i(small)s, and decimal fixed point
7549 type declarations with @i(digits) up to at least 18.
7550 @begin{ImplNote}
7551 The accuracy requirements for multiplication, division, and conversion
7552 (see @RefSec{Model of Floating Point Arithmetic})
7553 are such that
7554 support for arbitrary @i(small)s should be practical without undue
7555 implementation effort. Therefore, implementations should support fixed point
7556 types with arbitrary values for @i(small) (within reason).
7557 One reasonable limitation would be to limit support to fixed point types
7558 that can be converted to the most precise floating point type
7559 without loss of precision (so that Fixed_IO is implementable in terms
7560 of Float_IO).
7561 @end{ImplNote}
7562 @end{ImplPerm}
7563
7564 @begin{Notes}
7565 @Leading@;The base range of
7566 an ordinary fixed point type need not include the specified bounds
7567 themselves
7568 so that the range specification can be given in a natural way, such as:
7569 @leading@begin(Example)
7570 @b(type) Fraction @b(is delta) 2.0**(-15) @b(range) -1.0 .. 1.0;
7571 @end(Example)
7572
7573 @NoPrefix@;With 2's complement hardware, such a type could have a
7574 signed 16-bit representation, using 1 bit for the sign
7575 and 15 bits for fraction, resulting in a base range of
7576 @en@;1.0 .. 1.0@en@;2.0**(@en@;15).
7577 @end{Notes}
7578
7579 @begin{Examples}
7580 @Leading@keepnext@i(Examples of fixed point types and subtypes:)
7581 @begin(Example)
7582 @key(type) Volt @key(is) @key(delta) 0.125 @key(range) 0.0 .. 255.0;
7583
7584 -- @RI[A pure fraction which requires all the available]
7585 -- @RI[space in a word can be declared as the type Fraction:]
7586 @key(type) Fraction @key(is) @key(delta) System.Fine_Delta @key(range) -1.0 .. 1.0;
7587 -- @RI[Fraction'Last = 1.0 @en System.Fine_Delta]
7588
7589 @key(type) Money @key(is) @key(delta) 0.01 @key(digits) 15; -- @RI[decimal fixed point]
7590 @key(subtype) Salary @key(is) Money @key(digits) 10;
7591 -- @RI[Money'Last = 10.0**13 @en 0.01, Salary'Last = 10.0**8 @en 0.01]
7592 @end(Example)
7593 @end{Examples}
7594
7595 @begin{Inconsistent83}
7596 @Defn{inconsistencies with Ada 83}
7597 In Ada 95, S'Small always equals S'Base'Small,
7598 so if an implementation chooses a @i(small) for a fixed point type smaller
7599 than required by the @i(delta), the value of S'Small in Ada 95 might not be
7600 the same as it was in Ada 83.
7601 @end{Inconsistent83}
7602
7603 @begin{Extend83}
7604 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0005-1]}
7605 @Defn{extensions to Ada 83}
7606 Decimal fixed point types are new, though their
7607 capabilities are essentially similar to that available
7608 in Ada 83 with a fixed point type whose @i(small) equals its @i(delta)
7609 @Chg{Version=[3],New=[and both are],Old=[equals]}
7610 a power of 10. However, in the Information Systems Annex, additional
7611 requirements are placed on the support of decimal fixed point types
7612 (e.g. a minimum of 18 digits of precision).
7613 @end{Extend83}
7614
7615 @begin{DiffWord83}
7616 The syntax rules for @ntf{fixed_point_constraint} and
7617 @ntf{fixed_accuracy_definition} are removed. The syntax rule for
7618 @nt{fixed_point_definition} is new.
7619 A syntax rule for @nt<delta_constraint> is included in the
7620 Obsolescent features (to be compatible with Ada 83's
7621 @ntf<fixed_point_constraint>).
7622 @end{DiffWord83}
7623
7624 @begin{DiffWord95}
7625 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00100-01]}
7626 @ChgAdded{Version=[2],Text=[Added wording to define the
7627 machine numbers of fixed point types; this is needed by the static
7628 evaluation rules.]}
7629 @end{DiffWord95}
7630
7631 @begin{Incompatible2012}
7632 @ChgRef{Version=[4],Kind=[AddedNormal],ARef=[AI12-0152-1]}
7633 @ChgAdded{Version=[4],Text=[@Defn{incompatibilities with Ada 2012}@b<Corrigendum:>
7634 Changed the syntax so that the value following @key[digits] in a
7635 @nt<digits_constraint> is a @nt<simple_expression>. This is compatible
7636 with one very unlikely exception: if the @key[digits] expression is
7637 a static expression of a modular type using an unparenthesized logical
7638 operator (like @key[and] or @key[or]). Parenthesizing the expression
7639 will make it legal in that case. The change is necessary to eliminate
7640 syntax ambguities in @nt<derived_type_definition>s.]}
7641 @end{Incompatible2012}
7642
7643 @begin{DiffWord2012}
7644 @ChgRef{Version=[4],Kind=[AddedNormal],ARef=[AI12-0159-1]}
7645 @ChgAdded{Version=[4],Text=[@b<Corrigendum>:Added wording to define the
7646 expected type for a @nt{digits_constraint}. This was missing since Ada 95,
7647 but as it is obvious and unchanged from Ada 83, we don't consider it an
7648 incompatibility.]}
7649 @end{DiffWord2012}
7650
7651
7652
7653 @LabeledSubClause{Operations of Fixed Point Types}
7654
7655 @begin{StaticSem}
7656 @Leading@;The following attributes are defined for
7657 @PrefixType{every fixed point subtype S}:
7658 @begin(description)
7659 @ChgAttribute{Version=[5], Kind=[Revised], ChginAnnex=[F], Leading=[F],
7660 Prefix=<S>, AttrName=<Small>, Ref=[8652/0005], ARef=[AI95-00054-01], ARef=[AI12-0367-1],
7661 Text=[S'Small
7662 denotes the @i(small) of the type of S.
7663 The value of this attribute is of the type @i(universal_real).]}
7664 @PDefn2{Term=[specifiable], Sec=(of Small for fixed point types)}
7665 @Defn{Small clause}
7666 Small may be specified
7667 for nonderived@Chg{New=[ ordinary],Old=[]} fixed point types
7668 via an @nt{attribute_@!definition_@!clause}
7669 (see @RefSecNum{Operational and Representation Attributes});
7670 the expression of such a clause shall be
7671 static@Chg{Version=[5],New=[ and
7672 positive],Old=[]}.@Chg{Version=[3],New=[@AspectDefn{Small}],Old=[]}
7673
7674 @ChgAspectDesc{Version=[3],Kind=[AddedNormal],Aspect=[Small],
7675 Text=[@ChgAdded{Version=[3],Text=[Scale factor for a fixed point type.]}]}
7676
7677 @Attribute{Prefix=<S>, AttrName=<Delta>,
7678 Text=[S'Delta
7679 denotes the @i(delta) of the fixed point subtype S.
7680 The value of this attribute is of the type @i(universal_real).]}
7681 @begin{Reason}
7682
7683 The @i(delta) is associated with the @i(sub)type as opposed
7684 to the type,
7685 because of the possibility of an (obsolescent) @nt<delta_constraint>.@end{reason}
7686
7687 @Attribute{Prefix=<S>, AttrName=<Fore>,
7688 Text=[S'Fore yields the minimum number of characters needed
7689 before the decimal point
7690 for the decimal representation of any value of the subtype S, assuming
7691 that the representation does not include an exponent, but includes
7692 a one-character prefix that is either a minus sign or a space.
7693 (This minimum number does not include superfluous zeros or
7694 underlines, and is at least 2.) The value of this attribute
7695 is of the type @i(universal_integer).]}
7696
7697 @Attribute{Prefix=<S>, AttrName=<Aft>,
7698 Text=<S'Aft yields the number of decimal digits needed after
7699 the decimal point to accommodate the @i(delta) of the subtype
7700 S, unless the @i(delta) of the subtype S is greater than 0.1,
7701 in which case the attribute yields the value one. @Redundant[(S'Aft
7702 is the smallest positive integer N for which (10**N)*S'Delta is
7703 greater than or equal to one.)] The value of this attribute is of
7704 the type @i(universal_integer).>}
7705 @end(description)
7706 @EndPrefixType{}
7707
7708 @begin{WideAbove}
7709 @Leading@;The following additional attributes are defined for
7710 @PrefixType{every decimal fixed point subtype S}:
7711 @end{WideAbove}
7712 @begin(description)
7713 @Attribute{Prefix=<S>, AttrName=<Digits>,
7714 Text=[S'Digits denotes the @i(digits) of the decimal
7715 fixed point subtype S, which corresponds to the number
7716 of decimal digits that are representable in objects of the
7717 subtype.
7718 The value of this attribute is of the type @i(universal_integer).]}
7719 Its value is determined as follows:
7720 @Defn2{Term=[digits], Sec=(of a decimal fixed point subtype)}
7721 @begin(itemize)
7722 For a first subtype or a subtype
7723 defined by a @nt<subtype_indication> with
7724 a @nt<digits_constraint>, the digits is the value
7725 of the expression given after the reserved word @key(digits);
7726
7727 For a subtype defined by a @nt<subtype_indication> without
7728 a @nt<digits_constraint>, the digits of the subtype
7729 is the same as that of the subtype denoted
7730 by the @nt<subtype_mark> in the @nt<subtype_indication>.
7731 @begin(ImplNote)
7732 Although a decimal subtype can be both range-constrained
7733 and digits-constrained, the digits constraint is intended
7734 to control the Size attribute of the subtype. For decimal
7735 types, Size can be important because input/output of decimal types
7736 is so common.
7737 @end(ImplNote)
7738
7739 The digits of a base subtype is the largest integer
7740 @i(D) such that the range
7741 @en@;(10**@i(D)@en@;1)*@i(delta) .. +(10**@i(D)@en@;1)*@i(delta)
7742 is included in the base range of the type.
7743
7744 @end(itemize)
7745
7746 @Attribute{Prefix=<S>, AttrName=<Scale>,
7747 Text=[S'Scale denotes the @i(scale) of the subtype S,
7748 defined as the value N such that S'Delta = 10.0**(@en@;N).
7749 @Defn2{Term=[scale], Sec=(of a decimal fixed point subtype)}
7750 @Redundant{The scale indicates the position of the point relative
7751 to the rightmost significant digits of values of subtype S.}
7752 The value of this attribute is of the type @i{universal_integer}.]}
7753 @begin{Ramification}
7754 S'Scale is negative if S'Delta is greater than one.
7755 By contrast, S'Aft is always positive.
7756 @end{Ramification}
7757
7758 @AttributeLeading{Prefix=<S>, AttrName=<Round>,
7759 Text=[S'Round denotes a function with
7760 the following specification:
7761 @begin(Descexample)
7762 @b(function) S'Round(@RI(X) : @RI(universal_real))
7763 @b(return) S'Base
7764 @end(Descexample)
7765
7766 @NoPrefix@;The function returns the value obtained by rounding X (away
7767 from 0, if X is midway between two values of the type of S).]}
7768 @end(description)
7769 @EndPrefixType{}
7770 @end{StaticSem}
7771
7772 @begin{Notes}
7773 All subtypes of a fixed point type will have the same value
7774 for the Delta attribute, in the absence of @nt<delta_constraint>s
7775 (see @RefSecNum(Reduced Accuracy Subtypes)).
7776
7777 S'Scale is not always the same as S'Aft for a decimal subtype;
7778 for example, if S'Delta = 1.0 then
7779 S'Aft is 1 while S'Scale is 0.
7780
7781 @PDefn2{Term=[predefined operations],Sec=(of a fixed point type)}
7782 The predefined operations of a fixed point type include the assignment
7783 operation, qualification, the membership tests, and
7784 explicit conversion to and from other numeric types. They also
7785 include the relational operators and the following predefined
7786 arithmetic operators:
7787 the binary and unary adding operators @en@; and +, multiplying
7788 operators, and the unary operator @key(abs).
7789
7790 As for all types, objects of a fixed point type
7791 have Size and Address attributes
7792 (see @RefSecNum(Operational and Representation Attributes)).
7793 Other attributes of fixed point types are defined in
7794 @RefSecNum{Attributes of Fixed Point Types}.
7795 @end{Notes}
7796
7797 @begin{DiffWord95}
7798 @ChgRef{Version=[2],Kind=[AddedNormal],Ref=[8652/0005],ARef=[AI95-00054-01]}
7799 @ChgAdded{Version=[2],Text=[@b<Corrigendum:> Clarified that @i<small> may be
7800 specified only for ordinary fixed point types.]}
7801 @end{DiffWord95}
7802
7803 @begin{DiffWord2012}
7804 @ChgRef{Version=[5],Kind=[AddedNormal],ARef=[AI12-0367-1]}
7805 @ChgAdded{Version=[5],Text=[@b<Correction:> Clarified that @i<small> may be
7806 specified only with positive values.]}
7807 @end{DiffWord2012}
7808