Debian Codegraph @

source_2020/03c.mss

raw
1 @Part(03, Root="ada.mss")
2
3 @Comment{$Date: 2020/06/03 00:09:00 $}
4
5 @Comment{$Source: e:\\cvsroot/ARM/Source/03c.mss,v $}
6 @Comment{$Revision: 1.149 $}
7
8 @LabeledClause{Tagged Types and Type Extensions}
9
10 @begin{Intro}
11 @redundant[@PDefn{dispatching operation}
12 @Defn{polymorphism}
13 @IndexSee{Term=[dynamic binding],See=(dispatching operation)}
14 @IndexSeeAlso{Term=[generic unit],See=(dispatching operation)}
15 @IndexSeeAlso{Term=[variant],See=(tagged type)}
16 Tagged types and type extensions support
17 object-oriented programming, based on
18 inheritance with extension and run-time polymorphism via
19 @i(dispatching operations).
20 @IndexSee{Term=[object-oriented programming (OOP)],See=[tagged types and type extensions]}
21 @IndexSee{Term=[OOP (object-oriented programming)],See=[tagged types and type extensions]}
22 @IndexSeeAlso{Term=[inheritance],See=[tagged types and type extension]}]
23 @end{Intro}
24
25 @begin{MetaRules}
26 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00251-01]}
27 The intended implementation model is for @Chg{Version=[2],New=[the static
28 portion of ],Old=[]}a tag to be represented as a
29 pointer to a statically allocated and link-time initialized type
30 descriptor. The type descriptor contains the address of the code for
31 each primitive operation of the type. It probably also contains
32 other information, such as might make membership tests convenient and
33 efficient.@Chg{Version=[2],New=[ Tags for nested type extensions must also have
34 a dynamic part that identifies the particular elaboration of the type.],Old=[]}
35
36 The primitive operations of a tagged type are known at its first
37 freezing point; the type descriptor is laid out at that point.
38 It contains linker symbols for each primitive operation; the linker
39 fills in the actual addresses.
40
41 @ChgRef{Version=[2],Kind=[Added],ARef=[AI95-00251-01]}
42 @ChgAdded{Version=[2],Text=[Primitive operations of type extensions that are
43 declared at a level deeper than the level of the ultimate ancestor from which
44 they are derived can
45 be represented by wrappers that use the dynamic part of the tag to call the
46 actual primitive operation. The dynamic part would generally be some way to
47 represent the static link or display necessary for making a nested call. One
48 implementation strategy would be to store that information in the extension
49 part of such nested type extensions, and use the dynamic part of the tag to
50 point at it. (That way, the @lquotes@;dynamic@rquotes@; part of the tag could
51 be static, at the cost of indirect access.)]}
52
53 @ChgRef{Version=[2],Kind=[Added],ARef=[AI95-00251-01]}
54 @ChgAdded{Version=[2],Text=[If the tagged type is descended from any interface
55 types, it also will need to include @lquotes@;subtags@rquotes@; (one for
56 each interface) that describe the mapping of the primitive operations of the
57 interface to the primitives of the type. These subtags could directly reference
58 the primitive operations (for faster performance), or simply provide the tag
59 @lquotes@;slot@rquotes@; numbers for the primitive operations (for easier
60 derivation). In either case, the subtags would be used for calls that dispatch
61 through a class-wide type of the interface.]}
62
63 Other implementation models are possible.
64
65 The rules ensure that @lquotes@;dangling dispatching@rquotes@; is impossible;
66 that is, when a dispatching call is made, there is always a body to
67 execute. This is different from some other object-oriented
68 languages, such as Smalltalk, where it is possible to get a run-time
69 error from a missing method.
70
71 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00251-01]}
72 Dispatching calls should be efficient, and should have a bounded
73 worst-case execution time. This is important in a language intended
74 for real-time applications. In the intended implementation model, a
75 dispatching call involves calling indirect through the appropriate
76 slot in the dispatch table. No complicated "method lookup" is
77 involved@Chg{Version=[2],New=[ although a call which is dispatching on
78 an interface may require a lookup of the appropriate interface subtag],Old=[]}.
79
80 The programmer should have the choice at each call site of a
81 dispatching operation whether to do a dispatching call or a
82 statically determined call (i.e. whether the body executed should be
83 determined at run time or at compile time).
84
85 The same body should be executed for a call where the tag is
86 statically determined to be T'Tag as for a dispatching call where the
87 tag is found at run time to be T'Tag. This allows one to test a
88 given tagged type with statically determined calls, with some
89 confidence that run-time dispatching will produce the same behavior.
90
91 All views of a type should share the same type descriptor and the
92 same tag.
93
94 The visibility rules determine what is legal at compile time; they
95 have nothing to do with what bodies can be executed at run time.
96 Thus, it is possible to dispatch to a subprogram whose declaration is
97 not visible at the call site. In fact, this is one of the primary
98 facts that gives object-oriented programming its power. The
99 subprogram that ends up being dispatched to by a given call might
100 even be designed long after the call site has been coded and
101 compiled.
102
103 Given that Ada has overloading, determining whether a given
104 subprogram overrides another is based both on the names and the type
105 profiles of the operations.
106
107 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00401-01]}
108 When a type extension is declared, if there is any place within its
109 immediate scope where a certain subprogram of the parent
110 @Chg{Version=[2],New=[or progenitor ],Old=[]}is visible,
111 then a matching subprogram should override. If there is no such
112 place, then a matching subprogram should be totally unrelated, and
113 occupy a different slot in the type descriptor. This is important to
114 preserve the privacy of private parts; when an operation declared in
115 a private part is inherited, the inherited version can be overridden
116 only in that private part, in the package body, and in any children
117 of the package.
118
119 If an implementation shares code for instances
120 of generic bodies, it should be
121 allowed to share type descriptors of tagged types
122 declared in the generic body, so long as they are not extensions of types
123 declared in the specification of the generic unit.
124 @end{MetaRules}
125
126 @begin{StaticSem}
127 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00345-01]}
128 @Defn{tagged type}
129 A record type or private type that has the reserved word @key(tagged)
130 in its declaration is called a @i(tagged) type.@Chg{Version=[2],New=[ In
131 addition, an interface type is a tagged type, as is a task or protected
132 type derived from an interface (see @RefSecNum{Interface Types}).],Old=[]}
133 @Redundant[When deriving
134 from a tagged type, @Chg{Version=[2],New=[as],Old=[additional components
135 may be defined. As]} for any derived type,
136 additional primitive subprograms may be defined,
137 and inherited primitive subprograms may be overridden.]
138 @Defn{type extension}
139 @Defn2{Term=[extension], Sec=(of a type)}
140 The derived type is called an @i(extension)
141 of @Chg{Version=[2],New=[its],Old=[the]} ancestor
142 @Chg{Version=[2],New=[types],Old=[type]}, or simply a @i(type
143 extension).@Chg{Version=[2],New=[],Old=[ @Defn2{Term=[extension], Sec=(of a record type)}
144 @Defn{private extension}
145 @Defn2{Term=[extension], Sec=(of a private type)}
146 Every type extension is also a tagged type, and
147 is either a @i(record extension) or a @i(private extension) of
148 some other tagged type.
149 A record extension is defined by a @nt<derived_type_definition>
150 with a @nt<record_extension_part>.
151 A private extension, which is a partial view of a record extension,
152 can be declared in the visible part of a package
153 (see @RefSecNum(Private Types and Private Extensions))
154 or in a generic formal part
155 (see @RefSecNum(Formal Private and Derived Types)).]}
156
157 @ChgRef{Version=[2],Kind=[Added],ARef=[AI95-00345-01]}
158 @ChgAdded{Version=[2],Text=[@Defn2{Term=[extension], Sec=(of a record type)}
159 @Defn{private extension}
160 @Defn2{Term=[extension], Sec=(of a private type)}
161 Every type extension is also a tagged type, and
162 is a @i(record extension) or a @i(private extension) of some other
163 tagged type, or a noninterface synchronized tagged type (see
164 @RefSecNum{Interface Types}).
165 A record extension is defined by a @nt<derived_type_definition>
166 with a @nt<record_extension_part> (see @RefSecNum{Type Extensions})@Redundant[,
167 which may include the definition of additional components].
168 A private extension, which is a partial view of a record extension or
169 of a synchronized tagged type,
170 can be declared in the visible part of a package
171 (see @RefSecNum(Private Types and Private Extensions))
172 or in a generic formal part
173 (see @RefSecNum(Formal Private and Derived Types)).]}
174 @ToGlossary{Term=<Tagged type>,
175 Text=<The objects of a tagged type have a run-time type tag,
176 which indicates the specific type with which the object was originally
177 created.
178 An operand of a class-wide tagged type
179 can be used in a dispatching call;
180 the tag indicates which subprogram body to invoke.
181 Nondispatching calls, in which the subprogram body to invoke
182 is determined at compile time, are also allowed.
183 Tagged types may be extended with additional components.>}
184 @begin{Ramification}
185 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00218-03]}
186 If a tagged type is declared other than in a @nt{package_specification},
187 it is impossible to add new primitive subprograms for that type,
188 although it can inherit primitive subprograms,
189 and those can be overridden.
190 If the user incorrectly thinks a certain subprogram is primitive when it
191 is not, and tries to call it with a dispatching call, an error message
192 will be given at the call site.@Chg{Version=[2],New=[ Similarly, by using
193 an @nt{overriding_indicator} (see @RefSecNum{Subprogram Declarations}),
194 the user can declare that a subprogram is intended to be overriding, and
195 get an error message when they made a mistake. The use of
196 @nt{overriding_indicator}s is highly recommended in new code that does not
197 need to be compatible with Ada 95.],Old=[]}
198
199 @ChgRef{Version=[2],Kind=[DeletedNoDelMsg],ARef=[AI95-00344-01]}
200 @ChgDeleted{Version=[2],Text=[Note that the accessibility rules imply that a
201 tagged type declared in a library @nt{package_specification} cannot be
202 extended in a nested subprogram or task body.]}
203 @end{Ramification}
204
205 @Defn{tag of an object}
206 An object of a tagged type has an associated (run-time)
207 @i(tag) that identifies the specific tagged type used to create
208 the object originally.
209 @Redundant[
210 The tag of an operand of a class-wide tagged type @i(T)'Class
211 controls which subprogram body is to be executed when a
212 primitive subprogram of type @i(T) is applied to
213 the operand
214 (see @RefSecNum(Dispatching Operations of Tagged Types));
215 @Defn{dispatching}
216 using a tag to control which body to execute is called @i(dispatching).]
217 @IndexSee{Term=[type tag],See=[tag]}
218 @IndexSee{Term=[run-time type],See=[tag]}
219 @IndexSeeAlso{Term=[type],See=[tag]}
220 @IndexSeeAlso{Term=[class],See=[tag]}
221
222 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00344-01]}
223 The tag of a specific tagged type identifies
224 the @nt<full_type_declaration> of the type@Chg{Version=[2],New=[, and
225 for a type extension, is sufficient to uniquely identify the type among
226 all descendants of the same ancestor],Old=[]}.
227 If a declaration for a tagged type occurs within a
228 @nt{generic_package_declaration},
229 then the corresponding type declarations in distinct
230 instances of the generic package are associated with distinct tags.
231 For a tagged type that is local to a generic package body@Chg{Version=[2],
232 New=[ and with all of its ancestors (if any) also local to the
233 generic body],Old=[]},
234 the language does not specify whether repeated instantiations
235 of the generic body result in distinct tags.@PDefn{Unspecified}
236 @begin{Reason}
237 @ChgRef{Version=[2],Kind=[Deleted],ARef=[AI95-00344-01]}
238 @ChgDeleted{Version=[2],Text=[This eases generic code sharing.]}
239 @end{reason}
240
241 @begin{ImplNote}
242 @ChgRef{Version=[2],Kind=[Added],ARef=[AI95-00344-01]}
243 @ChgAdded{Version=[2],Text=[In most cases, a tag need only identify a particular
244 tagged type declaration, and can therefore be a simple link-time-known
245 address. However, for tag checks
246 (see @RefSecNum{Dispatching Operations of Tagged Types}) it is essential
247 that each descendant (that currently exists) of a given type have
248 a unique tag. Hence, for types declared in shared generic bodies
249 where an ancestor comes from outside the generic, or for types
250 declared at a deeper level than an ancestor, the tag needs to be
251 augmented with some kind of dynamic descriptor (which may be a
252 static link, global display, instance descriptor pointer, or combination).
253 This implies that type Tag may need to be two words, the second of which
254 is normally null, but in these identified special cases needs to
255 include a static link or equivalent. Within an object of one of
256 these types with a two-word tag, the two parts of the tag would
257 typically be separated, one part as the first word of the object,
258 the second placed in the first extension part that corresponds to a
259 type declared more nested than its parent or declared in a shared
260 generic body when the parent is declared outside. Alternatively,
261 by using an extra level of indirection, the type Tag could remain
262 a single-word.]}
263
264 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00344-01]}
265 @Chg{Version=[2],New=[For types that are not type extensions (even
266 for ones declared in nested scopes), we do not require that],
267 Old=[The language does not specify whether]}
268 repeated elaborations of the same @nt<full_type_declaration>
269 correspond to distinct tags. @Chg{Version=[2],New=[This was done so that
270 Ada 2005 implementations of tagged types could maintain representation
271 compatibility with Ada 95 implementations. Only type extensions that were
272 not allowed in Ada 95 require additional information with the tag.],
273 Old=[In most cases, we
274 expect that all elaborations will correspond to the same tag,
275 since the tag will frequently be the address (or index) of a statically
276 allocated type descriptor. However, with shared
277 generics, the type descriptor might have to be allocated on a per-instance
278 basis, which in some implementation models implies per-elaboration of the
279 instantiation.]}
280 @end{implnote}
281
282 @begin{Honest}
283 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00344-01]}
284 @ChgAdded{Version=[2],Text=[The wording @lquotes@;is sufficient to uniquely
285 identify the type among all descendants of the same ancestor@rquotes@; only
286 applies to types that currently exist. It is not necessary to distinguish
287 between descendants that currently exist, and descendants of the same type
288 that no longer exist.
289 For instance, the address of the stack frame of the subprogram that created
290 the tag is sufficient to meet the requirements of this rule, even though
291 it is possible, after the subprogram returns, that a later call of the
292 subprogram could have the same stack frame and thus have an identical tag.]}
293 @end{Honest}
294
295 @Leading@keepnext@;The following language-defined library package exists:
296 @begin{Example}
297 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00362-01]}
298 @ChgRef{Version=[5],Kind=[Revised],ARef=[AI12-0241-1]}
299 @ChildUnit{Parent=[Ada],Child=[Tags]}@key[package] Ada.Tags @Chg{Version=[5],New=[],Old=[ @key[is]]}
300 @Chg{Version=[2],New=[@Chg{Version=[5],New=[@key[with]],Old=[@key[pragma]]} Preelaborate@Chg{Version=[5],New=[, Nonblocking @key[is]],Old=[(Tag);]}
301 ],Old=[]}@key[type] @AdaTypeDefn{Tag} @key[is] @key[private];@Chg{Version=[2],New=[
302 @key[pragma] Preelaborable_Initialization(Tag);],Old=[]}
303
304 @ChgRef{Version=[2],Kind=[Added],ARef=[AI95-00260-02]}
305 @ChgAdded{Version=[2],Text=[ @AdaObjDefn{No_Tag} : @key[constant] Tag;]}
306
307 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00400-01]}
308 @key[function] @AdaSubDefn{Expanded_Name}(T : Tag) @key[return] String;@Chg{Version=[2],New=[
309 @key[function] @AdaSubDefn{Wide_Expanded_Name}(T : Tag) @key[return] Wide_String;
310 @key[function] @AdaSubDefn{Wide_Wide_Expanded_Name}(T : Tag) @key[return] Wide_Wide_String;],Old=[]}
311 @key[function] @AdaSubDefn{External_Tag}(T : Tag) @key[return] String;
312 @key[function] @AdaSubDefn{Internal_Tag}(External : String) @key[return] Tag;
313
314 @ChgRef{Version=[2],Kind=[Added],ARef=[AI95-00344-01]}
315 @ChgAdded{Version=[2],Text=[ @key[function] @AdaSubDefn{Descendant_Tag}(External : String; Ancestor : Tag) @key[return] Tag;
316 @key[function] @AdaSubDefn{Is_Descendant_At_Same_Level}(Descendant, Ancestor : Tag)
317 @key[return] Boolean;]}
318
319 @ChgRef{Version=[2],Kind=[Added],ARef=[AI95-00260-02]}
320 @ChgAdded{Version=[2],Text=[ @key[function] @AdaSubDefn{Parent_Tag} (T : Tag) @key[return] Tag;]}
321
322 @ChgRef{Version=[2],Kind=[Added],ARef=[AI95-00405-01]}
323 @ChgAdded{Version=[2],Text=[ @key[type] @AdaTypeDefn{Tag_Array} @key[is array] (Positive @key[range] <>) @key[of] Tag;]}
324
325 @ChgRef{Version=[2],Kind=[Added],ARef=[AI95-00405-01]}
326 @ChgAdded{Version=[2],Text=[ @key[function] @AdaSubDefn{Interface_Ancestor_Tags} (T : Tag) @key[return] Tag_Array;]}
327
328 @ChgRef{Version=[3],Kind=[Added],ARef=[AI05-0173-1]}
329 @ChgAdded{Version=[3],Text=[ @key[function] @AdaSubDefn{Is_Abstract} (T : Tag) @key[return] Boolean;]}
330
331 @AdaExcDefn{Tag_Error} : @key[exception];
332
333 @key[private]
334 ... -- @RI{not specified by the language}
335 @key[end] Ada.Tags;
336 @end{Example}
337 @begin{Reason}
338 Tag is a nonlimited, definite subtype,
339 because it needs the equality operators,
340 so that tag checking makes sense.
341 Also, equality, assignment, and object declaration
342 are all useful capabilities for this subtype.
343
344 For an object X and a type T,
345 @lquotes@;X'Tag = T'Tag@rquotes@; is not needed,
346 because a membership test can be used.
347 However, comparing the tags of two objects
348 cannot be done via membership.
349 This is one reason to allow equality for type Tag.
350 @end{Reason}
351
352 @ChgRef{Version=[2],Kind=[Added],ARef=[AI95-00260-02]}
353 @ChgAdded{Version=[2],Text=[No_Tag is the default initial value of type Tag.]}
354 @begin{Reason}
355 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00260-02]}
356 @ChgAdded{Version=[2],Text=[This is similar to the requirement that all
357 access values be initialized to @key[null].]}
358 @end{Reason}
359
360 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00400-01]}
361 The function @Chg{Version=[2],New=[Wide_@!Wide_@!Expanded_@!Name],
362 Old=[Expanded_@!Name]} returns the full expanded name of the
363 first subtype of the specific type identified by the tag,
364 in upper case, starting with a root library unit.
365 The result is implementation defined if the type is declared within
366 an unnamed @nt{block_statement}.
367 @begin{Honest}
368 This name, as well as each @nt{prefix} of it,
369 does not denote a @nt{renaming_declaration}.
370 @end{Honest}
371 @ChgImplDef{Version=[2],Kind=[Revised],InitialVersion=[0],
372 Text=[The result of @Chg{Version=[2],
373 New=[Tags.Wide_@!Wide_@!Expanded_@!Name],Old=[Tags.Expanded_@!Name]} for types
374 declared within an unnamed @nt{block_statement}.]}
375
376 @ChgRef{Version=[2],Kind=[Added],ARef=[AI95-00400-01]}
377 @ChgAdded{Version=[2],Text=[The function Expanded_Name (respectively,
378 Wide_Expanded_Name) returns the same sequence of graphic characters as that
379 defined for Wide_Wide_Expanded_Name, if all the graphic characters are defined
380 in Character (respectively, Wide_Character); otherwise, the sequence of
381 characters is implementation defined, but no shorter than that returned by
382 Wide_Wide_Expanded_Name for the same value of the argument.]}
383 @ChgImplDef{Version=[2],Kind=[AddedNormal],Text=[@Chg{Version=[2],New=[
384 The sequence of characters of the value returned by Tags.Expanded_Name
385 (respectively, Tags.Wide_Expanded_Name)
386 when some of the graphic characters of Tags.Wide_Wide_Expanded_Name are not
387 defined in Character (respectively, Wide_Character).],Old=[]}]}
388
389 The function External_Tag returns a string to be used in an
390 external representation for the given tag. The call External_Tag(S'Tag)
391 is equivalent to the @nt<attribute_reference> S'External_Tag
392 (see @RefSecNum{Operational and Representation Attributes}).
393 @begin{Reason}
394 It might seem redundant to provide both the function External_Tag and
395 the attribute External_Tag.
396 The function is needed because the attribute can't be applied to
397 values of type Tag.
398 The attribute is needed so that it can be @Chg{Version=[2],
399 New=[specified],Old=[specifiable]}
400 via an @nt{attribute_definition_clause}.
401 @end{Reason}
402
403 @ChgRef{Version=[2],Kind=[Added],ARef=[AI95-00417-01]}
404 @ChgAdded{Version=[2],Text=[The string returned by the functions Expanded_Name,
405 Wide_@!Expanded_@!Name, Wide_Wide_@!Expanded_@!Name, and External_Tag has lower bound
406 1.]}
407
408 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00279-01]}
409 The function Internal_Tag returns @Chg{Version=[2],New=[a],Old=[the]} tag that
410 corresponds to the given external tag, or raises Tag_Error if the given string
411 is not the external tag for any specific
412 type of the partition.@Chg{Version=[2],New=[ Tag_Error is also raised
413 if the specific type identified is a library-level type whose tag
414 has not yet been created (see @RefSecNum{Freezing Rules}).],Old=[]}
415
416 @begin{Reason}
417 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00279-01]}
418 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0005-1]}
419 @ChgAdded{Version=[2],Text=[The check for uncreated library-level types
420 prevents a reference to the type before execution reaches the freezing point
421 of the type. This is important so that T'Class'Input or an instance of
422 Tags.Generic_Dispatching_Constructor do not try to create an object of a type
423 that hasn't been frozen (which @Chg{Version=[3],New=[might],Old=[may]}
424 not have yet elaborated its constraints).
425 We don't require this behavior for non-library-level types as the tag can
426 be created multiple times and possibly multiple copies can exist at the
427 same time, making the check complex.]}
428 @end{Reason}
429
430 @ChgRef{Version=[2],Kind=[Added],ARef=[AI95-00344-01]}
431 @ChgRef{Version=[3],Kind=[RevisedAdded],ARef=[AI05-0113-1]}
432 @ChgAdded{Version=[2],Text=[The function Descendant_Tag returns the (internal)
433 tag for the type that corresponds to the given external tag and is both a
434 descendant of the type identified by the Ancestor tag and has the same
435 accessibility level as the identified ancestor. Tag_Error is raised if External
436 is not the external tag for such a type. Tag_Error is also raised if the
437 specific type identified is a library-level type whose tag has not yet been
438 created@Chg{Version=[3],New=[, or if the given external tag identifies more than
439 one type that has the appropriate Ancestor and accessibility level],Old=[]}.]}
440
441 @begin{Reason}
442 @ChgRef{Version=[2],Kind=[AddedNormal]}
443 @ChgAdded{Version=[2],Text=[Descendant_Tag is used by T'Class'Input to
444 identify the type identified by an external tag. Because there can be
445 multiple elaborations of a given type declaration, Internal_Tag does not
446 have enough information to choose a unique such type. Descendant_Tag does
447 not return the tag for types declared at deeper accessibility levels than
448 the ancestor because there could be ambiguity in the presence of
449 recursion or multiple tasks. Descendant_Tag can
450 be used in constructing a user-defined replacement for T'Class'Input.]}
451
452 @ChgRef{Version=[3],Kind=[Added],ARef=[AI05-0113-1]}
453 @ChgAdded{Version=[3],Text=[Rules for specifying external tags will usually
454 prevent an external tag from identifying more than one type. However, an
455 external tag can identify multiple types if a generic body contains a
456 derivation of a tagged type declared outside of the generic, and there are
457 multiple instances at the same accessibility level as the type. (The Standard
458 allows default external tags to not be unique in this case.)]}
459 @end{Reason}
460
461 @ChgRef{Version=[2],Kind=[Added],ARef=[AI95-00344-01]}
462 @ChgAdded{Version=[2],Text=[The function Is_Descendant_At_Same_Level returns
463 True if the Descendant tag identifies a type that is both a descendant of the
464 type identified by Ancestor and at the same accessibility level. If not, it
465 returns False.]}
466
467 @begin{Reason}
468 @ChgRef{Version=[2],Kind=[AddedNormal]}
469 @ChgAdded{Version=[2],Text=[Is_Descendant_At_Same_Level (or something similar
470 to it) is used by T'Class'Output to determine whether the item being
471 written is at the same accessibility level as T. It may be used to
472 determine prior to using T'Class'Output whether Tag_Error will be raised,
473 and also can be used in constructing a user-defined replacement
474 for T'Class'Output.]}
475 @end{Reason}
476
477 @ChgRef{Version=[3],Kind=[Added],ARef=[AI05-0115-1]}
478 @ChgAdded{Version=[3],Text=[For the purposes of the dynamic semantics of
479 functions Descendant_Tag and Is_Descendant_At_Same_Level, a tagged type T2
480 is a @i<descendant> of
481 a type T1 if it is the same as T1, or if its parent type or one of its
482 progenitor types is a descendant of type T1 by this rule@Redundant[,
483 even if at the point of the declaration of T2, one of the derivations
484 in the chain is not visible].@Defn2{Term=[descendant],Sec=[at run time]}]}
485
486 @begin{Discussion}
487 @ChgRef{Version=[3],Kind=[Added]}
488 @ChgAdded{Version=[3],Text=[In other contexts, @ldquote@;descendant@rdquote
489 is dependent on visibility, and the particular view a derived type has of
490 its parent type. See @RefSecNum{Private Operations}.]}
491 @end{Discussion}
492
493 @ChgRef{Version=[2],Kind=[Added],ARef=[AI95-00260-02]}
494 @ChgRef{Version=[3],Kind=[RevisedAdded]}@ChgNote{Paragraph number changed}
495 @ChgRef{Version=[4],Kind=[RevisedAdded],ARef=[AI12-0056-1]}
496 @ChgAdded{Version=[2],Text=[The function Parent_Tag returns the tag of the
497 parent type of the type whose tag is T. If the type does not have a parent type
498 (that is, it was not @Chg{Version=[4],New=[defined],Old=[declared]} by a
499 @Chg{Version=[4],New=[@nt{derived_type_definition}],Old=[derived_type_declaration]}),
500 then No_Tag is returned.]}
501
502 @begin{Ramification}
503 @ChgRef{Version=[2],Kind=[AddedNormal]}
504 @ChgRef{Version=[4],Kind=[Revised],ARef=[AI12-0005-1]}
505 @ChgAdded{Version=[2],Text=[The parent type is always the parent of the full
506 type; a private extension appears to define a parent type, but it does not
507 (only the various forms of derivation do that). As this is a run-time
508 operation, ignoring @Chg{Version=[4],New=[privacy],Old=[privateness]} is OK.]}
509 @end{Ramification}
510
511 @ChgRef{Version=[2],Kind=[Added],ARef=[AI95-00405-01]}
512 @ChgRef{Version=[3],Kind=[RevisedAdded]}@ChgNote{Paragraph number changed}
513 @ChgAdded{Version=[2],Text=[The function Interface_Ancestor_Tags returns an
514 array containing the tag of each interface ancestor type of the type whose tag
515 is T, other than T itself. The lower bound of the returned array is 1, and the
516 order of the returned tags is unspecified. Each tag appears in the result
517 exactly once.@Redundant[ If the type whose tag is T has no interface ancestors,
518 a null array is returned.]]}@PDefn{Unspecified}
519
520 @begin{Ramification}
521 @ChgRef{Version=[2],Kind=[AddedNormal]}
522 @ChgAdded{Version=[2],Text=[The result of Interface_Ancestor_Tags includes the
523 tag of the parent type, if the parent is an interface.]}
524
525 @ChgRef{Version=[2],Kind=[AddedNormal]}
526 @ChgAdded{Version=[2],Text=[Indirect interface ancestors are included in the
527 result of Interface_Ancestor_Tags. That's because where an interface appears
528 in the derivation tree has no effect on the semantics of the type; the only
529 interesting property is whether the type has an interface as an ancestor.]}
530 @end{Ramification}
531
532 @ChgRef{Version=[3],Kind=[Added],ARef=[AI05-0173-1]}
533 @ChgAdded{Version=[3],Text=[The function Is_Abstract returns True if the type
534 whose tag is T is abstract, and False otherwise.]}
535
536 For @PrefixType{every subtype S of a tagged type @i(T)
537 (specific or class-wide)}, the following attributes are
538 defined:
539 @begin(description)
540 @Attribute{Prefix=<S>, AttrName=<Class>,
541 Text=[S'Class
542 denotes a subtype of the class-wide type
543 (called @i(T)'Class in this International Standard) for the class
544 rooted at @i(T) (or if S already denotes a class-wide subtype,
545 then S'Class is the same as S).
546
547 @Noprefix@Defn2{Term=[unconstrained], Sec=(subtype)}
548 @Defn2{Term=[constrained], Sec=(subtype)}
549 S'Class is unconstrained. However,
550 if S is constrained, then the values of S'Class are only those
551 that when converted to the type @i(T) belong to S.]}
552 @begin{Ramification}
553 This attribute is defined for both specific
554 and class-wide subtypes. The definition is such
555 that S'Class'Class is the same as S'Class.
556
557 Note that if S is constrained, S'Class is only partially constrained,
558 since there might be additional discriminants
559 added in descendants of @i(T) which are not constrained.
560 @end{Ramification}
561 @begin{Reason}
562 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00326-01]}
563 The Class attribute is not defined for untagged subtypes
564 (except for incomplete types and private types
565 whose full view is tagged
566 @em see @Chg{Version=[2],New=[@RefSecNum{The Class Attribute of Untagged Incomplete Types}],
567 Old=[@RefSecNum{Incomplete Type Declarations}]} and
568 @RefSecNum{Private Operations})
569 so as to preclude implicit conversion in the absence of run-time
570 type information. If it were defined for untagged subtypes, it would
571 correspond to the concept of universal types provided for the predefined
572 numeric classes.
573 @end{Reason}
574
575 @Attribute{Prefix=<S>, AttrName=<Tag>,
576 Text=[S'Tag denotes the tag of
577 the type @i(T) (or if @i(T) is class-wide, the tag of the root type of the
578 corresponding class).
579 The value of this attribute is of type Tag.]}
580 @begin{Reason}
581 S'Class'Tag equals S'Tag, to avoid generic
582 contract model problems when S'Class is the actual
583 type associated with a generic formal derived type.@end{reason}
584 @end(description)
585 @EndPrefixType{}
586
587 Given @PrefixType{a @nt<prefix> X that is of a class-wide
588 tagged type @Redundant[(after any implicit dereference)]},
589 the following attribute is defined:
590 @begin(description)
591 @Attribute{Prefix=<X>, AttrName=<Tag>,
592 Text=[X'Tag denotes the tag of X.
593 The value of this attribute is of type Tag.]}
594 @begin(Reason)
595 X'Tag is not defined if X is of a specific type.
596 This is primarily to avoid confusion that might result
597 about whether the Tag attribute should reflect the tag of
598 the type of X, or the tag of X. No such
599 confusion is possible if X is of a class-wide type.
600 @end(Reason)
601 @end(description)
602 @EndPrefixType{}
603
604 @ChgRef{Version=[2],Kind=[Added],ARef=[AI95-00260-02],ARef=[AI95-00441-01]}
605 @ChgAdded{Version=[2],Type=[Leading],Text=[The following language-defined
606 generic function exists:]}
607
608 @begin{Example}
609 @ChgRef{Version=[2],Kind=[Added]}
610 @ChgRef{Version=[3],Kind=[RevisedAdded],ARef=[AI05-0229-1]}
611 @ChgRef{Version=[5],Kind=[RevisedAdded],ARef=[AI12-0241-1]}
612 @ChgAdded{Version=[2],Text=[@ChildUnit{Parent=[Ada.Tags],Child=[Generic_@!Dispatching_@!Constructor]}@key{generic}
613 @key{type} T (<>) @key{is abstract tagged limited private};
614 @key{type} Parameters (<>) @key{is limited private};
615 @key{with function} Constructor (Params : @key{not null access} Parameters)
616 @key{return} T @key{is abstract};
617 @key{function} Ada.Tags.Generic_Dispatching_Constructor
618 (The_Tag : Tag;
619 Params : @key{not null access} Parameters) @key{return} T'Class@Chg{Version=[3],New=[
620 @key{with} @Chg{Version=[5],New=[Preelaborate, ],Old=[]}Convention => Intrinsic@Chg{Version=[5],New=[,
621 Nonblocking => Constructor'Nonblocking],Old=[]}],Old=[]};@Chg{Version=[5],New=[],Old=[
622 @key{pragma} Preelaborate(Generic_Dispatching_Constructor);]}@Chg{Version=[3],New=[],Old=[
623 @key{pragma} Convention(Intrinsic, Generic_Dispatching_Constructor);]}]}
624 @end{Example}
625
626 @ChgRef{Version=[2],Kind=[Added],ARef=[AI95-00260-02]}
627 @ChgAdded{Version=[2],Text=[Tags.Generic_Dispatching_Constructor provides
628 a mechanism to create an object of an appropriate type from just a tag value.
629 The function Constructor is expected to create the object given a reference to
630 an object of type Parameters.]}
631
632 @begin{Discussion}
633 @ChgRef{Version=[2],Kind=[AddedNormal]}
634 @ChgAdded{Version=[2],Text=[This specification is designed to make it easy to
635 create dispatching constructors for streams; in particular, this can be used to
636 construct overridings for T'Class'Input.]}
637
638 @ChgRef{Version=[2],Kind=[AddedNormal]}
639 @ChgRef{Version=[5],Kind=[Revised],ARef=[AI12-0005-1]}
640 @ChgAdded{Version=[2],Text=[Note that @Chg{Version=[5],New=[almost ],Old=[]}any
641 tagged type @Chg{Version=[5],New=[can be used in an instance of
642 Generic_Dispatching_Constructor. Using a tagged incomplete view or a tagged
643 partial view before the completion of the type in such an instance would be
644 illegal; all other tagged types can be used in an instance of
645 Generic_Dispatching_Constructor],Old=[will match T (see
646 @RefSecNum{Formal Private and Derived Types})]}.]}
647 @end{Discussion}
648
649 @end{StaticSem}
650
651 @begin{RunTime}
652 @Leading@keepnext@;The tag associated with an object of a tagged type is
653 determined as follows:
654 @begin(Itemize)
655 @PDefn2{Term=[tag of an object], Sec=(stand-alone object, component, or @nt<aggregate>)}
656 The tag of a stand-alone object, a component, or an
657 @nt<aggregate> of a specific tagged type @i(T)
658 identifies @i(T).
659 @begin{Discussion}
660 The tag of a formal parameter of type @i(T)
661 is not necessarily the tag of @i(T), if, for example, the actual was a
662 type conversion.
663 @end{Discussion}
664
665 @PDefn2{Term=[tag of an object], Sec=(object created by an @nt<allocator>)}
666 The tag of an object created by an allocator for an
667 access type with a specific designated tagged type @i(T),
668 identifies @i(T).
669 @begin{Discussion}
670 The tag of an object designated by a
671 value of such an access type might not be @i(T), if, for
672 example, the access value is the result of a type conversion.@end{discussion}
673
674 @PDefn2{Term=[tag of an object], Sec=(class-wide object)}
675 The tag of an object of a class-wide tagged type
676 is that of its initialization expression.
677 @begin{Ramification}
678 The tag of an object (even a class-wide one)
679 cannot be changed after it is initialized, since a @lquotes@;class-wide@rquotes@;
680 @nt{assignment_statement} raises Constraint_Error if the tags don't
681 match, and a @lquotes@;specific@rquotes@; @nt{assignment_statement} does not affect
682 the tag.
683 @end{Ramification}
684
685 @PDefn2{Term=[tag of an object], Sec=(returned by a function)}
686 The tag of the result returned by a function whose
687 result type is a specific tagged type @i(T) identifies @i(T).
688 @begin{ImplNote}
689 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00318-02]}
690 @Chg{Version=[2],New=[For a limited tagged type, the return object is
691 @lquotes@;built in place@rquotes in the ultimate result object with the
692 appropriate tag.], Old=[This requires
693 a runtime check for limited tagged types, since they are
694 returned "by-reference."]}
695 For a nonlimited
696 type, a new anonymous object with the appropriate tag
697 is created as part of the function
698 return@Chg{Version=[2],New=[],Old=[, and then assigned the value of the
699 return expression]}.
700 See @RefSec{Return Statements}.
701 @end{ImplNote}
702
703 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00318-02]}
704 @PDefn2{Term=[tag of an object], Sec=(returned by a function)}
705 The tag of the result returned by a
706 function with a class-wide result
707 type is that of the return @Chg{Version=[2],New=[object],Old=[expression]}.
708 @end(Itemize)
709
710 @PDefn2{Term=[tag of an object], Sec=(preserved by type conversion and parameter passing)}
711 The tag is preserved by type conversion and by parameter passing.
712 The tag of a value is the tag of the associated object
713 (see @RefSecNum{Formal Parameter Modes}).
714
715 @ChgRef{Version=[2],Kind=[Added],ARef=[AI95-00260-02],ARef=[AI95-00344-01],ARef=[AI95-00405-01]}
716 @ChgRef{Version=[3],Kind=[RevisedAdded],ARef=[AI05-0092-1],ARef=[AI05-0262-1]}
717 @ChgAdded{Version=[2],Text=[Tag_Error is raised by a call of Descendant_Tag,
718 Expanded_Name, External_Tag, @Chg{Version=[3],New=[Interface_@!Ancestor_@!Tags],
719 Old=[Interface_Ancestor_Tag]},@Chg{Version=[3],New=[
720 Is_Abstract,],Old=[]}
721 Is_Descendant_@!At_Same_Level,
722 @Chg{Version=[3],New=[],Old=[or ]}Parent_Tag@Chg{Version=[3],New=[,
723 Wide_Expanded_Name, or Wide_Wide_Expanded_Name],Old=[]} if any
724 tag passed is No_Tag.]}
725
726 @ChgRef{Version=[2],Kind=[Added],ARef=[AI95-00260-02]}
727 @ChgAdded{Version=[2],Text=[An instance of Tags.Generic_Dispatching_Constructor
728 raises Tag_Error if The_Tag does not represent a concrete descendant of T or
729 if the innermost master (see @RefSecNum{Completion and Finalization}) of this
730 descendant is not also a master of the instance.
731 Otherwise, it dispatches to the primitive function denoted by the formal
732 Constructor for the type identified by The_Tag, passing Params, and
733 returns the result. Any exception raised by the function is propagated.]}
734
735 @begin{Ramification}
736 @ChgRef{Version=[2],Kind=[AddedNormal]}
737 @ChgAdded{Version=[2],Text=[The tag check checks both that The_Tag is in
738 T'Class, and that it is not abstract. These checks are similar to the ones
739 required by streams for T'Class'Input
740 (see @RefSecNum{Stream-Oriented Attributes}). In addition, there is a
741 check that the tag identifies a type declared on the current dynamic
742 call chain, and not a more nested type or a type declared by another
743 task. This check is not necessary for streams, because the stream attributes
744 are declared at the same dynamic level as the type used.]}
745 @end{Ramification}
746
747 @end{RunTime}
748
749 @begin{Erron}
750 @ChgRef{Version=[2],Kind=[Added],ARef=[AI95-00260-02]}
751 @ChgAdded{Version=[2],Text=[@PDefn2{Term=(erroneous execution),Sec=(cause)}
752 If an internal tag provided to an instance of
753 Tags.Generic_Dispatching_Constructor or to any subprogram declared in
754 package Tags identifies either a type that is not
755 library-level and whose tag has not been created
756 (see @RefSecNum{Freezing Rules}), or a type that does not exist in the
757 partition at the time of the call, then execution is erroneous.]}
758
759 @begin{Ramification}
760 @ChgRef{Version=[2],Kind=[AddedNormal]}
761 @ChgAdded{Version=[2],Text=[One reason that a type might not exist in
762 the partition is that the tag refers to a type whose declaration was
763 elaborated as part of an execution of a @nt{subprogram_body} which has been
764 left (see @RefSecNum{Completion and Finalization}).]}
765
766 @ChgRef{Version=[2],Kind=[AddedNormal]}
767 @ChgAdded{Version=[2],Text=[We exclude tags of library-level types from
768 the current execution of the partition, because misuse of such tags
769 should always be detected. T'Tag freezes the type (and thus creates the tag),
770 and Internal_Tag and Descendant_Tag
771 cannot return the tag of a library-level type that has not been created.
772 All ancestors of a tagged type must be frozen no later than the (full)
773 declaration of a type that uses them, so Parent_Tag and Interface_Ancestor_Tags
774 cannot return a tag that has not been created.
775 Finally, library-level types never cease to exist while the partition is
776 executing. Thus, if the tag comes from
777 a library-level type, there cannot be erroneous execution (the use of
778 Descendant_Tag rather than Internal_Tag can help ensure that the tag is
779 of a library-level type). This is also similar to the rules for T'Class'Input
780 (see @RefSecNum{Stream-Oriented Attributes}).]}
781 @end{Ramification}
782 @begin{Discussion}
783 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00344-01]}
784 @ChgAdded{Version=[2],Text=[Ada 95 allowed Tag_Error in this case, or expected
785 the functions to work. This worked because most implementations used tags
786 constructed at link-time, and each elaboration of the same @nt{type_declaration}
787 produced the same tag. However, Ada 2005 requires at least part of the tags
788 to be dynamically constructed for a type derived from a type at a shallower
789 level. For dynamically constructed tags, detecting the error can be expensive
790 and unreliable. To see
791 this, consider a program containing two tasks. Task A creates a nested tagged
792 type, passes the tag to task B (which saves it), and then terminates. The
793 nested tag (if dynamic) probably will need to refer in some way to the stack
794 frame for task A.
795 If task B later tries to use the tag created by task A, the tag's reference to
796 the stack frame of A probably is a dangling pointer. Avoiding this would
797 require some sort of protected tag manager, which would be a bottleneck in a
798 program's performance. Moreover, we'd still have a race condition; if task A
799 terminated after the tag check, but before the tag was used, we'd still have
800 a problem. That means that all of these operations would have to be serialized.
801 That could be a significant performance drain, whether or not nested tagged
802 types are ever used. Therefore, we allow execution to become erroneous
803 as we do for other dangling pointers. If the implementation can detect the
804 error, we recommend that Tag_Error be raised.]}
805 @end{Discussion}
806 @end{Erron}
807
808 @begin{ImplPerm}
809 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00260-02],ARef=[AI95-00279-01]}
810 The implementation of @Chg{Version=[2],New=[Internal_Tag and Descendant_Tag],
811 Old=[the functions in Ada.Tags]}
812 may raise Tag_Error if no specific type corresponding to the
813 @Chg{Version=[2],New=[string External],Old=[tag]} passed
814 as a parameter exists in the partition at the time the function is
815 called@Chg{Version=[2],New=[, or if there is no such type whose innermost
816 master is a master of the point of the function call],Old=[]}.
817 @begin{Reason}
818 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00260-02],ARef=[AI95-00279-01],ARef=[AI95-00344-01]}
819 @Chg{Version=[2],New=[Locking would be required to ensure that the mapping of
820 strings to tags never returned tags of types which no longer exist, because
821 types can cease to exist (because they belong to another task, as described
822 above) during the execution of these operations. Moreover, even if these
823 functions did use locking, that would not prevent the type from ceasing to
824 exist at the instant that the function returned. Thus, we do not require the
825 overhead of locking;],Old=[In most implementations,
826 repeated elaborations of the same
827 @nt{type_declaration} will all produce the same tag.
828 In such an implementation, Tag_Error will be raised in cases where the
829 internal or external tag was passed from a different partition.
830 However, some implementations might create a new tag value at run time
831 for each elaboration of a @nt{type_declaration}.
832 In that case, Tag_Error could also be raised if the created type
833 no longer exists because the subprogram
834 containing it has returned, for example.
835 We don't require the latter behavior;]} hence the word
836 @lquotes@;may@rquotes@; in this rule.
837 @end{Reason}
838 @end{ImplPerm}
839
840 @begin{ImplAdvice}
841 @ChgRef{Version=[2],Kind=[Added],ARef=[AI95-00260-02]}
842 @ChgRef{Version=[3],Kind=[RevisedAdded],ARef=[AI05-0113-1]}
843 @ChgAdded{Version=[2],Text=[Internal_Tag should return the tag of
844 a type@Chg{Version=[3],New=[, if one exists,],Old=[]} whose
845 innermost master is @Chg{Version=[3],New=[a],Old=[the]} master of the point of the function call.]}
846 @ChgImplAdvice{Version=[3],Kind=[Revised],InitialVersion=[2],
847 Text=[@Chg{Version=[2],
848 New=[Tags.Internal_Tag should return the tag of
849 a type@Chg{Version=[3],New=[, if one exists,],Old=[]} whose innermost master
850 is @Chg{Version=[3],New=[a],Old=[the]} master of the point of the function call.],Old=[]}.]}
851 @begin{Reason}
852 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00260-02],ARef=[AI95-00344-01]}
853 @ChgAdded{Version=[2],Text=[It's not helpful if Internal_Tag returns the tag of
854 some type in another task when one is available in the task that made the call.
855 We don't require this behavior (because it requires the same implementation
856 techniques we decided not to insist on previously), but encourage it.]}
857 @end{Reason}
858 @begin{Discussion}
859 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0113-1]}
860 @ChgAdded{Version=[3],Text=[There is no Advice for the result of Internal_Tag
861 if no such type exists. In most cases, the @ImplPermName can be
862 used to raise Tag_Error, but some other tag can be returned as well.]}
863 @end{Discussion}
864 @end{ImplAdvice}
865
866 @begin{Notes}
867 A type declared with the reserved word @key[tagged]
868 should normally be declared in a @nt{package_specification},
869 so that new primitive subprograms can be declared for it.
870
871 Once an object has been created,
872 its tag never changes.
873
874 Class-wide types are defined to have unknown discriminants
875 (see @RefSecNum(Discriminants)). This means that objects of a class-wide
876 type have to be explicitly initialized (whether created by
877 an @nt<object_declaration> or an @nt<allocator>),
878 and that @nt<aggregate>s have to be explicitly qualified with a specific
879 type when their expected type is class-wide.
880
881 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00260-02],ARef=[AI95-00326-01]}
882 @Chg{Version=[2],New=[The capability provided by
883 Tags.Generic_Dispatching_Constructor is sometimes known as a
884 @i<factory>.@Defn{factory}@Defn{class factory}],Old=[If S denotes an
885 untagged private type whose full type is tagged,
886 then S'Class is also allowed before the full type definition,
887 but only in the private part of the package in which the type is
888 declared
889 (see @RefSecNum(Private Operations)).
890 Similarly, the Class attribute is defined
891 for incomplete types whose full type is tagged, but only within
892 the library unit in which the incomplete type is declared
893 (see @RefSecNum(Incomplete Type Declarations)).]}
894 @end{Notes}
895
896 @begin{Examples}
897 @Leading@keepnext@i(Examples of tagged record types:)
898 @begin(Example)
899 @key(type) Point @key(is tagged)
900 @key(record)
901 X, Y : Real := 0.0;
902 @key(end record);
903
904 @key(type) Expression @key(is tagged null record);
905 --@RI[ Components will be added by each extension]
906 @end(Example)
907 @end{Examples}
908
909 @begin{Extend83}
910 @Defn{extensions to Ada 83}
911 Tagged types are a new concept.
912 @end{Extend83}
913
914 @begin{Inconsistent95}
915 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00279-01]}
916 @ChgAdded{Version=[2],Text=[@Defn{inconsistencies with Ada 95}
917 @b[Amendment Correction:] Added wording specifying that Internal_Tag
918 must raise Tag_Error if the tag of a library-level type has not yet been
919 created. Ada 95 gave an Implementation Permission to do this; we require
920 it to avoid erroneous execution when streaming in an object of a
921 library-level type that has not yet been elaborated. This is technically
922 inconsistent; a program that used Internal_Tag outside of streaming and
923 used a compiler that didn't take advantage of the Implementation Permission
924 would not have raised Tag_Error, and may have returned a useful tag. (If
925 the tag was used in streaming, the program would have been erroneous.)
926 Since such a program would not have been portable to a compiler that did
927 take advantage of the Implementation Permission, this is not a significant
928 inconsistency.]}
929
930 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00417-01]}
931 @ChgAdded{Version=[2],Text=<We now define the lower bound of the string
932 returned from [[Wide_]Wide_]Expanded_Name and External_Name. This makes
933 working with the returned string easier, and is consistent with many other
934 string-returning functions in Ada. This is technically an inconsistency; if a
935 program depended on some other lower bound for the string returned from one
936 of these functions, it could fail when compiled with Ada 2005. Such code is
937 not portable even between Ada 95 implementations, so it should be very
938 rare.>}
939 @end{Inconsistent95}
940
941 @begin{Incompatible95}
942 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00260-02],ARef=[AI95-00344-01],ARef=[AI95-00400-01],ARef=[AI95-00405-01]}
943 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0005-1]}
944 @ChgAdded{Version=[2],Text=[@Defn{incompatibilities with Ada 95}
945 Constant No_Tag, and functions Parent_Tag, Interface_Ancestor_Tags,
946 Descendant_Tag, Is_Descendant_At_Same_Level, Wide_Expanded_Name,
947 and Wide_Wide_Expanded_Name are @Chg{Version=[3],New=[],Old=[newly ]}added
948 to Ada.Tags.
949 If Ada.Tags is referenced in a @nt{use_clause}, and an entity @i<E> with the
950 same @nt{defining_identifier} as a new entity in Ada.Tags is defined in a
951 package that is also referenced in a @nt{use_clause}, the entity @i<E> may no
952 longer be use-visible, resulting in errors. This should be rare and is easily
953 fixed if it does occur.]}
954 @end{Incompatible95}
955
956 @begin{Extend95}
957 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00362-01]}
958 @ChgAdded{Version=[2],Text=[@Defn{extensions to Ada 95}
959 Ada.Tags is now defined to be preelaborated.]}
960
961 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00260-02]}
962 @ChgAdded{Version=[2],Text=[Generic function
963 Tags.Generic_Dispatching_Constructor is new.]}
964 @end{Extend95}
965
966 @begin{DiffWord95}
967 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00318-02]}
968 @ChgAdded{Version=[2],Text=[We talk about return objects rather than
969 return expressions, as functions can return using an
970 @nt{extended_return_statement}.]}
971
972 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00344-01]}
973 @ChgAdded{Version=[2],Text=[Added wording to define that tags for all
974 descendants of a tagged type must be distinct. This is needed to ensure
975 that more nested type extensions will work properly. The wording does not
976 require implementation changes for types that were allowed in Ada 95.]}
977 @end{DiffWord95}
978
979 @begin{Inconsistent2005}
980 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0113-1]}
981 @ChgAdded{Version=[3],Text=[@Defn{inconsistencies with Ada 2005}
982 @b[Correction:] Added wording specifying that Dependent_Tag
983 must raise Tag_Error if there is more than one type which matches the
984 requirements. If an implementation had returned a random tag of the matching
985 types, a program may have worked properly. However, such a program would
986 not be portable (another implementation may return a different tag) and the
987 conditions that would cause the problem are unlikely (most likely, a tagged
988 type extension declared in a generic body with multiple instances in the
989 same scope).]}
990 @end{Inconsistent2005}
991
992 @begin{Incompatible2005}
993 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0173-1]}
994 @ChgAdded{Version=[3],Text=[@Defn{incompatibilities with Ada 2005}
995 Function Is_Abstract is added to Ada.Tags.
996 If Ada.Tags is referenced in a @nt{use_clause}, and an entity @i<E> with the
997 @nt{defining_identifier} Is_Abstract is defined in a
998 package that is also referenced in a @nt{use_clause}, the entity @i<E> may no
999 longer be use-visible, resulting in errors. This should be rare and is easily
1000 fixed if it does occur.]}
1001 @end{Incompatible2005}
1002
1003 @begin{DiffWord2005}
1004 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0115-1]}
1005 @ChgAdded{Version=[3],Text=[@b<Correction:> We explicitly define the meaning
1006 of "descendant" at runtime, so that it does not depend on visibility
1007 as does the usual meaning.]}
1008 @end{DiffWord2005}
1009
1010
1011 @LabeledSubClause{Type Extensions}
1012
1013 @begin{Intro}
1014 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00345-01]}
1015 @Redundant[@Defn{type extension}
1016 @Defn2{Term=[extension], Sec=(of a type)}
1017 @Defn{record extension}
1018 @Defn2{Term=[extension], Sec=(of a record type)}
1019 @Defn{private extension}
1020 @Defn2{Term=[extension], Sec=(of a private type)}
1021 Every type extension is a tagged type, and
1022 is @Chg{Version=[2],New=[],Old=[either ]}a @i(record extension) or a
1023 @i(private extension) of
1024 some other tagged type@Chg{Version=[2],New=[, or a noninterface
1025 synchronized tagged type],Old=[]}.]
1026 @end{Intro}
1027
1028 @begin{MetaRules}
1029
1030 We want to make sure that we can extend a generic formal
1031 tagged type, without knowing its discriminants.
1032
1033 We don't want to allow components in an extension aggregate
1034 to depend on discriminants inherited from the parent value,
1035 since such dependence requires staticness in aggregates, at least for
1036 variants.
1037 @end{MetaRules}
1038
1039 @begin{Syntax}
1040 @Syn{lhs=<record_extension_part>,rhs="@key(with) @Syn2{record_definition}"}
1041 @end{Syntax}
1042
1043 @begin{Legality}
1044 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00344-01],ARef=[AI95-00345-01],ARef=[AI95-00419-01]}
1045 The parent type of a record extension shall not be
1046 a class-wide type@Chg{Version=[2],New=[ nor shall it be a synchronized
1047 tagged type (see @RefSecNum{Interface Types})],Old=[]}.
1048 If the parent type@Chg{Version=[2],New=[ or any progenitor],Old=[]} is
1049 nonlimited, then each of the
1050 components of the @nt{record_extension_part} shall be
1051 nonlimited.@Chg{Version=[2],New=[],Old=[
1052 @PDefn2{Term=[accessibility rule],Sec=(record extension)}
1053 The accessibility level
1054 (see @RefSecNum(Operations of Access Types))
1055 of a record extension shall not be statically deeper than that of its
1056 parent type.]}
1057 @PDefn{generic contract issue}
1058 In addition to the places where @LegalityTitle normally apply
1059 (see @RefSecNum{Generic Instantiation}),
1060 these rules apply also in the private part of an
1061 instance of a generic unit.
1062 @begin{Reason}
1063 If the parent is a limited formal type,
1064 then the actual might be nonlimited.
1065
1066 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00344-01]}
1067 @Chg{Version=[2],New=[Ada 95 required the record extensions to be the
1068 same level as the parent type. Now we use accessibility checks on class-wide
1069 @nt{allocator}s and return statements to prevent objects from living
1070 longer than their type.],
1071 Old=[A similar accessibility rule is not needed for
1072 private extensions, because in a package, the rule will apply to the
1073 @nt{full_type_declaration},
1074 and for a generic formal private extension,
1075 the actual is all that matters.]}
1076
1077 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00345-01]}
1078 @ChgAdded{Version=[2],Text=[Synchronized tagged types cannot be extended. We
1079 have this limitation so that all of the data of a task or protected type is
1080 defined within the type. Data defined outside of the type wouldn't be
1081 subject to the mutual exclusion properties of a protected type, and couldn't
1082 be used by a task, and thus doesn't seem to be worth the potential impact
1083 on implementations.]}
1084 @end{Reason}
1085
1086 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00344-01]}
1087 @Chg{Version=[2],New=[Within the body of a generic unit, or the body of any of
1088 its descendant library units, a tagged type],Old=[A type extension]}
1089 shall not be declared
1090 @Chg{Version=[2],New=[as a descendant of a formal type
1091 declared within the formal part of the generic unit],
1092 Old=[in a generic body if the parent type is declared outside that body]}.
1093
1094 @begin{Reason}
1095 This paragraph ensures that a dispatching call will never
1096 attempt to execute an inaccessible subprogram body.
1097
1098 @ChgRef{Version=[2],Kind=[Added],ARef=[AI95-00344-01]}
1099 @ChgAdded{Version=[2],Text=[The convoluted wording (@ldquote@;formal type declared
1100 within the formal part@rdquote@;) is necessary to include tagged types that
1101 are formal parameters of formal packages of the generic unit, as well as
1102 formal tagged and tagged formal derived types of the generic unit.]}
1103
1104 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00344-01]}
1105 @ChgNote{This rule is only about generic bodies (and always was only
1106 about generic bodies. So we drop the extra text.}
1107 @Chg{Version=[2],New=[This rule],Old=[The part about generic bodies]} is
1108 necessary in order to preserve the contract model.
1109
1110 @Leading@;@ChgRef{Version=[2],Kind=[Revised],ARef=[AI05-0005-1]}
1111 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00344-01]}
1112 @Chg{Version=[2],New=[If an ancestor],Old=[Since a generic unit can be instantiated at a
1113 deeper accessibility level than the generic unit, it is necessary to prevent
1114 type extensions whose parent is declared outside the generic unit.
1115 The same is true if the parent]} is a formal of the generic unit
1116 @Chg{Version=[2],New=[, we have a problem],Old=[.
1117 If the parent is declared in the @nt{generic_declaration}
1118 (but is not a formal), we don't run afoul of the accessibility rules,
1119 because we know that the instance declaration and body will be at the
1120 same accessibility level.
1121 However, we still have a problem in that case,]} because
1122 it might have an unknown number of@Chg{Version=[3],New=[],Old=[ abstract]}
1123 subprograms@Chg{Version=[3],New=[ that require overriding],Old=[]},
1124 as in the following example:
1125 @begin{Example}
1126 @ChgRef{Version=[2],Kind=[Revised]}
1127 @key[package] P @key[is]
1128 @key[type] T @key[is] @key[tagged] @key[null] @key[record];
1129 @key[function] F @key[return] T; --@RI{ Inherited versions will @Chg{Version=[2],New=[require overriding],Old=[be abstract]}.}
1130 @key[end] P;
1131
1132 @key[generic]
1133 @key[type] TT @key[is] @key[tagged] @key[private];
1134 @key[package] Gp @key[is]
1135 @key[type] NT @key[is] @key[abstract new] TT @key[with] @key[null] @key[record];
1136 @key[procedure] Q(X : @key[in] NT) @key[is abstract];
1137 @key[end] Gp;
1138
1139 @ChgRef{Version=[2],Kind=[Revised]}
1140 @key[package] @key[body] Gp @key[is]
1141 @key[type] NT2 @key[is] @key[new] NT @key[with] @key[null] @key[record]; --@RI{ Illegal!}
1142 @key[procedure] Q(X : @key[in] NT2) @key[is] @key[begin] @key[null]; @key[end] Q;
1143 --@RI{ Is this legal or not? Can't decide because}
1144 --@RI{ we don't know whether TT had any functions that @Chg{Version=[2],New=[require],Old=[go abstract]}}
1145 --@RI{ @Chg{Version=[2],New=[overriding ],Old=[]}on extension.}
1146 @key[end] Gp;
1147
1148 @key[package] I @key[is] @key[new] Gp(TT => P.T);
1149 @end{Example}
1150
1151 @ChgRef{Version=[2],Kind=[Revised]}
1152 I.NT is an abstract type with two abstract subprograms:
1153 F (inherited as abstract) and Q (explicitly declared as abstract).
1154 But the generic body doesn't know about F,
1155 so we don't know that it needs to be overridden to make a nonabstract
1156 extension of NT.@Chg{Version=[2],New=[],Old=[
1157 Furthermore, a formal tagged limited private type can be extended with
1158 limited components,
1159 but the actual might not be limited,
1160 which would allow assignment of limited types,
1161 which is bad.]} Hence, we have to disallow this
1162 case@Chg{Version=[2],New=[],Old=[ as well]}.
1163
1164 @ChgRef{Version=[2],Kind=[Added]}
1165 @ChgAdded{Version=[2],Text=[Similarly, since the actual type for a
1166 formal tagged limited private type can be a nonlimited type, we would have
1167 a problem if a type extension of a limited private formal type could be
1168 declared in a generic body. Such an
1169 extension could have a task component, for example, and an object of that
1170 type could be passed to a dispatching operation of a nonlimited ancestor
1171 type. That operation could try to copy the object with the task component.
1172 That would be bad. So we disallow this as well.]}
1173
1174 If TT were declared as abstract, then we could have the same
1175 problem with abstract procedures.
1176
1177 We considered disallowing all tagged types in a generic body,
1178 for simplicity.
1179 We decided not to go that far,
1180 in order to avoid unnecessary restrictions.
1181
1182 @PDefn2{Term=[accessibility rule],Sec=(not part of generic contract)}
1183 We also considered trying make the accessibility level part of the
1184 contract; i.e. invent some way of saying (in the
1185 @nt{generic_declaration}) @lquotes@;all instances of this generic unit will
1186 have the same accessibility level as the
1187 @nt{generic_declaration}.@rquotes@;
1188 Unfortunately, that doesn't solve the part of the problem having to do
1189 with abstract types.
1190
1191 @ChgRef{Version=[2],Kind=[Deleted]}
1192 @ChgDeleted{Version=[2],Text=[Children of
1193 generic units obviate the need for extension in the body somewhat.]}
1194 @end{Reason}
1195
1196 @begin{Ramification}
1197 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00344]}
1198 @ChgAdded{Version=[2],Text=[This rule applies to types with ancestors (directly
1199 or indirectly) of formal interface types
1200 (see @RefSecNum{Formal Interface Types}), formal tagged private types
1201 (see @RefSecNum{Formal Private and Derived Types}), and
1202 formal derived private types whose ancestor type is tagged
1203 (see @RefSecNum{Formal Private and Derived Types}).]}
1204 @end{Ramification}
1205 @end{Legality}
1206
1207 @begin{StaticSem}
1208 @ChgRef{Version=[2],Kind=[Added],ARef=[AI95-00391-01]}
1209 @ChgAdded{Version=[2],Text=[@defn{null extension}
1210 A record extension is a @i{null extension} if its declaration
1211 has no @nt{known_discriminant_part} and its @nt{record_extension_part}
1212 includes no @nt{component_declaration}s.]}
1213
1214 @ChgRef{Version=[5],Kind=[Added],ARef=[AI12-0191-1]}
1215 @ChgAdded{Version=[5],Text=[@defn2{Term=<component>,Sec=(of the nominal subtype)}
1216 @defn2{Term=<subcomponent>,Sec=(of the nominal subtype)}@defn2{Term=<part>,Sec=(of the nominal subtype)}
1217 In the case where the (compile-time) view of an object @i<X> is of a
1218 tagged type T1 or T1'Class and the (run-time) tag of @i<X> is T2'Tag,
1219 only the components (if any) of @i<X> that are components of T1
1220 (or that are discriminants which correspond to a discriminant
1221 of T1) are said to be @i<components of the nominal type> of @i<X>.
1222 Similarly, only parts (respectively, subcomponents) of T1 are parts
1223 (respectively, subcomponents) of the nominal type of @i<X>.]}
1224
1225 @begin{Ramification}
1226 @ChgRef{Version=[5],Kind=[AddedNormal],ARef=[AI12-0191-1]}
1227 @ChgAdded{Version=[5],Text=[For example, if T2 is an
1228 undiscriminated extension of T1 which declares a component named Comp,
1229 then @i<X>.Comp is not a component of the nominal type of @i<X>.]}
1230 @end{Ramification}
1231
1232 @begin{Discussion}
1233 @ChgRef{Version=[5],Kind=[AddedNormal],ARef=[AI12-0191-1]}
1234 @ChgAdded{Version=[5],Type=[Leading],Text=[For example, there is a
1235 @RunTimeTitle rule that finalization of an object includes finalization of
1236 its components (see @RefSecNum{Completion and Finalization}). In the
1237 following case:]}
1238 @begin{Example}
1239 @ChgRef{Version=[5],Kind=[AddedNormal]}
1240 @ChgAdded{Version=[5],Text=[@key[type] T1 @key[is tagged null record];
1241 @key[type] T2 @key[is new] T1 @key[with record]
1242 Comp : Some_Controlled_Type;
1243 @key[end record];
1244 @key[function] Func @key[return] T1'Class @key[is] (T2'(@key[others] => <>));
1245 X : T1'Class := Func;]}
1246 @end{Example}
1247
1248 @ChgRef{Version=[5],Kind=[AddedNormal]}
1249 @ChgAdded{Version=[5],Text=[the rule that @ldquote@;every component of the
1250 object is finalized@rdquote (as opposed to something like @ldquote@;every
1251 component of the nominal type of the object is finalized@rdquote) means that
1252 the finalization of X will include finalization of X.Comp. For another
1253 example, see the rule about accessibility checking of access discriminants of
1254 parts of function results in @RefSecNum{Return Statements}. In contrast, the
1255 rules in @RefSecNum{Type Invariants} explicitly state that type invariant
1256 checks are only performed for parts which are of the type-invariant bearing
1257 type and which are parts of the nominal type of the object (as opposed to for
1258 all parts, whether part of the nominal type or not, which are of the
1259 invariant-bearing type). Similarly, the rule in
1260 @RefSecNum{Stream-Oriented Attributes} governing which components of a
1261 composite value are read and written by the default implementations of Read
1262 and Write for a composite type states that only the components of the object
1263 which are components of the nominal type of the object are read or written.]}
1264
1265 @end{Discussion}
1266
1267 @end{StaticSem}
1268
1269 @begin{RunTime}
1270 @PDefn2{Term=[elaboration], Sec=(record_extension_part)}
1271 The elaboration of a @nt{record_extension_part} consists
1272 of the elaboration of the @nt{record_definition}.
1273 @end{RunTime}
1274
1275 @begin{Notes}
1276 The term @lquotes@;type extension@rquotes@; refers to a type as a whole.
1277 The term @lquotes@;extension part@rquotes@; refers to the piece
1278 of text that defines the additional components (if any) the
1279 type extension has relative to its specified ancestor type.
1280 @begin(Discussion)
1281 We considered other terminology, such as @lquotes@;extended type.@rquotes@;
1282 However, the terms @lquotes@;private extended type@rquotes@; and @lquotes@;record extended type@rquotes@;
1283 did not convey the proper meaning. Hence, we have chosen
1284 to uniformly use the term @lquotes@;extension@rquotes@; as the type resulting
1285 from extending a type, with @lquotes@;private extension@rquotes@; being one
1286 produced by privately extending the type, and @lquotes@;record extension@rquotes@;
1287 being one produced by extending the type with an additional record-like set
1288 of components.
1289 Note also that the term @lquotes@;type extension@rquotes@; refers to the result
1290 of extending a type in the language Oberon as well (though there
1291 the term @lquotes@;extended type@rquotes@; is also used, interchangeably, perhaps because
1292 Oberon doesn't have the concept of a @lquotes@;private extension@rquotes@;).
1293 @end(Discussion)
1294
1295 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00344-01]}
1296 @Chg{Version=[2],New=[],Old=[The accessibility rules imply that a tagged type
1297 declared in a library @nt{package_specification} can be extended only
1298 at library level or as a generic formal. ]}When
1299 @Chg{Version=[2],New=[an],Old=[the]} extension is declared immediately within
1300 a @Chg{Version=[2],New=[body],Old=[@nt{package_body}]},
1301 primitive subprograms are inherited and are overridable,
1302 but new primitive subprograms cannot be added.
1303
1304 A @nt<name> that denotes a component (including a discriminant) of
1305 the parent type is not allowed within the
1306 @nt{record_extension_part}.
1307 Similarly, a @nt<name> that denotes a component defined within the
1308 @nt{record_extension_part} is not allowed within
1309 the @nt{record_extension_part}.
1310 It is permissible to use a @nt<name>
1311 that denotes a discriminant of the record extension, providing there is
1312 a new @nt{known_discriminant_part} in the enclosing type declaration.
1313 (The full rule is given in @RefSecNum(Record Types).)
1314 @begin(Reason)
1315 The restriction against depending on
1316 discriminants of the parent is to simplify the definition of extension
1317 aggregates. The restriction against using parent components in other
1318 ways is methodological; it presumably simplifies implementation as
1319 well.
1320 @end(Reason)
1321
1322 Each visible component of a record extension has to have a
1323 unique name, whether the component is (visibly) inherited
1324 from the parent type or declared in the
1325 @nt<record_extension_part> (see @RefSecNum{Visibility}).
1326 @end{Notes}
1327
1328 @begin{Examples}
1329 @Leading@keepnext@i{Examples of record extensions (of types defined above in @RefSecNum(Tagged Types and Type Extensions)):}
1330 @begin(Example)
1331 @key(type) Painted_Point @key(is new) Point @key(with)
1332 @key(record)
1333 Paint : Color := White;
1334 @key(end record);
1335 --@RI[ Components X and Y are inherited]
1336
1337 Origin : @key(constant) Painted_Point := (X | Y => 0.0, Paint => Black);
1338
1339 @key(type) Literal @key(is new) Expression @key(with)
1340 @key(record) --@RI[ a leaf in an Expression tree]
1341 Value : Real;
1342 @key(end record);
1343
1344 @key(type) Expr_Ptr @key(is access all) Expression'Class;
1345 --@RI[ see @RefSecNum(Access Types)]
1346
1347 @key(type) Binary_Operation @key(is new) Expression @key(with)
1348 @key(record) --@RI[ an internal node in an Expression tree]
1349 Left, Right : Expr_Ptr;
1350 @key(end record);
1351
1352 @key(type) Addition @key(is new) Binary_Operation @key(with null record);
1353 @key(type) Subtraction @key(is new) Binary_Operation @key(with null record);
1354 --@RI[ No additional components needed for these extensions]
1355
1356 Tree : Expr_Ptr := --@RI[ A tree representation of @lquotes@;5.0 + (13.0@en@;7.0)@rquotes@;]
1357 @key(new) Addition'(
1358 Left => @key(new) Literal'(Value => 5.0),
1359 Right => @key(new) Subtraction'(
1360 Left => @key(new) Literal'(Value => 13.0),
1361 Right => @key(new) Literal'(Value => 7.0)));
1362 @end(Example)
1363
1364 @end{Examples}
1365
1366 @begin{Extend83}
1367 @Defn{extensions to Ada 83}
1368 Type extension is a new concept.
1369 @end{Extend83}
1370
1371 @begin{Extend95}
1372 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00344-01]}
1373 @ChgAdded{Version=[2],Text=[@Defn{extensions to Ada 95}
1374 Type extensions now can be
1375 declared in more nested scopes than their parent types. Additional
1376 accessibility checks on @nt{allocator}s and return statements prevent
1377 objects from outliving their type.]}
1378 @end{Extend95}
1379
1380 @begin{DiffWord95}
1381 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00345-01]}
1382 @ChgAdded{Version=[2],Text=[Added wording to prevent extending synchronized
1383 tagged types.]}
1384
1385 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00391-01]}
1386 @ChgAdded{Version=[2],Text=[Defined null extension for use elsewhere.]}
1387 @end{DiffWord95}
1388
1389 @begin{Diffword2012}
1390 @ChgRef{Version=[5],Kind=[AddedNormal],ARef=[AI12-0191-1]}
1391 @ChgAdded{Version=[5],Text=[Defined the term @ldquote@;components of
1392 the nominal type@rdquote to remove a confusion as to how components are
1393 described in @RunTimeTitle rules.]}
1394 @end{Diffword2012}
1395
1396
1397 @LabeledSubClause{Dispatching Operations of Tagged Types}
1398
1399 @begin{Intro}
1400 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00260-02],ARef=[AI95-00335-01]}
1401 @ChgRef{Version=[5],Kind=[Revised],ARef=[AI12-0342-1]}
1402 @RootDefn{dispatching operation}
1403 @Defn2{Term=[dispatching call], Sec=(on a dispatching operation)}
1404 @Defn2{Term=[nondispatching call], Sec=(on a dispatching operation)}
1405 @Defn{statically determined tag}
1406 @Defn{dynamically determined tag}
1407 @Defn{polymorphism}
1408 @Defn{run-time polymorphism}
1409 @Defn2{Term=[controlling tag], Sec=(for a call on a dispatching operation)}
1410 The primitive subprograms of a tagged type@Chg{Version=[2],New=[, the
1411 subprograms declared by @nt{formal_@!abstract_@!subprogram_@!declaration}s,
1412 @Chg{Version=[5],New=[the subprograms identified by the user-defined literal
1413 aspects of a specific tagged type (see @RefSecNum{User-Defined Literals}),],Old=[]}
1414 and the stream attributes of a specific tagged type that are available (see
1415 @RefSecNum{Stream-Oriented Attributes}) at the end of the declaration list
1416 where the type is declared],Old=[]}
1417 are called @i(dispatching operations).
1418 @Redundant[A dispatching operation can be called using a statically
1419 determined @i{controlling} tag, in which case the body to be
1420 executed is determined at compile time.
1421 Alternatively, the controlling tag can be dynamically determined,
1422 in which case the call @i{dispatches} to a
1423 body that is determined at run time;]
1424 such a call is termed a @i{dispatching call}.
1425 @Redundant[As explained below, the properties of the operands
1426 and the context of a particular call on a dispatching operation
1427 determine how the controlling tag is determined,
1428 and hence whether or not the call is a dispatching call.
1429 Run-time polymorphism is achieved when a dispatching operation is called
1430 by a dispatching call.]
1431 @IndexSee{Term=[object-oriented programming (OOP)],See=[dispatching operations of tagged types]}
1432 @IndexSee{Term=[OOP (object-oriented programming)],See=[dispatching operations of tagged types]}
1433 @IndexSee{Term=[message],See=[dispatching call]}
1434 @IndexSee{Term=[method],See=[dispatching subprogram]}
1435 @IndexSee{Term=[virtual function],See=[dispatching subprogram]}
1436 @begin{Reason}
1437 @ChgRef{Version=[2],Kind=[Added],ARef=[AI95-00335-01]}
1438 @ChgAdded{Version=[2],Text=[For the stream attributes of a type
1439 declared immediately within a @nt{package_specification} that has a
1440 partial view, the declaration list to consider is the visible part of the
1441 package. Stream attributes that are not available in the same declaration
1442 list are not dispatching as there is no guarantee that descendants of the
1443 type have available attributes (there is such a guarantee for visibly
1444 available attributes). If we allowed dispatching for any available
1445 attribute, then for attributes defined in the private part we could end up
1446 executing a nonexistent body.]}
1447 @end{Reason}
1448
1449 @end{Intro}
1450
1451 @begin{MetaRules}
1452 The controlling tag determination rules are analogous to the
1453 overload resolution rules, except they deal with run-time
1454 type identification (tags) rather than compile-time type
1455 resolution. As with overload resolution, controlling tag determination
1456 may depend on operands or result context.
1457 @end{MetaRules}
1458
1459 @begin{StaticSem}
1460 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00260-02],ARef=[AI95-00416-01]}
1461 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0076-1]}
1462 @Defn{call on a dispatching operation}
1463 @Defn{dispatching operation}
1464 A @i{call on a dispatching operation} is a call whose @nt<name> or
1465 @nt<prefix> denotes the declaration of@Chg{Version=[2],New=[],
1466 Old=[ a primitive subprogram of a tagged type, that is,]} a dispatching
1467 operation.
1468 @Defn{controlling operand}
1469 A @i{controlling operand} in a call on a dispatching operation of a tagged
1470 type @i(T) is one whose corresponding formal parameter is of type @i(T)
1471 or is of an anonymous access type with designated type @i(T);
1472 @Defn{controlling formal parameter}
1473 the corresponding formal parameter is called a
1474 @i(controlling formal parameter).
1475 If the controlling formal parameter is an access parameter, the
1476 controlling operand is the object designated by the actual parameter,
1477 rather than the actual parameter itself.
1478 @Defn{controlling result}@Chg{Version=[3],New=[@Defn2{Term=[function],Sec=[with a controlling result]}],Old=[]}
1479 If the call is to a (primitive) function with result type
1480 @i(T)@Chg{Version=[3],New=[ (a @i{function with a controlling result})],Old=[]},
1481 then the call has a @i(controlling result) @em
1482 the context of the call can control the dispatching.@Chg{Version=[2],
1483 New=[ Similarly, if the call is to a function with
1484 @Chg{Version=[3],New=[an ],Old=[]}access result type designating
1485 @i(T)@Chg{Version=[3],New=[ (a @i{function with a controlling access result})],Old=[]},
1486 then the call has a @i(controlling access result), and
1487 the context can similarly control dispatching.],Old=[]}@Chg{Version=[3],New=[@Defn{controlling access result}@Defn2{Term=[function],Sec=[with a controlling access result]}],Old=[]}
1488 @begin{Ramification}
1489 This definition implies that a call through the dereference of an
1490 access-to-subprogram value is never considered a call on
1491 a dispatching operation.
1492 Note also that if the @nt{prefix} denotes a @nt{renaming_declaration},
1493 the place where the renaming occurs determines whether it is
1494 primitive; the thing being renamed is irrelevant.
1495 @end{Ramification}
1496
1497 @ChgRef{Version=[5],Kind=[Revised],ARef=[AI12-0236-1]}
1498 @Leading@;A @nt<name> or expression of a tagged type
1499 is either @i(statically) tagged,
1500 @i(dynamically) tagged, or @i(tag indeterminate), according
1501 to whether, when used as a controlling operand, the tag
1502 that controls dispatching is determined statically by the operand's
1503 (specific) type, dynamically by its tag at run time, or from context. A
1504 @nt<qualified_expression> or parenthesized expression is statically,
1505 dynamically, or indeterminately tagged according to its
1506 operand.@Chg{Version=[5],New=[ A @nt{conditional_expression} is statically,
1507 dynamically, or indeterminately tagged according to rules given in
1508 @RefSecNum{Conditional Expressions}. A @nt{declare_expression} is statically,
1509 dynamically, or indeterminately tagged according to its
1510 @SynI{body_}@nt{expression}.],Old=[]} For other kinds of @nt<name>s and
1511 expressions, this is determined as follows:
1512 @begin(Itemize)
1513 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00416-01]}
1514 @Defn{statically tagged}
1515 The @nt<name> or expression is @i(statically
1516 tagged) if it is of a specific tagged type and,
1517 if it is a call with a controlling result@Chg{Version=[2],New=[ or
1518 controlling access result],Old=[]}, it has at least
1519 one statically tagged controlling operand;
1520 @begin{Discussion}
1521 It is illegal to have both statically tagged and
1522 dynamically tagged controlling operands in the same call -- see below.
1523 @end{discussion}
1524
1525 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00416-01]}
1526 @Defn{dynamically tagged}
1527 The @nt<name> or expression is @i(dynamically tagged)
1528 if it is of a class-wide type, or it is a call with
1529 a controlling result@Chg{Version=[2],New=[ or
1530 controlling access result],Old=[]} and at least one dynamically
1531 tagged controlling operand;
1532
1533 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00416-01]}
1534 @Defn{tag indeterminate}
1535 The @nt<name> or expression is @i(tag indeterminate)
1536 if it is a call with a controlling result@Chg{Version=[2],New=[ or
1537 controlling access result],Old=[]}, all of whose
1538 controlling operands (if any) are tag indeterminate.
1539 @end(itemize)
1540
1541 @ChgRef{Version=[1],Kind=[Revised],Ref=[8652/0010],ARef=[AI95-00127-01]}
1542 @Redundant[A @nt<type_conversion> is statically or dynamically
1543 tagged according to whether the type determined by the @nt<subtype_mark>
1544 is specific or class-wide, respectively.]
1545 @Chg{New=[For an object that is designated by an expression whose expected type
1546 is an anonymous access-to-specific tagged type, the object is dynamically
1547 tagged if the expression, ignoring enclosing parentheses, is of the form
1548 X'Access, where X is of a class-wide type, or is of the form
1549 @key(new) T'(...), where T denotes a class-wide subtype. Otherwise, the object],
1550 Old=[For a controlling operand that is designated by an actual parameter,
1551 the controlling operand]} is statically or dynamically tagged according to
1552 whether the designated type @Chg{New=[of the type of the expression],
1553 Old=[of the actual parameter]} is specific or class-wide, respectively.
1554 @begin{Ramification}
1555 A @nt<type_conversion> is never tag indeterminate, even if its
1556 operand is. A designated object is never tag indeterminate.
1557
1558 @ChgRef{Version=[1],Kind=[Added],Ref=[8652/0010],ARef=[AI95-00127-01]}
1559 @ChgAdded{Version=[1],Text=[Allocators and access attributes of class-wide types can be used as
1560 the controlling parameters of dispatching calls.]}
1561 @end{Ramification}
1562 @end{StaticSem}
1563
1564 @begin{Legality}
1565 A call on a dispatching operation shall not
1566 have both dynamically tagged and statically tagged controlling operands.
1567 @begin{Reason}
1568 This restriction is intended to minimize
1569 confusion between whether the dynamically tagged operands
1570 are implicitly converted to, or tag checked against the
1571 specific type of the statically tagged operand(s).
1572 @end{Reason}
1573
1574 @ChgRef{Version=[1],Kind=[Revised],Ref=[8652/0010],ARef=[AI95-00127-01]}
1575 If the expected type for an expression or @nt<name>
1576 is some specific tagged type, then the expression or @nt<name>
1577 shall not be dynamically tagged unless it is a controlling operand in a call
1578 on a dispatching operation.
1579 Similarly, if the expected type for an expression
1580 is an anonymous access-to-specific
1581 tagged type, then the @Chg{New=[object designated by the expression
1582 shall not be dynamically tagged unless it is],Old=[expression shall not be
1583 of an access-to-class-wide type unless it designates]} a controlling
1584 operand in a call on a dispatching operation.
1585 @begin(Reason)
1586 This prevents implicit "truncation"
1587 of a dynamically-tagged value to the specific type of the
1588 target object/formal. An explicit conversion is required to request
1589 this truncation.
1590 @end(Reason)
1591 @begin(Ramification)
1592 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00252-01]}@ChgNote{Add info about prefix calls}
1593 @ChgRef{Version=[4],Kind=[Revised],ARef=[AI12-0039-1]}
1594 This rule applies to all expressions
1595 or @nt<name>s with a specific expected type, not just those that
1596 are actual parameters to a dispatching call. This rule does not apply to
1597 a membership test whose
1598 @Chg{Version=[4],New=[@SynI{tested_}@nt{simple_expression}],Old=[@nt<expression>]}
1599 is class-wide, since any type that covers the tested type is explicitly allowed.
1600 See @RefSecNum(Relational Operators and Membership Tests).@Chg{Version=[2],
1601 New=[ This rule also doesn't apply to a @nt{selected_component} whose
1602 @nt{selector_name} is a subprogram, since the rules explicitly say that
1603 the prefix may be class-wide (see @RefSecNum{Selected Components}).],Old=[]}
1604 @end(Ramification)
1605
1606 @ChgRef{Version=[1],Kind=[Revised],Ref=[8652/0011],ARef=[AI95-00117-01]}
1607 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00430-01]}
1608 In the declaration of a dispatching operation of a tagged type,
1609 everywhere a subtype of the tagged type appears as a
1610 subtype of the profile (see @RefSecNum(Subprogram Declarations)),
1611 it shall statically match the first subtype of the tagged type.
1612 @PDefn2{Term=[statically matching],Sec=(required)}
1613 If the dispatching operation overrides an inherited subprogram,
1614 it shall be subtype conformant with the inherited subprogram.
1615 @Defn2{Term=[subtype conformance],Sec=(required)}
1616 @Chg{New=[The convention of an inherited @Chg{Version=[2],New=[],
1617 Old=[or overriding ]}dispatching operation is
1618 the convention of the corresponding primitive operation of the parent
1619 @Chg{Version=[2],New=[or progenitor ],Old=[]}type. @Chg{Version=[2],New=[The
1620 default convention of a dispatching operation that overrides an inherited
1621 primitive operation is the convention of the inherited operation; if the
1622 operation overrides multiple inherited operations, then they shall all
1623 have the same convention. ],Old=[]}An
1624 explicitly declared],Old=[A]} dispatching operation shall not be of convention
1625 Intrinsic.@Chg{New=[],Old=[ If a dispatching operation overrides the predefined
1626 equals operator, then it shall be of convention Ada @Redundant[(either
1627 explicitly or by default @em see @RefSecNum{Conformance Rules})].]}
1628 @begin{Reason}
1629 These rules ensure that constraint checks can be performed by the
1630 caller in a dispatching call, and parameter passing conventions
1631 match up properly. A special rule on aggregates
1632 prevents values of a tagged type from being created that
1633 are outside of its first subtype.
1634 @end{reason}
1635
1636 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00416-01]}
1637 The @nt<default_expression> for a controlling formal parameter
1638 of a dispatching operation shall be tag indeter@!minate.@Chg{Version=[2],
1639 New=[],Old=[ A controlling formal parameter that is an access parameter
1640 shall not have a @nt<default_expression>.]}
1641 @begin(Reason)
1642 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00416-01]}
1643 @Chg{Version=[2],New=[This rule],Old=[The first part]} ensures
1644 that the @nt{default_expression} always produces the "correct"
1645 tag when called with or without dispatching,
1646 or when inherited by a descendant. If
1647 it were statically tagged, the default would be useless for
1648 a dispatching call; if it were dynamically tagged, the default
1649 would be useless for a nondispatching call.
1650
1651 @ChgRef{Version=[2],Kind=[DeletedNoDelMsg],ARef=[AI95-00416-01]}
1652 @ChgDeleted{Version=[2],Text=[The second part is consistent with the
1653 first part, since designated objects are never tag-indeterminate.]}
1654 @end(Reason)
1655
1656 @ChgRef{Version=[2],Kind=[Added],ARef=[AI95-00404-01]}
1657 @ChgAdded{Version=[2],Text=[If a dispatching operation is defined by a
1658 @nt{subprogram_renaming_declaration} or the instantiation of a generic
1659 subprogram, any access parameter of the renamed subprogram or the generic
1660 subprogram that corresponds to a controlling access parameter of the
1661 dispatching operation, shall have a subtype that excludes null.]}
1662
1663 A given subprogram shall not be a dispatching operation of two
1664 or more distinct tagged types.
1665 @begin{Reason}
1666 This restriction minimizes
1667 confusion since multiple dispatching is not provided. The normal
1668 solution is to replace all but one of the tagged types with their
1669 class-wide types.
1670 @end{reason}
1671 @begin{ramification}
1672 @ChgRef{Version=[1],Kind=[Added],Ref=[8652/0098],ARef=[AI95-00183-01]}
1673 @ChgAdded{Version=[1],Text=[This restriction applies even if the partial view (see
1674 @RefSecNum{Private Types and Private Extensions}) of one or both
1675 of the types is untagged. This follows from the definition of dispatching
1676 operation: the operation is a dispatching operation anywhere the full
1677 views of the (tagged) types are visible.]}
1678 @end{ramification}
1679
1680 The explicit declaration of a primitive subprogram of a
1681 tagged type shall occur before the type is frozen
1682 (see @RefSecNum{Freezing Rules}).
1683 @Redundant[For example, new dispatching operations cannot be added after
1684 objects or values of the type exist,
1685 nor after deriving a record extension from it,
1686 nor after a body.]
1687
1688 @comment{The following is a "fix" to keep consistent with v. 5.95;
1689 appearently 6.0 is different.
1690 @begin{Discussion}
1691 @ChgRef{Version=[1],Kind=[Deleted]}
1692 @ChgDeleted{Version=[1],Text=[Old @b{Change}.]}
1693 @end{Discussion}}
1694 @begin{Reason}
1695 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00344-01]}@ChgNote{Tags now have two parts, logically}
1696 This rule is needed
1697 because (1) we don't want people dispatching to things that haven't
1698 been declared yet, and (2) we want to allow @Chg{Version=[2],New=[the static
1699 part of ],Old=[]}tagged type descriptors
1700 to be static (allocated statically, and initialized to link-time-known
1701 symbols). Suppose T2 inherits primitive P from T1, and then
1702 overrides P. Suppose P is called @i{before} the declaration of the
1703 overriding P. What should it dispatch to? If the answer is the new
1704 P, we've violated the first principle above. If the answer is the
1705 old P, we've violated the second principle. (A call
1706 to the new one necessarily raises Program_Error, but that's
1707 beside the point.)
1708
1709 Note that a call upon a dispatching operation of type @i(T) will freeze @i(T).
1710
1711 We considered applying this rule to all derived types,
1712 for uniformity.
1713 However, that would be upward incompatible,
1714 so we rejected the idea.
1715 As in Ada 83, for an untagged type, the above call upon P will call the
1716 old P (which is arguably confusing).
1717 @end{Reason}
1718 @begin{ImplNote}
1719 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00326-01]}@ChgNote{We have tagged incomplete types now, and they don't freeze}
1720 Because of this rule,
1721 the type descriptor can be created (presumably containing linker
1722 symbols pointing at the not-yet-compiled bodies) at the first
1723 freezing point of the type.
1724 It also prevents, for a @Chg{Version=[2],New=[(nonincomplete) ],Old=[]}tagged
1725 type declared in a
1726 @nt{package_specification}, overriding in the body or by a child subprogram.
1727 @end{ImplNote}
1728 @begin{Ramification}
1729 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00251-01]}@ChgNote{Interfaces cause this too}
1730 A consequence is that for a @Chg{Version=[2],New=[tagged type declaration],
1731 Old=[@ntf{derived_type_declaration}]} in a
1732 @nt{declarative_part}, only the @Chg{Version=[2],New=[last (overriding)],Old=[first]}
1733 primitive subprogram can be
1734 declared by a @nt{subprogram_body}.@Chg{Version=[2],New=[ (Other overridings
1735 must be provided by @nt{subprogram_declaration}s.)],Old=[]}
1736 @end{Ramification}
1737 @begin{Honest}
1738 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0222-1]}
1739 @ChgAdded{Version=[3],Text=[This rule applies only to "original" declarations
1740 and not to the completion of a primitive subprogram, even though a completion
1741 is technically an explicit declaration, and it may declare a primitive
1742 subprogram.]}
1743 @end{Honest}
1744
1745 @end{Legality}
1746
1747 @begin{RunTime}
1748 @Leading@PDefn2{Term=[execution], Sec=(call on a dispatching operation)}
1749 @Defn{controlling tag value}
1750 For the execution of a call on a dispatching operation of a type @i(T),
1751 the @i(controlling tag value) determines
1752 which subprogram body is executed.
1753 The controlling tag value is defined as follows:
1754 @begin(itemize)
1755 @PDefn{statically determined tag}
1756 If one or more controlling operands are statically tagged, then
1757 the controlling tag value is @i(statically determined) to be the tag
1758 of @i(T).
1759
1760 If one or more controlling operands are dynamically tagged, then
1761 the controlling tag value is not statically determined, but is
1762 rather determined by
1763 the tags of the controlling operands.
1764 @IndexCheck{Tag_Check}
1765 If there is more than one dynamically tagged controlling operand,
1766 a check is made that they all have the same tag.
1767 @Defn2{Term=(Constraint_Error),Sec=(raised by failure of runtime check)}
1768 If this check fails, Constraint_Error is raised
1769 unless the call is a @nt<function_call> whose @nt<name> denotes
1770 the declaration of an equality operator (predefined or user defined) that
1771 returns Boolean,
1772 in which case the result of the call is defined to indicate
1773 inequality, and no @nt<subprogram_body> is executed.
1774 This check is performed prior to evaluating any tag-indeterminate
1775 controlling operands.
1776 @begin(Reason)
1777 Tag mismatch is considered an error (except for "=" and "/=")
1778 since the corresponding primitive
1779 subprograms in each specific type expect all controlling
1780 operands to be of the same type.
1781 For tag mismatch with an equality operator, rather than raising
1782 an exception, "=" returns False and "/=" returns True.
1783 No equality operator is actually invoked, since there
1784 is no common tag value to control the dispatch.
1785 Equality is a special case to be consistent with the existing
1786 Ada 83 principle that equality comparisons, even
1787 between objects with different constraints, never raise Constraint_Error.
1788 @end(Reason)
1789
1790 @Leading@keepnext@;@ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00196-01]}
1791 If all of the controlling operands @Chg{Version=[2],New=[(if any) ],Old=[]}are
1792 tag-indeterminate, then:
1793 @begin(inneritemize)
1794 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00239-01],ARef=[AI95-00416-01]}
1795 If the call has a controlling result@Chg{Version=[2],New=[ or controlling
1796 access result],Old=[]} and is itself@Chg{Version=[2],New=[, or designates,],Old=[]}
1797 a (possibly parenthesized or qualified)
1798 controlling operand of an enclosing call on a dispatching operation
1799 of @Chg{Version=[2],New=[a descendant of ],Old=[]}type @i(T),
1800 then its controlling tag value is determined by the controlling tag
1801 value of this enclosing call;
1802
1803 @begin{Discussion}
1804 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00239-01]}
1805 @ChgAdded{Version=[2],Text=[For code that a user can write explicitly,
1806 the only contexts that can control dispatching of a function with a
1807 controlling result of type T are those that involve controlling operands
1808 of the same type T: if the two types differ there is an illegality and
1809 the dynamic semantics are irrelevant.]}
1810
1811 @ChgRef{Version=[2],Kind=[AddedNormal]}
1812 @ChgAdded{Version=[2],Text=[In the case of an inherited subprogram
1813 however, if a default expression is a function call, it may be of type T
1814 while the parameter is of a type derived from T. To cover this case, we
1815 talk about "a descendant of T" above. This is safe, because if the type
1816 of the parameter is descended from the type of the function result, it is
1817 guaranteed to inherit or override the function, and this ensures that
1818 there will be an appropriate body to dispatch to. Note that abstract
1819 functions are not an issue here because the call to the function is a
1820 dispatching call, so it is guaranteed to always land on a concrete
1821 body.]}
1822 @end{Discussion}
1823
1824 @ChgRef{Version=[2],Kind=[Added],ARef=[AI95-00196-01],ARef=[AI95-00416-01]}
1825 @ChgAdded{Version=[2],Text=[If the call has a controlling result or
1826 controlling access result and (possibly parenthesized, qualified, or
1827 dereferenced) is the expression of an @nt{assignment_statement} whose
1828 target is of a class-wide type, then its controlling tag value is
1829 determined by the target;]}
1830
1831 @PDefn{statically determined tag}
1832 Otherwise, the controlling tag value is statically determined to be
1833 the tag of type @i(T).
1834 @begin{Ramification}
1835 This includes the cases of
1836 a tag-indeterminate procedure call, and
1837 a tag-indeterminate @nt{function_call} that is
1838 used to initialize a class-wide formal parameter or class-wide
1839 object.
1840 @end{Ramification}
1841 @end(inneritemize)
1842 @end(itemize)
1843
1844 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00345-01]}
1845 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0126-1]}
1846 @ChgAdded{Version=[2],Type=[Leading],Text=[]}@ChgNote{Dummy add to allow conditional "leading"}
1847 For the execution of a call on a dispatching operation,
1848 the @Chg{Version=[2],New=[action performed is determined by the properties
1849 of the corresponding dispatching operation],Old=[body executed is the one for
1850 the corresponding primitive subprogram]} of the specific type
1851 identified by the controlling tag value@Chg{Version=[3],New=[:],Old=[.
1852 @Chg{Version=[2],New=[If the corresponding operation is],Old=[The body
1853 for an]} explicitly declared
1854 @Chg{Version=[2],New=[for this type, @Redundant[even if the declaration occurs
1855 in a private part], then the action comprises an invocation of the],
1856 Old=[dispatching operation is the corresponding]}
1857 explicit body for the
1858 @Chg{Version=[2],New=[operation. If the corresponding operation is
1859 implicitly declared for this type:],Old=[subprogram.
1860 The body for an implicitly
1861 declared dispatching operation that is overridden is the body for the
1862 overriding subprogram, @Redundant[even if the overriding occurs in a private
1863 part.] The body for an inherited dispatching operation that is not overridden
1864 is the body of the corresponding subprogram of the parent or ancestor type.]}]}
1865
1866 @begin{Itemize}
1867 @ChgRef{Version=[3],Kind=[Added],ARef=[AI05-0126-1]}
1868 @ChgAdded{Version=[3],Text=[if the corresponding operation is explicitly
1869 declared for this type, @Redundant[even if the declaration occurs in a private
1870 part], then the action comprises an invocation of the explicit body for the
1871 operation;]}
1872
1873 @ChgRef{Version=[2],Kind=[Added],ARef=[AI95-00345-01]}
1874 @ChgRef{Version=[3],Kind=[RevisedAdded],ARef=[AI05-0126-1]}
1875 @ChgAdded{Version=[2],Text=[if the
1876 @Chg{Version=[3],New=[corresponding ],Old=[]}operation is
1877 @Chg{Version=[3],New=[implicitly
1878 declared for this type and is ],Old=[]}implemented by an entry or
1879 protected subprogram (see @RefSecNum{Task Units and Task Objects} and
1880 @RefSecNum{Protected Units and Protected Objects}), then the action comprises a
1881 call on this entry or protected subprogram, with the target object being given
1882 by the first actual parameter of the call, and the actual parameters of the
1883 entry or protected subprogram being given by the remaining actual parameters of
1884 the call, if any;]}
1885
1886 @ChgRef{Version=[3],Kind=[Added],ARef=[AI05-0197-1]}
1887 @ChgAdded{Version=[3],Text=[if the corresponding operation is a predefined
1888 operator then the action comprises an invocation of that operator;]}
1889
1890 @ChgRef{Version=[2],Kind=[Added],ARef=[AI95-00345-01]}
1891 @ChgRef{Version=[3],Kind=[RevisedAdded],ARef=[AI05-0126-1],ARef=[AI05-0197-1],ARef=[AI05-0250-1],ARef=[AI05-0254-1]}
1892 @ChgAdded{Version=[2],Text=[otherwise, the action is the same as the action for
1893 the corresponding operation of the parent type@Chg{Version=[3],New=[ or
1894 progenitor type from which the operation was inherited except that additional
1895 invariant checks (see @RefSecnum{Type Invariants}) and class-wide postcondition
1896 checks (see @RefSecNum{Preconditions and Postconditions}) may apply. If there is
1897 more than one such corresponding operation, the action is that for the operation
1898 that is not a null procedure, if any; otherwise, the action is that of an
1899 arbitrary one of the operations],Old=[]}.]}
1900 @end{Itemize}
1901
1902 @begin{Honest}
1903 @ChgRef{Version=[3],Kind=[Deleted],ARef=[AI05-0126-1]}
1904 @ChgDeleted{Version=[3],Text=[In the unusual case in which a
1905 dispatching subprogram is explicitly declared (overridden) by a body (with no
1906 preceding @nt{subprogram_declaration}), the body for that dispatching subprogram
1907 is that body; that is, the @lquotes@;corresponding explicit body@rquotes@; in
1908 the above rule is the body itself.]}
1909 @end{Honest}
1910 @begin{Ramification}
1911 @ChgRef{Version=[3],Kind=[Added],ARef=[AI05-0005-1],ARef=[AI05-0126-1]}
1912 @ChgAdded{Version=[3],Text=[@ldquote@;Corresponding dispatching operation@rdquote
1913 refers to the inheritance relationship between subprograms. Primitive
1914 operations are always inherited for a type T, but they might not be declared if
1915 the primitive operation is never visible within the immediate scope of the type
1916 T. If no corresponding operation is declared, the last bullet is used and the
1917 corresponding operation of the parent type is executed (an explicit body that
1918 happens to have the same name and profile is not called in that case).]}
1919
1920 @ChgRef{Version=[3],Kind=[Added],ARef=[AI05-0005-1],ARef=[AI05-0126-1]}
1921 @ChgAdded{Version=[3],Text=[We have to talk about progenitors in the last
1922 bullet in case the corresponding operation is a null procedure inherited
1923 from an interface. In that case, the parent type might not even have the
1924 operation in question.]}
1925
1926 @ChgRef{Version=[3],Kind=[Added],ARef=[AI05-0197-1]}
1927 @ChgAdded{Version=[3],Text=[For the last bullet, if there are multiple
1928 corresponding operations for the parent and progenitors, all but one of them
1929 have to be a null procedure. (If the progenitors declared abstract routines,
1930 there would have to be an explicit overriding of the operation, and then the
1931 first bullet would apply.) We call the nonnull routine if one exists.]}
1932
1933 @ChgRef{Version=[3],Kind=[Added],ARef=[AI05-0126-1]}
1934 @ChgAdded{Version=[3],Text=[Any explicit declaration for an inherited
1935 corresponding operation has to be an overriding routine.
1936 These rules mean that a dispatching call executes the
1937 overriding routine (if any) for the specific type.]}
1938 @end{Ramification}
1939 @begin{Reason}
1940 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0005-1]}
1941 @Leading@;The wording of the above @Chg{Version=[3],New=[rules],Old=[rule]}
1942 is intended to ensure that the same body is executed for a given tag,
1943 whether that tag is determined statically or dynamically.
1944 For a type declared in a package,
1945 it doesn't matter whether a given subprogram is
1946 overridden in the visible part or the private part,
1947 and it doesn't matter whether the call is inside or outside the package.
1948 For example:
1949 @begin{Example}
1950 @key[package] P1 @key[is]
1951 @key[type] T1 @key[is] @key[tagged] @key[null] @key[record];
1952 @key[procedure] Op_A(Arg : @key[in] T1);
1953 @key[procedure] Op_B(Arg : @key[in] T1);
1954 @key[end] P1;
1955
1956 @key[with] P1; @key[use] P1;
1957 @key[package] P2 @key[is]
1958 @key[type] T2 @key[is] @key[new] T1 @key[with] @key[null] @key[record];
1959 @key[procedure] Op_A(Param : @key[in] T2);
1960 @key[private]
1961 @key[procedure] Op_B(Param : @key[in] T2);
1962 @key[end] P2;
1963
1964 @ChgRef{Version=[1],Kind=[Revised]}@ChgNote{Presentation AI-00009 & AI-00114}
1965 @key[with] P1; @key[with] P2;
1966 @key[procedure] Main @key[is]
1967 X : @Chg{New=[P2.],Old=[]}T2;
1968 Y : @Chg{New=[P1.],Old=[]}T1'Class := X;
1969 @key[begin]
1970 P2.Op_A(Param => X); --@RI{ Nondispatching call@Chg{New=[ to a dispatching operation],Old=[]}.}
1971 P1.Op_A(Arg => Y); --@RI{ Dispatching call.}
1972 P2.Op_B(Arg => X); --@RI{ Nondispatching call@Chg{New=[ to a dispatching operation],Old=[]}.}
1973 P1.Op_B(Arg => Y); --@RI{ Dispatching call.}
1974 @key[end] Main;
1975 @end{Example}
1976
1977 The two calls to Op_A both execute the body of Op_A that has to occur in
1978 the body of package P2.
1979 Similarly,
1980 the two calls to Op_B both execute the body of Op_B that has to occur in
1981 the body of package P2,
1982 even though Op_B is overridden in the private part of P2.
1983 Note, however, that the formal parameter names are different for P2.Op_A
1984 versus P2.Op_B.
1985 The overriding declaration for P2.Op_B is not visible in Main,
1986 so the name in the call actually denotes the implicit declaration
1987 of Op_B inherited from T1.
1988
1989
1990 If a call occurs in the program text before an overriding,
1991 which can happen only if the call is part of a default expression,
1992 the overriding will still take effect for that call.
1993
1994 @end{Reason}
1995
1996 @begin{ImplNote}
1997 Even when a tag is not @i(statically determined), a compiler
1998 might still be able to figure it out and thereby avoid
1999 the overhead of run-time dispatching.
2000 @end{implnote}
2001
2002 @end{RunTime}
2003
2004 @begin{Notes}
2005
2006 The body to be executed for a call on a dispatching operation is
2007 determined by the tag;
2008 it does not matter whether that tag is determined statically or
2009 dynamically,
2010 and it does not matter whether the subprogram's declaration is visible at
2011 the place of the call.
2012
2013
2014 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00260-02]}
2015 This subclause covers calls on @Chg{Version=[2],New=[dispatching],
2016 Old=[primitive]} subprograms of a tagged type.
2017 Rules for tagged type membership tests are described
2018 in @RefSecNum(Relational Operators and Membership Tests).
2019 Controlling tag determination for an
2020 @nt{assignment_statement}
2021 is described in @RefSecNum(Assignment Statements).
2022
2023 A dispatching call can dispatch to a body whose declaration is
2024 not visible at the place of the call.
2025
2026 A call through an access-to-subprogram value is never
2027 a dispatching call, even if the
2028 access value designates a dispatching operation. Similarly
2029 a call whose @nt<prefix> denotes a @nt<subprogram_renaming_declaration>
2030 cannot be a dispatching call unless the renaming itself is the
2031 declaration of a primitive subprogram.
2032 @end{Notes}
2033
2034 @begin{Extend83}
2035 @Defn{extensions to Ada 83}
2036 The concept of dispatching operations is new.
2037 @end{Extend83}
2038
2039 @begin{Incompatible95}
2040 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00404-01]}
2041 @ChgAdded{Version=[2],Text=[@Defn{incompatibilities with Ada 95}
2042 If a dispatching operation is defined by a
2043 @nt{subprogram_renaming_declaration}, and it has a controlling access
2044 parameter, Ada 2005 requires the subtype of the parameter to exclude null.
2045 The same applies to instantiations. This is required so that all
2046 calls to the subprogram operate the same way (controlling access parameters
2047 have to exclude null so that dispatching calls will work).
2048 Since Ada 95 didn't have the notion of access subtypes
2049 that exclude null, and all access parameters excluded null, it had no such
2050 rules. These rules will require the
2051 addition of an explicit @key{not null} on nondispatching operations that are
2052 later renamed to be dispatching, or on a generic that is used to define a
2053 dispatching operation.]}
2054 @end{Incompatible95}
2055
2056 @begin{Extend95}
2057 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00416-01]}
2058 @ChgAdded{Version=[2],Text=[@Defn{extensions to Ada 95}
2059 Functions that have an access result type can be dispatching in
2060 the same way as a function that returns a tagged object directly.]}
2061 @end{Extend95}
2062
2063 @begin{Diffword95}
2064 @ChgRef{Version=[2],Kind=[AddedNormal],Ref=[8652/0010],ARef=[AI95-00127-01]}
2065 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0299-1]}
2066 @ChgAdded{Version=[2],Text=[@b<Corrigendum:>@ChgNote{This is documented as an extension in
2067 the two @Chg{Version=[3],New=[clauses],Old=[sections]} referenced below.}
2068 Allocators and access attributes of objects of class-wide types
2069 can be used as the controlling parameter in a dispatching calls. This
2070 was an oversight in the definition of Ada 95. (See @RefSecNum{Operations of Access Types} and
2071 @RefSecNum{Allocators}).]}
2072
2073 @ChgRef{Version=[2],Kind=[AddedNormal],Ref=[8652/0011],ARef=[AI95-00117-01],ARef=[AI95-00430-01]}
2074 @ChgAdded{Version=[2],Text=[@b<Corrigendum:> Corrected the conventions of
2075 dispatching operations. This is extended in Ada 2005 to cover operations
2076 inherited from progenitors, and to ensure that the conventions of all
2077 inherited operations are the same.]}
2078
2079 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00196-01]}
2080 @ChgAdded{Version=[2],Text=[Clarified the wording to ensure that functions with
2081 no controlling operands are tag-indeterminate, and to describe that the
2082 controlling tag can come from the target of an @nt{assignment_statement}.]}
2083
2084 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00239-01]}
2085 @ChgAdded{Version=[2],Text=[Fixed the wording to cover default expressions
2086 inherited by derived subprograms. A literal reading of the old wording
2087 would have implied that operations would be called with objects of the
2088 wrong type.]}
2089
2090 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00260-02]}
2091 @ChgAdded{Version=[2],Text=[An abstract formal subprogram is a dispatching
2092 operation, even though it is not a primitive operation. See
2093 @RefSec{Formal Subprograms}.]}
2094
2095 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00345-01]}
2096 @ChgAdded{Version=[2],Text=[Dispatching calls include operations
2097 implemented by entries and protected operations, so we have to update the
2098 wording to reflect that.]}
2099
2100 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00335-01]}
2101 @ChgAdded{Version=[2],Text=[A stream attribute of a tagged type is
2102 usually a dispatching operation, even though it is not a primitive
2103 operation. If they weren't dispatching, T'Class'Input and T'Class'Output
2104 wouldn't work.]}
2105 @end{Diffword95}
2106
2107 @begin{Diffword2005}
2108 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0076-1]}
2109 @ChgAdded{Version=[3],Text=[@b<Correction:> Defined
2110 @ldquote@;function with a controlling result@rdquote, as it is used
2111 in @RefSecNum{Abstract Types and Subprograms}.]}
2112
2113 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0126-1],ARef=[AI05-0197-1]}
2114 @ChgAdded{Version=[3],Text=[@b<Correction:> Corrected holes in the
2115 definition of dynamic dispatching: the behavior for operations that are
2116 never declared and/or inherited from a progenitor were not specified.]}
2117 @end{Diffword2005}
2118
2119 @begin{Diffword2012}
2120 @ChgRef{Version=[5],Kind=[AddedNormal],ARef=[AI12-0236-1]}
2121 @ChgAdded{Version=[5],Text=[Added a special rule for taggedness of
2122 @nt{declare_expression}s, and added a pointer to the existing special
2123 rules for @nt{conditional_expression}s, as the list of exceptions to the
2124 usual rules appear to be exhaustive.]}
2125
2126 @ChgRef{Version=[5],Kind=[AddedNormal],ARef=[AI12-0342-1]}
2127 @ChgAdded{Version=[5],Text=[Added wording to clarify that user-defined
2128 literals are dispatching operations. User-defined literal aspects follow the
2129 model of stream-oriented attributes, and thus need to be mentioned in the
2130 same place.]}
2131 @end{Diffword2012}
2132
2133
2134 @LabeledSubClause{Abstract Types and Subprograms}
2135
2136 @begin{Intro}
2137 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00345-01]}
2138 @redundant[@Defn{abstract type}
2139 @IndexSeeAlso{Term=[abstract data type (ADT)],See=(abstract type)}
2140 @IndexSeeAlso{Term=[ADT (abstract data type)],See=(abstract type)}
2141 @IndexSee{Term=[concrete type],See=(nonabstract type)}
2142 An @i(abstract type) is a tagged type intended
2143 for use as @Chg{Version=[2],New=[an ancestor of other types],Old=[a parent
2144 type for type extensions]}, but which is not allowed to have objects of its own.
2145 @Defn{abstract subprogram}
2146 @IndexSee{Term=[concrete subprogram],See=(nonabstract subprogram)}
2147 An @i(abstract subprogram) is a subprogram that has no body,
2148 but is intended to be overridden at some point when inherited.
2149 Because objects of an abstract type cannot be created,
2150 a dispatching call to an abstract subprogram always
2151 dispatches to some overriding body.]
2152 @ChgToGlossary{Version=[2],Kind=[Added],Term=<Abstract type>,
2153 Text=<@ChgAdded{Version=[2],Text=[An abstract type is a tagged type
2154 intended for use as an ancestor of other types, but which is not allowed to
2155 have objects of its own.]}>}
2156 @end{Intro}
2157
2158 @begin{MetaRules}
2159 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0299-1]}
2160 An abstract subprogram has no body, so the
2161 rules in this @Chg{Version=[3],New=[subclause],Old=[clause]} are
2162 designed to ensure (at compile time)
2163 that the body will never be invoked.
2164 We do so primarily by disallowing the creation of
2165 values of the abstract type.
2166 Therefore, since type conversion and parameter passing
2167 don't change the tag, we know we will
2168 never get a class-wide value with a tag identifying an abstract type.
2169 This means that we only have to disallow nondispatching calls
2170 on abstract subprograms (dispatching calls will never reach them).
2171 @end{MetaRules}
2172
2173 @begin{Syntax}
2174 @ChgRef{Version=[2],Kind=[Added],ARef=[AI95-00218-03],ARef=[AI95-00348-01]}
2175 @ChgRef{Version=[3],Kind=[RevisedAdded],ARef=[AI05-0183-1]}
2176 @AddedSyn{Version=[2],lhs=<@Chg{Version=[2],New=<abstract_subprogram_declaration>,Old=<>}>,
2177 rhs="@Chg{Version=[2],New=<
2178 [@Syn2{overriding_indicator}]
2179 @Syn2{subprogram_specification} @key{is} @key{abstract}@Chg{Version=[3],New=<
2180 [@Syn2{aspect_specification}]>,Old=[]};>,Old=<>}"}
2181 @end{Syntax}
2182
2183 @begin{StaticSem}
2184 @ChgRef{Version=[2],Kind=[Added],ARef=[AI95-00345-01]}
2185 @Chg{Version=[2],New=[@Defn{abstract type}
2186 @Defn2{Term=[type], Sec=(abstract)}Interface types
2187 (see @RefSecNum{Interface Types}) are
2188 abstract types. In addition, a tagged type that has the reserved word
2189 @key{abstract} in its declaration is an abstract type. The class-wide type
2190 (see @RefSecNum{Derivation Classes}) rooted at an abstract type is not itself
2191 an abstract type.],Old=[]}
2192 @end{StaticSem}
2193
2194 @begin{Legality}
2195 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00345-01]}
2196 @Chg{Version=[2],New=[Only a tagged type shall have],Old=[@Defn{abstract type}
2197 @Defn2{Term=[type], Sec=(abstract)}
2198 An @i{abstract type} is a specific type
2199 that has]} the reserved word @key{abstract} in its
2200 declaration.@Chg{Version=[2],New=[],Old=[Only a tagged type is allowed to be
2201 declared abstract.]}
2202 @begin{Ramification}@ChgNote{These AARM notes really belong on the
2203 Static Semantics paragraph, but I won't move them, as it's not worth the time.}
2204 Untagged types are never abstract,
2205 even though they can have primitive abstract subprograms.
2206 Such subprograms cannot be called,
2207 unless they also happen to be dispatching operations of
2208 some tagged type, and then only via a dispatching call.
2209
2210 Class-wide types are never abstract.
2211 If T is abstract, then it is illegal to declare a stand-alone
2212 object of type T,
2213 but it is OK to declare a stand-alone object of type T'Class;
2214 the latter will get a tag from its initial value,
2215 and this tag will necessarily be different from T'Tag.
2216 @end{Ramification}
2217
2218 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00260-02],ARef=[AI95-00348-01]}
2219 @Defn{abstract subprogram}
2220 @Defn2{Term=[subprogram], Sec=(abstract)}
2221 A subprogram declared by an @nt{abstract_@!subprogram_@!declaration}
2222 @Chg{Version=[2],New=[or a
2223 @nt{formal_@!abstract_@!subprogram_@!declaration} (see @RefSecNum{Formal Subprograms})],
2224 Old=[(see @RefSecNum{Subprogram Declarations})]}
2225 is an @i{abstract subprogram}.
2226 If it is a primitive subprogram of a tagged type,
2227 then the tagged type shall be abstract.
2228 @begin{Ramification}
2229 @Leading@keepnext@;Note that for a private type, this applies to both views.
2230 The following is illegal:
2231 @begin{Example}
2232 @key[package] P @key[is]
2233 @key[type] T @key[is] @key[abstract] @key[tagged] @key[private];
2234 @key[function] Foo (X : T) @key[return] Boolean @key[is] @key[abstract]; --@RI{ Illegal!}
2235 @key[private]
2236 @key[type] T @key[is] @key[tagged] @key[null] @key[record]; --@RI{ Illegal!}
2237 X : T;
2238 Y : Boolean := Foo (T'Class (X));
2239 @key[end] P;
2240 @end{Example}
2241
2242 The full view of T is not abstract,
2243 but has an abstract operation Foo,
2244 which is illegal.
2245 The two lines marked "--@i{ Illegal!}" are illegal when taken together.
2246 @end{Ramification}
2247 @begin{Reason}
2248 @Leading@;@ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00310-01]}
2249 We considered disallowing untagged types from having abstract
2250 primitive subprograms.
2251 However, we rejected that plan, because it introduced some silly
2252 anomalies, and because such subprograms are harmless@Chg{Version=[2],
2253 New=[],Old=[ (if not terribly useful)]}.
2254 For example:
2255 @begin{Example}
2256 @ChgRef{Version=[1],Kind=[Revised]}@ChgNote{Presentation AI-00010}
2257 @key[package] P @key[is]
2258 @key[type] Field_Size @key[is] @key[range] 0..100;
2259 @key[type] T @key[is] @key[abstract tagged] @key[null] @key[record];
2260 @key[procedure] Print(X : @key[in] T; F : @key[in] Field_Size := 0) @key[is] @Chg{New=[@key[abstract]],Old=[abstract]};
2261 . . .
2262 @key[package] Q @key[is]
2263 @key[type] My_Field_Size @key[is] @key[new] Field_Size;
2264 --@RI{ implicit declaration of Print(X : T; F : My_Field_Size := 0) @Chg{New=[@key[is abstract]],Old=[is abstract]};}
2265 @key[end] Q;
2266 @end{Example}
2267
2268 It seemed silly to make the derivative of My_Field_Size illegal,
2269 just because there was an implicitly declared abstract subprogram
2270 that was not primitive on some tagged type.
2271 Other rules could be formulated to solve this problem,
2272 but the current ones seem like the simplest.
2273
2274 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00310-01]}
2275 @ChgAdded{Version=[2],Text=[In Ada 2005, abstract primitive subprograms of
2276 an untagged type may be used to @lquotes@;undefine@rquotes@; an operation.]}
2277 @end{Reason}
2278
2279 @begin{Ramification}
2280 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00260-02]}
2281 @ChgAdded{Version=[2],Text=[Note that the second sentence does not apply to
2282 abstract formal subprograms, as they are never primitive operations of
2283 a type.]}
2284 @end{Ramification}
2285
2286 @Leading@;@ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00251-01],ARef=[AI95-00334-01],ARef=[AI95-00391-01]}
2287 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0097-1],ARef=[AI05-0198-1]}
2288 @Chg{Version=[2],New=[If a type has an implicitly declared primitive subprogram
2289 that is inherited or is @Chg{Version=[3],New=[a],Old=[the]} predefined
2290 @Chg{Version=[3],New=[],Old=[equality ]}operator, and the corresponding
2291 primitive subprogram of],Old=[For a derived type, if]}
2292 the parent or ancestor type
2293 @Chg{Version=[2],New=[is abstract or is a function with a controlling access
2294 result, or if a type other than a
2295 @Chg{Version=[3],New=[nonabstract ],Old=[]}null extension inherits a],
2296 Old=[has an abstract primitive subprogram, or a primitive]}
2297 function with a controlling result, then:
2298 @begin{Ramification}
2299 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0068-1]}
2300 @ChgAdded{Version=[3],Text=[These rules apply to each view of the type
2301 individually. That is necessary to preserve privacy. For instance, in the
2302 following example:]}
2303 @begin{Example}
2304 @ChgRef{Version=[3],Kind=[AddedNormal]}
2305 @ChgAdded{Version=[3],Text=[@key[package] P @key[is]
2306 @key[type] I @key[is interface];
2307 @key[procedure] Op (X : I) @key[is abstract];
2308 @key[end] P;]}
2309
2310 @ChgRef{Version=[3],Kind=[AddedNormal]}
2311 @ChgAdded{Version=[3],Text=[@key[with] P;
2312 @key[package] Q @key[is]
2313 @key[type] T @key[is abstract new] P.I @key[with private];
2314 -- @RI[Op inherited here.]
2315 @key[private]
2316 @key[type] T @key[is abstract new] P.I @key[with null record];
2317 @key[procedure] Op (X : T) @key[is null];
2318 @key[end] Q;]}
2319
2320 @ChgRef{Version=[3],Kind=[AddedNormal]}
2321 @ChgAdded{Version=[3],Text=[@key[with] Q;
2322 @key[package] R @key[is]
2323 @key[type] T2 @key[is new] Q.T @key[with null record];
2324 -- @RI[Illegal. Op inherited here, but requires overriding.]
2325 @key[end] R;]}
2326 @end{Example}
2327 @ChgRef{Version=[3],Kind=[AddedNormal]}
2328 @ChgAdded{Version=[3],Text=[If this did not depend on the view,
2329 this would be legal. But in that case, the fact that Op is overridden
2330 in the private part would be visible; package R would have to be
2331 illegal if no overriding was in the private part.]}
2332
2333 @ChgRef{Version=[3],Kind=[AddedNormal]}
2334 @ChgAdded{Version=[3],Text=[Note that this means that whether an inherited
2335 subprogram is abstract or concrete depends on where it inherited.
2336 In the case of Q, Q.Op in the visible part is abstract,
2337 while Q.Op in the private part is concrete. That is, R is illegal since
2338 it is an unrelated unit (and thus it cannot see the private part), but if
2339 R had been a private child of Q, it would have been legal.]}
2340 @end{Ramification}
2341 @begin{Itemize}
2342 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00251-01],ARef=[AI95-00334-01]}
2343 If the @Chg{Version=[2],New=[],Old=[derived ]}type is abstract or untagged,
2344 the @Chg{Version=[2],New=[implicitly declared],Old=[inherited]} subprogram is
2345 @i{abstract}.
2346 @begin{Ramification}
2347 Note that it is possible to override a concrete subprogram
2348 with an abstract one.
2349 @end{Ramification}
2350
2351 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00391-01]}
2352 @ChgRef{Version=[4],Kind=[Revised],ARef=[AI12-0080-1]}
2353 Otherwise, the subprogram shall be overridden with a nonabstract
2354 subprogram@Chg{Version=[2],New=[ or, in the case of a private extension
2355 inheriting a @Chg{Version=[4],New=[nonabstract ],Old=[]}function with a
2356 controlling result, have a full type that is a null
2357 extension],Old=[]}@Redundant[; for a type declared in the visible part of
2358 a package, the overriding may be either in the visible or the private part].
2359 @Chg{Version=[2],New=[Such a subprogram is said to
2360 @i{require overriding}.@Defn{require overriding} ],Old=[]}However,
2361 if the type is a generic formal type,
2362 the subprogram need not be overridden for the formal type itself;
2363 @Redundant[a nonabstract version will necessarily be provided by the
2364 actual type.]
2365 @begin{Reason}
2366 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00228-01],ARef=[AI95-00391-01]}
2367 A function that returns the parent type @Chg{Version=[2],New=[requires
2368 overriding],Old=[becomes abstract]}@ChgNote{Can't leave this ancient and broken terminology around here!!}
2369 for @Chg{Version=[2],New=[a],Old=[an abstract]} type
2370 extension @Chg{Version=[2],New=[(or becomes abstract for an abstract type)],
2371 Old=[(if not overridden)]} because conversion
2372 from a parent type to a type extension is
2373 not defined, and function return semantics is defined in terms
2374 of conversion@Chg{Version=[2],New=[ (other than for a null extension;
2375 see below)],Old=[]}. (Note that parameters of mode @key{in out} or
2376 @key{out} do not have this problem, because the tag of the actual
2377 is not changed.)
2378
2379 @Leading@keepnext@;Note that the overriding required above can be in the
2380 private part, which allows the following:
2381 @begin{Example}
2382 @key[package] Pack1 @key[is]
2383 @key[type] Ancestor @key[is] @key[abstract] ...;
2384 @key[procedure] Do_Something(X : @key[in] Ancestor) @key[is] @key[abstract];
2385 @key[end] Pack1;
2386
2387 @key[with] Pack1; @key[use] Pack1;
2388 @key[package] Pack2 @key[is]
2389 @key[type] T1 @key[is] @key[new] Ancestor @key[with] @key[record] ...;
2390 --@RI{ A concrete type.}
2391 @key[procedure] Do_Something(X : @key[in] T1); --@RI{ Have to override.}
2392 @key[end] Pack2;
2393
2394 @key[with] Pack1; @key[use] Pack1;
2395 @key[with] Pack2; @key[use] Pack2;
2396 @key[package] Pack3 @key[is]
2397 @key[type] T2 @key[is] @key[new] Ancestor @key[with] @key[private];
2398 --@RI{ A concrete type.}
2399 @key[private]
2400 @key[type] T2 @key[is] @key[new] T1 @key[with] --@RI{ Parent different from ancestor.}
2401 @key[record] ... @key[end] @key[record];
2402 --@RI{ Here, we inherit Pack2.Do_Something.}
2403 @key[end] Pack3;
2404 @end{Example}
2405
2406 @ChgRef{Version=[1],Kind=[Revised]}@ChgNote{Presentation AI-00011}
2407 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00228-01]}
2408 T2 inherits an abstract Do_Something, but @Chg{New=[T2],Old=[T]} is not
2409 abstract, so Do_Something has to be overridden.
2410 However, it is OK to override it in the private part.
2411 In this case, we override it by inheriting a concrete version
2412 from a different type.
2413 Nondispatching calls to Pack3.Do_Something are allowed
2414 both inside and outside package Pack3@Chg{Version=[2],New=[, as the
2415 client @lquotes@;knows@rquotes@; that the subprogram was necessarily
2416 overridden somewhere],Old=[]}.
2417
2418 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00391-01]}
2419 @ChgAdded{Version=[2],Text=[For a null extension, the result of a function
2420 with a controlling result is defined in terms of an @nt{extension_aggregate}
2421 with a @key{null record} extension part
2422 (see @RefSecNum{Derived Types and Classes}). This means that these
2423 restrictions on functions with a controlling result do not have to apply to
2424 null extensions.]}
2425
2426 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00391-01]}
2427 @ChgAdded{Version=[2],Text=[However, functions with controlling access
2428 results still require overriding. Changing the tag in place might clobber
2429 a preexisting object, and allocating new memory would possibly change the
2430 pool of the object, leading to storage leaks. Moreover, copying the object
2431 isn't possible for limited types. We don't need to restrict functions
2432 that have an access return type of an untagged type, as derived types
2433 with primitive subprograms have to have the same representation as their
2434 parent type.]}
2435 @end{Reason}
2436 @end{Itemize}
2437
2438 A call on an abstract subprogram shall be a dispatching call;
2439 @Redundant[nondispatching calls to an abstract subprogram are not
2440 allowed.]
2441 @begin{Ramification}
2442 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00310-01]}
2443 If an abstract subprogram is not a dispatching operation of
2444 some tagged type, then it cannot be called at
2445 all.@Chg{Version=[2],New=[ In Ada 2005, such subprograms are not
2446 even considered by name resolution (see @RefSecNum{Subprogram Calls}).],Old=[]}
2447 @end{Ramification}
2448
2449 @ChgRef{Version=[5],Kind=[Added],ARef=[AI12-0189-1],ARef=[AI12-0292-1],ARef=[AI12-0320-1]}
2450 @ChgAdded{Version=[5],Text=[If the @nt{name} or @nt{prefix} given in an
2451 @nt{iterator_procedure_call} (see @RefSecNum{Procedural Iterators}) denotes
2452 an abstract subprogram, the subprogram shall be a dispatching subprogram.]}
2453
2454 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0073-1],ARef=[AI05-0203-1]}
2455 The type of an @nt{aggregate}, or of an object created by an
2456 @nt{object_declaration} or an @nt{allocator},
2457 or a generic formal object of mode @key[in],
2458 shall not be abstract.
2459 The type of the target of an assignment
2460 operation (see @RefSecNum{Assignment Statements}) shall not
2461 be abstract.
2462 The type of a component shall not be abstract.
2463 If the result type of a function is abstract,
2464 then the function shall be abstract.@Chg{Version=[3],New=[
2465 If a function has an access result type
2466 designating an abstract type, then the function shall be abstract.
2467 The type denoted by a @nt{return_subtype_indication} (see
2468 @RefSecNum{Return Statements}) shall not be abstract. A generic function
2469 shall not have an abstract result type or an access result type designating an
2470 abstract type.],Old=[]}
2471 @begin{Reason}
2472 This ensures that values of an abstract type cannot be created,
2473 which ensures that a dispatching call to an abstract subprogram
2474 will not try to execute the nonexistent body.
2475
2476 Generic formal objects of mode @key[in] are like constants;
2477 therefore they should be forbidden for abstract types. Generic formal
2478 objects of mode @key[in out] are like renamings; therefore, abstract
2479 types are OK for them, though probably not terribly useful.
2480
2481 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0073-1]}
2482 @ChgAdded{Version=[3],Text=[Generic functions returning a formal
2483 abstract type are illegal because any instance would have to be
2484 instantiated with a nonabstract type in order to avoid violating
2485 the function rule (generic functions cannot be declared abstract).
2486 But that would be an implied contract; it would be better for the
2487 contract to be explicit by the formal type not being declared
2488 abstract. Moreover, the implied contract does not add any capability.]}
2489 @end{Reason}
2490
2491 If a partial view is not abstract, the corresponding
2492 full view shall not be abstract.
2493 If a generic formal type is abstract,
2494 then for each primitive subprogram of the formal that is not abstract,
2495 the corresponding primitive subprogram of the actual shall
2496 not be abstract.
2497 @begin{Discussion}
2498 By contrast, we allow the actual type to be nonabstract
2499 even if the formal type is declared abstract.
2500 Hence, the most general formal tagged type possible is "@key(type)
2501 T(<>) @key(is abstract tagged limited private);".
2502
2503 For an abstract private extension declared in the visible
2504 part of a package, it is only possible for the
2505 full type to be nonabstract if the private extension has
2506 no abstract dispatching operations.
2507 @end{Discussion}
2508 @begin{Honest}
2509 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00294-01]}
2510 @ChgAdded{Version=[2],Type=[Leading],Text=[In the sentence about primitive
2511 subprograms above, there is some ambiguity as to what is meant by
2512 @lquotes@;corresponding@rquotes@; in the
2513 case where an inherited operation is overridden. This is best explained by
2514 an example, where the implicit declarations are shown as comments:]}
2515 @begin{Example}
2516 @ChgRef{Version=[2],Kind=[AddedNormal]}
2517 @ChgAdded{Version=[2],Text=[@key{package} P1 @key{is}
2518 @key{type} T1 @key{is abstract tagged null record};
2519 @key{procedure} P (X : T1); -- @RI[(1)]
2520 @key{end} P1;]}
2521
2522 @ChgRef{Version=[2],Kind=[AddedNormal]}
2523 @ChgAdded{Version=[2],Text=[@key{package} P2 @key{is}
2524 @key{type} T2 @key{is abstract new} P1.T1 @key{with null record};
2525 -- @RI[@key{procedure} P (X : T2); -- (2)]
2526 @key{procedure} P (X : T2) @key{is abstract}; -- (3)
2527 end P2;]}
2528
2529 @ChgRef{Version=[2],Kind=[AddedNormal]}
2530 @ChgAdded{Version=[2],Text=[@key{generic}
2531 @key{type} D @key{is abstract new} P1.T1 @key{with private};
2532 -- @RI[@key{procedure} P (X : D); -- (4)]
2533 @key{procedure} G (X : D);]}
2534
2535 @ChgRef{Version=[2],Kind=[AddedNormal]}
2536 @ChgAdded{Version=[2],Text=[@key{procedure} I @key{is new} G (P2.T2); -- @RI[Illegal.]]}
2537 @end{Example}
2538
2539 @ChgRef{Version=[2],Kind=[AddedNormal]}
2540 @Chg{Version=[2],New=[Type T2 inherits a nonabstract procedure P (2) from the
2541 primitive procedure P (1) of T1. P (2) is overridden by the explicitly declared
2542 abstract procedure P (3). Type D inherits a nonabstract procedure P (4) from P
2543 (1). In instantiation I, the operation corresponding to P (4) is the one which
2544 is not overridden, that is, P (3): the overridden operation P (2) does not
2545 @lquotes@;reemerge@rquotes@;. Therefore, the instantiation is illegal.],Old=[]}
2546 @end{Honest}
2547
2548 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0073-1]}
2549 For an abstract type declared in a visible part,
2550 an abstract primitive subprogram
2551 shall not be declared in the private part,
2552 unless it is overriding an abstract subprogram
2553 implicitly declared in the visible part.
2554 For a tagged type declared in a visible part,
2555 a primitive function with a controlling result@Chg{Version=[3],New=[
2556 or a controlling access result],Old=[]} shall not be declared
2557 in the private part, unless it is overriding a function
2558 implicitly declared in the visible part.
2559 @begin{Reason}
2560 @Leading@;The @lquotes@;visible part@rquotes@; could be that of a package
2561 or a generic package. This rule is needed because a nonabstract type extension
2562 declared outside the package would not know about any abstract primitive
2563 subprograms or primitive functions with controlling results
2564 declared in the private part, and wouldn't know that they
2565 need to be overridden with nonabstract subprograms.
2566 The rule applies to a tagged record type or record extension declared
2567 in a visible part,
2568 just as to a tagged private type or private extension.
2569 The rule applies to explicitly and implicitly declared abstract
2570 subprograms:
2571 @begin{Example}
2572 @key[package] Pack @key[is]
2573 @key[type] T @key[is] @key[abstract] @key[new] T1 @key[with] @key[private];
2574 @key[private]
2575 @key[type] T @key[is] @key[abstract] @key[new] T2 @key[with] @key[record] ... @key[end] @key[record];
2576 ...
2577 @key[end] Pack;
2578 @end{Example}
2579
2580 The above example would be illegal if T1 has a nonabstract primitive
2581 procedure P, but T2 overrides P with an abstract one;
2582 the private part should override P with a nonabstract version.
2583 On the other hand, if the P were abstract for both T1 and T2,
2584 the example would be legal as is.
2585 @end{Reason}
2586
2587 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00260-02]}
2588 A generic actual subprogram shall not be an abstract
2589 subprogram @Chg{Version=[2],New=[unless the generic formal subprogram is
2590 declared by a @nt{formal_abstract_subprogram_declaration}],Old=[]}.
2591 The @nt{prefix} of an @nt{attribute_reference} for the Access,
2592 Unchecked_Access, or Address attributes shall not denote an abstract subprogram.
2593 @begin{Ramification}
2594 An @nt{abstract_subprogram_declaration} is not syntactically a
2595 @nt{subprogram_declaration}.
2596 Nonetheless, an abstract subprogram is a subprogram,
2597 and an @nt{abstract_subprogram_declaration} is a declaration of a subprogram.
2598
2599 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00260-02]}
2600 The part about generic actual subprograms includes those given by
2601 default.@Chg{Version=[2],New=[ Of course, an abstract formal subprogram's
2602 actual subprogram can be abstract.],Old=[]}
2603 @end{Ramification}
2604 @end{Legality}
2605
2606 @begin{Runtime}
2607 @ChgRef{Version=[2],Kind=[Added],ARef=[AI95-00348-01]}
2608 @ChgAdded{Version=[2],Text=[@PDefn2{Term=[elaboration], Sec=(abstract_subprogram_declaration)}
2609 The elaboration of an @nt{abstract_subprogram_declaration} has no effect.]}
2610 @end{Runtime}
2611
2612 @begin{Notes}
2613 Abstractness is not inherited; to declare an abstract type,
2614 the reserved word @key[abstract] has to be used
2615 in the declaration of the type extension.
2616 @begin{Ramification}
2617 A derived type can be abstract even if its parent is not.
2618 Similarly, an inherited concrete subprogram can be overridden with an
2619 abstract subprogram.
2620 @end{Ramification}
2621
2622 A class-wide type is never abstract. Even if a class
2623 is rooted at an abstract type, the class-wide type for the
2624 class is not abstract, and an object of the class-wide type
2625 can be created; the tag of such an object will identify
2626 some nonabstract type in the class.
2627 @end{Notes}
2628
2629 @begin{Examples}
2630 @Leading@keepnext@i(Example of an abstract type representing a set of natural numbers:)
2631 @begin{Example}
2632 @key(package) Sets @key(is)
2633 @key(subtype) Element_Type @key(is) Natural;
2634 @key(type) Set @key(is abstract tagged null record);
2635 @key(function) Empty @key(return) Set @key(is abstract);
2636 @key(function) Union(Left, Right : Set) @key(return) Set @key(is abstract);
2637 @key(function) Intersection(Left, Right : Set) @key(return) Set @key(is abstract);
2638 @key(function) Unit_Set(Element : Element_Type) @key(return) Set @key(is abstract);
2639 @key(procedure) Take(Element : @key(out) Element_Type;
2640 From : @key(in out) Set) @key(is abstract);
2641 @key(end) Sets;
2642 @end{Example}
2643 @end{Examples}
2644
2645 @begin{Notes}
2646 @i(Notes on the example:)
2647 Given the above abstract type, one could then derive
2648 various (nonabstract) extensions of the type, representing
2649 alternative implementations of a set. One might use a bit
2650 vector, but impose an upper bound on the largest element representable,
2651 while another might use a hash table, trading off space for flexibility.
2652 @begin{Discussion}
2653 One way to export a type from a package with some components visible
2654 and some components private is as follows:
2655 @begin{Example}
2656 @key[package] P @key[is]
2657 @key[type] Public_Part @key[is] @key[abstract] @key[tagged]
2658 @key[record]
2659 ...
2660 @key[end] @key[record];
2661 @key[type] T @key[is] @key[new] Public_Part @key[with] @key[private];
2662 ...
2663 @key[private]
2664 @key[type] T @key[is] @key[new] Public_Part @key[with]
2665 @key[record]
2666 ...
2667 @key[end] @key[record];
2668 @key[end] P;
2669 @end{Example}
2670
2671 The fact that Public_Part is abstract tells clients they have to
2672 create objects of type T instead of Public_Part.
2673 Note that the public part has to come first;
2674 it would be illegal to declare a private type Private_Part,
2675 and then a record extension T of it,
2676 unless T were in the private part after the full declaration of Private_Part,
2677 but then clients of the package would not have visibility to T.
2678 @end{Discussion}
2679 @end{Notes}
2680
2681 @begin{Extend95}
2682 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00391-01]}
2683 @ChgAdded{Version=[2],Text=[@Defn{extensions to Ada 95}
2684 It is not necessary to override functions with a controlling result
2685 for a null extension. This makes it easier to derive a tagged type
2686 to complete a private type.]}
2687 @end{Extend95}
2688
2689 @begin{Diffword95}
2690 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00251-01],ARef=[AI95-00345-01]}
2691 @ChgAdded{Version=[2],Text=[Updated the wording to reflect the addition of
2692 interface types (see @RefSecNum{Interface Types}).]}
2693
2694 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00260-02]}
2695 @ChgAdded{Version=[2],Text=[Updated the wording to reflect the addition of
2696 abstract formal subprograms (see @RefSecNum{Formal Subprograms}).]}
2697
2698 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00334-01]}
2699 @ChgAdded{Version=[2],Text=[The wording of shall-be-overridden was clarified
2700 so that it clearly applies to abstract predefined equality.]}
2701
2702 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00348-01]}
2703 @ChgAdded{Version=[2],Text=[Moved the syntax and elaboration rule for
2704 @nt{abstract_subprogram_declaration} here, so the syntax and most of the
2705 semantics are together (which is consistent with null procedures).]}
2706
2707 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00391-01]}
2708 @ChgAdded{Version=[2],Text=[We define the term @i<require overriding>
2709 to make other wording easier to understand.]}
2710 @end{Diffword95}
2711
2712 @begin{Incompatible2005}
2713 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0073-1]}
2714 @ChgAdded{Version=[3],Text=[@Defn{incompatibilities with Ada 2005}@b<Correction:>
2715 Added rules to eliminate holes with controlling access results and generic
2716 functions that return abstract types. While these changes are technically
2717 incompatible, it is unlikely that they could be used in a program without
2718 violating some other rule of the use of abstract types.]}
2719
2720 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0097-1]}
2721 @ChgAdded{Version=[3],Text=[@b<Correction:> Corrected a minor
2722 glitch having to do with abstract null extensions. The Ada 2005
2723 rule allowed such extensions to inherit concrete operations in some
2724 rare cases. It is unlikely that these cases exist in user code.]}
2725 @end{Incompatible2005}
2726
2727 @begin{Extend2005}
2728 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0183-1]}
2729 @ChgAdded{Version=[3],Text=[@Defn{extensions to Ada 2005}
2730 An optional @nt{aspect_specification} can be used in an
2731 @nt{abstract_subprogram_declaration}.
2732 This is described in @RefSecNum{Aspect Specifications}.]}
2733 @end{Extend2005}
2734
2735 @begin{Diffword2005}
2736 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0198-1]}
2737 @ChgAdded{Version=[3],Text=[@b<Correction:> Clarified that the predefined
2738 operator corresponding to an inherited abstract operator is also abstract. The
2739 Ada 2005 rules caused the predefined operator and the inherited operator to
2740 override each other, which is weird. But the effect is the same either way
2741 (the operator is not considered for resolution).]}
2742
2743 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0203-1]}
2744 @ChgAdded{Version=[3],Text=[@b<Correction:> Added wording to
2745 disallow abstract return objects. These were illegal in Ada 2005 by other
2746 rules; the extension to support class-wide type better opened a hole which
2747 has now been plugged.]}
2748 @end{Diffword2005}
2749
2750
2751 @LabeledAddedSubClause{Version=[2],Name=[Interface Types]}
2752
2753 @begin{Intro}
2754 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00251-01],ARef=[AI95-00345-01]}
2755 @ChgAdded{Version=[2],Text=[@Redundant[An interface type is an abstract tagged
2756 type that provides a restricted form of multiple inheritance. A tagged type,
2757 task type, or protected type may have one or more interface types as
2758 ancestors.]]}
2759 @ChgToGlossary{Version=[2],Kind=[AddedNormal],Term=<Interface type>,
2760 Text=<@ChgAdded{Version=[2],Text=[An interface type is a form of abstract
2761 tagged type which has no components or concrete operations
2762 except possibly null procedures. Interface types are used for
2763 composing other interfaces and tagged types and thereby
2764 provide multiple inheritance. Only an interface type can be used as a
2765 progenitor of another type.]}>}
2766 @end{Intro}
2767
2768 @begin{MetaRules}
2769 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00251-01],ARef=[AI95-00345-01]}
2770 @ChgAdded{Version=[2],Type=[Leading],Text=[The rules are designed so that an
2771 interface can be used as either a parent type or a progenitor type without
2772 changing the meaning. That's important so that the order that interfaces are
2773 specified in a @nt{derived_type_definition} is not significant. In particular,
2774 we want:]}
2775 @begin{Example}
2776 @ChgRef{Version=[2],Kind=[AddedNormal]}
2777 @ChgAdded{Version=[2],Text=[@key{type} Con1 @key{is new} Int1 @key{and} Int2 @key{with null record};
2778 @key{type} Con2 @key{is new} Int2 @key{and} Int1 @key{with null record};]}
2779 @end{Example}
2780 @ChgRef{Version=[2],Kind=[AddedNormal]}
2781 @ChgAdded{Version=[2],Type=[Trailing],Text=[to mean exactly the same thing.]}
2782 @end{MetaRules}
2783
2784 @begin{Syntax}
2785
2786 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00251-01],ARef=[AI95-00345-01]}
2787 @AddedSyn{Version=[2],lhs=<@Chg{Version=[2],New=<interface_type_definition>,Old=<>}>,
2788 rhs="@Chg{Version=[2],New=<
2789 [@key{limited} | @key{task} | @key{protected} | @key{synchronized}] @key{interface} [@key{and} @Syn2{interface_list}]>,Old=<>}"}
2790
2791 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00251-01],ARef=[AI95-00419-01]}
2792 @Syn{lhs=<@Chg{Version=[2],New=<interface_list>,Old=<>}>,
2793 rhs="@Chg{Version=[2],New=<@SynI{interface_}@Syn2{subtype_mark} {@key{and} @SynI{interface_}@Syn2{subtype_mark}}>,Old=<>}"}
2794
2795 @end{Syntax}
2796
2797 @begin{StaticSem}
2798
2799 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00251-01]}
2800 @Chg{Version=[2],New=[An interface type (also called an @i{interface})
2801 is@RootDefn{interface}@PDefn2{Term=[interface],Sec=[type]}
2802 a specific abstract tagged type that is defined by
2803 an @nt{interface_type_definition}.],Old=[]}
2804
2805 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00345-01]}
2806 @ChgAdded{Version=[2],Text=[An interface with the reserved word @key{limited},
2807 @key{task}, @key{protected},
2808 or @key{synchronized} in its definition is termed, respectively, a @i{limited
2809 interface}, a @i{task interface}, a @i{protected interface}, or a
2810 @i{synchronized interface}.
2811 In addition,@PDefn2{Term=[interface],Sec=[synchronized]}
2812 @PDefn2{Term=[interface],Sec=[protected]}
2813 @PDefn2{Term=[interface],Sec=[task]}
2814 @PDefn2{Term=[interface],Sec=[limited]}
2815 @PDefn2{Term=[interface],Sec=[nonlimited]}
2816 @Defn{synchronized interface}
2817 @Defn{protected interface}
2818 @Defn{task interface}
2819 @Defn{limited interface}
2820 @Defn{nonlimited interface}
2821 all task and protected interfaces
2822 are synchronized interfaces, and all synchronized interfaces are limited
2823 interfaces.]}
2824 @ChgToGlossary{Version=[2],Kind=[AddedNormal],Term=<Synchronized>,
2825 Text=<@ChgAdded{Version=[2],Text=[A synchronized entity is one
2826 that will work safely with multiple tasks at one time. A synchronized
2827 interface can be an ancestor of a task or a protected type. Such a
2828 task or protected type is called a synchronized tagged type.]}>}
2829
2830 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00345-01],ARef=[AI95-00443-01]}
2831 @ChgAdded{Version=[2],Text=[@Defn{synchronized tagged type}
2832 @PDefn2{Term=[type],Sec=[synchronized tagged]}
2833 @PDefn2{Term=[tagged type],Sec=[synchronized]}
2834 @PDefn2{Term=[tagged type],Sec=[task]}
2835 @PDefn2{Term=[tagged type],Sec=[protected]}
2836 @Defn{task tagged type}
2837 @Defn{protected tagged type}
2838 @Redundant[A task or protected type derived from an interface is a tagged type.]
2839 Such a tagged type is called a @i<synchronized> tagged
2840 type, as are synchronized interfaces and private extensions whose declaration
2841 includes the reserved word @b{synchronized}.]}
2842
2843 @begin{TheProof}
2844 @ChgRef{Version=[2],Kind=[AddedNormal]}
2845 @ChgAdded{Version=[2],Text=[The full definition of tagged types given in
2846 @RefSecNum{Tagged Types and Type Extensions} includes task and protected types
2847 derived from interfaces.]}
2848 @end{TheProof}
2849 @begin{Ramification}
2850 @ChgRef{Version=[2],Kind=[AddedNormal]}
2851 @ChgAdded{Version=[2],Text=[The class-wide type associated with a tagged task
2852 type (including a task interface type) is a task type, because
2853 @lquotes@;task@rquotes is one of the language-defined classes of types (see
2854 @RefSecNum{Types and Subtypes}). However, the class-wide type associated with an
2855 interface is @i<not> an interface type, as @lquotes@;interface@rquotes is
2856 @i<not> one of the language-defined classes (as it is not closed under
2857 derivation). In this sense, @lquotes@;interface@rquotes is similar to
2858 @lquotes@;abstract@rquotes. The class-wide type associated with an interface is
2859 a concrete (nonabstract) indefinite tagged composite type.]}
2860
2861 @ChgRef{Version=[2],Kind=[AddedNormal]}
2862 @ChgAdded{Version=[2],Text=[@lquotes@;Private extension@rquotes@; includes
2863 generic formal private extensions, as explained in
2864 @RefSecNum{Formal Private and Derived Types}.]}
2865 @end{Ramification}
2866
2867 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00345-01]}
2868 @ChgAdded{Version=[2],Text=[A task interface is an @Redundant[abstract] task
2869 type. A protected interface is an @Redundant[abstract] protected type.]}
2870 @begin{TheProof}
2871 @ChgRef{Version=[2],Kind=[AddedNormal]}
2872 @ChgAdded{Version=[2],Text=[The @lquotes@;abstract@rquotes follows
2873 from the definition of an interface type.]}
2874 @end{TheProof}
2875 @begin{Reason}
2876 @ChgRef{Version=[2],Kind=[AddedNormal]}
2877 @ChgAdded{Version=[2],Text=[This ensures that task operations (like abort and
2878 the Terminated attribute) can be applied to a task interface type and the
2879 associated class-wide type. While there are no protected type operations,
2880 we apply the same rule to protected interfaces for consistency.]}
2881 @end{Reason}
2882
2883 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00251-01]}
2884 @Chg{Version=[2],New=[@Redundant[An interface type has no components.]],Old=[]}
2885 @begin{TheProof}
2886 @ChgRef{Version=[2],Kind=[AddedNormal]}
2887 @ChgAdded{Version=[2],Text=[This follows from the syntax and the fact that
2888 discriminants are not allowed for interface types.]}
2889 @end{TheProof}
2890
2891 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00419-01]}
2892 @ChgAdded{Version=[2],Text=[@Defn{progenitor subtype}@Defn{progenitor type}
2893 An @Syni(interface_)@nt{subtype_mark} in an @nt{interface_list} names a
2894 @i(progenitor subtype); its type is the @i(progenitor type).
2895 An interface type inherits user-defined primitive subprograms from each
2896 progenitor type in the same way that a derived type inherits user-defined
2897 primitive subprograms from its progenitor types
2898 (see @RefSecNum{Derived Types and Classes}).]}
2899 @ChgToGlossary{Version=[2],Kind=[Added],Term=<Progenitor>,
2900 Text=<@ChgAdded{Version=[2],Text=[A progenitor of a derived type is
2901 one of the types given in the definition of the derived type other
2902 than the first. A progenitor is always an interface type.
2903 Interfaces, tasks, and protected types may also have progenitors.]}>}
2904
2905 @end{StaticSem}
2906
2907 @begin{Legality}
2908
2909 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00251-01]}
2910 @Chg{Version=[2],New=[All user-defined primitive subprograms of an interface
2911 type shall be abstract subprograms or null procedures.],Old=[]}
2912
2913 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00251-01]}
2914 @Chg{Version=[2],New=[The type of a subtype named in an @nt{interface_list}
2915 shall be an interface type.],Old=[]}
2916
2917 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00251-01],ARef=[AI95-00345-01]}
2918 @ChgAdded{Version=[2],Text=[A type derived from a nonlimited interface shall be
2919 nonlimited.]}
2920
2921 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00345-01]}
2922 @ChgAdded{Version=[2],Text=[An interface derived from a task interface shall
2923 include the reserved word @key{task} in its
2924 definition; any other type derived from a task interface shall be a private
2925 extension or a task type declared by a task declaration (see
2926 @RefSecNum{Task Units and Task Objects}).]}
2927
2928 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00345-01]}
2929 @ChgAdded{Version=[2],Text=[An interface derived from a
2930 protected interface shall include
2931 the reserved word @key{protected} in its definition; any other type derived
2932 from a protected interface shall be a private extension or a protected type
2933 declared by a protected declaration (see
2934 @RefSecNum{Protected Units and Protected Objects}).]}
2935
2936 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00345-01]}
2937 @ChgAdded{Version=[2],Text=[An interface derived from
2938 a synchronized interface shall include one of the reserved words @key{task},
2939 @key{protected}, or @key{synchronized} in its definition; any other type
2940 derived from a synchronized interface shall be a private extension, a task
2941 type declared by a task declaration, or a protected type declared by a protected
2942 declaration.]}
2943
2944 @begin{Reason}
2945 @ChgRef{Version=[2],Kind=[AddedNormal]}
2946 @ChgAdded{Version=[2],Text=[We require that an interface descendant of a
2947 task, protected, or synchronized interface repeat the explicit kind of
2948 interface it will be, rather than simply inheriting it, so that a reader is
2949 always aware of whether the interface provides synchronization and whether
2950 it may be implemented only by a task or protected type. The only place where
2951 inheritance of the kind of interface might be useful would be in a generic
2952 if you didn't know the kind of the actual interface. However, the value of
2953 that is low because you cannot implement an interface properly if you don't
2954 know whether it is a task, protected, or synchronized interface. Hence, we
2955 require the kind of the actual interface to match the kind of the formal
2956 interface (see @RefSecNum{Formal Interface Types}).]}
2957 @end{Reason}
2958
2959 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00345-01]}
2960 @ChgAdded{Version=[2],Text=[No type shall be derived from both a task interface
2961 and a protected interface.]}
2962
2963 @begin{Reason}
2964 @ChgAdded{Version=[2],Text=[This prevents a single private
2965 extension from inheriting from both a task and a protected interface. For a
2966 private type, there can be no legal completion. For a generic formal derived
2967 type, there can be no possible matching type (so no instantiation could be
2968 legal). This rule provides early detection of the errors.]}
2969 @end{Reason}
2970
2971 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00251-01]}
2972 @ChgAdded{Version=[2],Text=[In addition to the places where @LegalityTitle
2973 normally apply (see @RefSecNum{Generic Instantiation}), these rules apply also
2974 in the private part of an instance of a generic
2975 unit.@PDefn{generic contract issue}]}
2976 @begin{Ramification}
2977 @ChgRef{Version=[2],Kind=[AddedNormal]}
2978 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0299-1]}
2979 @ChgAdded{Version=[2],Text=[This paragraph is intended to apply to all of the
2980 @LegalityTitle@; in this @Chg{Version=[3],New=[subclause],Old=[clause]}. We
2981 cannot allow interface types which do not
2982 obey these rules, anywhere. Luckily, deriving from a formal type (which might
2983 be an interface) is not allowed for any tagged types in a generic body. So
2984 checking in the private part of a generic covers all of the cases.]}
2985 @end{Ramification}
2986
2987 @end{Legality}
2988
2989 @begin{Runtime}
2990 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00251-01]}
2991 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0070-1]}
2992 @ChgAdded{Version=[2],Text=[The elaboration of an
2993 @nt{interface_type_definition} @Chg{Version=[3],New=[creates
2994 the interface type and its first subtype],Old=[has no effect]}.]}
2995 @begin{Discussion}
2996 @ChgRef{Version=[2],Kind=[AddedNormal]}
2997 @ChgRef{Version=[3],Kind=[Revised]}
2998 @ChgAdded{Version=[2],Text=[@Chg{Version=[3],New=[There is no other
2999 effect. ],Old=[]}An @nt{interface_list} is made up of
3000 @nt{subtype_mark}s, which do not need to be elaborated, so the
3001 @nt{interface_list} does not either. This is consistent with the
3002 handling of @nt{discriminant_part}s.]}
3003 @end{Discussion}
3004 @end{Runtime}
3005
3006 @begin{Notes}
3007 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00411-01]}
3008 @ChgAdded{Version=[2],Text=[Nonlimited interface types have predefined
3009 nonabstract equality operators. These may be overridden with user-defined
3010 abstract equality operators. Such operators will then require
3011 an explicit overriding for any nonabstract descendant of the interface.]}
3012 @end{Notes}
3013
3014 @begin{Examples}
3015
3016 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00433-01]}
3017 @ChgAdded{Version=[2],Type=[Leading],Text=[@i{Example of a limited
3018 interface and a synchronized interface extending it:}]}
3019
3020 @begin{Example}
3021 @ChgRef{Version=[2],Kind=[AddedNormal]}
3022 @ChgAdded{Version=[2],Text=[@key{type} Queue @key{is limited interface};
3023 @key{procedure} Append(Q : @key{in out} Queue; Person : @key{in} Person_Name) @key{is abstract};
3024 @key{procedure} Remove_First(Q : @key{in out} Queue;
3025 Person : @key{out} Person_Name) @key{is abstract};
3026 @key{function} Cur_Count(Q : @key{in} Queue) @key{return} Natural @key{is abstract};
3027 @key{function} Max_Count(Q : @key{in} Queue) @key{return} Natural @key{is abstract};
3028 -- @RI[See @RefSecNum{Incomplete Type Declarations} for Person_Name.]]}
3029
3030 @ChgRef{Version=[2],Kind=[AddedNormal]}
3031 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0004-1]}
3032 @ChgAdded{Version=[2],Text=[Queue_Error : @key{exception};
3033 --@RI[ Append raises Queue_Error if @Chg{Version=[3],New=[Cur_Count],Old=[Count]}(Q) = Max_Count(Q)]
3034 --@RI[ Remove_First raises Queue_Error if @Chg{Version=[3],New=[Cur_Count],Old=[Count]}(Q) = 0]]}
3035
3036 @ChgRef{Version=[2],Kind=[AddedNormal]}
3037 @ChgAdded{Version=[2],Text=[@key{type} Synchronized_Queue @key{is synchronized interface and} Queue; --@RI[ see @RefSecNum{Example of Tasking and Synchronization}]
3038 @key{procedure} Append_Wait(Q : @key{in out} Synchronized_Queue;
3039 Person : @key{in} Person_Name) @key{is abstract};
3040 @key{procedure} Remove_First_Wait(Q : @key{in out} Synchronized_Queue;
3041 Person : @key{out} Person_Name) @key{is abstract};]}
3042
3043 @ChgRef{Version=[2],Kind=[AddedNormal]}
3044 @ChgAdded{Version=[2],Text=[...]}
3045
3046 @ChgRef{Version=[2],Kind=[AddedNormal]}
3047 @ChgAdded{Version=[2],Text=[@key{procedure} Transfer(From : @key{in out} Queue'Class;
3048 To : @key{in out} Queue'Class;
3049 Number : @key{in} Natural := 1) @key{is}
3050 Person : Person_Name;
3051 @key{begin}
3052 @key{for} I @key{in} 1..Number @key{loop}
3053 Remove_First(From, Person);
3054 Append(To, Person);
3055 @key{end loop};
3056 @key{end} Transfer;]}
3057 @end{Example}
3058
3059 @ChgRef{Version=[2],Kind=[AddedNormal]}
3060 @ChgAdded{Version=[2],Text=[This defines a Queue interface defining a queue of
3061 people. (A similar design could be created to define any kind of queue simply
3062 by replacing Person_Name by an appropriate type.) The Queue interface has four
3063 dispatching operations, Append, Remove_First, Cur_Count, and Max_Count. The
3064 body of a class-wide operation, Transfer is also shown. Every nonabstract
3065 extension of Queue must provide implementations for at least its four
3066 dispatching operations, as they are abstract. Any object of a type derived from
3067 Queue may be passed to Transfer as either the From or the To operand. The two
3068 operands need not be of the same type in any given call.]}
3069
3070 @ChgRef{Version=[2],Kind=[AddedNormal]}
3071 @ChgAdded{Version=[2],Text=[The Synchronized_Queue interface inherits the four
3072 dispatching operations from Queue and adds two additional dispatching
3073 operations, which wait if necessary rather than raising the Queue_Error
3074 exception. This synchronized interface may only be implemented by a task or
3075 protected type, and as such ensures safe concurrent access.]}
3076
3077 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00433-01]}
3078 @ChgAdded{Version=[2],Type=[Leading],Text=[@i{Example use of the interface:}]}
3079
3080 @begin{Example}
3081 @ChgRef{Version=[2],Kind=[AddedNormal]}
3082 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0004-1]}
3083 @ChgAdded{Version=[2],Text=[@key{type} Fast_Food_Queue @key{is new} Queue @key{with record} ...;
3084 @key{procedure} Append(Q : @key{in out} Fast_Food_Queue; Person : @key{in} Person_Name);
3085 @key{procedure} Remove_First(Q : @key{in out} Fast_Food_Queue; Person : @Chg{Version=[3],New=[@key{out}],Old=[@key{in}]} Person_Name);
3086 @key{function} Cur_Count(Q : @key{in} Fast_Food_Queue) @key{return} Natural;
3087 @key{function} Max_Count(Q : @key{in} Fast_Food_Queue) @key{return} Natural;]}
3088
3089 @ChgRef{Version=[2],Kind=[AddedNormal]}
3090 @ChgAdded{Version=[2],Text=[...]}
3091
3092 @ChgRef{Version=[2],Kind=[AddedNormal]}
3093 @ChgAdded{Version=[2],Text=[Cashier, Counter : Fast_Food_Queue;]}
3094
3095 @ChgRef{Version=[2],Kind=[AddedNormal]}
3096 @ChgRef{Version=[5],Kind=[Revised],ARef=[AI12-0312-1]}
3097 @ChgAdded{Version=[2],Text=[...
3098 --@RI[ Add @Chg{Version=[5],New=[Casey],Old=[George]} (see @RefSecNum{Incomplete Type Declarations}) to the cashier's queue:]
3099 Append (Cashier, @Chg{Version=[5],New=[Casey],Old=[George]});
3100 --@RI[ After payment, move @Chg{Version=[5],New=[Casey],Old=[George]} to the sandwich counter queue:]
3101 Transfer (Cashier, Counter);
3102 ...]}
3103 @end{Example}
3104
3105 @ChgRef{Version=[2],Kind=[AddedNormal]}
3106 @ChgAdded{Version=[2],Text=[An interface such as Queue can be used directly as
3107 the parent of a new type (as shown here), or can be used as a progenitor when a
3108 type is derived. In either case, the primitive operations of the
3109 interface are inherited. For Queue, the implementation of the four inherited
3110 routines must be provided. Inside the call of Transfer, calls will dispatch to
3111 the implementations of Append and Remove_First for type Fast_Food_Queue.]}
3112
3113 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00433-01]}
3114 @ChgAdded{Version=[2],Type=[Leading],Text=[@i{Example of a task interface:}]}
3115
3116 @begin{Example}
3117 @ChgRef{Version=[2],Kind=[AddedNormal]}
3118 @ChgAdded{Version=[2],Text=[@key{type} Serial_Device @key{is task interface}; --@RI[ see @RefSecNum{Task Units and Task Objects}]
3119 @key{procedure} Read (Dev : @key{in} Serial_Device; C : @key{out} Character) @key{is abstract};
3120 @key{procedure} Write(Dev : @key{in} Serial_Device; C : @key{in} Character) @key{is abstract};]}
3121 @end{Example}
3122
3123 @ChgRef{Version=[2],Kind=[AddedNormal]}
3124 @ChgAdded{Version=[2],Text=[The Serial_Device interface has two dispatching
3125 operations which are intended to be implemented by task entries (see 9.1).]}
3126
3127 @end{Examples}
3128
3129 @begin{Extend95}
3130 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00251-01],ARef=[AI95-00345-01]}
3131 @ChgAdded{Version=[2],Text=[@Defn{extensions to Ada 95}Interface types
3132 are new. They provide multiple inheritance of interfaces, similar to the
3133 facility provided in Java and other recent language designs.]}
3134 @end{Extend95}
3135
3136 @begin{DiffWord2005}
3137 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0070-1]}
3138 @ChgAdded{Version=[3],Text=[@b<Correction:> Corrected the definition
3139 of elaboration for an @nt{interface_type_definition} to match that
3140 of other type definitions.]}
3141 @end{DiffWord2005}
3142
3143
3144 @LabeledClause{Access Types}
3145
3146 @begin{Intro}
3147 @Defn{access type}
3148 @Defn{access value}
3149 @Defn{designate}
3150 A value of an access type (an @i(access value))
3151 provides indirect access to the object or subprogram
3152 it @i(designates). Depending on its type, an access value
3153 can designate either subprograms, objects created by allocators
3154 (see @RefSecNum(Allocators)), or more generally @i(aliased) objects of
3155 an appropriate type.
3156 @IndexSee{Term=[pointer],See=(access value)}
3157 @IndexSee{Term=[pointer type],See=(access type)}
3158 @begin(Discussion)
3159 A @nt<name> @i(denotes) an entity; an access value @i(designates) an
3160 entity. The @lquotes@;dereference@rquotes@; of an access value X, written
3161 @lquotes@;X.@key[all]@rquotes@;, is a @nt<name> that denotes the entity designated by X.
3162 @end(Discussion)
3163 @end{Intro}
3164
3165 @begin{MetaRules}
3166 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0299-1]}
3167 Access values should always be well defined
3168 (barring uses of certain unchecked features of @Chg{Version=[3],New=[Clause],Old=[Section]}
3169 @RefSecNum{Representation Issues}).
3170 In particular, uninitialized access variables should be prevented
3171 by compile-time rules.
3172 @end{MetaRules}
3173
3174 @begin{Syntax}
3175 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00231-01]}
3176 @Syn{lhs=<access_type_definition>,rhs="
3177 @Chg{Version=[2],New=<[@Syn2{null_exclusion}] >,Old=<>}@Syn2{access_to_object_definition}
3178 | @Chg{Version=[2],New=<[@Syn2{null_exclusion}] >,Old=<>}@Syn2{access_to_subprogram_definition}"}
3179
3180 @Syn{lhs=<access_to_object_definition>,rhs="
3181 @key{access} [@Syn2{general_access_modifier}] @Syn2{subtype_indication}"}
3182 @Syn{lhs=<general_access_modifier>,rhs="@key{all} | @key{constant}"}
3183
3184 @Syn{lhs=<access_to_subprogram_definition>,rhs="
3185 @key{access} [@key{protected}] @key{procedure} @Syn2{parameter_profile}
3186 | @key{access} [@key{protected}] @key{function} @Syn2{parameter_and_result_profile}"}
3187
3188 @ChgRef{Version=[2],Kind=[Added],ARef=[AI95-00231-01]}
3189 @AddedSyn{Version=[2],lhs=<@Chg{Version=[2],New=[null_exclusion],Old=[]}>,
3190 rhs="@Chg{Version=[2],New=[@key{not} @key{null}],Old=[]}"}
3191
3192 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00231-01],ARef=[AI95-00254-01],ARef=[AI95-00404-01]}
3193 @Syn{lhs=<access_definition>,rhs="@Chg{Version=[2],New=<
3194 [@Syn2{null_exclusion}] @key{access} [@key{constant}] @Syn2{subtype_mark}
3195 | [@Syn2{null_exclusion}] @key{access} [@key{protected}] @key{procedure} @Syn2{parameter_profile}
3196 | [@Syn2{null_exclusion}] @key{access} [@key{protected}] @key{function} @Syn2{parameter_and_result_profile}>,
3197 Old=[@key{access} @Syn2{subtype_mark}]}"}
3198
3199 @end{Syntax}
3200
3201 @begin{StaticSem}
3202 @ChgRef{Version=[1],Kind=[Revised],Ref=[8652/0012],ARef=[AI95-00062-01]}
3203 @Defn{access-to-object type}
3204 @Defn{access-to-subprogram type}
3205 @Defn{pool-specific access type}
3206 @Defn{general access type}
3207 There are two kinds of access types, @i{access-to-object} types, whose
3208 values designate objects, and @i(access-to-subprogram) types, whose
3209 values designate subprograms.
3210 @Defn{storage pool}
3211 Associated with an access-to-object type is a @i(storage pool);
3212 several access types may share the same storage pool.
3213 @Chg{New=[All descendants of an access type share the same storage pool.],Old=[]}
3214 @Defn{pool element}
3215 A storage pool is an area of storage used to hold dynamically
3216 allocated objects (called @i(pool elements)) created
3217 by allocators@Redundant[; storage pools
3218 are described further in @RefSec(Storage Management)].
3219
3220 @Defn{pool-specific access type}
3221 @Defn{general access type}
3222 Access-to-object types are further subdivided into
3223 @i(pool-specific) access types, whose values can designate only
3224 the elements of their associated storage pool,
3225 and @i(general) access types, whose
3226 values can designate the elements of any storage pool,
3227 as well as aliased objects created by declarations
3228 rather than allocators,
3229 and aliased subcomponents of other objects.
3230 @begin(ImplNote)
3231 The value of an access type will typically be a machine address.
3232 However, a value of a pool-specific access type can be
3233 represented as an offset (or index) relative to its storage pool,
3234 since it can point only to the elements of that pool.
3235 @end(ImplNote)
3236
3237 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00225-01],ARef=[AI95-00363-01]}
3238 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0053-1],ARef=[AI05-0142-4],ARef=[AI05-0277-1]}
3239 @ChgRef{Version=[5],Kind=[Revised],ARef=[AI12-0228-1],ARef=[AI12-0324-1]}
3240 @Defn{aliased}
3241 A view of an object is defined to be @i(aliased) if
3242 it is defined by an @nt<object_@!declaration>@Chg{Version=[3],New=[,],Old=[ or]}
3243 @nt<component_@!definition>@Chg{Version=[3],New=[,
3244 @nt{parameter_@!specification}, or
3245 @nt{extended_return_object_declaration}],Old=[]}
3246 with the reserved word @key(aliased), or by a renaming of an aliased view.
3247 In addition, the dereference of an access-to-object
3248 value denotes an aliased view, as does a view conversion
3249 (see @RefSecNum{Type Conversions}) of an aliased view.@Chg{Version=[5],New=[
3250 A @nt{qualified_expression} denotes an aliased view when the
3251 operand denotes an aliased view.],Old=[]}
3252 @Chg{Version=[2],New=[The],Old=[Finally, the]} current instance of
3253 @Chg{Version=[3],New=[an immutably limited type (see @RefSecNum{Limited Types})
3254 is],Old=[a limited@Chg{Version=[2],New=[ tagged],Old=[]} type,
3255 @Chg{Version=[2],New=[a protected type, a task type, or a type that has the
3256 reserved word @key{limited} in its full definition is also],Old=[]}]}
3257 @Chg{Version=[2],New=[defined to be aliased. Finally,],Old=[and]}
3258 a formal parameter or generic formal object of a
3259 tagged type @Chg{Version=[2],New=[is],Old=[are]} defined to be aliased.
3260 @Redundant[Aliased views are the ones that can be designated by an
3261 access value.]
3262 @Chg{Version=[2],New=[],Old=[@Defn2{Term=[constrained], Sec=(object)}
3263 @Defn2{Term=[unconstrained], Sec=(object)}
3264 @Defn{constrained by its initial value}
3265 If the view defined by an @nt{object_@!declaration} is aliased,
3266 and the type of the object has discriminants,
3267 then the object is constrained;
3268 if its nominal subtype is unconstrained,
3269 then the object is constrained by its initial value.
3270 @Redundant[Similarly, if the object created by an @nt<allocator>
3271 has discriminants, the object is constrained,
3272 either by the designated subtype, or by its initial value.]]}
3273 @ToGlossary{Term=<Aliased>,
3274 Text=<An aliased view of an object is one that can be designated by an
3275 access value.
3276 Objects allocated by allocators are aliased.
3277 Objects can also be explicitly declared as aliased with
3278 the reserved word @key(aliased).
3279 The Access attribute can be used to create an access value
3280 designating an aliased object.>}
3281 @begin(Ramification)
3282 The current instance of a nonlimited type is not aliased.
3283
3284 The object created by an allocator is aliased, but not its
3285 subcomponents, except of course for those that themselves have @key(aliased)
3286 in their @nt<component_definition>.
3287
3288 The renaming of an aliased object is aliased.
3289
3290 Slices are never aliased.
3291 See @RefSecNum{Slices} for more discussion.
3292 @end(Ramification)
3293 @begin(Reason)
3294 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00225-01]}
3295 The current instance of a limited type is defined to be aliased
3296 so that an access discriminant of a component can be initialized
3297 with T'Access inside the definition of T.@Chg{Version=[2],New=[ Note that
3298 we don't want this to apply to a type that could become nonlimited later
3299 within its immediate scope, so we require the full definition to be limited.],Old=[]}
3300
3301 A formal parameter of a tagged type is defined to be aliased
3302 so that a (tagged) parameter X may be passed to an access parameter P
3303 by using P => X'Access. Access parameters are most important
3304 for tagged types because of dispatching-on-access-parameters
3305 (see @RefSecNum(Dispatching Operations of Tagged Types)).
3306 By restricting this to formal parameters, we minimize problems
3307 associated with allowing components that are not declared aliased
3308 to be pointed-to from within the same record.
3309
3310 @Leading@;A view conversion of an aliased view is aliased so that
3311 the type of an access parameter can be changed without
3312 first converting to a named access type. For example:
3313 @begin{Example}
3314 @key(type) T1 @key(is tagged) ...;
3315 @key(procedure) P(X : @key(access) T1);
3316
3317 @key(type) T2 @key(is new) T1 @key(with) ...;
3318 @key(procedure) P(X : @key(access) T2) @key(is)
3319 @key(begin)
3320 P(T1(X.@key(all))'Access); --@RI[ hand off to T1's P]
3321 . . . --@RI[ now do extra T2-specific processing]
3322 @key(end) P;
3323 @end{Example}
3324
3325 @ChgRef{Version=[2],Kind=[Deleted],ARef=[AI95-00363-01]}
3326 @ChgDeleted{Version=[2],Text=[The rule about objects with discriminants is
3327 necessary because values of a constrained access subtype
3328 can designate an object whose nominal subtype is unconstrained;
3329 without this rule, a check on every use of such values would
3330 be required to ensure that the discriminants of the object had not
3331 changed.
3332 With this rule (among others), we ensure that if there might
3333 exist aliased views of a discriminated object, then the object is
3334 necessarily constrained.
3335 Note that this rule is necessary only for untagged types,
3336 since a discriminant of a tagged type can't have a default,
3337 so all tagged discriminated objects are always constrained
3338 anyway.]}
3339 @ChgNote{This rule was a disaster, so it thankfully has been repealed.
3340 We instead make general access constrained subtypes illegal if the type
3341 allows unconstrained instances, see Discriminant Constraints.}
3342
3343 @ChgRef{Version=[2],Kind=[Revised]}@ChgNote{Eilers reported double word}
3344 We considered making more kinds of objects aliased by default.
3345 In particular, any object of a by-reference type will pretty
3346 much have to be allocated at an addressable location,
3347 so it can be passed by reference without using bit-field
3348 pointers. Therefore, one might wish to allow the Access and
3349 @Chg{Version=[2],New=[],Old=[and ]}Unchecked_Access attributes for such
3350 objects. However, private parts are transparent to the definition of
3351 @lquotes@;by-reference type@rquotes@;, so if we made all objects of a by-reference
3352 type aliased, we would be violating the privacy of private parts.
3353 Instead, we would have to define a concept of @lquotes@;visibly by-reference@rquotes@;
3354 and base the rule on that.
3355 This seemed to complicate the rules more than it was worth,
3356 especially since there is no way to declare an untagged limited
3357 private type to be by-reference, since the full type might by
3358 nonlimited.
3359 @end(Reason)
3360 @begin{Discussion}
3361 Note that we do not use the term @lquotes@;aliased@rquotes@; to refer to formal
3362 parameters that are referenced through multiple access paths
3363 (see @RefSecNum{Formal Parameter Modes}).
3364 @end{Discussion}
3365
3366 An @nt{access_to_object_definition} defines
3367 an access-to-object type and its first subtype;
3368 @Defn2{Term=[designated subtype], Sec=(of a named access type)}
3369 @Defn2{Term=[designated type], Sec=(of a named access type)}
3370 the @nt<subtype_@!indication> defines the @i(designated subtype)
3371 of the access type.
3372 If a @nt<general_@!access_@!modifier> appears, then the access type
3373 is a general access type.
3374 @Defn{access-to-constant type}
3375 If the modifier is the reserved word @key(constant), then the type is an
3376 @i(access-to-constant type)@Redundant[; a designated object cannot be updated
3377 through a value of such a type].
3378 @Defn{access-to-variable type}
3379 If the modifier is the reserved word @key(all),
3380 then the type is an @i(access-to-variable type)@Redundant[; a designated object
3381 can be both read and updated through a value of such a type].
3382 If no @nt<general_@!access_@!modifier> appears in the
3383 @nt<access_to_@!object_@!definition>, the access type is a
3384 pool-specific access-to-variable type.
3385 @begin{Honest}
3386 The type of the designated subtype is called the
3387 @i{designated type}.
3388 @end{Honest}
3389 @begin(Reason)
3390 The modifier @key(all) was picked to suggest that
3391 values of a general access type could point into @lquotes@;all@rquotes@; storage pools,
3392 as well as to objects declared aliased, and that @lquotes@;all@rquotes@; access
3393 (both read and update) to the designated object was provided.
3394 We couldn't think of any use for pool-specific
3395 access-to-constant types, so any access type defined with
3396 the modifier @key(constant) is considered a general access type,
3397 and can point into any storage pool or at other (appropriate)
3398 aliased objects.
3399 @end(Reason)
3400 @begin(ImplNote)
3401 The predefined generic Unchecked_Deallocation can be
3402 instantiated for any named access-to-variable type. There
3403 is no (language-defined) support for deallocating objects
3404 designated by a value of an access-to-constant type. Because of this,
3405 an allocator for an access-to-constant type can allocate
3406 out of a storage pool with no support for deallocation.
3407 Frequently, the allocation can be done at link-time,
3408 if the size and initial value are known then.
3409 @end(ImplNote)
3410 @begin(Discussion)
3411 For the purpose of generic formal type matching, the relevant
3412 subclasses of access types are access-to-subprogram
3413 types, access-to-constant types, and (named) access-to-variable types,
3414 with its subclass (named) general access-to-variable types.
3415 Pool-specific access-to-variable types are not a separately matchable
3416 subclass of types, since they don't have any @lquotes@;extra@rquotes@; operations
3417 relative to all (named) access-to-variable types.
3418 @end(Discussion)
3419
3420 @Defn{access-to-subprogram type}
3421 An @nt{access_to_subprogram_definition} defines
3422 an access-to-subprogram type and its first subtype;
3423 @Defn2{Term=[designated profile], Sec=(of an access-to-subprogram type)}
3424 the @nt<parameter_profile> or @nt<parameter_and_result_profile>
3425 defines the @i(designated profile) of the access type.
3426 @Defn2{Term=[calling convention], Sec=(associated with a designated profile)}
3427 There is a @i(calling convention) associated with the designated
3428 profile@Redundant[; only subprograms with this
3429 calling convention can be designated by
3430 values of the access type.]
3431 By default, the calling convention is @lquotes@i(protected)@rquotes@; if the reserved
3432 word @key(protected) appears, and @lquotes@;Ada@rquotes@; otherwise.
3433 @Redundant[See @RefSecNum{Interface to Other Languages}
3434 for how to override this default.]
3435 @begin(Ramification)
3436 The calling convention @i(protected) is
3437 in italics to emphasize that it cannot be specified explicitly
3438 by the user. This is a consequence of it being a reserved word.
3439 @end(Ramification)
3440 @begin(ImplNote)
3441 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00254-01]}
3442 For @Chg{Version=[2],New=[a named],Old=[an]} access-to-subprogram type, the
3443 representation of an access value might include
3444 implementation-defined information needed to support
3445 up-level references @em for example, a static link.
3446 The accessibility rules (see @RefSecNum(Operations of Access Types)) ensure
3447 that in a "global-display-based" implementation model (as opposed to
3448 a static-link-based model), @Chg{Version=[2],New=[a named],Old=[an]}
3449 access-to-(unprotected)-subprogram value need consist only of the
3450 address of the subprogram. The global display is guaranteed
3451 to be properly set up any time the designated subprogram is called.
3452 Even in a static-link-based model, the only time a static link
3453 is definitely required is for an access-to-subprogram type declared
3454 in a scope nested at least two levels deep within subprogram or
3455 task bodies, since values of such a type might designate subprograms
3456 nested a smaller number of levels. For the normal case of
3457 @Chg{Version=[2],New=[a named],Old=[an]} access-to-subprogram type
3458 declared at the outermost (library) level,
3459 a code address by itself should be sufficient to represent the
3460 access value in many implementations.
3461
3462 For access-to-protected-subprogram, the access values will necessarily
3463 include both an address (or other identification) of the code of the
3464 subprogram, as well as the address of the associated protected object.
3465 This could be thought of as a static link, but it will be needed even
3466 for global-display-based implementation models. It corresponds
3467 to the value of the @lquotes@;implicit parameter@rquotes@; that is passed into
3468 every call of a protected operation, to identify the current instance
3469 of the protected type on which they are to operate.
3470
3471 Any Elaboration_Check is performed when a call
3472 is made through an access value, rather than when the
3473 access value is first "created" via a 'Access.
3474 For implementation models that normally put that check at the
3475 call-site, an access value will have to point to a separate
3476 entry point that does the check. Alternatively, the
3477 access value could point to a "subprogram descriptor" that
3478 consisted of two words (or perhaps more), the first being
3479 the address of the code, the second being the elaboration bit.
3480 Or perhaps more efficiently, just the address of the code,
3481 but using the trick that the descriptor is initialized to
3482 point to a Raise-Program-Error routine initially, and then
3483 set to point to the "real" code when the body is elaborated.
3484
3485 For implementations that share code between generic instantiations,
3486 the extra level of indirection suggested above to support
3487 Elaboration_Checks could also be used to provide a pointer to the
3488 per-instance data area normally required when calling shared code.
3489 The trick would be to put a pointer to the per-instance data
3490 area into the subprogram descriptor, and then make sure that
3491 the address of the subprogram descriptor is loaded into a
3492 "known" register whenever an indirect call is performed.
3493 Once inside the shared code, the address of the per-instance
3494 data area can be retrieved out of the subprogram descriptor,
3495 by indexing off the "known" register.
3496
3497 @ChgRef{Version=[2],Kind=[Deleted],ARef=[AI95-00344-01]}
3498 @ChgNote{This is not remotely true with nested extensions and with
3499 interfaces. I don't much feel like trying to explain this properly.}
3500 @ChgDeleted{Version=[2],Text=[Essentially the same implementation issues
3501 arise for calls on dispatching operations of tagged types, except that
3502 the static link is always known "statically."]}
3503
3504 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00254-01]}
3505 Note that access parameters of an
3506 anonymous access-to-subprogram type are @Chg{Version=[2],New=[],Old=[not ]}permitted.
3507 @Chg{Version=[2],New=[Such],Old=[If there were such]} parameters@Chg{Version=[2],
3508 New=[ represent],Old=[,]} full @lquotes@;downward@rquotes@;
3509 closures@Chg{Version=[2],New=[],Old=[would be required]}, meaning that
3510 in an implementation that uses a per-task (global) display,
3511 the display @Chg{Version=[2],New=[will],Old=[would]} have to be passed
3512 as a hidden parameter,
3513 and reconstructed at the point of call.@Chg{Version=[2],New=[],
3514 Old=[ This was felt to be an undue implementation burden,
3515 given that an equivalent (actually, more general) capability
3516 is available via formal subprogram parameters to a generic.]}
3517 @end(ImplNote)
3518
3519 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00230-01],ARef=[AI95-00231-01],ARef=[AI95-00254-01]}
3520 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0264-1]}
3521 @Defn{anonymous access type}
3522 @Defn2{Term=[designated subtype], Sec=(of an anonymous access type)}
3523 @Defn2{Term=[designated type], Sec=(of an anonymous access type)}
3524 An @nt{access_definition} defines an anonymous
3525 general @Chg{Version=[2],New=[access type or an
3526 anonymous access-to-subprogram type. For a general access type,],
3527 Old=[access-to-variable type;]} the @nt<subtype_mark> denotes
3528 its @i(designated subtype)@Chg{Version=[2],New=[; if the
3529 @nt{general_@!access_@!modifier} @key{constant} appears, the type is an
3530 access-to-constant type; otherwise@Chg{Version=[3],New=[,],Old=[]} it is
3531 an access-to-variable type. For an access-to-subprogram type, the
3532 @nt{parameter_@!profile} or @nt{parameter_@!and_@!result_@!profile} denotes its
3533 @i{designated profile}.@Defn2{Term=[designated profile], Sec=(of an anonymous access type)}],
3534 Old=[. @Redundant[An @nt<access_definition> is used in the
3535 specification of an access discriminant
3536 (see @RefSecNum(Discriminants)) or an access
3537 parameter (see @RefSecNum(Subprogram Declarations)).]]}
3538
3539 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00230-01],ARef=[AI95-00231-01]}
3540 @Defn2{Term=[null value], Sec=(of an access type)}
3541 For each @Chg{Version=[2],New=[],Old=[(named) ]}access type, there is
3542 @Chg{Version=[2],New=[],Old=[a literal @key(null) which has ]}a null
3543 access value designating no entity at all@Chg{Version=[2],New=[, which can be
3544 obtained by (implicitly) converting the literal @key{null} to the access
3545 type],Old=[]}.
3546 @Redundant[The null value of @Chg{Version=[2],New=[an],Old=[a named]} access
3547 type is the default initial value of the type.]
3548 @Chg{Version=[2],New=[Nonnull],Old=[Other]} values of an
3549 access@Chg{Version=[2],New=[-to-object],Old=[]} type are
3550 obtained by evaluating @Chg{Version=[2],New=[],Old=[an
3551 @nt<attribute_reference> for the Access or Unchecked_Access
3552 attribute of an aliased view of an object or nonintrinsic
3553 subprogram, or, in the case of a named access-to-object type,]}
3554 an @nt<allocator>@Redundant[, which
3555 returns an access value designating a newly created object
3556 (see @RefSecNum(Operations of Access Types))]@Chg{Version=[2],New=[, or in the
3557 case of a general access-to-object type, evaluating an
3558 @nt{attribute_reference} for the Access or Unchecked_Access
3559 attribute of an aliased view of an object. Nonnull values of an
3560 access-to-subprogram type are obtained by evaluating an
3561 @nt{attribute_reference} for the Access attribute of a
3562 nonintrinsic subprogram],Old=[]}.
3563
3564 @begin{Ramification}
3565 @ChgRef{Version=[2],Kind=[Deleted],ARef=[AI95-00231-01]}
3566 @ChgDeleted{Version=[2],Text=[A value of an anonymous access type
3567 (that is, the value of an access parameter or access discriminant)
3568 cannot be null.]}
3569 @end{ramification}
3570 @begin{Reason}
3571 @ChgRef{Version=[2],Kind=[Deleted],ARef=[AI95-00231-01]}
3572 @ChgDeleted{Version=[2],Text=[Access parameters allow dispatching on the
3573 tag of the object designated
3574 by the actual parameter (which gets converted to the anonymous access
3575 type as part of the call).
3576 In order for dispatching to work properly,
3577 there had better be such an object.
3578 Hence, the type conversion will raise Constraint_Error if the value of
3579 the actual parameter is null.]}
3580 @end{Reason}
3581
3582 @ChgRef{Version=[2],Kind=[Added],ARef=[AI95-00231-01]}
3583 @ChgAdded{Version=[2],Text=[@Defn2{Term=[excludes null],Sec=[subtype]}
3584 A @nt{null_exclusion} in a construct specifies
3585 that the null value does not belong to the access subtype defined by the
3586 construct, that is, the access subtype @i{excludes null}. In addition, the
3587 anonymous access subtype defined by the @nt{access_definition} for a controlling
3588 access parameter (see @RefSecNum{Dispatching Operations of Tagged Types})
3589 excludes null. Finally, for a @nt{subtype_indication} without a
3590 @nt{null_exclusion}, the subtype denoted by the @nt{subtype_indication}
3591 excludes null if and only if the subtype denoted by the @nt{subtype_mark} in
3592 the @nt{subtype_indication} excludes null.]}
3593 @begin{Reason}
3594 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00231-01]}
3595 @ChgAdded{Version=[2],Text=[An @nt{access_definition} used in a controlling
3596 parameter excludes null because it is necessary to read the tag to
3597 dispatch, and null has no tag. We would have preferred to
3598 require @key{not null} to be specified for such
3599 parameters, but that would have been too incompatible with Ada 95 code
3600 to require.]}
3601
3602 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00416-01]}
3603 @ChgAdded{Version=[2],Text=[Note that we considered imposing a similar
3604 implicit null exclusion for controlling access results, but chose not to do
3605 that, because there is no Ada 95 compatibility issue, and there is no
3606 automatic null check inherent in the use of a controlling access result. If a
3607 null check is necessary, it is because there is a dereference of the result,
3608 or because the value is passed to a parameter whose subtype excludes null.
3609 If there is no dereference of the result, a null return value is perfectly
3610 acceptable, and can be a useful indication of a particular status of the
3611 call.]}
3612 @end{Reason}
3613
3614 @ChgRef{Version=[1],Kind=[Revised],Ref=[8652/0013],ARef=[AI95-00012-01]}
3615 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0264-1]}
3616 @PDefn2{Term=[constrained],Sec=(subtype)}
3617 @PDefn2{Term=[unconstrained],Sec=(subtype)}
3618 @Redundant[All subtypes of an access-to-subprogram type
3619 are constrained.] The first subtype of a type defined by
3620 an @Chg{New=[@nt<access_definition>],Old=[@nt<access_type_definition>]} or an
3621 @nt<access_to_object_definition> is unconstrained if the designated subtype
3622 is an unconstrained array or discriminated @Chg{New=[subtype],Old=[type]};
3623 otherwise@Chg{Version=[3],New=[,],Old=[]} it is constrained.
3624 @begin(TheProof)
3625 The @LegalityTitle on @nt<range_constraint>s (see @RefSecNum(Scalar Types))
3626 do not permit the @nt<subtype_mark> of the @nt<subtype_indication> to denote
3627 an access-to-scalar type, only a scalar type.
3628 The @LegalityTitle on @nt<index_constraint>s
3629 (see @RefSecNum(Index Constraints and Discrete Ranges)) and
3630 @nt<discriminant_constraint>s (see @RefSecNum(Discriminant Constraints))
3631 both permit access-to-composite types in a @nt<subtype_indication>
3632 with such _@nt<constraint>s. Note that an access-to-access-to-composite
3633 is never permitted in a @nt<subtype_indication> with a @nt<constraint>.
3634 @end(TheProof)
3635 @begin(Reason)
3636 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00363-01]}
3637 Only @nt<composite_constraint>s are permitted
3638 for an access type, and only
3639 on access-to-composite types.
3640 A constraint on an access-to-scalar or access-to-access type
3641 might be violated due to assignments
3642 via other access paths that were not so constrained. By contrast,
3643 if the designated subtype is an array or discriminated
3644 type@Chg{Version=[2],New=[ without defaults],Old=[]},
3645 the constraint could not be violated by unconstrained assignments,
3646 since array objects are always constrained, and
3647 @Chg{Version=[2],New=[],Old=[aliased]} discriminated objects are
3648 also constrained @Chg{Version=[2],New=[when the type does not have defaults
3649 for its discriminants. Constraints are not allowed on general access-to-unconstrained
3650 discriminated types if the type has defaults for its discriminants;
3651 constraints on pool-specific access types are usually allowed because
3652 allocated objects are usually constrained by their initial value.],
3653 Old=[(by fiat, see @StaticSemTitle).]}
3654 @end(Reason)
3655 @end{StaticSem}
3656
3657 @begin{Legality}
3658 @ChgRef{Version=[2],Kind=[Added],ARef=[AI95-00231-01]}
3659 @ChgAdded{Version=[2],Text=[If a
3660 @nt{subtype_@!indication}, @nt{discriminant_@!specification},
3661 @nt{parameter_@!specification}, @nt{parameter_@!and_@!result_@!profile},
3662 @nt{object_@!renaming_@!declaration}, or @nt{formal_@!object_@!declaration}
3663 has a @nt{null_@!exclusion}, the @nt{subtype_@!mark} in that construct
3664 shall denote an access subtype that does not exclude null.]}
3665 @begin(Honest)
3666 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00231-01]}
3667 @ChgAdded{Version=[2],Text=[This means @lquotes@;directly allowed in@rquotes;
3668 we are not talking about a @nt{null_exclusion} that occurs in an
3669 @nt{access_definition} in one of these constructs (for an
3670 @nt{access_definition}, the @nt{subtype_mark} in such an
3671 @nt{access_definition} is not restricted).]}
3672 @end(Honest)
3673 @begin(Reason)
3674 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00231-01]}
3675 @ChgAdded{Version=[2],Text=[This is similar to doubly constraining a
3676 composite subtype, which we also don't allow.]}
3677 @end(Reason)
3678 @end{Legality}
3679
3680 @begin{RunTime}
3681 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00231-01]}
3682 @PDefn2{Term=[compatibility],
3683 Sec=(composite_constraint with an access subtype)}
3684 A @nt<composite_constraint> is @i(compatible) with an unconstrained
3685 access subtype if it is compatible with the designated
3686 subtype.@Chg{Version=[2],New=[ A @nt{null_exclusion} is compatible with any
3687 access subtype that does not exclude null.],Old=[]}
3688 @PDefn2{Term=[satisfies], Sec=(for an access value)}
3689 An access value @i(satisfies) a @nt<composite_constraint> of an access
3690 subtype if it equals the null value of its type
3691 or if it designates an object whose value satisfies the
3692 constraint.@Chg{Version=[2],New=[ An access value satisfies an exclusion
3693 of the null value if it does not equal the
3694 null value of its type.],Old=[]}
3695
3696 @PDefn2{Term=[elaboration], Sec=(access_type_definition)}
3697 The elaboration of an @nt{access_type_definition}
3698 creates the access type and its first subtype.
3699 For an access-to-object type,
3700 this elaboration includes the elaboration of the @nt{subtype_indication},
3701 which creates the designated subtype.
3702
3703 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00230-01],ARef=[AI95-00254-01]}
3704 @PDefn2{Term=[elaboration], Sec=(access_definition)}
3705 The elaboration of an @nt{access_definition} creates
3706 an anonymous@Chg{Version=[2],New=[],Old=[ general]} access@Chg{Version=[2],
3707 New=[],Old=[-to-variable]} type@Chg{Version=[2],New=[],
3708 Old=[ @Redundant[(this happens as part of the initialization of
3709 an access parameter or access discriminant)]]}.
3710 @end{RunTime}
3711
3712 @begin{Notes}
3713 Access values are called @lquotes@;pointers@rquotes@; or @lquotes@;references@rquotes@; in
3714 some other languages.
3715
3716 Each access-to-object type has an associated storage pool;
3717 several access types can share the same pool.
3718 An object can be created in the storage pool of an
3719 access type by an @nt{allocator} (see @RefSecNum{Allocators})
3720 for the access type.
3721 A storage pool (roughly) corresponds to what some other languages
3722 call a @lquotes@;heap.@rquotes@;
3723 See @RefSecNum{Storage Management} for a discussion of pools.
3724
3725 Only @nt<index_constraint>s and @nt<discriminant_constraint>s
3726 can be applied to access types
3727 (see @RefSecNum{Index Constraints and Discrete Ranges} and
3728 @RefSecNum{Discriminant Constraints}).
3729 @end{Notes}
3730
3731 @begin{Examples}
3732 @Leading@keepnext@i{Examples of access-to-object types:}
3733 @begin{Example}
3734 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00433-01]}
3735 @ChgRef{Version=[4],Kind=[Revised],ARef=[AI12-0056-1]}
3736 @Chg{Version=[4],New=[@key[type] Frame @key<is access> Matrix; --@RI[ see @RefSecNum{Array Types}]
3737 ],Old=[]}@key[type] Peripheral_Ref @key<is @Chg{Version=[2],New=[not null ],Old=[]}access> Peripheral; --@RI[ see @RefSecNum{Variant Parts and Discrete Choices}]
3738 @key[type] Binop_Ptr @key[is access all] Binary_Operation'Class;
3739 --@RI[ general access-to-class-wide, see @RefSecNum{Type Extensions}]
3740 @end{Example}
3741
3742 @begin{WideAbove}
3743 @leading@keepnext@i{Example of an access subtype:}
3744 @end{WideAbove}
3745 @begin{Example}
3746 @key[subtype] Drum_Ref @key[is] Peripheral_Ref(Drum); --@RI[ see @RefSecNum{Variant Parts and Discrete Choices}]
3747 @end{Example}
3748
3749 @begin{WideAbove}
3750 @leading@keepnext@i{Example of an access-to-subprogram type:}
3751 @end{WideAbove}
3752 @begin{Example}
3753 @key[type] Message_Procedure @key[is] @key[access] @key[procedure] (M : @key[in] String := "Error!");
3754 @key[procedure] Default_Message_Procedure(M : @key[in] String);
3755 Give_Message : Message_Procedure := Default_Message_Procedure'Access;
3756 ...
3757 @key[procedure] Other_Procedure(M : @key[in] String);
3758 ...
3759 Give_Message := Other_Procedure'Access;
3760 ...
3761 Give_Message("File not found."); --@RI{ call with parameter (.@key[all] is optional)}
3762 Give_Message.@key[all]; --@RI{ call with no parameters}
3763 @end{Example}
3764 @end{Examples}
3765
3766 @begin{Extend83}
3767 @Defn{extensions to Ada 83}
3768 The syntax for @nt{access_type_definition} is
3769 changed to support general access
3770 types (including access-to-constants) and access-to-subprograms.
3771 The syntax rules for @nt{general_access_modifier} and
3772 @nt{access_definition} are new.
3773 @end{Extend83}
3774
3775 @begin{DiffWord83}
3776 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0190-1]}
3777 We use the term "storage pool" to talk about the data area from which
3778 allocation takes place. The term "collection" is @Chg{Version=[3],New=[only
3779 used for finalization],Old=[no longer used]}. ("Collection" and "storage pool"
3780 are not the same thing because multiple unrelated access types can share the
3781 same storage pool; see @RefSecNum(Storage Management) for more discussion.)
3782 @end{DiffWord83}
3783
3784 @begin{Inconsistent95}
3785 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00231-01]}
3786 @ChgAdded{Version=[2],Text=[@Defn{inconsistencies with Ada 95}
3787 Access discriminants and noncontrolling access parameters no longer
3788 exclude null. A program which passed @key{null} to such an access
3789 discriminant or access parameter and expected it to raise Constraint_Error
3790 may fail @ChgNote{but not if the parameter is dereferenced in the subprogram or
3791 record }when compiled with Ada 2005. One hopes that there no such programs
3792 outside of the ACATS. (Of course, a program which actually wants to pass
3793 @key{null} will work, which is far more likely.)]}
3794
3795 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00363-01]}
3796 @ChgAdded{Version=[2],Text=[Most unconstrained aliased objects
3797 with defaulted discriminants are no longer
3798 constrained by their initial values. This means that a program that
3799 raised Constraint_Error from an attempt to change the discriminants
3800 will no longer do so. The change only affects programs that depended
3801 on the raising of Constraint_Error in this case, so the inconsistency
3802 is unlikely to occur outside of the ACATS. This change may however cause
3803 compilers to implement these objects differently, possibly taking additional
3804 memory or time. This is unlikely to be worse than the differences caused by
3805 any major compiler upgrade.]}
3806 @end{Inconsistent95}
3807
3808 @begin{Incompatible95}
3809 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00225-01]}
3810 @ChgAdded{Version=[2],Text=[@Defn{incompatibilities with Ada 95}
3811 @B[Amendment Correction:] The rule defining when a current instance of a
3812 limited type is considered to be aliased has been tightened to apply only to
3813 types that cannot become nonlimited. A program that attempts to take 'Access
3814 of the current instance of a limited type that can become nonlimited will be
3815 illegal in Ada 2005. While original Ada 95 allowed the current instance of
3816 any limited type to be treated as aliased, this was inconsistently
3817 implemented in compilers, and was likely to not work as expected for types
3818 that are ultimately nonlimited.]}
3819
3820 @ChgRef{Version=[5],Kind=[AddedNormal],ARef=[AI12-0289-1]}
3821 @ChgAdded{Version=[5],Text=[@B[Correction:] Static matching (see
3822 @RefSecNum{Statically Matching Constraints and Subtypes}) requires that both
3823 anonymous access types exclude null; and full conformance requires statically
3824 matching subtypes. Because of the definition of @ldquote@;excludes null@rdquote
3825 given in this subclause, an access parameter that designates an untagged
3826 private type P (which does not exclude null) does not match its completion if
3827 P is completed with a tagged type (in that case, the parameter is controlling
3828 and thus excludes null, regardless of whether there is an explicit null
3829 exclusion on the body). Similar considerations apply in contexts where mode
3830 conformance and subtype conformance are required (for instance, subprogram
3831 renaming).]}
3832 @end{Incompatible95}
3833
3834 @begin{Extend95}
3835 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00231-01]}
3836 @Chg{Version=[2],New=[@Defn{extensions to Ada 95}The @nt{null_exclusion} is
3837 new. It can be used in both anonymous and named access type definitions.
3838 It is most useful to declare that parameters cannot be @key{null},
3839 thus eliminating the need for checks on use.],Old=[]}
3840
3841 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00231-01],ARef=[AI95-00254-01],ARef=[AI95-00404-01]}
3842 @Chg{Version=[2],New=[The kinds of anonymous
3843 access types allowed were increased by adding anonymous access-to-constant
3844 and anonymous access-to-subprogram types. Anonymous access-to-subprogram
3845 types used as parameters allow passing of subprograms at any level.],Old=[]}
3846 @end{Extend95}
3847
3848 @begin{DiffWord95}
3849 @ChgRef{Version=[2],Kind=[AddedNormal],Ref=[8652/0012],ARef=[AI95-00062-01]}
3850 @ChgAdded{Version=[2],Text=[@b<Corrigendum:> Added accidentally-omitted
3851 wording that says that a derived access type shares its storage pool with its
3852 parent type. This was clearly intended, both because of a note in
3853 @RefSecNum{Derived Types and Classes}, and because anything else would
3854 have been incompatible with Ada 83.]}
3855
3856 @ChgRef{Version=[2],Kind=[AddedNormal],Ref=[8652/0013],ARef=[AI95-00012-01]}
3857 @ChgAdded{Version=[2],Text=[@b<Corrigendum:> Fixed typographical errors in
3858 the description of when access types are constrained.]}
3859
3860 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00230-01]}
3861 @ChgAdded{Version=[2],Text=[The wording was fixed to allow @nt{allocator}s and
3862 the literal @key{null} for anonymous access types. The former was clearly
3863 intended by Ada 95; see the @ImplAdviceTitle in @RefSecNum{Storage Management}.]}
3864
3865 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00363-01]}
3866 @ChgAdded{Version=[2],Text=[The rules about aliased objects being constrained by
3867 their initial values now apply only to allocated objects, and thus have
3868 been moved to @RefSec{Allocators}.]}
3869 @end{DiffWord95}
3870
3871 @begin{DiffWord2005}
3872 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0053-1],ARef=[AI05-0277-1]}
3873 @ChgAdded{Version=[3],Text=[@b<Correction:> The rule about a current instance
3874 being aliased now is worded in terms of immutably limited types.
3875 Wording was also added to make extended return object declarations that have the
3876 keyword @key[aliased] be considered aliased. This latter was a significant
3877 oversight in Ada 2005 @em technically, the keyword @key[aliased] had no
3878 effect. But of course implementations followed the intent, not the letter of
3879 the Standard.]}
3880
3881 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0142-4]}
3882 @ChgAdded{Version=[3],Text=[Explicitly aliased parameters (see
3883 @RefSecNum{Subprogram Declarations}) are defined to be aliased.]}
3884 @end{DiffWord2005}
3885
3886 @begin{Extend2012}
3887 @ChgRef{Version=[5],Kind=[AddedNormal],ARef=[AI12-0228-1]}
3888 @ChgAdded{Version=[5],Text=[@Defn{extensions to Ada 2012}@b<Correction:>
3889 A @nt{qualified_expression} of an aliased object
3890 is now also aliased.]}
3891 @end{Extend2012}
3892
3893
3894 @LabeledSubClause{Incomplete Type Declarations}
3895
3896 @begin{Intro}
3897 There are no particular limitations on the designated type of an
3898 access type. In particular, the type of a component of the
3899 designated type can be another access type, or even the same access
3900 type. This permits mutually dependent and recursive access types.
3901 An @nt<incomplete_type_declaration> can be used to introduce a type
3902 to be used as a designated type, while deferring its full definition
3903 to a subsequent @nt<full_type_declaration>.
3904 @end{Intro}
3905
3906 @begin{Syntax}
3907 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00326-01]}
3908 @Syn{lhs=<incomplete_type_declaration>,
3909 rhs="@key{type} @Syn2{defining_identifier} [@Syn2{discriminant_part}]@Chg{Version=[2],New=< [@key{is tagged}]>,Old=<>};"}
3910 @end{Syntax}
3911
3912 @begin{StaticSem}
3913 @ChgRef{Version=[2],Kind=[Added],ARef=[AI95-00326-01]}
3914 @ChgRef{Version=[4],Kind=[RevisedAdded],ARef=[AI12-0137-1]}
3915 @ChgAdded{Version=[2],Text=[@Defn{incomplete type}@Defn{incomplete view}
3916 An @nt{incomplete_type_declaration} declares
3917 an @i{incomplete view} of a
3918 type and its first subtype; the first subtype is unconstrained if
3919 a @nt<discriminant_part> appears. If the
3920 @nt{incomplete_@!type_@!declaration} includes the reserved word @key{tagged}, it
3921 declares a @i{tagged incomplete view}.@Defn2{Term=[incomplete view],Sec=[tagged]}@Defn{tagged incomplete view}
3922 @Chg{Version=[4],New=[If @i{T} denotes a tagged incomplete view, then
3923 @i{T}'Class denotes a tagged incomplete view. ],Old=[]}@Redundant[An incomplete
3924 view of a type is a limited view of the type (see @RefSecNum{Limited Types}).]]}
3925
3926 @ChgRef{Version=[2],Kind=[Added],ARef=[AI95-00326-01]}
3927 @ChgAdded{Version=[2],Type=[Leading],Text=[Given an access type @i{A} whose
3928 designated type @i{T} is
3929 an incomplete view, a dereference of a value of type @i{A} also
3930 has this incomplete view except when:]}
3931 @begin{Discussion}
3932 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0208-1]}
3933 @ChgAdded{Version=[3],Text=[Whether the designated type is an incomplete view
3934 (and thus whether this set of rules applies) is determined by the view of the
3935 type at the declaration of the access type; it does not change during the life
3936 of the type.]}
3937 @end{Discussion}
3938 @begin{Itemize}
3939 @ChgRef{Version=[2],Kind=[Added]}
3940 @Chg{Version=[2],New=[it occurs within the immediate scope of the completion
3941 of @i{T}, or],Old=[]}
3942
3943 @ChgRef{Version=[2],Kind=[Added]}
3944 @ChgRef{Version=[3],Kind=[RevisedAdded],ARef=[AI05-0208-1]}
3945 @ChgAdded{Version=[2],Text=[it occurs within the scope of a @nt{nonlimited_with_clause}
3946 that mentions a library package in whose visible part the completion of @i{T}
3947 is declared@Chg{Version=[3],New=[, or],Old=[.]}]}
3948
3949 @ChgRef{Version=[3],Kind=[Added],ARef=[AI05-0208-1]}
3950 @ChgAdded{Version=[3],Text=[it occurs within the scope of the completion
3951 of @i{T} and @i{T} is an incomplete view declared by an
3952 @nt{incomplete_type_declaration}.]}
3953 @end{Itemize}
3954
3955 @ChgRef{Version=[2],Kind=[Added]}
3956 @ChgRef{Version=[3],Kind=[RevisedAdded],ARef=[AI05-0162-1]}
3957 @ChgAdded{Version=[2],Text=[In these cases, the dereference has the
3958 @Chg{Version=[3],New=[],Old=[full ]}view
3959 of @i{T}@Chg{Version=[3],New=[
3960 visible at the point of the dereference],Old=[]}.]}
3961 @begin{Discussion}
3962 @ChgRef{Version=[2],Kind=[AddedNormal]}
3963 @ChgAdded{Version=[2],Type=[Leading],Text=[We need the @lquotes@;in
3964 whose visible part@rquotes@; rule so that the second rule doesn't trigger
3965 in the body of a package with a @key{with} of a child unit:]}
3966 @begin{Example}
3967 @ChgRef{Version=[2],Kind=[AddedNormal]}
3968 @Chg{Version=[2],New=[@Key{package} P @Key{is}
3969 @Key{private}
3970 @Key{type} T;
3971 @Key{type} PtrT @Key{is access} T;
3972 @Key{end} P;],Old=[]}
3973
3974 @ChgRef{Version=[2],Kind=[AddedNormal]}
3975 @Chg{Version=[2],New=[@Key{private package} P.C @Key{is}
3976 Ptr : PtrT;
3977 @Key{end} P.C;],Old=[]}
3978
3979 @ChgRef{Version=[2],Kind=[AddedNormal]}
3980 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0005-1]}
3981 @Chg{Version=[2],New=[@Key{with} P.C;
3982 @Key{package body} P @Key{is}
3983 -- @RI{Ptr.all'Size is not legal here, but @Chg{Version=[3],New=[we are within],Old=[it is in]} the scope}
3984 -- @RI{of a @nt{nonlimited_with_clause} @RI{for P.}}
3985 @Key{type} T @Key{is} ...
3986 -- @RI{Ptr.all'Size is legal here.}
3987 @Key{end} P;],Old=[]}
3988 @end{Example}
3989 @end{Discussion}
3990
3991 @ChgRef{Version=[2],Kind=[Added],ARef=[AI95-00412-01]}
3992 @ChgRef{Version=[3],Kind=[RevisedAdded],ARef=[AI05-0162-1],ARef=[AI05-0208-1]}
3993 @ChgAdded{Version=[2],Text=[Similarly, if a @nt{subtype_mark} denotes a
3994 @nt{subtype_declaration} defining a subtype of an incomplete view @i<T>, the
3995 @nt{subtype_mark} denotes an incomplete view except under the
3996 same @Chg{Version=[3],New=[three],Old=[two]}
3997 circumstances given above, in which case it denotes the
3998 @Chg{Version=[3],New=[],Old=[full ]}view of @i<T>@Chg{Version=[3],New=[ visible at the
3999 point of the @nt{subtype_mark}],Old=[]}.]}
4000 @end{StaticSem}
4001
4002 @begin{Legality}
4003 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0162-1]}
4004 @PDefn2{Term=[requires a completion], Sec=(@nt<incomplete_type_declaration>)}
4005 An @nt{incomplete_@!type_@!declaration} requires a completion, which shall
4006 be a @Chg{Version=[3],New=[@nt{type_@!declaration} other than an
4007 @nt{incomplete_@!type_@!declaration}],Old=[@nt{full_@!type_@!declaration}]}.
4008 @Redundant[If the @nt{incomplete_@!type_@!declaration} occurs immediately
4009 within either the visible part of a
4010 @nt{package_@!specification} or a @nt<declarative_@!part>,
4011 then the @Chg{Version=[3],New=[@nt{type_@!declaration}],
4012 Old=[@nt{full_@!type_@!declaration}]} shall occur later and immediately within this
4013 visible part or @nt<declarative_@!part>.
4014 If the @nt{incomplete_@!type_@!declaration} occurs
4015 immediately within the private part of a
4016 given @nt<package_@!specification>, then the
4017 @Chg{Version=[3],New=[@nt{type_@!declaration}],
4018 Old=[@nt{full_@!type_@!declaration}]} shall occur later and immediately
4019 within either the private part itself, or the @nt{declarative_@!part}
4020 of the corresponding @nt{package_@!body}.]
4021 @begin{TheProof}
4022 This is implied by the next AARM-only rule,
4023 plus the rules in @RefSec{Completions of Declarations}
4024 which require a completion to appear later and immediately within
4025 the same declarative region.
4026 @end{TheProof}
4027 @begin{Honest}
4028 If the @nt{incomplete_type_declaration} occurs immediately within
4029 the visible part of a @nt{package_specification},
4030 then the @Chg{Version=[3],New=[completing @nt{type_@!declaration}],
4031 Old=[@nt{full_@!type_@!declaration}]}
4032 shall occur immediately within this visible part.
4033 @end{Honest}
4034 @begin(Honest)
4035 If the implementation supports it, an
4036 @nt{incomplete_type_declaration} can be @Chg{Version=[3],New=[imported
4037 (using aspect Import, see @RefSecNum{Interfacing Aspects}), in which
4038 case no explicit completion is allowed],Old=[completed by a @nt{pragma}
4039 Import]}.
4040 @end(Honest)
4041
4042 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00326-01]}
4043 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0162-1]}
4044 @Chg{Version=[2],New=[If an @nt{incomplete_@!type_@!declaration} includes the
4045 reserved word @key{tagged}, then a @Chg{Version=[3],New=[@nt{type_@!declaration}],
4046 Old=[@nt{full_@!type_@!declaration}]} that completes
4047 it shall declare a tagged type. ],Old=[]}If an @nt{incomplete_@!type_@!declaration}
4048 has a @nt{known_@!discriminant_@!part},
4049 then a @Chg{Version=[3],New=[@nt{type_@!declaration}],
4050 Old=[@nt{full_@!type_@!declaration}]} that completes it shall have a fully
4051 conforming (explicit) @nt{known_@!discriminant_@!part}
4052 (see @RefSecNum(Conformance Rules)).
4053 @Defn2{Term=[full conformance],Sec=(required)}
4054 @Redundant[If an @nt{incomplete_@!type_@!declaration} has no @nt<discriminant_part>
4055 (or an @nt<unknown_@!discriminant_@!part>),
4056 then a corresponding @Chg{Version=[3],New=[@nt{type_@!declaration}],
4057 Old=[@nt{full_@!type_@!declaration}]} is nevertheless allowed
4058 to have discriminants, either explicitly, or inherited via derivation.]
4059
4060
4061 @Leading@keepnext@;@ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00326-01]}
4062 @Chg{Version=[2],New=[A],Old=[The only allowed uses of a]} @nt{name} that
4063 denotes an @Chg{Version=[2],New=[incomplete view of a type may be used],
4064 Old=[@nt{incomplete_type_declaration} are]} as follows:
4065 @begin(Discussion)
4066 @ChgRef{Version=[2],Kind=[DeletedNoDelMsg],ARef=[AI95-00326-01]}
4067 @ChgDeleted{Version=[2],Text=[No need to say "prior to the end of the
4068 @nt{full_type_declaration}" since the name would not denote the
4069 @nt{incomplete_type_declaration} after the end of the
4070 @nt{full_type_declaration}. Also, with child library units, it would not be
4071 well defined whether they come before or after the @nt<full_type_declaration>
4072 for deferred incomplete types.]}
4073 @end(Discussion)
4074 @begin(itemize)
4075 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0098-1]}
4076 as the @nt{subtype_mark} in the @nt{subtype_indication}
4077 of an @nt{access_to_@!object_@!definition};
4078 @Redundant[the only form of @nt{constraint} allowed in this
4079 @nt{subtype_indication} is a @nt{discriminant_constraint}@Chg{Version=[3],New=[
4080 @Redundant[(a @nt{null_exclusion} is not allowed)]],Old=[]};]
4081 @begin(ImplNote)
4082 We now allow @nt<discriminant_constraint>s even if the
4083 full type is deferred to the package body. However, there
4084 is no particular implementation burden because we have
4085 dropped the concept of the dependent compatibility check.
4086 In other words, we have effectively repealed AI83-00007.
4087 @end(ImplNote)
4088
4089 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00326-01],ARef=[AI95-00412-01]}@ChgNote{The old rule is moved}
4090 as the @nt{subtype_mark} @Chg{Version=[2],New=[in the @nt{subtype_indication}
4091 of a @nt{subtype_declaration}; the @nt{subtype_@!indication} shall not have a
4092 @nt{null_@!exclusion} or a @nt{constraint};],Old=[defining the subtype
4093 of a parameter or result of an @nt{access_to_@!subprogram_@!definition};]}
4094 @begin{Reason}
4095 @ChgRef{Version=[2],Kind=[DeletedNoDelMsg],ARef=[AI95-00326-01]}@ChgNote{Really moved}
4096 @ChgDeleted{Version=[2],Text=[This allows, for example, a record to have a
4097 component designating a subprogram that takes that same record
4098 type as a parameter.]}
4099 @end{Reason}
4100
4101 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00326-01]}
4102 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0151-1]}
4103 as the @nt<subtype_mark> in an
4104 @nt<access_definition>@Chg{Version=[2],New=[@Chg{Version=[3],New=[ for
4105 an access-to-object type;],Old=[.]}],Old=[;]}
4106 @begin{Honest}
4107 @ChgRef{Version=[2],Kind=[AddedNormal]}
4108 @ChgAdded{Version=[2],Text=[This does not mean any random @nt{subtype_mark}
4109 in a construct that makes up an @nt<access_definition>, such as
4110 a @nt<formal_part>, just the one given directly in the syntax of
4111 @nt<access_definition>.]}
4112 @end{Honest}
4113
4114 @ChgRef{Version=[3],Kind=[Added],ARef=[AI05-0151-1]}
4115 @ChgAdded{Version=[3],Text=[as the @nt{subtype_mark} defining the subtype
4116 of a parameter or result in a profile occurring within a
4117 @nt{basic_declaration};]}
4118 @begin{Ramification}
4119 @ChgRef{Version=[3],Kind=[AddedNormal]}
4120 @ChgAdded{Version=[3],Text=[But not in the profile for a body or entry.]}
4121 @end{Ramification}
4122
4123 @ChgRef{Version=[3],Kind=[Added],ARef=[AI05-0213-1]}
4124 @ChgAdded{Version=[3],Text=[as a generic actual parameter whose corresponding
4125 generic formal parameter is a formal incomplete type (see
4126 @RefSecNum{Formal Private and Derived Types}).]}
4127 @end{Itemize}
4128
4129 @ChgRef{Version=[2],Kind=[Added],ARef=[AI95-00326-01]}
4130 @ChgAdded{Version=[2],KeepNext=[T],Type=[Leading],Text=[If such a @nt{name}
4131 denotes a tagged incomplete view, it may also be used:]}
4132
4133 @begin{Itemize}
4134 @ChgRef{Version=[2],Kind=[Added],ARef=[AI95-00326-01]}
4135 @ChgRef{Version=[3],Kind=[RevisedAdded],ARef=[AI05-0151-1]}
4136 @ChgAdded{Version=[2],Text=[as the @nt{subtype_mark} defining the subtype of a
4137 parameter in @Chg{Version=[3],New=[the profile for a @nt{subprogram_body},
4138 @nt{entry_body}, or @nt{accept_statement}],Old=[a @nt{formal_part}]};]}
4139
4140 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00326-01]}
4141 as the @nt{prefix} of an @nt{attribute_reference}
4142 whose @nt{attribute_@!designator}
4143 is Class; such an @nt{attribute_@!reference}
4144 is @Chg{Version=[2],New=[],Old=[similarly ]}restricted to the uses
4145 allowed here;
4146 @Chg{Version=[2],New=[it denotes a tagged incomplete view],
4147 Old=[when used in this way,
4148 the corresponding @nt{full_type_@!declaration} shall
4149 declare a tagged type, and the @nt<attribute_@!reference>
4150 shall occur in the same library unit as
4151 the @nt<incomplete_@!type_@!declaration>]}.
4152 @begin{Reason}
4153 @ChgRef{Version=[2],Kind=[Deleted],ARef=[AI95-00326-01]}
4154 @ChgDeleted{Version=[2],Text=[This is to prevent
4155 children from imposing requirements on their ancestor library
4156 units for deferred incomplete types.]}
4157 @end{reason}
4158 @end(itemize)
4159
4160 @ChgRef{Version=[2],Kind=[Added],ARef=[AI95-00326-01]}
4161 @ChgRef{Version=[3],Kind=[DeletedAdded],ARef=[AI05-0151-1]}
4162 @ChgAdded{Version=[2],Type=[Leading],Text=[@Chg{Version=[3],New=[],Old=[If
4163 such a @nt{name} occurs within
4164 the declaration list containing the completion of the
4165 incomplete view, it may also be used:]}]}
4166
4167 @begin{Itemize}
4168 @ChgRef{Version=[2],Kind=[Added],ARef=[AI95-00326-01]}@ChgNote{Really moved}
4169 @ChgRef{Version=[3],Kind=[DeletedAdded],ARef=[AI05-0098-1],ARef=[AI05-0151-1]}@ChgNote{Now part of the next paragraph}
4170 @ChgAdded{Version=[2],Text=[@Chg{Version=[3],New=[],Old=[as the @nt{subtype_mark} defining the subtype of a
4171 parameter or result of an @nt{access_to_@!subprogram_@!definition}.]}]}
4172 @begin{Reason}
4173 @ChgRef{Version=[2],Kind=[AddedNormal]}
4174 @ChgRef{Version=[3],Kind=[Deleted]}
4175 @ChgAdded{Version=[2],Text=[@Chg{Version=[3],New=[],Old=[This allows,
4176 for example, a record to have a
4177 component designating a subprogram that takes that same record
4178 type as a parameter.]}]}
4179 @end{Reason}
4180 @end{Itemize}
4181
4182 @ChgRef{Version=[2],Kind=[Added],ARef=[AI95-00326-01]}
4183 @ChgAdded{Version=[2],Text=[If any of the above uses occurs as part of the
4184 declaration of a primitive subprogram of the incomplete view,
4185 and the declaration occurs immediately within the private part of a package, then
4186 the completion of the incomplete view shall also
4187 occur immediately within the private part; it shall not be deferred to the
4188 package body.]}
4189 @begin{Reason}
4190 @ChgRef{Version=[2],Kind=[AddedNormal]}
4191 @ChgAdded{Version=[2],Text=[This fixes a hole in Ada 95 where a dispatching
4192 operation with an access parameter could be declared in a private part
4193 and a dispatching call on it could occur in a child even though there is
4194 no visibility on the full type, requiring access to the controlling tag
4195 without access to the representation of the type.]}
4196 @end{Reason}
4197
4198 @ChgRef{Version=[2],Kind=[Added],ARef=[AI95-00326-01]}
4199 @ChgAdded{Version=[2],Text=[No other uses of a @nt{name} that denotes an
4200 incomplete view of a type are allowed.]}
4201
4202 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00326-01]}
4203 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0151-1]}
4204 @Chg{Version=[2],New=[A @nt{prefix} that denotes an object],
4205 Old=[A dereference (whether implicit or explicit @em see @RefSecNum(Names))]}
4206 shall not be of an incomplete @Chg{Version=[2],New=[view],Old=[type]}.@Chg{Version=[3],New=[
4207 An actual parameter in a call shall not be of an untagged incomplete
4208 view. The result object of a function call shall not be of an
4209 incomplete view. A @nt{prefix} shall not denote a subprogram
4210 having a formal parameter of an untagged incomplete view,
4211 nor a return type that is an incomplete view.],Old=[]}
4212 @begin{Reason}
4213 @ChgRef{Version=[2],Kind=[AddedNormal]}
4214 @ChgAdded{Version=[2],Text=[We used to disallow all dereferences of an incomplete
4215 type. Now we only disallow such dereferences when used as a @nt{prefix}.
4216 Dereferences used in other contexts do not pose a problem since normal type
4217 matching will preclude their use except when the full type is @lquotes@;nearby@rquotes@;
4218 as context (for example, as the expected type).]}
4219
4220 @ChgRef{Version=[2],Kind=[AddedNormal]}
4221 @ChgAdded{Version=[2],Text=[This also disallows @nt{prefix}es that are
4222 directly of an incomplete view. For instance, a parameter @i{P} can be
4223 declared of a tagged incomplete type, but we don't want to allow @i{P}'Size,
4224 @i{P}'Alignment, or the like, as representation values aren't known for an
4225 incomplete view.]}
4226
4227 @ChgRef{Version=[2],Kind=[AddedNormal]}
4228 @ChgAdded{Version=[2],Text=[We say @lquotes@;denotes an object@rquotes
4229 so that prefixes that directly name an incomplete view are not covered;
4230 the previous rules cover such cases, and we certainly don't want to ban
4231 Incomp'Class.]}
4232
4233 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0151-1]}
4234 @ChgAdded{Version=[3],Text=[As subprogram profiles now may include any
4235 kind of incomplete type, we also disallow passing objects of untagged
4236 incomplete types in subprogram calls (as the parameter passing method
4237 is not known as it is for tagged types) and disallow returning any
4238 sort of incomplete objects (since we don't know how big they are).]}
4239 @end{Reason}
4240
4241 @ChgRef{Version=[5],Kind=[Added],ARef=[AI12-0155-1]}
4242 @ChgAdded{Version=[5],Text=[The controlling operand or controlling result of
4243 a dispatching call shall not be of an incomplete view if the operand or result
4244 is dynamically tagged.]}
4245
4246 @begin{Reason}
4247 @ChgRef{Version=[5],Kind=[AddedNormal]}
4248 @ChgAdded{Version=[5],Type=[Leading],Text=[This rule is needed to prevent
4249 the following case:]}
4250
4251 @begin{Example}
4252 @ChgRef{Version=[5],Kind=[AddedNormal]}
4253 @ChgAdded{Version=[5],Text=[@key[package] Pack @key[is]
4254 @key[type] T @key[is tagged];
4255 @key[function] F @key[return access] T'Class;
4256 @key[function] G (X : @key[access] T) @key[return] Integer;
4257 I : Integer := G (F); -- @RI{Illegal by above rule.}
4258 @key[type] T @key[is tagged null record];
4259 @key[end] Pack;]}
4260 @end{Example}
4261
4262 @ChgRef{Version=[5],Kind=[AddedNormal]}
4263 @ChgAdded{Version=[5],Text=[If this was not illegal, the compiler would
4264 have to generate a dispatching call on G without necessarily knowing where
4265 the tag of type T is stored (the completion of T might not be until the
4266 body of Pack). The fact that any such call will raise Program_Error does
4267 not absolve us of detecting the problem; see the @MetaRulesTitle
4268 in @RefSecNum{Freezing Rules}.]}
4269 @end{Reason}
4270
4271 @end{Legality}
4272
4273 @begin{StaticSem}
4274 @ChgRef{Version=[2],Kind=[DeletedNoDelMsg],ARef=[AI95-00326-01]}
4275 @ChgDeleted{Version=[2],Text=[@Defn{incomplete type}
4276 An @nt{incomplete_type_declaration} declares an incomplete
4277 type and its first subtype; the first subtype is unconstrained if
4278 a @nt<known_discriminant_part> appears.]}
4279 @begin{Reason}
4280 @ChgRef{Version=[2],Kind=[DeletedNoDelMsg]}
4281 @ChgDeleted{Version=[2],Text=[If an @nt<unknown_discriminant_part> or
4282 no @nt{discriminant_part}
4283 appears, then the constrainedness of the first subtype doesn't matter
4284 for any other rules or semantics, so we don't bother defining it.
4285 The case with a @nt<known_discriminant_part> is the only case in which
4286 a constraint could later be given in a @nt{subtype_indication} naming
4287 the incomplete type.]}
4288 @end{Reason}
4289 @end{StaticSem}
4290 @begin{NotIso}
4291 @ChgAdded{Version=[2],Noparanum=[T],Text=[@Shrink{@i<Paragraph 11 was
4292 deleted.>}]}@Comment{This message should be deleted if the paragraphs
4293 are ever renumbered.}
4294 @end{NotIso}
4295
4296 @begin{RunTime}
4297 @PDefn2{Term=[elaboration], Sec=(incomplete_type_declaration)}
4298 The elaboration of an @nt{incomplete_type_declaration} has no effect.
4299 @begin(Reason)
4300 An incomplete type has no real existence, so it doesn't need to be
4301 "created" in the usual sense we do for other types.
4302 It is roughly equivalent to a "forward;" declaration in Pascal.
4303 Private types are different, because they have a different
4304 set of characteristics from their full type.
4305 @end(Reason)
4306 @end{RunTime}
4307
4308 @begin{Notes}
4309 @PDefn{completion legality}
4310 Within a @nt<declarative_part>, an @nt<incomplete_type_declaration>
4311 and a corresponding @nt<full_type_declaration> cannot be separated
4312 by an intervening body.
4313 This is because a type has to
4314 be completely defined before it is frozen, and a body freezes
4315 all types declared prior to it in the same @nt<declarative_part>
4316 (see @RefSecNum{Freezing Rules}).
4317
4318 @ChgRef{Version=[3],Kind=[Added],ARef=[AI05-0151-1],ARef=[AI05-0269-1]}
4319 @ChgAdded{Version=[3],Text=[A @nt{name} that denotes an object of an
4320 incomplete view is defined to be of a limited type. Hence, the target of
4321 an assignment statement cannot be of an incomplete view.]}
4322
4323 @end{Notes}
4324
4325 @begin{Examples}
4326 @Leading@keepnext@i(Example of a recursive type:)
4327 @begin(Example)
4328 @key(type) Cell; --@RI[ incomplete type declaration]
4329 @key(type) Link @key(is) @key(access) Cell;
4330
4331 @key(type) Cell @key(is)
4332 @key(record)
4333 Value : Integer;
4334 Succ : Link;
4335 Pred : Link;
4336 @key(end) @key(record);
4337
4338 Head : Link := @key(new) Cell'(0, @key(null), @key(null));
4339 Next : Link := Head.Succ;
4340 @end(Example)
4341
4342 @i(Examples of mutually dependent access types:)
4343 @begin(Example)
4344 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00433-01]}
4345 @key(type) Person(<>); --@RI[ incomplete type declaration]
4346 @key(type) Car@Chg{Version=[2],New=[ @key{is tagged};],Old=[; ]} --@RI[ incomplete type declaration]
4347
4348 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00433-01]}
4349 @key(type) Person_Name @key(is) @key(access) Person;
4350 @key(type) Car_Name @key(is) @key(access) @key(all) Car@Chg{Version=[2],New=['Class],Old=[]};
4351
4352 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00433-01]}
4353 @key(type) Car @key(is)@Chg{Version=[2],New=[ @key(tagged)],Old=[]}
4354 @key(record)
4355 Number : Integer;
4356 Owner : Person_Name;
4357 @key(end) @key(record);
4358
4359
4360 @key(type) Person(Sex : Gender) @key(is)
4361 @key(record)
4362 Name : String(1 .. 20);
4363 Birth : Date;
4364 Age : Integer @key(range) 0 .. 130;
4365 Vehicle : Car_Name;
4366 @key(case) Sex @key(is)
4367 @key(when) M => Wife : Person_Name(Sex => F);
4368 @key(when) F => Husband : Person_Name(Sex => M);
4369 @key(end) @key(case);
4370 @key(end) @key(record);
4371
4372 @ChgRef{Version=[5],Kind=[Revised],ARef=[AI12-0312-1]}
4373 My_Car, Your_Car, Next_Car : Car_Name := @key[new] Car; --@RI[ see @RefSecNum{Allocators}]
4374 @Chg{Version=[5],New=[Casey],Old=[George]} : Person_Name := @key[new] Person(M);
4375 ...
4376 @Chg{Version=[5],New=[Casey],Old=[George]}.Vehicle := Your_Car;
4377 @end(Example)
4378
4379 @end{Examples}
4380
4381 @begin{Extend83}
4382 @Defn{extensions to Ada 83}
4383 The @nt{full_type_declaration} that completes an
4384 @nt{incomplete_type_declaration} may have a
4385 @nt{known_discriminant_part} even if the
4386 @nt{incomplete_type_declaration} does not.
4387
4388 @ChgRef{Version=[1],Kind=[Revised]}@ChgNote{Presentation AI-00013}
4389 A @nt<discriminant_constraint> may be applied
4390 to an incomplete type, even if @Chg{New=[],Old=[it ]}its completion is
4391 deferred to the package body, because there is no
4392 @lquotes@;dependent compatibility check@rquotes@; required any more.
4393 Of course, the constraint can be specified only if
4394 a @nt<known_discriminant_part> was given in the
4395 @nt<incomplete_type_declaration>. As mentioned in the previous
4396 paragraph, that is no longer required even when the full type
4397 has discriminants.
4398 @end{Extend83}
4399
4400 @begin{DiffWord83}
4401 @Leading@;Dereferences producing incomplete types
4402 were not explicitly disallowed in RM83, though
4403 AI83-00039 indicated that it was not strictly necessary since
4404 troublesome cases would result in Constraint_Error at run time,
4405 since the access value would necessarily be null.
4406 However, this introduces an undesirable implementation burden,
4407 as illustrated by Example 4 of AI83-00039:
4408 @begin{example}
4409 @key[package] Pack @key[is]
4410 @key[type] Pri @key[is] @key[private];
4411 @key[private]
4412 @key[type] Sep;
4413 @key[type] Pri @key[is] @key[access] Sep;
4414 X : Pri;
4415 @key[end] Pack;
4416
4417 @key[package] @key[body] Pack @key[is] --@RI{ Could be separately compiled!}
4418 @key[type] Sep @key[is] ...;
4419 X := @key[new] Sep;
4420 @key[end] Pack;
4421
4422 @key[pragma] Elaborate(Pack);
4423 @key[private] @key[package] Pack.Child @key[is]
4424 I : Integer := X.@key{all}'Size; --@RI{ Legal, by AI-00039.}
4425 @key[end] Pack.Child;
4426 @end{example}
4427
4428 Generating code for the above example could be a serious implementation
4429 burden, since it would require all aliased objects to store size dope,
4430 and for that dope to be in the same format for all kinds of types
4431 (or some other equivalently inefficient implementation).
4432 On the contrary, most implementations allocate dope differently (or
4433 not at all) for different designated subtypes.
4434 @end{DiffWord83}
4435
4436 @begin{Incompatible95}
4437 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00326-01]}
4438 @ChgAdded{Version=[2],Text=[@Defn{incompatibilities with Ada 95}
4439 It is now illegal to use an incomplete view (type) as the parameter or result
4440 of an access-to-subprogram type unless the incomplete view is completed in
4441 the same declaration list as the use. This was allowed in Ada 95 for
4442 incomplete types where the completion was deferred to the body. By
4443 disallowing this rare use of incomplete views, we can allow the use of
4444 incomplete views in many more places, which is especially valuable for
4445 limited views.]}
4446
4447 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00326-01]}
4448 @ChgAdded{Version=[2],Text=[It is now illegal to use an incomplete view
4449 (type) in a primitive subprogram of the type unless the incomplete view is
4450 completed in the package specification. This was allowed in Ada 95 for
4451 incomplete types where the completion was deferred to the body (the use would
4452 have to be in an access parameter). This incompatibility was caused by the
4453 fix for the hole noted in @LegalityTitle above.]}
4454 @end{Incompatible95}
4455
4456 @begin{Extend95}
4457 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00326-01]}
4458 @ChgAdded{Version=[2],Text=[@Defn{extensions to Ada 95}Tagged incomplete types
4459 are new. They are allowed in parameter declarations as well as the usual
4460 places, as tagged types are always by-reference types (and thus there can
4461 be no code generation issue).]}
4462
4463 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00412-01]}
4464 @ChgAdded{Version=[2],Text=[A @nt{subtype_declaration} can be used to
4465 give a new name to an incomplete view of a type. This is valuable to
4466 give shorter names to entities imported with a @nt{limited_with_clause}.]}
4467 @end{Extend95}
4468
4469 @begin{DiffWord95}
4470 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00326-01]}
4471 @ChgAdded{Version=[2],Text=[The description of incomplete types as
4472 @i{incomplete views} is new. Ada 95 defined these as separate types, but
4473 neglected to give any rules for matching them with other types. Luckily,
4474 implementers did the right thing anyway. This change also makes it easier to
4475 describe the meaning of a limited view.]}
4476 @end{DiffWord95}
4477
4478 @begin{Extend2005}
4479 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0098-1]}
4480 @ChgAdded{Version=[3],Text=[@Defn{extensions to Ada 2005}@b<Correction:>
4481 Fixed the definition so that an anonymous access-to-subprogram type can use an
4482 incomplete view in the same way that a named access-to-subprogram type can.]}
4483
4484 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0151-1]}
4485 @ChgAdded{Version=[3],Text=[Incomplete types now can be used
4486 in subprogram declarations. The type has to be complete before any calls
4487 or the body is declared. This reduces the places where access types are
4488 required for types imported from limited views of packages.]}
4489
4490 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0162-1]}
4491 @ChgAdded{Version=[3],Text=[Incomplete types now can be
4492 completed by private types and private extensions. Since this can already
4493 happen for limited views, there is no remaining reason to disallow it for
4494 explicitly declared incomplete types.]}
4495 @end{Extend2005}
4496
4497 @begin{DiffWord2005}
4498 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0208-1]}
4499 @ChgAdded{Version=[3],Text=[@b<Correction:> Changed the
4500 rules of uses of dereferences of incomplete views such that it does not
4501 introduce an unintentional incompatibility with Ada 83 and Ada 95.]}
4502
4503 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0213-1]}
4504 @ChgAdded{Version=[3],Text=[Incomplete types now can be used as actuals to
4505 formal incomplete types (see @RefSecNum{Formal Private and Derived Types}).]}
4506 @end{DiffWord2005}
4507
4508 @begin{DiffWord2012}
4509 @ChgRef{Version=[4],Kind=[AddedNormal],ARef=[AI12-0137-1]}
4510 @ChgRef{Version=[5],Kind=[Revised],ARef=[AI12-0005-1]}
4511 @ChgAdded{Version=[4],Text=[@b<Corrigendum:> Changed the wording to clarify
4512 that the class-wide type associated with a specific tagged type that has
4513 an incomplete view is also an incomplete view.
4514 While this was previously undefined, an interpretation where it is not
4515 an incomplete view @Chg{Version=[5],New=[],Old=[is ]}leads to semantic
4516 nonsense, and thus we don't consider
4517 this a potential incompatibility, as compilers most likely are doing the
4518 right thing.]}
4519
4520 @ChgRef{Version=[5],Kind=[AddedNormal],ARef=[AI12-0155-1]}
4521 @ChgAdded{Version=[5],Text=[@b<Correction:> Added a rule preventing a
4522 dispatching call on an incomplete type before the completion. This is
4523 not an incompatibility as previously this was prevented by the freezing
4524 rules. However, that violated the intended design of the freezing rules,
4525 so we've now changed to an explicit @LegalityName here, and eliminated the
4526 associated freezing rules.]}
4527 @end{DiffWord2012}
4528
4529
4530 @LabeledSubClause{Operations of Access Types}
4531
4532 @begin{Intro}
4533 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0299-1]}
4534 @Redundant[The attribute Access is used to create access values
4535 designating aliased objects and nonintrinsic subprograms.
4536 The @lquotes@;accessibility@rquotes@; rules prevent dangling references
4537 (in the absence of uses of certain unchecked features
4538 @em see @Chg{Version=[3],New=[Clause],Old=[Section]}
4539 @RefSecNum{Representation Issues}).]
4540 @end{Intro}
4541
4542 @begin{MetaRules}
4543 It should be possible for an access value to designate an object
4544 declared by an object declaration, or a subcomponent thereof.
4545 In implementation terms, this means pointing at stack-allocated and
4546 statically allocated data structures.
4547 However, dangling references should be prevented, primarily via
4548 compile-time rules, so long as features like Unchecked_Access and
4549 Unchecked_Deallocation are not used.
4550
4551 In order to create such access values, we require that the access type be a
4552 general access type, that the designated object be aliased,
4553 and that the accessibility rules be obeyed.
4554 @end{MetaRules}
4555
4556 @begin{Resolution}
4557 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00235-01]}
4558 @PDefn2{Term=[expected type], Sec=(access attribute_reference)}
4559 For an @nt<attribute_reference> with @nt<attribute_designator>
4560 Access (or Unchecked_Access @em see @RefSecNum(Unchecked Access Value Creation)),
4561 the expected type shall be a single
4562 access type@Chg{Version=[2],New=[ @i<A> such that:],Old=[@Redundant[; the
4563 @nt<prefix> of such an @nt<attribute_reference>
4564 is never interpreted as an @nt<implicit_dereference>].
4565 @PDefn2{Term=[expected profile],
4566 Sec=(Access @nt<attribute_reference> @nt<prefix>)}
4567 If the expected type is an access-to-subprogram type,
4568 then the expected profile of the @nt<prefix> is the
4569 designated profile of the access type.]}
4570 @begin{Itemize}
4571 @ChgRef{Version=[2],Kind=[Added],ARef=[AI95-00235-01]}
4572 @Chg{Version=[2],New=[@i{A} is an access-to-object type with designated type
4573 @i{D} and the type of the @nt{prefix} is @i{D}'Class or is covered by @i{D}, or],Old=[]}
4574
4575 @ChgRef{Version=[2],Kind=[Added],ARef=[AI95-00235-01]}
4576 @Chg{Version=[2],New=[@i{A} is an access-to-subprogram type whose designated
4577 profile is type conformant with that of the prefix.],Old=[]}
4578 @end{Itemize}
4579
4580 @ChgRef{Version=[2],Kind=[Added],ARef=[AI95-00235-01]}
4581 @Chg{Version=[2],New=[@Redundant[The @nt{prefix} of such an
4582 @nt{attribute_reference} is never interpreted as an @nt{implicit_dereference}
4583 or a parameterless @nt{function_call} (see @RefSecNum{Attributes}).]
4584 @PDefn2{Term=[expected profile],
4585 Sec=(Access @nt<attribute_reference> @nt<prefix>)}
4586 @PDefn2{Term=[expected type],
4587 Sec=(Access @nt<attribute_reference> @nt<prefix>)}
4588 The designated type or profile of the expected type of the @nt{attribute_reference}
4589 is the expected type or profile for the @nt{prefix}.],Old=[]}
4590 @begin(Discussion)
4591 Saying that the expected type shall be a "single access type"
4592 is our "new" way of saying that the type has to be determinable from
4593 context using only the fact that it is an access type.
4594 See @RefSecNum{Literals} and @RefSecNum{The Context of Overload Resolution}.
4595 Specifying the expected profile only implies type conformance.
4596 The more stringent subtype conformance is required by a Legality
4597 Rule. This is the only Resolution Rule that applies to the
4598 @nt<name> in a @nt{prefix} of an @nt{attribute_reference}.
4599 In all other cases, the @nt{name} has to be resolved without
4600 using context. See @RefSecNum{Attributes}.
4601
4602 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00235-01]}
4603 @ChgAdded{Version=[2],Type=[Leading],Text=[Saying @lquotes@;single access
4604 type@rquotes@; is a bit of a fudge. Both the context and the @nt{prefix} may
4605 provide both multiple types; @lquotes@;single@rquotes@; only means that a
4606 single, specific interpretation must remain after resolution. We say
4607 @lquotes@;single@rquotes@; here to trigger the @LegalityTitle of
4608 @RefSecNum{The Context of Overload Resolution}. The resolution of an access
4609 attribute is similar to that of an @nt{assignment_statement}. For example:]}
4610 @begin{Example}
4611 @ChgRef{Version=[2],Kind=[AddedNormal]}
4612 @Chg{Version=[2],New=[@key{type} Int_Ptr @key{is access all} Integer;
4613 @key{type} Char_Ptr @key{is access all} Character;
4614 @key{type} Float_Ptr @key{is access all} Float;],Old=[]}
4615
4616 @ChgRef{Version=[2],Kind=[AddedNormal]}
4617 @Chg{Version=[2],New=[@key{function} Zap (Val : Int_Ptr) @key{return} Float; -- @RI[(1)]
4618 @key{function} Zap (Val : Float_Ptr) @key{return} Float; -- @RI[(2)]
4619 @key{function} Zop @key{return} Int_Ptr; -- @RI[(3)]
4620 @key{function} Zop @key{return} Char_Ptr; -- @RI[(4)]],Old=[]}
4621
4622 @ChgRef{Version=[2],Kind=[AddedNormal]}
4623 @Chg{Version=[2],New=[Result : Float := Zap (Zop.@key{all}'Access); -- @RI[Resolves to Zap (1) and Zop (3).]],Old=[]}
4624 @end{Example}
4625 @end(Discussion)
4626 @end{Resolution}
4627
4628 @begin{StaticSem}
4629
4630 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00162-01]}
4631 @Defn{accessibility level}
4632 @Defn2{Term=[level],Sec=(accessibility)}
4633 @Defn2{Term=[deeper],Sec=(accessibility level)}
4634 @Defn2{Term=[depth],Sec=(accessibility level)}
4635 @Defn2{Term=[dangling references],Sec=(prevention via accessibility rules)}
4636 @Defn{lifetime}
4637 @Redundant[The accessibility rules,
4638 which prevent dangling references,
4639 are written in terms of @i{accessibility levels},
4640 which reflect the run-time nesting of @i{masters}. As explained in
4641 @RefSecNum{Completion and Finalization},
4642 a master is the execution of a
4643 @Chg{Version=[2],New=[certain construct, such as],Old=[,@nt{task_body}, a @nt{block_statement},]}
4644 a @nt{subprogram_body}@Chg{Version=[2],New=[],Old=[, an @nt{entry_body}, or an @nt{accept_statement}]}.
4645 An accessibility level is @i{deeper than} another if it is more
4646 deeply nested at run time.
4647 For example, an object declared local to a called subprogram has a deeper
4648 accessibility level than an object declared local to the calling
4649 subprogram.
4650 The accessibility rules for access types require that the
4651 accessibility level of an object designated by an access value be no
4652 deeper than that of the access type.
4653 This ensures that the object will live at least as long as the access
4654 type, which in turn ensures that the access value cannot later
4655 designate an object that no longer exists.
4656 The Unchecked_Access attribute may be used to circumvent the
4657 accessibility rules.]
4658
4659 @begin{Discussion}
4660 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0005-1]}
4661 @ChgAdded{Version=[3],Text=[The Unchecked_Access attribute acts as if the
4662 object was declared at library-level; this applies even when it is used as the
4663 value of anonymous access type.
4664 See @RefSecNum{Unchecked Access Value Creation}.]}
4665
4666 @ChgRef{Version=[3],Kind=[AddedNormal]}
4667 @ChgAdded{Version=[3],Text=[Subclause @RefSecNum{Operations of Access Types},
4668 home of the accessibility rules, is informally known
4669 as the @ldquote@;Heart of Darkness@rdquote amongst the maintainers of Ada.
4670 Woe unto all who enter here (well, at least unto anyone that needs to understand
4671 any of these rules).
4672 @Defn{Heart of Darkness}@IndexSeeAlso{Term=[accessibility rules],See=[Heart of Darkness]}]}
4673 @end{Discussion}
4674
4675 @Defn{statically deeper}
4676 @Defn2{Term=[deeper],Sec=(statically)}
4677 @Redundant[A given accessibility level is said to be @i{statically
4678 deeper} than another if the given level is known at compile time (as
4679 defined below) to be deeper than the other for all possible executions.
4680 In most cases, accessibility is enforced at compile time by
4681 @LegalityTitle.
4682 Run-time accessibility checks are also used,
4683 since the @LegalityTitle do not cover
4684 certain cases involving access parameters and generic packages.]
4685
4686 @ChgRef{Version=[5],Kind=[Revised],ARef=[AI12-0345-1]}
4687 @Leading@keepnext@;Each master, and each entity and view created by it,
4688 has an accessibility level@Chg{Version=[5],New=[; when two levels are defined to
4689 be the same, the accessibility levels of the two associated entities are said to
4690 be @i<tied>@Defn2{Term=[tied],Sec=[accessibility levels]} to each
4691 other],Old=[]}:
4692 @begin{Itemize}
4693 The accessibility level of a given master is deeper than
4694 that of each dynamically enclosing master,
4695 and deeper than that of each master upon which the task executing the
4696 given master directly depends
4697 (see @RefSecNum{Task Dependence - Termination of Tasks}).
4698
4699 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00162-01],ARef=[AI95-00416-01]}
4700 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0235-1]}
4701 @ChgRef{Version=[4],Kind=[Revised],ARef=[AI12-0067-1],ARef=[AI12-0089-1]}
4702 @ChgRef{Version=[5],Kind=[Revised],ARef=[AI12-0345-1]}
4703 An entity or view @Chg{Version=[2],New=[defined],Old=[created]} by a
4704 declaration@Chg{Version=[2],New=[ and created as part of its elaboration],Old=[]}
4705 has the same accessibility level
4706 as the innermost @Chg{Version=[2],New=[],Old=[enclosing ]}master
4707 @Chg{Version=[2],New=[of the declaration ],Old=[]}except in the
4708 cases of renaming and derived access types described below.
4709 @Chg{Version=[5],New=[A formal],Old=[@Chg{Version=[3],New=[Other than for an
4710 explicitly aliased parameter@Chg{Version=[4],New=[ of a function or
4711 generic function],Old=[]}, a formal],Old=[A]}]} parameter of a
4712 @Chg{Version=[3],New=[callable entity],Old=[master]} has the same
4713 accessibility level as the master@Chg{Version=[3],New=[ representing the
4714 invocation of the entity],Old=[]}.
4715 @begin{Reason}
4716 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00416-01]}
4717 @ChgAdded{Version=[2],Text=[This rule defines the @lquotes@;normal@rquotes
4718 accessibility of entities. In the absence of special rules below, we intend
4719 for this rule to apply.]}
4720 @end{Reason}
4721 @begin{Discussion}
4722 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00416-01]}
4723 @ChgRef{Version=[4],Kind=[Revised],ARef=[AI12-0005-1]}
4724 @ChgRef{Version=[5],Kind=[Revised],ARef=[AI12-0005-1]}
4725 @ChgAdded{Version=[2],Text=[This rule defines the accessibility of all
4726 named access types, as well as the accessibility level of
4727 @Chg{Version=[4],New=[],Old=[all ]}anonymous access
4728 types @Chg{Version=[4],New=[@Chg{Version=[5],New=[defined by],Old=[in]}
4729 a @nt{component_definition}],Old=[other
4730 than those for access parameters and access discriminants.]} Special rules
4731 exist for the accessibility level of @Chg{Version=[4],New=[other],Old=[such]}
4732 anonymous types. Components@Chg{Version=[4],New=[],Old=[,
4733 stand-alone objects, and function results]} whose
4734 (anonymous) type is defined by an @nt{access_definition} have
4735 accessibility levels corresponding to named access types defined at
4736 the same point.]}
4737 @end{Discussion}
4738 @begin{Ramification}
4739 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00230-01]}
4740 @ChgAdded{Version=[2],Text=[Because accessibility level is determined
4741 by where the @nt{access_definition} is elaborated, for a type extension,
4742 the anonymous access types of components (other than access discriminants)
4743 inherited from the parent have the same accessibility as they did in the
4744 parent; those in the extension part have the accessibility
4745 determined by the scope where the type extension is declared.
4746 Similarly, the types of the nondiscriminant access components
4747 of a derived untagged type have the same accessibility as they
4748 did in the parent.]}
4749 @end{Ramification}
4750 @begin{Honest}
4751 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0235-1]}
4752 @ChgAdded{Version=[3],Text=[We use "invocation of" in the parameter case
4753 as a master is formally an execution of something. But we mean this to be
4754 interpreted statically (for instance, as the body of the subprogram) for the
4755 purposes of computing "statically deeper than" (see below).]}
4756 @end{Honest}
4757 @begin{Ramification}
4758 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0235-1]}
4759 @ChgAdded{Version=[3],Text=[Note that accessibility can differ depending on
4760 the view of an object (for both static and dynamic accessibility). For
4761 instance, the accessibility level of a formal parameter may be different than
4762 the accessibility level of the corresponding actual parameter. This occurs
4763 in other cases as well.]}
4764 @end{Ramification}
4765 @begin{Reason}
4766 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0235-1]}
4767 @ChgAdded{Version=[3],Text=[We define the (dynamic) accessibility of formal
4768 parameters in order that it does not depend on the parameter passing model
4769 (by-reference or by-copy) as that is implementation defined. Otherwise, there
4770 would be a portability issue.]}
4771 @end{Reason}
4772
4773 @ChgRef{Version=[5],Kind=[Revised],ARef=[AI12-0371-1]}
4774 The accessibility level of
4775 a view of an object or subprogram defined by a @nt{renaming_declaration}
4776 is the same as that of
4777 the renamed view@Chg{Version=[5],New=[, unless the renaming is of a formal
4778 subprogram, in that case the accessibility level is
4779 that of the instance],Old=[]}.
4780
4781 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00416-01]}
4782 The accessibility level of
4783 a view conversion@Chg{Version=[2],New=[, @nt{qualified_expression}, or
4784 parenthesized expression,],Old=[]}
4785 is the same as that of
4786 the operand.
4787
4788 @ChgRef{Version=[3],Kind=[Added],ARef=[AI05-0188-1]}
4789 @ChgRef{Version=[5],Kind=[RevisedAdded],ARef=[AI12-0292-1]}
4790 @ChgAdded{Version=[3],Text=[The accessibility level of a
4791 @nt{conditional_expression} @Chg{Version=[5],New=[(see
4792 @RefSecNum{Conditional Expressions}) ],Old=[]}is
4793 the accessibility level of the evaluated
4794 @Syni{dependent_}@nt{expression}.]}
4795
4796 @ChgRef{Version=[5],Kind=[Added],ARef=[AI12-0236-1]}
4797 @ChgAdded{Version=[5],Text=[The accessibility level of a
4798 @nt{declare_expression} @Chg{Version=[5],New=[(see
4799 @RefSecNum{Declare Expressions}) ],Old=[]}is
4800 the accessibility level of the @Syni{body_}@nt{expression}.]}
4801
4802 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00318-02],ARef=[AI95-00416-01]}
4803 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0234-1]}
4804 @ChgRef{Version=[4],Kind=[Revised],ARef=[AI12-0027-1]}
4805 @Chg{Version=[2],New=[The],Old=[For a function whose result type is a
4806 return-by-reference type,
4807 the accessibility level of the result object is the same as
4808 that of the master that elaborated the function body. For
4809 any other function, the]} accessibility level of @Chg{Version=[2],New=[an
4810 @nt{aggregate} @Chg{Version=[3],New=[],Old=[or the result of a function call @Redundant[(or equivalent use
4811 of an operator)] ]}that is
4812 used (in its entirety) to directly initialize part of an],Old=[the result]}
4813 object is that of the
4814 @Chg{Version=[2],New=[object being initialized. In other contexts, the
4815 accessibility level of an @nt{aggregate} @Chg{Version=[3],New=[],Old=[or the
4816 result of a function call ]}is that of the innermost
4817 master that evaluates the @nt{aggregate}@Chg{Version=[3],New=[],Old=[ or
4818 function call]}],Old=[execution of the called
4819 function]}.@Chg{Version=[4],New=[ Corresponding rules apply to a value conversion
4820 (see @RefSecNum{Type Conversions}).],Old=[]}
4821
4822 @ChgRef{Version=[3],Kind=[Added],ARef=[AI05-0234-1]}
4823 @ChgAdded{Version=[3],Type=[Leading],Text=[The accessibility level of the result
4824 of a function call is that of the @i<master of the function call>, which is
4825 determined by the point of call as follows:@Defn{master of a call}@Defn2{Term=[call],Sec=[master of]}@Defn2{Term=[function call],Sec=[master of]}]}
4826
4827 @begin{InnerItemize}
4828
4829 @ChgRef{Version=[3],Kind=[Added]}
4830 @ChgAdded{Version=[3],Text=[If the result is used (in its entirety) to
4831 directly initialize part of an object, the master is that of the object being
4832 initialized. In the case where the initialized object is a coextension
4833 (see below) that becomes a coextension of another object, the master is that
4834 of the eventual object to which the coextension will be transferred.]}
4835
4836 @begin{Honest}
4837 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00416-01]}
4838 @ChgAdded{Version=[2],Text=[The first sentence is talking about a static
4839 use of the entire return object @em a slice that happens to be the entire
4840 return object doesn't count. On the other hand, this is intended to allow
4841 parentheses and @nt{qualified_expression}s.]}
4842 @end{Honest}
4843 @begin{Ramification}
4844 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00416-01]}
4845 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0234-1]}
4846 @ChgAdded{Version=[2],Text=[If the function is used as a @nt{prefix},
4847 @Chg{Version=[3],New=[this bullet does not apply],Old=[the second sentence
4848 applies]}. Similarly, an @nt{assignment_statement} is not an initialization
4849 of an object, so @Chg{Version=[3],New=[this bullet does not apply],Old=[the second sentence
4850 applies]}.]}
4851 @end{Ramification}
4852
4853 @ChgRef{Version=[3],Kind=[Added]}
4854 @ChgRef{Version=[5],Kind=[RevisedAdded],ARef=[AI12-0278-1]}
4855 @ChgAdded{Version=[3],Text=[If the result is of an anonymous access type and
4856 is @Chg{Version=[5],New=[converted to a named access type],Old=[the operand
4857 of an explicit conversion]}, the master is that of the target type of the
4858 conversion;]}
4859
4860 @begin{Ramification}
4861 @ChgRef{Version=[5],Kind=[Added],ARef=[AI12-0278-1]}
4862 @ChgAdded{Version=[5],Text=[The conversion can be an explicit type
4863 conversion, or an implicit subtype conversion (these happen when anonymous
4864 access types are allowed to match named general access types, see
4865 @RefSecNum{The Context of Overload Resolution}).]}
4866 @end{Ramification}
4867
4868 @ChgRef{Version=[3],Kind=[Added]}
4869 @ChgAdded{Version=[3],Text=[If the result is of an anonymous access type and
4870 defines an access discriminant, the master is the same as that for an object
4871 created by an anonymous @nt{allocator} that defines an access discriminant
4872 (even if the access result is of an access-to-subprogram type).]}
4873
4874 @ChgRef{Version=[3],Kind=[Added]}
4875 @ChgRef{Version=[5],Kind=[RevisedAdded],ARef=[AI12-0345-1]}
4876 @ChgAdded{Version=[3],Text=[If the call itself defines the result of a
4877 function to which one of the above rules applies, @Chg{Version=[5],New=[or
4878 has an accessibility level that is tied to the result of such a
4879 function, ],Old=[]}these rules are applied recursively;]}
4880
4881 @ChgRef{Version=[3],Kind=[Added]}
4882 @ChgAdded{Version=[3],Text=[In other cases, the master of the call is that of
4883 the innermost master that evaluates the function call.]}
4884
4885 @begin{Ramification}
4886 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00318-02],ARef=[AI95-00416-01]}
4887 @ChgAdded{Version=[2],Text=[The @lquotes@;innermost master which evaluated
4888 the function call@rquotes@; does not include the function call itself (which
4889 might be a master).]}
4890
4891 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00318-02],ARef=[AI95-00416-01]}
4892 @ChgAdded{Version=[2],Text=[We really mean the innermost master here,
4893 which could be a very short lifetime. Consider a function call used as
4894 a parameter of a procedure call. In this case the innermost master which
4895 evaluated the function call is the procedure call.]}
4896 @end{Ramification}
4897
4898 @end{InnerItemize}
4899
4900 @begin{Ramification}
4901 @ChgRef{Version=[3],Kind=[Added],ARef=[AI05-0234-1]}
4902 @ChgAdded{Version=[3],Text=[These rules do not mention whether the result
4903 object is built-in-place (see @RefSecNum{Assignment and Finalization}). In
4904 particular, in the case where building in place is optional, the choice
4905 whether or not to build-in-place has no effect on masters, lifetimes, or
4906 accessibility.]}
4907 @end{Ramification}
4908
4909 @begin{ImplNote}
4910 @ChgRef{Version=[3],Kind=[Added],ARef=[AI05-0234-1]}
4911 @ChgAdded{Version=[3],Type=[Leading],Text=[There are several cases where the
4912 implementation may have to pass in the accessibility level of the result
4913 object on a call, to support later rules where the accessibility level comes
4914 from the master of the call:]}
4915
4916 @begin{Itemize}
4917 @ChgRef{Version=[3],Kind=[Added]}
4918 @ChgAdded{Version=[3],Text=[when the function result may have a part with
4919 access discriminants;]}
4920
4921 @ChgRef{Version=[3],Kind=[Added]}
4922 @ChgAdded{Version=[3],Text=[when the function result type is an anonymous
4923 access type;]}
4924
4925 @ChgRef{Version=[3],Kind=[Added]}
4926 @ChgRef{Version=[5],Kind=[RevisedAdded],ARef=[AI12-0345-1]}
4927 @ChgAdded{Version=[3],Text=[when the function result is built-in-place@Chg{Version=[5],New=[.],Old=[;]}]}
4928
4929 @ChgRef{Version=[3],Kind=[Added]}
4930 @ChgRef{Version=[5],Kind=[DeletedAdded],ARef=[AI12-0345-1]}
4931 @ChgAdded{Version=[3],Text=[@Chg{Version=[5],New=[],Old=[when the function
4932 has an explicitly aliased parameter.]}]}
4933 @end{Itemize}
4934
4935 @ChgRef{Version=[3],Kind=[Added]}
4936 @ChgAdded{Version=[3],Text=[In particular, this implies passing a level
4937 parameter when the result type is class-wide, since descendants may add access
4938 discriminants. For most implementations this will mean that functions with
4939 controlling results will also need a level parameter.]}
4940 @end{ImplNote}
4941
4942 @ChgRef{Version=[3],Kind=[Added],ARef=[AI05-0284-1]}
4943 @ChgAdded{Version=[3],NoPrefix=[T],Text=[In the case of a call to a function
4944 whose result type is an anonymous access type, the accessibility level of the
4945 type of the result of the function call is also determined by the point of call
4946 as described above.]}
4947
4948 @ChgRef{Version=[2],Kind=[Added],ARef=[AI95-00416-01]}
4949 @ChgRef{Version=[3],Kind=[RevisedAdded]}@ChgNote{Just because the paragraph number is changed}
4950 @ChgAdded{Version=[2],Text=[Within a return statement, the accessibility level
4951 of the return object is that of the execution of the return statement. If the
4952 return statement completes normally by returning from the
4953 function, then prior to leaving the function, the accessibility level
4954 of the return object changes to be a level determined by the point
4955 of call, as does the level of any coextensions (see below) of the
4956 return object.]}
4957
4958 @begin{Reason}
4959 @ChgRef{Version=[2],Kind=[AddedNormal]}
4960 @ChgAdded{Version=[2],Text=[We define the accessibility level of the return
4961 object during the return statement to be that of the return statement itself
4962 so that the object may be designated by objects local to the return
4963 statement, but not by objects outside the return statement. In addition, the
4964 intent is that the return object gets finalized if the return statement ends
4965 without actually returning (for example, due to propagating an exception, or
4966 a goto). For a normal return, of course, no finalization is done before
4967 returning.]}
4968 @end{Reason}
4969
4970 The accessibility level of
4971 a derived access type
4972 is the same as that of
4973 its ultimate ancestor.
4974
4975 @ChgRef{Version=[2],Kind=[Added],ARef=[AI95-00230-01]}
4976 @ChgAdded{Version=[2],Text=[The accessibility level of the anonymous access
4977 type defined by an @nt{access_definition} of an
4978 @nt{object_renaming_declaration} is the same as that of the renamed view.]}
4979
4980 @ChgRef{Version=[5],Kind=[Added],ARef=[AI12-0156-1]}
4981 @ChgAdded{Version=[5],Text=[The accessibility level of the anonymous access
4982 type defined by an @nt{access_definition} of a
4983 @nt{loop_parameter_subtype_indication} is that of the loop parameter.]}
4984
4985 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00230-01],ARef=[AI95-00416-01]}
4986 @ChgNote{Use ChgAdded below to get conditional Leading}
4987 @ChgAdded{Version=[2],Type=[Leading],Text=[]}The accessibility level
4988 of the anonymous access type of an access discriminant
4989 @Chg{Version=[2],New=[in the @nt{subtype_indication} or
4990 @nt{qualified_expression} of an @nt{allocator}, or in the @nt{expression} or
4991 @nt{return_@!subtype_@!indication} of a return statement is determined as
4992 follows:],Old=[is the same as that of the containing object or associated
4993 constrained subtype.]}
4994
4995 @begin{InnerItemize}
4996 @ChgRef{Version=[2],Kind=[Added]}
4997 @ChgAdded{Version=[2],Text=[If the value of the access discriminant is
4998 determined by a @nt{discriminant_association} in a @nt{subtype_indication},
4999 the accessibility level of the object or subprogram designated by
5000 the associated value (or library level if the value is null);]}
5001 @begin{Discussion}
5002 @ChgRef{Version=[2],Kind=[AddedNormal]}
5003 @ChgAdded{Version=[2],Type=[Leading],Text=[This deals with the following cases,
5004 when they occur in the context of an @nt{allocator} or return statement:]}
5005 @begin{InnerItemize}
5006 @ChgRef{Version=[2],Kind=[AddedNormal]}
5007 @ChgAdded{Version=[2],Text=[An @nt{extension_aggregate} where the
5008 @nt{ancestor_part} is a @nt{subtype_mark} denoting a constrained subtype;]}
5009
5010 @ChgRef{Version=[2],Kind=[AddedNormal]}
5011 @ChgAdded{Version=[2],Text=[An uninitialized @nt{allocator} where the
5012 @nt{subtype_indication} defines a constrained subtype;]}
5013
5014 @ChgRef{Version=[2],Kind=[AddedNormal]}
5015 @ChgAdded{Version=[2],Text=[A discriminant of an object with a constrained
5016 nominal subtype, including constrained components, the result of calling
5017 a function with a constrained result subtype, the dereference of an
5018 access-to-constrained subtype, etc.]}
5019 @end{InnerItemize}
5020 @end{Discussion}
5021 @begin{Ramification}
5022 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0281-1]}
5023 @ChgAdded{Version=[3],Text=[The @nt{subtype_indication} mentioned in this
5024 bullet is not necessarily the one given in the @nt{allocator} or
5025 return statement that is determining the accessibility level; the constrained
5026 subtype might have been defined in an earlier declaration (as a named
5027 subtype).]}
5028
5029 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0005-1]}
5030 @ChgAdded{Version=[3],Text=[If the value for this rule and the next one is
5031 derived from an Unchecked_Access attribute, the accessibility is library-level
5032 no matter what the accessibility level of the object is (see
5033 @RefSecNum{Unchecked Access Value Creation}).]}
5034 @end{Ramification}
5035
5036 @ChgRef{Version=[3],Kind=[Added],ARef=[AI05-0234-1]}
5037 @ChgAdded{Version=[3],Text=[If the value of the access discriminant is
5038 determined by a @nt{default_expression} in the declaration of the discriminant,
5039 the level of the object or subprogram designated by the associated value (or
5040 library level if null);]}
5041 @begin{Discussion}
5042 @ChgRef{Version=[3],Kind=[Added]}
5043 @ChgAdded{Version=[3],Text=[This covers the case of an unconstrained
5044 subcomponent of a limited type with defaulted access discriminants.]}
5045 @end{Discussion}
5046
5047 @ChgRef{Version=[2],Kind=[Added]}
5048 @ChgRef{Version=[3],Kind=[RevisedAdded],ARef=[AI05-0004-1]}
5049 @ChgAdded{Version=[2],Text=[If the value of the access discriminant is
5050 determined by a @Chg{Version=[3],New=[@nt{record_component_association}],
5051 Old=[@ntf{component_association}]} in an @nt{aggregate}, the
5052 accessibility level of the object or subprogram designated by the associated
5053 value (or library level if the value is null);]}
5054
5055 @begin{Discussion}
5056 @ChgRef{Version=[2],Kind=[AddedNormal]}
5057 @ChgAdded{Version=[2],Text=[In this bullet, the @nt{aggregate} has to occur
5058 in the context of an @nt{allocator} or return statement, while the
5059 @nt{subtype_indication} of the previous bullet can occur anywhere
5060 (it doesn't have to be directly given in the @nt{allocator} or
5061 return statement).]}
5062 @end{Discussion}
5063
5064 @ChgRef{Version=[2],Kind=[Added]}
5065 @ChgRef{Version=[3],Kind=[RevisedAdded]}@ChgNote{Just because the paragraph number is changed}
5066 @ChgAdded{Version=[2],Text=[In other cases, where the value of the access
5067 discriminant is determined by an object
5068 with an unconstrained nominal subtype, the accessibility level of the object.]}
5069
5070 @end{InnerItemize}
5071 @begin{Discussion}
5072 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00416-01]}
5073 @ChgAdded{Version=[2],Text=[In other words, if you know the value of the
5074 discriminant for an @nt{allocator} or return statement from a discriminant
5075 constraint or an @nt{aggregate} component
5076 association, then that determines the accessibility level; if you don't know
5077 it, then it is based on the object itself.]}
5078 @end{Discussion}
5079
5080 @ChgRef{Version=[2],Kind=[Added],ARef=[AI95-00416-01]}
5081 @ChgRef{Version=[3],Kind=[RevisedAdded]}@ChgNote{Just because the paragraph number is changed}
5082 @ChgAdded{Version=[2],Text=[The accessibility level of the anonymous access
5083 type of an access discriminant in any other context is that of the
5084 enclosing object.]}
5085
5086 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00162-01],ARef=[AI95-00254-01]}
5087 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0270-1]}
5088 The accessibility level of
5089 the anonymous access type of an access
5090 parameter@Chg{Version=[2],New=[ specifying an access-to-object type],Old=[]}
5091 is the same as that of
5092 the view designated by the actual@Chg{Version=[3],New=[ (or library-level
5093 if the actual is null)],Old=[]}.@Chg{Version=[2],New=[],Old=[ If the
5094 actual is an @nt{allocator},
5095 this is the accessibility level of the execution of the called
5096 subprogram.]}
5097 @begin{Ramification}
5098 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0005-1]}
5099 @ChgAdded{Version=[3],Text=[If the value of the actual is derived from an
5100 Unchecked_Access attribute, the accessibility is always library-level (see
5101 @RefSecNum{Unchecked Access Value Creation}).]}
5102 @end{Ramification}
5103
5104
5105 @ChgRef{Version=[2],Kind=[Added],ARef=[AI95-00254-01]}
5106 @ChgAdded{Version=[2],Text=[The accessibility level of the anonymous access type
5107 of an access parameter specifying an access-to-subprogram type is
5108 deeper than that of any master; all such
5109 anonymous access types have this same level.]}
5110 @begin{Reason}
5111 @ChgRef{Version=[2],Kind=[AddedNormal]}
5112 @ChgAdded{Version=[2],Text=[@Defn{downward closure}
5113 @Defn2{Term=[closure],Sec=(downward)}
5114 These represent @lquotes@;downward closures@rquotes@; and
5115 thus require passing of static links or global display information (along
5116 with generic sharing information if the implementation does sharing) along
5117 with the address of the subprogram. We must prevent conversions of these to
5118 types with @lquotes@;normal@rquotes@; accessibility, as those typically don't
5119 include the extra information needed to make a call.]}
5120 @end{Reason}
5121
5122 @ChgRef{Version=[4],Kind=[Added],ARef=[AI12-0070-1]}
5123 @ChgAdded{Version=[4],Text=[The accessibility level of the anonymous access
5124 subtype defined by a @nt{return_subtype_indication} that is
5125 an @nt{access_definition} (see @RefSecNum{Return Statements})
5126 is that of the result subtype of the enclosing function.]}
5127
5128 @ChgRef{Version=[3],Kind=[Added],ARef=[AI05-0148-1],ARef=[AI05-0240-1]}
5129 @ChgRef{Version=[4],Kind=[RevisedAdded],ARef=[AI12-0070-1]}@ChgNote{Just to reflect the paragraph number change}
5130 @ChgAdded{Version=[3],Text=[The accessibility level of the type of a stand-alone
5131 object of an anonymous access-to-object type is the same as the accessibility
5132 level of the type of the access value most recently assigned to the
5133 object@Redundant[; accessibility checks ensure that this
5134 is never deeper than that of the declaration of the stand-alone object].]}
5135
5136 @ChgRef{Version=[3],Kind=[Added],ARef=[AI05-0142-4],ARef=[AI05-0240-1]}
5137 @ChgRef{Version=[4],Kind=[RevisedAdded],ARef=[AI12-0070-1]}@ChgNote{Just to reflect the paragraph number change}
5138 @ChgRef{Version=[5],Kind=[DeletedAdded],ARef=[AI12-0345-1]}
5139 @ChgAdded{Version=[3],Text=[@Chg{Version=[5],New=[],Old=[The accessibility level of an
5140 explicitly aliased (see @RefSecNum{Subprogram Declarations}) formal parameter in
5141 a function body is determined by the point of call; it is the same level that
5142 the return object ultimately will have.]}]}
5143
5144 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00416-01]}
5145 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0051-1],ARef=[AI05-0253-1]}
5146 @ChgNote{Use ChgAdded below to get conditional Leading}
5147 @ChgAdded{Version=[2],Type=[Leading],Text=[]}
5148 The accessibility level of an object created by an @nt{allocator}
5149 is the same as that of
5150 the access type@Chg{Version=[2],New=[, except for an @nt{allocator} of an
5151 anonymous access type @Chg{Version=[3],New=[(an @i<anonymous allocator>) in
5152 @Defn{anonymous allocator}certain contexts, as follows: For an anonymous
5153 allocator that defines the result of a function with an access result, the
5154 accessibility level is determined as though the @nt{allocator} were in place
5155 of the call of the function; in the special case of a call that is the operand of a
5156 type conversion, the level is that of the target access type of the
5157 conversion],Old=[that defines the value of an access parameter or an access
5158 discriminant]}. For an @Chg{Version=[3],New=[anonymous
5159 allocator],Old=[@nt{allocator}]} defining the value of an access parameter, the
5160 accessibility level is that of the innermost master of the call.
5161 @Chg{Version=[3],New=[For an anonymous allocator whose type is that of a
5162 stand-alone object of an anonymous access-to-object type, the accessibility
5163 level is that of the declaration of the stand-alone object. ],Old=[]}For one
5164 defining an access discriminant, the accessibility level is determined as
5165 follows:],Old=[.]}
5166
5167 @begin{InnerItemize}
5168
5169 @ChgRef{Version=[2],Kind=[Added],ARef=[AI95-00416-01]}
5170 @ChgRef{Version=[3],Kind=[RevisedAdded],ARef=[AI05-0024-1]}
5171 @ChgAdded{Version=[2],Text=[for an @nt{allocator} used to define the
5172 @Chg{Version=[3],New=[discriminant of an object,
5173 the level of the object],Old=[constraint in a
5174 @nt{subtype_declaration}, the level of the @nt{subtype_declaration}]};]}
5175
5176 @ChgRef{Version=[2],Kind=[Added],ARef=[AI95-00416-01]}
5177 @ChgRef{Version=[3],Kind=[RevisedAdded],ARef=[AI05-0024-1]}
5178 @ChgAdded{Version=[2],Text=[for an @nt{allocator} used to define the constraint
5179 in a @Chg{Version=[3],New=[@nt{subtype_indication} in any other context, the
5180 level of the master that elaborates the
5181 @nt{subtype_indication}.],Old=[@nt{component_definition}, the level of the
5182 enclosing type;]}]}
5183
5184 @ChgRef{Version=[2],Kind=[Added],ARef=[AI95-00416-01]}
5185 @ChgRef{Version=[3],Kind=[DeletedAdded],ARef=[AI05-0024-1]}
5186 @ChgAdded{Version=[2],Text=[@Chg{Version=[3],New=[],Old=[for an @nt{allocator}
5187 used to define the discriminant of an object, the level of the object.]}]}
5188
5189 @end{InnerItemize}
5190
5191 @ChgRef{Version=[2],Kind=[Added],ARef=[AI95-00416-01]}
5192 @ChgRef{Version=[3],Kind=[RevisedAdded],ARef=[AI05-0024-1],ARef=[AI05-0066-1]}
5193 @ChgAdded{Version=[2],NoPrefix=[T],Text=[@Defn2{Term=[coextension],Sec=(of an object)}
5194 In @Chg{Version=[3],New=[the first],Old=[this last]} case, the allocated object
5195 is said to be a @i{coextension} of the object whose discriminant designates it,
5196 as well as of any object of which the discriminated object is itself a
5197 coextension or subcomponent.@Chg{Version=[3],New=[ If the allocated object is
5198 a coextension of an
5199 anonymous object representing the result of an aggregate or function
5200 call that is used (in its entirety) to directly initialize a part of
5201 an object, after the result is assigned, the coextension becomes a
5202 coextension of the object being initialized and is no longer
5203 considered a coextension of the anonymous object.],Old=[]}
5204 All coextensions of an object @Chg{Version=[3],New=[@Redundant[(which have not
5205 thus been transfered by such an initialization)] ],Old=[]}are finalized when
5206 the object is finalized (see @RefSecNum{Completion and Finalization}).]}
5207 @begin{Ramification}
5208 @ChgRef{Version=[2],Kind=[Added]}
5209 @ChgAdded{Version=[2],Text=[The rules of access discriminants are such that
5210 when the space for an object with a coextension is reclaimed, the space for
5211 the coextensions can be reclaimed. Hence, there is implementation advice (see
5212 13.11) that an object and its coextensions all be allocated from the same
5213 storage pool (or stack frame, in the case of a declared object).]}
5214 @end{Ramification}
5215
5216 @ChgRef{Version=[3],Kind=[Added],ARef=[AI05-0051-1]}
5217 @ChgAdded{Version=[3],Text=[Within a return statement, the accessibility level
5218 of the anonymous access type of an access result is that of the master of the
5219 call.]}
5220
5221 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0014-1]}
5222 The accessibility level of a view of an object or subprogram
5223 @Chg{Version=[3],New=[designated by],Old=[denoted by a dereference of]} an
5224 access value is the same as that of the access type.
5225 @begin{Discussion}
5226 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0005-1],ARef=[AI05-0014-1]}
5227 @ChgAdded{Version=[3],Text=[This rule applies even when no dereference exists,
5228 for example when an access value is passed as an access parameter.
5229 This rule ensures that implementations are not required to include dynamic
5230 accessibility values with all access values.]}
5231 @end{Discussion}
5232
5233 The accessibility level of
5234 a component, protected subprogram, or entry
5235 of (a view of) a composite object
5236 is the same as that of
5237 (the view of) the composite object.
5238 @end{Itemize}
5239
5240 @ChgRef{Version=[2],Kind=[Added],ARef=[AI95-00416-01]}
5241 @ChgRef{Version=[3],Kind=[RevisedAdded],ARef=[AI05-0262-1]}
5242 @ChgRef{Version=[5],Kind=[RevisedAdded],ARef=[AI12-0236-1],ARef=[AI12-0317-1]}
5243 @ChgAdded{Version=[2],Text=[In the above rules, the
5244 @Chg{Version=[5],New=[operative constituents of a @nt{name} or @nt{expression}
5245 (see @RefSecNum{Expressions}) are],Old=[operand of a view
5246 conversion, parenthesized expression or @nt{qualified_expression} is]}
5247 considered to be used in a@Chg{Version=[5],New=[ given],Old=[]} context if the
5248 @Chg{Version=[5],New=[enclosing @nt{name} or
5249 @nt{expression}],Old=[view conversion, parenthesized
5250 expression or @nt{qualified_expression}
5251 itself]} is used in that context.@Chg{Version=[5],New=[],Old=[@Chg{Version=[3],New=[
5252 Similarly, a @SynI{dependent_}@nt{expression} of a @nt{conditional_expression}
5253 is considered to be used in a context if the @nt{conditional_expression} itself
5254 is used in that context.],Old=[]}]}]}
5255
5256 @begin{Discussion}
5257 @ChgRef{Version=[5],Kind=[AddedNormal]}
5258 @ChgAdded{Version=[5],Text=[This means that constructs like parenthesized
5259 expressions, @nt{qualified_expression}s, and @nt{conditional_expression}s
5260 are ignored for the purposes of calculating accessibility levels,
5261 determining the master of a function call, and so on.]}
5262 @end{Discussion}
5263
5264 @begin{WideAbove}
5265 @Leading@Defn{statically deeper}
5266 @Defn2{Term=[deeper],Sec=(statically)}
5267 One accessibility level is defined to be
5268 @i{statically deeper} than another in the following cases:
5269 @end{WideAbove}
5270 @begin{Itemize}
5271 For a master that is statically nested within another master,
5272 the accessibility level of the inner master is statically deeper than
5273 that of the outer master.
5274 @begin{Honest}
5275 Strictly speaking, this should talk about the @i{constructs}
5276 (such as @ntf{subprogram_bodies})
5277 being statically nested within one another;
5278 the masters are really the @i{executions} of those constructs.
5279 @end{Honest}
5280 @begin{Honest}
5281 If a given accessibility level is statically deeper than another,
5282 then each level defined to be the same as the given
5283 level is statically deeper than each level defined to be the same as
5284 the other level.
5285 @end{Honest}
5286
5287 @ChgRef{Version=[2],Kind=[Added],ARef=[AI95-00254-01]}
5288 @ChgAdded{Version=[2],Text=[The accessibility level of the anonymous access type
5289 of an access parameter specifying an access-to-subprogram type is
5290 statically deeper than that of any master; all such
5291 anonymous access types have this same level.]}
5292 @begin{Ramification}
5293 @ChgRef{Version=[2],Kind=[AddedNormal]}
5294 @ChgAdded{Version=[2],Text=[This rule means that it is illegal to convert an
5295 access parameter specifying an access to subprogram to a
5296 named access to subprogram type, but it is allowed to pass such an access
5297 parameter to another access parameter (the implicit conversion's accessibility
5298 will succeed).]}
5299 @end{Ramification}
5300
5301 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00254-01]}
5302 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0082-1]}
5303 The statically deeper relationship does not apply to the accessibility
5304 level of the anonymous type of an access parameter@Chg{Version=[2],
5305 New=[ specifying an access-to-object type],Old=[]}@Chg{Version=[3],
5306 New=[ nor does it apply to a descendant of a generic formal type],Old=[]};
5307 that is, such an accessibility level is not considered to be statically
5308 deeper, nor statically shallower, than any other.
5309
5310 @ChgRef{Version=[3],Kind=[Added],ARef=[AI05-0148-1]}
5311 @ChgAdded{Version=[3],Text=[The statically deeper relationship does not apply to
5312 the accessibility level of the type of a stand-alone object of an anonymous
5313 access-to-object type; that is, such an accessibility level is not considered to
5314 be statically deeper, nor statically shallower, than any other.]}
5315
5316 @begin{Ramification}
5317 @ChgRef{Version=[3],Kind=[AddedNormal]}
5318 @ChgAdded{Version=[3],Text=[In these cases, we use dynamic accessibility
5319 checks.]}
5320 @end{Ramification}
5321
5322 @ChgRef{Version=[3],Kind=[Added],ARef=[AI05-0142-4],ARef=[AI05-0235-1]}
5323 @ChgRef{Version=[4],Kind=[RevisedAdded],ARef=[AI12-0089-1],ARef=[AI12-0157-1]}
5324 @ChgRef{Version=[5],Kind=[DeletedAdded],ARef=[AI12-0277-1],ARef=[AI12-0324-1],ARef=[AI12-0345-1]}
5325 @ChgAdded{Version=[3],Text=[@Chg{Version=[5],New=[],Old=[Inside a return
5326 statement that applies to a function
5327 @Chg{Version=[4],New=[or generic function ],Old=[]}@i<F>,
5328 @Chg{Version=[4],New=[or @Chg{Version=[5],New=[inside ],Old=[]}the
5329 return expression of an expression function
5330 @i<F>, ],Old=[]}when determining
5331 whether the accessibility level of an explicitly aliased
5332 parameter of @i<F> is statically deeper than the level of the return object of
5333 @i<F>, the level of the return object is considered to be the same as that of
5334 the level of the explicitly aliased parameter; for statically comparing with the
5335 level of other entities, an explicitly aliased parameter of @i<F> is considered to
5336 have the accessibility level of @Chg{Version=[5],New=[a parameter of @i<F>
5337 that is not explicitly aliased],Old=[the body of @i<F>]}.]}]}
5338
5339 @ChgRef{Version=[3],Kind=[Added],ARef=[AI05-0051-1],ARef=[AI05-0234-1],ARef=[AI05-0235-1]}
5340 @ChgRef{Version=[4],Kind=[RevisedAdded],ARef=[AI12-0089-1],ARef=[AI12-0157-1]}
5341 @ChgAdded{Version=[3],Text=[For determining whether a level is statically deeper
5342 than the level of the anonymous access type of an access result of a
5343 function@Chg{Version=[4],New=[ or generic function @i<F>],Old=[]},
5344 when within a return statement that applies to
5345 @Chg{Version=[4],New=[@i<F> or the return expression of expression
5346 function @i<F>],Old=[the function]}, the level
5347 of the master of the call is presumed to be the same as that of the level
5348 of the master that elaborated the@Chg{Version=[4],New=[],Old=[ function]}
5349 body@Chg{Version=[4],New=[ of @i<F>],Old=[]}.]}
5350
5351 @begin{Honest}
5352 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0235-1]}
5353 @ChgRef{Version=[5],Kind=[Deleted],ARef=[AI12-0345-1]}
5354 @ChgAdded{Version=[3],Text=[@Chg{Version=[5],New=[],Old=[This rule has no
5355 effect if the previous bullet also applies (that is, the @ldquote@;a level@rdquote
5356 is of an explicitly aliased parameter).]}]}
5357
5358 @ChgRef{Version=[5],Kind=[AddedNormal],ARef=[AI12-0005-1]}
5359 @ChgAdded{Version=[5],Text=[For an expression function @i{F}, the
5360 @ldquote@;body of @i{F}@rdquote is the
5361 @nt{expression_function_declaration} of @i{F}.]}
5362 @end{Honest}
5363
5364
5365 @Redundant[For determining whether one level is statically deeper than another
5366 when within a generic package body, the generic package is presumed to be
5367 instantiated at the same level as where it was declared;
5368 runtime checks are needed in the case of more deeply nested instantiations.]
5369 @begin{TheProof}
5370 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0082-1]}
5371 @ChgAdded{Version=[3],Text=[A generic package does not introduce a new master,
5372 so it has the static level of its declaration; the rest follows from the
5373 other @ldquote@;statically deeper@rdquote rules.]}
5374 @end{TheProof}
5375
5376 For determining whether one level is statically deeper than another when
5377 within the declarative region of a @nt{type_declaration},
5378 the current instance of the type is presumed to be an object created at
5379 a deeper level than that of the type.
5380 @begin{Ramification}
5381 In other words, the rules are checked at compile time of the
5382 @nt{type_declaration}, in an assume-the-worst manner.
5383 @end{Ramification}
5384 @end{Itemize}
5385
5386 @ChgRef{Version=[5],Kind=[Added],ARef=[AI12-0345-1]}
5387 @ChgAdded{Version=[5],Text=[Notwithstanding other rules given above, the
5388 accessibility level of an entity that is tied to that of an explicitly aliased
5389 formal parameter of an enclosing function is considered (both statically and
5390 dynamically) to be the same as that of an entity whose accessibility level is
5391 tied to that of the return object of that function.]}
5392
5393 @begin{Ramification}
5394 @ChgRef{Version=[5],Kind=[AddedNormal]}
5395 @ChgAdded{Version=[5],Text=[This rule only applies when the level of an
5396 explicitly aliased parameter of a function is compared to that of the return
5397 object of the function. If a value designating the explicitly aliased
5398 parameter is created and stored in a stand-alone object or passed as a
5399 parameter, this special property is lost (even for the dynamic accessibility
5400 of anonymous access types in these contexts).]}
5401 @end{Ramification}
5402
5403 @begin{ImplNote}
5404 @ChgRef{Version=[5],Kind=[AddedNormal]}
5405 @ChgAdded{Version=[5],Text=[When this rule applies, no dynamic accessibility
5406 check should be made, even when one would normally be part of the execution
5407 of the construct. All places where this rule applies are known at
5408 compile-time.]}
5409 @end{ImplNote}
5410
5411
5412 @Defn{library level}
5413 @Defn2{Term=[level],Sec=(library)}
5414 The accessibility level of all library units is called the
5415 @i{library level};
5416 a library-level declaration or entity is one whose accessibility level
5417 is the library level.
5418 @begin{Ramification}
5419 @nt{Library_unit_declaration}s are library level.
5420 Nested declarations are library level if they are nested only within
5421 packages (possibly more than one),
5422 and not within subprograms, tasks, etc.
5423 @end{Ramification}
5424 @begin{Honest}
5425 @ChgRef{Version=[2],Kind=[Revised]}
5426 @Leading@;The definition of the accessibility level of the anonymous type
5427 of an access parameter@Chg{Version=[2],New=[ specifying an access-to-object
5428 type],Old=[]} cheats a bit, since it refers to the view designated
5429 by the actual, but access values designate objects, not views of objects.
5430 What we really mean is the view that @lquotes@;would be@rquotes@; denoted by an
5431 expression @lquotes@;X.@key[all]@rquotes@;, where X is the actual, even though such
5432 an expression is a figment of our imagination.
5433 The definition is intended to be equivalent to the
5434 following more verbose version:
5435 The accessibility level of the anonymous type of an access parameter is
5436 as follows:
5437 @begin{Itemize}
5438 if the actual is
5439 an expression of a named access type @em
5440 the accessibility level of that type;
5441
5442 if the actual is
5443 an @nt{allocator} @em
5444 the accessibility level of the execution of the called
5445 subprogram;
5446
5447 @ChgRef{Version=[1],Kind=[Revised]}@ChgNote{To be consistent with 8652/0006}
5448 if the actual is
5449 a reference to the Access attribute @em
5450 the accessibility level of the view denoted by the @Chg{New=[@nt{prefix}],Old=[prefix]};
5451
5452 if the actual is
5453 a reference to the Unchecked_Access attribute @em
5454 library accessibility level;
5455
5456 if the actual is
5457 an access parameter @em
5458 the accessibility level of its type.
5459 @end{Itemize}
5460
5461 Note that the @nt{allocator} case is explicitly mentioned in the RM95,
5462 because otherwise the definition would be circular:
5463 the level of the anonymous type is that of the view designated by the
5464 actual, which is that of the access type.
5465 @end{Honest}
5466 @begin{Discussion}
5467 A deeper accessibility level implies a shorter maximum lifetime.
5468 Hence, when a rule requires X to have a level that is
5469 @lquotes@;not deeper than@rquotes@; Y's level,
5470 this requires that X has a lifetime at least as long as Y.
5471 (We say @lquotes@;maximum lifetime@rquotes@; here, because the accessibility
5472 level really represents an upper bound on the lifetime;
5473 an object created by an @nt{allocator} can have its lifetime
5474 prematurely ended by an instance of Unchecked_Deallocation.)
5475
5476 Package elaborations are not masters, and are therefore
5477 invisible to the accessibility rules:
5478 an object declared immediately within a package has the
5479 same accessibility level as an object declared immediately within the
5480 declarative region containing the package.
5481 This is true even in the body of a package;
5482 it jibes with the fact that objects declared in a
5483 @nt{package_body} live as long as objects declared
5484 outside the package,
5485 even though the body objects are not visible outside the package.
5486
5487 Note that the level of the @i{view} denoted by X.@key[all]
5488 can be different from the level of the @i{object} denoted by X.@key[all].
5489 The former is determined by the type of X;
5490 the latter is determined either by the type of the @nt{allocator},
5491 or by the master in which the object was declared.
5492 The former is used in several @LegalityTitle and runtime checks;
5493 the latter is used to define when X.@key[all] gets finalized.
5494 The level of a view reflects what we can conservatively @lquotes@;know@rquotes@;
5495 about the object of that view;
5496 for example, due to @nt{type_conversion}s,
5497 an access value might designate an object that was allocated by an
5498 @nt{allocator} for a different access type.
5499
5500 Similarly, the level of the view denoted by X.@key[all].Comp
5501 can be different from the level of the object denoted by X.@key[all].Comp.
5502
5503 If Y is statically deeper than X,
5504 this implies that Y will be (dynamically) deeper than X in all
5505 possible executions.
5506
5507 @Leading@;Most accessibility checking is done at compile time;
5508 the rules are stated in terms of @lquotes@;statically deeper than@rquotes@;.
5509 The exceptions are:
5510 @begin{Itemize}
5511 @ChgRef{Version=[2],Kind=[Revised]}
5512 Checks involving access parameters@Chg{Version=[2],New=[ of an
5513 access-to-object type],Old=[]}. The fact that @lquotes@;statically deeper
5514 than@rquotes@; is not defined for the anonymous access type of an access
5515 parameter implies that any rule saying @lquotes@;shall not be statically
5516 deeper than@rquotes@; does not apply to such a type, nor to anything defined
5517 to have @lquotes@;the same@rquotes@; level as such a type.
5518
5519 @ChgRef{Version=[3],Kind=[Added],ARef=[AI05-0082-1]}
5520 @ChgAdded{Version=[3],Text=[Checks involving generic formal types
5521 and their descendants. This is because the actual type can be more
5522 or less deeply nested than the generic unit. Note that this only
5523 applies to the generic unit itself, and not to the instance. Any
5524 static checks needed in the instance will be performed. Any other
5525 checks (such as those in the generic body) will require a run-time
5526 check of some sort (although implementations that macro-expand
5527 generics can determine the result of the check when the generic
5528 is expanded).]}
5529
5530 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0082-1]}
5531 Checks involving @Chg{Version=[3],New=[other ],Old=[]}entities and
5532 views within generic packages. This is because an instantiation can
5533 be at a level that is more deeply nested than the generic package itself.
5534 In implementations that use a macro-expansion model of generics,
5535 these violations can be detected at macro-expansion time.
5536 For implementations that share generics,
5537 run-time code is needed to detect the error.
5538
5539 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00318-02],ARef=[AI95-00344-01],ARef=[AI95-00416-01]}
5540 Checks during function return@Chg{Version=[2],New=[ and @nt{allocator}s,
5541 for nested type extensions and access discriminants],Old=[]}.
5542 @end{Itemize}
5543
5544 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0005-1]}
5545 Note that runtime checks are not required
5546 for access discriminants@Chg{Version=[3],New=[ (except during
5547 function returns and @nt{allocator}s)],Old=[]}, because their accessibility is
5548 determined statically by the accessibility level of the enclosing object.
5549
5550 @ChgRef{Version=[2],Kind=[Revised]}
5551 @Chg{Version=[2],New=[],Old=[This ]}The accessibility level of the result
5552 object of a function reflects
5553 the time when that object will be finalized;
5554 we don't allow pointers to the object to survive beyond that time.
5555
5556 We sometimes use the terms @lquotes@;accessible@rquotes@;
5557 and @lquotes@;inaccessible@rquotes@; to mean that something has an
5558 accessibility level that is not deeper, or deeper,
5559 respectively, than something else.
5560 @end{Discussion}
5561 @begin(ImplNote)
5562 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00318-02],ARef=[AI95-00344-01],ARef=[AI95-00416-01]}
5563 If an accessibility @LegalityName is satisfied,
5564 then the corresponding runtime check (if any)
5565 cannot fail (and a reasonable implementation will not
5566 generate any checking code)
5567 unless @Chg{Version=[2],New=[one of the cases requiring runtime checks mentioned
5568 previously is],Old=[access parameters or shared generic bodies are]} involved.
5569
5570 Accessibility levels are defined in terms of the relations
5571 @lquotes@;the same as@rquotes@; and @lquotes@;deeper than@rquotes@;.
5572 To make the discussion more concrete,
5573 we can assign actual numbers to each level.
5574 Here, we assume that library-level accessibility is level 0,
5575 and each level defined as @lquotes@;deeper than@rquotes@; is one level deeper.
5576 Thus, a subprogram directly called from the environment task
5577 (such as the main subprogram) would be at level 1,
5578 and so on.
5579
5580 @ChgRef{Version=[2],Kind=[Revised]}
5581 Accessibility is not enforced at compile time for access
5582 parameters@Chg{Version=[2],New=[ of an access-to-object type],Old=[]}.
5583 The @lquotes@;obvious@rquotes@; implementation of the runtime checks would be
5584 inefficient, and would involve distributed overhead;
5585 therefore, an efficient method is given below.
5586 The @lquotes@;obvious@rquotes@; implementation would be to pass
5587 the level of the caller at each subprogram call,
5588 task creation, etc.
5589 This level would be incremented by 1 for each
5590 dynamically nested master.
5591 An Accessibility_Check would be implemented as a simple
5592 comparison @em checking that X is not deeper than Y
5593 would involve checking that X <= Y.
5594
5595 A more efficient method is based on passing @i{static}
5596 nesting levels
5597 (within constructs that correspond at run time to
5598 masters @em packages don't count).
5599 Whenever an access parameter is passed,
5600 an implicit extra parameter is passed with it.
5601 The extra parameter represents (in an indirect way)
5602 the accessibility level of the anonymous access type,
5603 and, therefore, the level of the view denoted
5604 by a dereference of the access parameter.
5605 This is analogous to the implicit @lquotes@;Constrained@rquotes@; bit associated
5606 with certain formal parameters of an unconstrained but definite
5607 composite subtype.
5608 In this method, we avoid distributed overhead:
5609 it is not necessary to pass any extra information
5610 to subprograms that have no access parameters.
5611 For anything other than an access parameter and its anonymous type,
5612 the static nesting level is known at compile time,
5613 and is defined analogously to the RM95 definition
5614 of accessibility level (e.g. derived access types
5615 get their nesting level from their parent).
5616 Checking @lquotes@;not deeper than@rquotes@; is a "<=" test on the levels.
5617
5618 @ChgRef{Version=[2],Kind=[Revised]}
5619 @Leading@keepnext@;For each access parameter@Chg{Version=[2],New=[ of
5620 an access-to-object type],Old=[]}, the static depth passed depends on the
5621 actual, as follows:
5622 @begin{Itemize}
5623 If the actual is
5624 an expression of a named access type,
5625 pass the static nesting level of that type.
5626
5627 If the actual is
5628 an @nt{allocator},
5629 pass the static nesting level of the caller,
5630 plus one.
5631
5632 @ChgRef{Version=[1],Kind=[Revised]}@ChgNote{To be consistent with 8652/0006}
5633 If the actual is
5634 a reference to the Access attribute,
5635 pass the level of the view denoted by the @Chg{New=[@nt{prefix}],Old=[prefix]}.
5636
5637 If the actual is
5638 a reference to the Unchecked_Access attribute,
5639 pass 0 (the library accessibility level).
5640
5641 @ChgRef{Version=[2],Kind=[Revised]}
5642 If the actual is an access parameter@Chg{Version=[2],New=[ of
5643 an access-to-object type],Old=[]},
5644 usually just pass along the level passed in.
5645 However, if the
5646 static nesting level of the formal (access) parameter is greater than
5647 the static nesting level of the actual (access) parameter,
5648 the level to
5649 be passed is the minimum of the static nesting level
5650 of the access parameter
5651 and the actual level passed in.
5652 @end{Itemize}
5653
5654 @ChgRef{Version=[2],Kind=[Revised]}
5655 For the Accessibility_Check associated with a @nt{type_conversion}
5656 of an access parameter@Chg{Version=[2],New=[ of
5657 an access-to-object type],Old=[]} of a given subprogram to a
5658 named access type,
5659 if the target type is statically nested within the subprogram,
5660 do nothing; the check can't fail in this case.
5661 Otherwise, check that the value passed in is <= the static
5662 nesting depth of the target type.
5663 The other Accessibility_Checks are handled in a similar manner.
5664
5665 This method, using statically known values most of the time,
5666 is efficient, and, more importantly, avoids distributed overhead.
5667
5668 @ChgRef{Version=[3],Kind=[Added],ARef=[AI05-0148-1]}
5669 @ChgAdded{Version=[3],Text=[The implementation of accessibility checks for
5670 stand-alone objects of anonymous access-to-object types can be similar to
5671 that for anonymous access-to-object parameters. A static level suffices; it
5672 can be calculated using rules similar to those previously described for access
5673 parameters.]}
5674
5675 @ChgRef{Version=[3],Kind=[Added],ARef=[AI05-0148-1]}
5676 @ChgAdded{Version=[3],Text=[One important difference between the stand-alone
5677 access variables and access parameters is that one can assign a local access
5678 parameter to a more global stand-alone access variable. Similarly, one can
5679 assign a more global access parameter to a more local stand-alone access
5680 variable.]}
5681
5682 @ChgRef{Version=[3],Kind=[Added],ARef=[AI05-0148-1]}
5683 @ChgAdded{Version=[3],Text=[For these cases, it is important to note that the
5684 @ldquote@;correct@rdquote static accessibility level for an access parameter
5685 assigned to a stand-alone access object is the minimum of the passed in
5686 level and the static accessibility level of the stand-alone object itself.
5687 This is true since the static accessibility level passed in might be deeper
5688 than that of the stand-alone object, but the dynamic accessibility of the
5689 passed in object clearly must be shallower than the stand-alone object
5690 (whatever is passed in must live at least as long as the subprogram call). We
5691 do not need to keep a more local static level as accesses to objects
5692 statically deeper than the stand-alone object cannot be stored into the
5693 stand-alone object.]}
5694 @end(ImplNote)
5695 @begin{Discussion}
5696 @Leading@keepnext@;Examples of accessibility:
5697 @begin{Example}
5698 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0005-1]}@Comment{A1 is access-to-variable, X better be a variable}
5699 @key[package] @key[body] Lib_Unit @key[is]
5700 @key[type] T @key[is] @key[tagged] ...;
5701 @key[type] A0 @key[is] @key[access] @key[all] T;
5702 Global: A0 := ...;
5703 @key[procedure] P(X: @Chg{Version=[3],New=[@key[in out] ],Old=[]}T) @key[is]
5704 Y: @key[aliased] T;
5705 @key[type] A1 @key[is] @key[access] @key[all] T;
5706 Ptr0: A0 := Global; --@RI{ OK.}
5707 Ptr1: A1 := X'Access; --@RI{ OK.}
5708 @key[begin]
5709 Ptr1 := Y'Access; --@RI{ OK;}
5710 Ptr0 := A0(Ptr1); --@RI{ Illegal type conversion!}
5711 Ptr0 := X'Access; --@RI{ Illegal reference to Access attribute!}
5712 Ptr0 := Y'Access; --@RI{ Illegal reference to Access attribute!}
5713 Global := Ptr0; --@RI{ OK.}
5714 @key[end] P;
5715 @key[end] Lib_Unit;
5716 @end{Example}
5717
5718 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0005-1]}
5719 The above illegal statements are illegal because the accessibility
5720 @Chg{Version=[3],New=[levels],Old=[level]} of X and Y are statically deeper
5721 than the accessibility level of A0.
5722 In every possible execution of any program including this library
5723 unit, if P is called, the accessibility level of X will be
5724 (dynamically) deeper than that of A0.
5725 Note that the accessibility levels of X and Y are the same.
5726
5727 @ChgRef{Version=[2],Kind=[Revised]}
5728 @Leading@keepnext@;Here's an example involving access
5729 parameters@Chg{Version=[2],New=[ of an access-to-object type],Old=[]}:
5730 @begin{Example}
5731 @key[procedure] Main @key[is]
5732 @key[type] Level_1_Type @key[is] @key[access] @key[all] Integer;
5733
5734 @key[procedure] P(X: @key[access] Integer) @key[is]
5735 @key[type] Nested_Type @key[is] @key[access] @key[all] Integer;
5736 @key[begin]
5737 ... Nested_Type(X) ... --@RI{ (1)}
5738 ... Level_1_Type(X) ... --@RI{ (2)}
5739 @key[end] P;
5740
5741 @key[procedure] Q(X: @key[access] Integer) @key[is]
5742 @key[procedure] Nested(X: @key[access] Integer) @key[is]
5743 @key[begin]
5744 P(X);
5745 @key[end] Nested;
5746 @key[begin]
5747 Nested(X);
5748 @key[end] Q;
5749
5750 @key[procedure] R @key[is]
5751 Level_2: @key[aliased] Integer;
5752 @key[begin]
5753 Q(Level_2'Access); --@RI{ (3)}
5754 @key[end] R;
5755
5756 Level_1: @key[aliased] Integer;
5757 @key[begin]
5758 Q(Level_1'Access); --@RI{ (4)}
5759 R;
5760 @key[end] Main;
5761 @end{Example}
5762
5763 The run-time Accessibility_Check at (1) can never fail,
5764 and no code should be generated to check it.
5765 The check at (2) will fail when called from (3),
5766 but not when called from (4).
5767
5768 @Leading@;Within a @nt{type_declaration}, the rules are checked in an
5769 assume-the-worst manner.
5770 For example:
5771 @begin{Example}
5772 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0298-1]}
5773 @key[package] P @key[is]
5774 @key[type] Int_Ptr @key[is] @key[access] @key[all] Integer;
5775 @key[type] Rec(D: @key[access] Integer) @key[is] @key[limited] @key[private];
5776 @key[private]
5777 @key[type] Rec_Ptr @key[is] @key[access] @key[all] Rec;
5778 @key[function] F(X: Rec_Ptr) @key[return] Boolean;
5779 @key[function] G(X: @key[access] Rec) @key[return] Boolean;
5780 @key[type] Rec(D: @key[access] Integer) @key[is]
5781 @Chg{Version=[3],New=[@key[limited] ],Old=[]}@key[record]
5782 C1: Int_Ptr := Int_Ptr(D); --@RI{ Illegal!}
5783 C2: Rec_Ptr := Rec'Access; --@RI{ Illegal!}
5784 C3: Boolean := F(Rec'Access); --@RI{ Illegal!}
5785 C4: Boolean := G(Rec'Access);
5786 @key[end] @key[record];
5787 @key[end] P;
5788 @end{Example}
5789
5790 C1, C2, and C3 are all illegal, because one might declare an object of
5791 type Rec at a more deeply nested place than the declaration of the type.
5792 C4 is legal, but the accessibility level of the object will be passed to
5793 function G, and constraint checks within G will prevent it from
5794 doing any evil deeds.
5795
5796 Note that we cannot defer the checks on C1, C2, and C3 until
5797 compile-time of the object creation, because that would cause violation
5798 of the privacy of private parts.
5799 Furthermore, the problems might occur within a task or protected body,
5800 which the compiler can't see while compiling an object creation.
5801 @end{Discussion}
5802
5803 @begin{WideAbove}
5804 @Leading@;The following attribute is defined for @PrefixType{a @nt{prefix} X that
5805 denotes an aliased view of an object}:
5806 @end{WideAbove}
5807 @begin(description)
5808 @ChgAttribute{Version=[1], Kind=[Revised], ChginAnnex=[F], Leading=[F],
5809 Prefix=<X>, AttrName=<Access>, Ref=[8652/0010], ARef=[AI95-00127-01],
5810 Text=<X'Access yields an access value that designates the object
5811 denoted by X. The type of X'Access is an access-to-object type,
5812 as determined by the expected type.
5813 The expected type shall be a general access type.>}
5814 @IndexSeeAlso{Term=[Unchecked_Access attribute],See=(Access attribute)}
5815 @EndPrefixType{}
5816 X shall denote an aliased view of an object@Redundant[, including possibly the
5817 current instance (see @RefSecNum{The Context of Overload Resolution})
5818 of a limited type within its definition, or a formal parameter
5819 or generic formal object of a tagged type].
5820 The view denoted by the @nt<prefix> X
5821 shall satisfy the following additional requirements, presuming the
5822 expected type for X'Access is the general access type
5823 @i(A)@Chg{New=[ with designated type @i(D)],Old=[]}:
5824 @begin(itemize)
5825 If @i(A) is an access-to-variable type, then the view shall be a
5826 variable; @Redundant[on the other hand, if @i(A) is an
5827 access-to-constant type, the view may be either a constant
5828 or a variable.]
5829 @begin{Discussion}
5830 The current instance of a limited type
5831 is considered a variable.
5832 @end{discussion}
5833
5834 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00363-01]}
5835 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0008-1],ARef=[AI05-0041-1]}
5836 The view shall not be a subcomponent that
5837 depends on discriminants of @Chg{Version=[3],New=[an object unless
5838 the object is known to be constrained],Old=[a
5839 variable whose nominal subtype is unconstrained,
5840 unless this subtype is indefinite,
5841 or the variable is @Chg{Version=[2],New=[constrained by its initial value],
5842 Old=[aliased]}]}.
5843
5844 @begin(Discussion)
5845 @comment{The following is a "fix" to keep consistent with v. 5.95;
5846 appearently 6.0 is different.
5847 @ChgRef{Version=[1],Kind=[Deleted]}
5848 @ChgDeleted{Version=[1],Text=[Old @b{Change}.]}}
5849
5850 This restriction is intended to be similar to the restriction
5851 on renaming discriminant-dependent subcomponents.
5852 @end{Discussion}
5853 @begin{Reason}
5854 This prevents references to subcomponents that might
5855 disappear or move or change constraints after creating the reference.
5856 @end{Reason}
5857 @begin{ImplNote}
5858 @Leading@;There was some thought to making this restriction
5859 more stringent, roughly:
5860 "X shall not denote a subcomponent of a variable
5861 with discriminant-dependent subcomponents, if the nominal
5862 subtype of the variable is an unconstrained definite subtype."
5863 This was because in some implementations, it is not
5864 just the discriminant-dependent subcomponents that might
5865 move as the result of an assignment that changed the discriminants
5866 of the enclosing object. However, it was decided not to make
5867 this change because a reasonable implementation strategy was identified
5868 to avoid such problems, as follows:
5869 @begin(Itemize)
5870 Place nondiscriminant-dependent components with any aliased parts
5871 at offsets preceding any discriminant-dependent components
5872 in a discriminated record type with defaulted discriminants.
5873
5874 Preallocate the maximum space for unconstrained discriminated
5875 variables with aliased subcomponents, rather than allocating
5876 the initial size and moving them to a larger (heap-resident)
5877 place if they grow as the result of an assignment.
5878 @end(Itemize)
5879
5880 Note that for objects of a by-reference type, it is not an error
5881 for a programmer to take advantage of the fact that such objects
5882 are passed by reference. Therefore, the above approach is also
5883 necessary for discriminated record types with components of
5884 a by-reference type.
5885
5886 To make the above strategy work, it is important that
5887 a component of a derived type is defined to be
5888 discriminant-dependent if it is inherited and the parent subtype
5889 constraint is defined in terms of a discriminant of the derived type
5890 (see @RefSecNum(Discriminants)).
5891 @end{ImplNote}
5892
5893 @ChgRef{Version=[1],Kind=[Revised],Ref=[8652/0010],ARef=[AI95-00127-01]}
5894 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00363-01]}
5895 If @Chg{New=[@i(A) is a named access type and @i(D) is a tagged type],
5896 Old=[the designated type of @i(A) is tagged]}, then the type of the view
5897 shall be covered by @Chg{New=[@i(D)],Old=[the designated type]};
5898 @Chg{New=[if @i(A) is anonymous and @i(D) is tagged, then the type of the
5899 view shall be either @i(D)'Class or a type covered by
5900 @Chg{Version=[2],New=[@i<D>],Old=[D]};],Old=[]}
5901 if @Chg{New=[@i(D) is untagged],Old=[@i(A)'s designated type is not tagged]},
5902 then the type of the view shall be
5903 @Chg{New=[@i(D)],Old=[the same]},
5904 and @Chg{Version=[2],New=[either:],Old=[@Chg{New=[],Old=[either ]}@i(A)'s
5905 designated subtype shall @Chg{New=[either ],Old=[]}
5906 statically match the nominal subtype of the view@Chg{New=[ or be],
5907 Old=[, or the designated subtype shall be]} discriminated
5908 and unconstrained;
5909 @PDefn2{Term=[statically matching],Sec=(required)}]}
5910 @begin{InnerItemize}
5911 @ChgRef{Version=[2],Kind=[Added],ARef=[AI95-00363-01]}
5912 @ChgAdded{Version=[2],Text=[the designated subtype of @i{A} shall statically
5913 match the nominal subtype of the view;
5914 or@PDefn2{Term=[statically matching],Sec=(required)}]}
5915
5916 @ChgRef{Version=[2],Kind=[Added],ARef=[AI95-00363-01]}
5917 @ChgRef{Version=[3],Kind=[RevisedAdded],ARef=[AI05-0041-1]}
5918 @ChgRef{Version=[4],Kind=[RevisedAdded],ARef=[AI12-0095-1]}
5919 @ChgAdded{Version=[2],Text=[@i{D} shall be discriminated in its full view
5920 and unconstrained in any partial view, and the designated subtype of
5921 @i{A} shall be unconstrained.@Chg{Version=[3],New=[@Chg{Version=[4],New=[],
5922 Old=[ For the purposes
5923 of determining within a generic body whether @i{D} is unconstrained
5924 in any partial view, a discriminated subtype is
5925 considered to have a constrained partial view if it is a descendant
5926 of an untagged generic formal private or derived type.]}],Old=[]}]}
5927 @end{InnerItemize}
5928 @begin{ImplNote}
5929 This ensures
5930 that the dope for an aliased array object can always be stored contiguous
5931 with it, but need not be if its nominal subtype is constrained.
5932 @end{implnote}
5933 @begin{Ramification}
5934 @ChgRef{Version=[1],Kind=[Added],Ref=[8652/0010],ARef=[AI95-00127-01]}
5935 @Chg{New=[An access attribute can be used as the controlling operand in a
5936 dispatching call; see @RefSecNum{Dispatching Operations of Tagged Types}.],
5937 Old=[]}
5938
5939 @ChgRef{Version=[2],Kind=[Added],ARef=[AI95-00363-01]}
5940 @Chg{Version=[2],New=[This does not require that types have a partial view
5941 in order to allow an access attribute of an unconstrained discriminated
5942 object, only that any partial view that does exist is unconstrained.],Old=[]}
5943 @end{Ramification}
5944
5945 @begin{Discussion}
5946 @ChgRef{Version=[4],Kind=[Added],ARef=[AI12-0095-1]}
5947 @ChgAdded{Version=[4],Text=[We assume the worst in a generic body whether
5948 or not a formal subtype has a constrained partial view; specifically, in a
5949 generic body a discriminated subtype is considered to have a constrained
5950 partial view if it is a descendant of an untagged generic formal private
5951 or derived type (see @RefSecNum{Formal Private and Derived Types} for the
5952 formal definition of this rule).]}
5953 @end{Discussion}
5954
5955 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0041-1]}
5956 The accessibility level of the view shall not be statically deeper
5957 than that of the access type @i{A}.@Chg{Version=[3],New=[],Old=[
5958 In addition to the places where @LegalityTitle normally apply
5959 (see @RefSecNum{Generic Instantiation}),
5960 this rule applies also in the private part of an
5961 instance of a generic unit.@PDefn{generic contract issue}]}
5962 @PDefn2{Term=[accessibility rule],Sec=(Access attribute)}
5963 @begin(Ramification)
5964 In an instance body, a runtime check applies.
5965
5966 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00230-01]}
5967 If @i(A) is an anonymous@Chg{Version=[2],New=[ access-to-object type of
5968 an access parameter],Old=[access type]}, then the view can never have a
5969 deeper accessibility level than @i(A)@Chg{Version=[2],New=[. The same is
5970 true for an anonymous access-to-object type of an access
5971 discriminant],Old=[]}, except when X'Access is used to initialize
5972 an access discriminant of an object created by an @nt<allocator>.
5973 The latter case is illegal if the accessibility level of X
5974 is statically deeper than that of the access type of the
5975 @nt<allocator>; a runtime check is needed in the case where the
5976 initial value comes from an access parameter.@Chg{Version=[2],New=[ Other
5977 anonymous access-to-object types have "normal" accessibility checks.],Old=[]}
5978 @end(Ramification)
5979 @end(itemize)
5980
5981 @ChgRef{Version=[3],Kind=[Added],ARef=[AI05-0041-1]}
5982 @ChgAdded{Version=[3],NoPrefix=[T],Text=[In addition to the places where
5983 @LegalityTitle normally apply
5984 (see @RefSecNum{Generic Instantiation}), these requirements apply
5985 also in the private part of an instance of a generic
5986 unit.@PDefn{generic contract issue}]}
5987
5988 @NoPrefix@IndexCheck{Accessibility_Check}
5989 @Defn2{Term=[Program_Error],Sec=(raised by failure of runtime check)}
5990 A check is made that the accessibility level of X is not
5991 deeper than that of the access type @i(A).
5992 If this check fails, Program_Error is raised.
5993 @begin{Ramification}
5994 @ChgRef{Version=[2],Kind=[Revised]}
5995 The check is needed for access parameters @Chg{Version=[2],New=[ of
5996 an access-to-object type],Old=[]} and in instance bodies.
5997
5998 @ChgRef{Version=[3],Kind=[Added],ARef=[AI05-0024-1]}
5999 @ChgAdded{Version=[3],Text=[Because there are no access parameters permitted for task
6000 entries, the accessibility levels are always comparable. We would have to
6001 switch to the terminology used in @RefSecNum{Allocators} and
6002 @RefSecNum{Return Statements} based on inclusion within
6003 masters if we relax this restriction. That might introduce unacceptable
6004 distributed overhead.]}
6005 @end{Ramification}
6006 @begin(ImplNote)
6007 @ChgRef{Version=[2],Kind=[Revised]}
6008 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0148-1]}
6009 This check requires that some indication of lifetime is
6010 passed as an implicit parameter along with access parameters@Chg{Version=[2],
6011 New=[ of an access-to-object type],Old=[]}.@Chg{Version=[3],New=[ A similar
6012 indication is required for stand-alone objects of anonymous access-to-object
6013 types.],Old=[]}No such requirement applies to @Chg{Version=[2],New=[other
6014 anonymous access types],Old=[access discriminants]}, since
6015 the checks associated with them are all compile-time checks.
6016 @end(ImplNote)
6017
6018 @NoPrefix@PDefn2{Term=[implicit subtype conversion],Sec=(Access attribute)}
6019 If the nominal subtype of X does not statically match the designated
6020 subtype of @i(A), a view conversion of X to the designated subtype
6021 is evaluated (which might raise Constraint_Error @em
6022 see @RefSecNum(Type Conversions))
6023 and the value of X'Access designates that view.
6024 @end(description)
6025
6026 The following attribute is defined for @PrefixType{a @nt{prefix} P that
6027 denotes a subprogram}:
6028 @begin(description)
6029 @ChgAttribute{Version=[5],Kind=[Revised],ChginAnnex=[F], Leading=[F],
6030 Prefix=<P>, AttrName=<Access>,ARef=[AI95-00229-01], ARef=[AI95-00254-01],ARef=[AI05-0239-1],ARef=[AI12-0064-2],
6031 Text=<P'Access yields an access value that designates the subprogram
6032 denoted by P.
6033 The type of P'Access is an access-to-subprogram type (@i(S)),
6034 as determined by the expected type.>}
6035 @EndPrefixType{}
6036 @PDefn2{Term=[accessibility rule],Sec=(Access attribute)}
6037 The accessibility level of P shall not be statically deeper than
6038 that of @i{S}.@Chg{Version=[5],New=[ If @i{S} is nonblocking, P shall
6039 be nonblocking. ],Old=[]}
6040 @PDefn{generic contract issue}
6041 In addition to the places where @LegalityTitle normally apply
6042 (see @RefSecNum{Generic Instantiation}),
6043 @Chg{Version=[5],New=[these rules apply],Old=[this rule applies]} also in
6044 the private part of an instance of a generic unit.
6045 The profile of P
6046 shall be @Chg{Version=[3],New=[subtype conformant],Old=[subtype-conformant]}
6047 with the designated profile of @i(S),
6048 and shall not be Intrinsic.
6049 @Defn2{Term=[subtype conformance],Sec=(required)}
6050 If the subprogram denoted by P is declared within a
6051 generic @Chg{Version=[2],New=[unit, and the expression P'Access occurs within
6052 the body of that generic unit or within the body of a generic unit declared
6053 within the declarative region of the generic unit, then the ultimate ancestor
6054 of @i{S} shall be either a nonformal type declared within the generic unit
6055 or an anonymous access type of an access parameter.],
6056 Old=[body, @i{S} shall be declared within the generic body.]}
6057
6058 @begin(Discussion)
6059 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00229-01]}
6060 The part about generic bodies is worded in terms of the denoted
6061 subprogram, not the denoted view; this implies that renaming is
6062 invisible to this part of the
6063 rule.@Chg{Version=[2],New=[ @lquotes@;Declared within the declarative region of
6064 the generic@rquotes@; is referring to child and nested generic
6065 units.],Old=[]} This rule is partly to prevent contract model problems
6066 with respect to the accessibility rules,
6067 and partly to ease shared-generic-body implementations,
6068 in which a subprogram declared in an instance needs to have a
6069 different calling convention from other subprograms with the same
6070 profile.
6071
6072 @Comment{The change is from AI05-0239-1, just punctuation}
6073 Overload resolution ensures only that the profile
6074 is @Chg{Version=[3],New=[type conformant],Old=[type-conformant]}.
6075 This rule specifies that subtype conformance is required (which also
6076 requires matching calling conventions).
6077 P cannot denote an entry because access-to-subprogram types
6078 never have the @i(entry) calling convention. P cannot denote
6079 an enumeration literal or an attribute function because
6080 these have intrinsic calling conventions.
6081 @end(Discussion)
6082 @end(description)
6083
6084 @end{StaticSem}
6085
6086 @begin{Legality}
6087 @ChgRef{Version=[3],Kind=[Added],ARef=[AI05-0188-1]}
6088 @ChgAdded{Version=[3],Type=[Leading],Text=[An @nt{expression} is said to have
6089 @i{distributed accessibility} if it
6090 is@Defn{distributed accessibility}@Defn2{Term=[accessibility],Sec=[distributed]}]}
6091
6092 @begin{Itemize}
6093 @ChgRef{Version=[3],Kind=[Added]}
6094 @ChgAdded{Version=[3],Text=[a @nt{conditional_expression} (see
6095 @RefSecNum{Conditional Expressions}); or]}
6096
6097 @ChgRef{Version=[5],Kind=[Added],ARef=[AI12-0236-1]}
6098 @ChgAdded{Version=[5],Text=[a @nt{declare_expression} (see
6099 @RefSecNum{Declare Expressions}) whose @SynI{body_}@nt{expression} has
6100 distributed accessibility; or]}
6101
6102 @ChgRef{Version=[3],Kind=[Added]}
6103 @ChgRef{Version=[5],Kind=[RevisedAdded]}@ChgNote{Paragraph number changed}
6104 @ChgAdded{Version=[3],Text=[a view conversion, @nt{qualified_expression},
6105 or parenthesized expression whose operand has distributed accessibility.]}
6106 @end{Itemize}
6107
6108 @ChgRef{Version=[3],Kind=[Added],ARef=[AI05-0188-1]}
6109 @ChgRef{Version=[5],Kind=[RevisedAdded]}@ChgNote{Paragraph number changed}
6110 @ChgAdded{Version=[3],Text=[The statically deeper relationship does not apply to
6111 the accessibility level of an @nt{expression} having distributed accessibility;
6112 that is, such an accessibility level is not considered to be statically deeper,
6113 nor statically shallower, than any other.]}
6114
6115 @ChgRef{Version=[3],Kind=[Added],ARef=[AI05-0188-1]}
6116 @ChgRef{Version=[5],Kind=[RevisedAdded]}@ChgNote{Paragraph number changed}
6117 @ChgAdded{Version=[3],Text=[Any static accessibility requirement that is imposed
6118 on an @nt{expression} that has distributed accessibility (or on its type) is
6119 instead imposed on the @SynI{dependent_}@nt{expression}s of the underlying
6120 @nt{conditional_expression}. This rule is applied recursively if a
6121 @SynI{dependent_}@nt{expression} also has distributed accessibility.]}
6122
6123 @begin{Discussion}
6124 @ChgRef{Version=[3],Kind=[AddedNormal]}
6125 @ChgAdded{Version=[3],Text=[This means that any @LegalityName requiring that
6126 the accessibility level of an @nt{expression} (or that of the type of an
6127 @nt{expression}) shall or shall not be statically deeper than some other level
6128 also applies, in the case where the @nt{expression} has distributed
6129 accessibility, to each @SynI{dependent_}@nt{expression} of the underlying
6130 @nt{conditional_expression}.]}
6131 @end{Discussion}
6132
6133 @end{Legality}
6134
6135 @begin{Notes}
6136 The Unchecked_Access attribute yields the same result as the Access
6137 attribute for objects, but has fewer restrictions
6138 (see @RefSecNum{Unchecked Access Value Creation}).
6139 There are other predefined operations that yield access values:
6140 an @nt<allocator> can be used to create an object, and return an
6141 access value that designates it (see @RefSecNum(Allocators));
6142 evaluating the literal @key(null) yields a null access value that designates
6143 no entity at all (see @RefSecNum(Literals)).
6144
6145 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00230-01]}
6146 @PDefn2{Term=[predefined operations],Sec=(of an access type)}
6147 The predefined operations of an access type also include
6148 the assignment operation, qualification, and membership tests.
6149 Explicit conversion is allowed between general access types with
6150 matching designated subtypes; explicit conversion is allowed
6151 between access-to-subprogram types with subtype conformant profiles
6152 (see @RefSecNum{Type Conversions}).
6153 @PDefn{subtype conformance}
6154 Named access types have predefined equality operators;
6155 anonymous access types do not@Chg{Version=[2],New=[, but they can use the
6156 predefined equality operators for @i<universal_access> ],Old=[]}(see
6157 @RefSecNum{Relational Operators and Membership Tests}).
6158 @begin(Reason)
6159 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00230-01]}
6160 @Chg{Version=[2],New=[Anonymous access types can use the universal access
6161 equality operators declared in Standard, while named access types cannot
6162 for compatibility reasons. ],Old=[]}By not
6163 having equality operators for anonymous access types,
6164 we eliminate the need to specify exactly where the
6165 predefined operators for anonymous access types would be defined, as
6166 well as the need for an implementer to insert an implicit
6167 declaration for "=", etc. at the appropriate place in their symbol table.
6168 Note that @Chg{Version=[2],New=[":=", ],Old=[]}'Access@Chg{Version=[2],New=[,],Old=[]} and
6169 ".@key[all]" are defined@Chg{Version=[2],New=[],Old=[, and ":=" is defined
6170 though useless since all instances are constant. The literal
6171 @key(null) is also defined for the
6172 purposes of overload resolution, but is disallowed by a @LegalityTitle
6173 of this subclause]}.
6174 @end(Reason)
6175
6176 The object or subprogram designated by an access value can be named
6177 with a dereference, either an @nt<explicit_@!dereference> or an
6178 @nt<implicit_dereference>. See @RefSecNum{Names}.
6179
6180 A call through the dereference of an access-to-subprogram
6181 value is never a dispatching call.
6182 @begin{TheProof}
6183 See @RefSecNum{Dispatching Operations of Tagged Types}.
6184 @end{TheProof}
6185
6186 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00254-01]}
6187 @Defn{downward closure}
6188 @Defn2{Term=[closure],Sec=(downward)}
6189 @Chg{Version=[2],New=[The],Old=[The accessibility rules imply that it
6190 is not possible to use the]} Access
6191 attribute@Chg{Version=[2],New=[ for subprograms and parameters of an
6192 anonymous access-to-subprogram type may together be used],Old=[]}
6193 to implement @lquotes@;downward closures@rquotes@; @em that is,
6194 to pass a more-nested subprogram as a parameter to a
6195 less-nested subprogram, as might be @Chg{Version=[2],
6196 New=[appropriate],Old=[desired for example]} for an
6197 iterator abstraction@Chg{Version=[2],New=[ or numerical integration.
6198 Downward],Old=[. Instead, downward]}
6199 closures can @Chg{Version=[2],New=[also ],Old=[]}be implemented using
6200 generic formal subprograms (see @RefSecNum{Formal Subprograms}).
6201 Note that Unchecked_Access is not allowed for subprograms.
6202
6203 Note that using
6204 an access-to-class-wide tagged type with a dispatching operation
6205 is a potentially more structured alternative to using an
6206 access-to-subprogram type.
6207
6208 An implementation may consider
6209 two access-to-subprogram values to be unequal,
6210 even though they designate the same subprogram. This might
6211 be because one points directly to the subprogram,
6212 while the other points to a special prologue that
6213 performs an Elaboration_Check and then jumps to the subprogram.
6214 See @RefSecNum(Relational Operators and Membership Tests).
6215 @begin{Ramification}
6216
6217 If equality of
6218 access-to-subprogram values is important to the logic
6219 of a program, a reference to the Access attribute of a subprogram
6220 should be evaluated only once
6221 and stored in a global constant for subsequent use and equality
6222 comparison.@end{ramification}
6223 @end{Notes}
6224
6225 @begin{Examples}
6226 @Leading@keepnext@i{Example of use of the Access attribute:}
6227 @begin{Example}
6228 @ChgRef{Version=[5],Kind=[Revised],ARef=[AI12-0312-1]}
6229 @Chg{Version=[5],New=[Becky],Old=[Martha]} : Person_Name := @key[new] Person(F); --@RI[ see @RefSecNum{Incomplete Type Declarations}]
6230 Cars @Chg{Version=[5],New=[],Old=[ ]}: @key[array] (1..2) @key[of] @key[aliased] Car;
6231 ...
6232 @Chg{Version=[5],New=[Becky],Old=[Martha]}.Vehicle := Cars(1)'Access;
6233 @Chg{Version=[5],New=[Casey],Old=[George]}.Vehicle := Cars(2)'Access;
6234 @end{Example}
6235 @end{Examples}
6236
6237 @begin{Extend83}
6238 @Defn{extensions to Ada 83}
6239 We no longer make things like 'Last and ".component"
6240 (basic) operations of an access type that need to be "declared"
6241 somewhere. Instead, implicit dereference
6242 in a @nt{prefix} takes care of them all. This means that
6243 there should never be a case when X.@key{all}'Last is legal
6244 while X'Last is not. See AI83-00154.
6245 @end{Extend83}
6246
6247 @begin{Incompatible95}
6248 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00363-01]}
6249 @Chg{Version=[2],New=[@Leading@;@Defn{incompatibilities with Ada 95} Aliased
6250 variables are not necessarily constrained in Ada 2005 (see
6251 @RefSecNum{Array Types}). Therefore, a subcomponent of an aliased variable
6252 may disappear or change shape, and taking 'Access of such a subcomponent
6253 thus is illegal, while the same operation would have been legal in Ada 95.
6254 Note that most allocated objects are
6255 still constrained by their initial value (see @RefSecNum{Allocators}), and thus
6256 legality of 'Access didn't change for them. For example:],Old=[]}
6257 @begin{Example}
6258 @ChgRef{Version=[2],Kind=[AddedNormal]}
6259 @Chg{Version=[2],New=[@key{type} T1 (D1 : Boolean := False) @key{is}
6260 @key{record}
6261 @key{case} D1 @key{is}
6262 @key{when} False =>
6263 C1 : @key{aliased} Integer;
6264 @key{when} True =>
6265 @key{null};
6266 @key{end} @key{case};
6267 @key{end} @key{record};
6268 @key{type} Acc_Int @key{is access all} Integer;],Old=[]}
6269
6270 @ChgRef{Version=[2],Kind=[AddedNormal]}
6271 @Chg{Version=[2],New=[A_T : @key{aliased} T1;
6272 Ptr : Acc_Int := A_T.C1'Access; -- @RI[Illegal in Ada 2005, legal in Ada 95]
6273 A_T := (D1 => True); -- @RI[Raised Constraint_Error in Ada 95, but does not]
6274 -- @RI[in Ada 2005, so Ptr would become invalid when this]
6275 -- @RI[is assigned (thus Ptr is illegal).]],Old=[]}
6276 @end{Example}
6277
6278 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00363-01]}
6279 @Chg{Version=[2],New=[If a discriminated full type has a partial view (private
6280 type) that is constrained, we do not allow 'Access on objects to create a value
6281 of an object of an
6282 access-to-unconstrained type. Ada 95 allowed this attribute and various
6283 access subtypes, requiring that the heap object be constrained and thus making
6284 details of the implementation of the private type visible to the client of
6285 the private type. See @RefSecNum{Allocators} for more on this topic.],Old=[]}
6286
6287 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00229-01],ARef=[AI95-00254-01]}
6288 @ChgAdded{Version=[2],Text=[@b[Amendment Correction:] Taking 'Access of a subprogram
6289 declared in a generic unit in the body of that generic is no longer allowed.
6290 Such references can easily be used to create dangling pointers, as
6291 @LegalityTitle are not rechecked in instance bodies. At the same time, the
6292 rules were loosened a bit where that is harmless, and also to allow any routine
6293 to be passed to an access parameter of an access-to-subprogram type. The now
6294 illegal uses of 'Access can almost always be moved to the private part of the
6295 generic unit, where they are still legal (and rechecked upon instantiation for
6296 possibly dangling pointers).]}
6297 @end{Incompatible95}
6298
6299 @begin{Extend95}
6300 @ChgRef{Version=[2],Kind=[AddedNormal],Ref=[8652/0010],ARef=[AI95-00127-01]}
6301 @ChgAdded{Version=[2],Text=[@b<Corrigendum:> @Defn{extensions to Ada 95}
6302 Access attributes of objects of class-wide types
6303 can be used as the controlling parameter in a dispatching calls (see
6304 @RefSecNum{Dispatching Operations of Tagged Types}). This was an oversight in
6305 Ada 95.]}
6306
6307 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00235-01]}
6308 @ChgAdded{Version=[2],Text=[@b[Amendment Correction:] The type of the prefix
6309 can now be used in resolving Access attributes. This allows more uses of the
6310 Access attribute to resolve. For example:]}
6311 @begin{Example}
6312 @ChgRef{Version=[2],Kind=[AddedNormal]}
6313 @ChgAdded{Version=[2],Text=[@key{type} Int_Ptr @key{is access all} Integer;
6314 @key{type} Float_Ptr @key{is access all} Float;]}
6315
6316 @ChgRef{Version=[2],Kind=[AddedNormal]}
6317 @ChgAdded{Version=[2],Text=[@key{function} Zap (Val : Int_Ptr) @key{return} Float;
6318 @key{function} Zap (Val : Float_Ptr) @key{return} Float;]}
6319
6320 @ChgRef{Version=[2],Kind=[AddedNormal]}
6321 @ChgAdded{Version=[2],Text=[Value : @key{aliased} Integer := 10;]}
6322
6323 @ChgRef{Version=[2],Kind=[AddedNormal]}
6324 @ChgAdded{Version=[2],Text=[Result1 : Float := Zap (Value'access); -- @RI[Ambiguous in Ada 95; resolves in Ada 2005.]
6325 Result2 : Float := Zap (Int_Ptr'(Value'access)); -- @RI[Resolves in Ada 95 and Ada 2005.]]}
6326 @end{Example}
6327 @ChgRef{Version=[2],Kind=[AddedNormal]}
6328 @ChgAdded{Version=[2],Text=[This change is upward compatible; any expression
6329 that does not resolve by the new rules would have failed a Legality Rule.]}
6330 @end{Extend95}
6331
6332 @begin{DiffWord95}
6333 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00162-01]}
6334 @ChgAdded{Version=[2],Text=[Adjusted the wording to reflect the fact that
6335 expressions and function calls are masters.]}
6336
6337 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00230-01],ARef=[AI95-00254-01],ARef=[AI95-00318-02],ARef=[AI95-00385-01],ARef=[AI95-00416-01]}
6338 @ChgAdded{Version=[2],Text=[Defined the accessibility of the various new kinds and
6339 uses of anonymous access types.]}
6340 @end{DiffWord95}
6341
6342 @begin{Incompatible2005}
6343 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0008-1]}
6344 @ChgAdded{Version=[3],Text=[@Defn{incompatibilities with Ada 2005}@b<Correction:>
6345 Simplified the description of when a discriminant-dependent component is
6346 allowed as the prefix of 'Access to when the object is known to be
6347 constrained. This fixes a confusion as to whether a subcomponent of an object
6348 that is not certain to be constrained can be used as a prefix of 'Access. The
6349 fix introduces an incompatibility, as the rule did not apply in Ada 95 if the
6350 prefix was a constant; but it now applies no matter what kind of object is
6351 involved. The incompatibility is not too bad, since most kinds of constants
6352 are known to be constrained.]}
6353
6354 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0041-1]}
6355 @ChgAdded{Version=[3],Text=[@b<Correction:> Corrected the checks for the
6356 constrainedness of the prefix of the Access attribute so that assume-the-worst
6357 is used in generic bodies. This may make some programs illegal, but those
6358 programs were at risk having objects disappear while valid access values still
6359 pointed at them.]}
6360 @end{Incompatible2005}
6361
6362 @begin{Extend2005}
6363 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0082-1]}
6364 @ChgAdded{Version=[3],Text=[@Defn{extensions to Ada 2005}@b<Correction:>
6365 Eliminated the static accessibility definition for generic formal types, as
6366 the actual can be more or less nested than the generic itself. This allows
6367 programs that were illegal for Ada 95 and for Ada 2005.]}
6368
6369 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0148-1],ARef=[AI05-0253-1]}
6370 @ChgAdded{Version=[3],Text=[Eliminate the static
6371 accessibility definition for stand-alone objects of anonymous access-to-object
6372 types. This allows such objects to be used as temporaries without causing
6373 accessibility problems.]}
6374 @end{Extend2005}
6375
6376 @begin{DiffWord2005}
6377 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0014-1]}
6378 @ChgAdded{Version=[3],Text=[@b<Correction:> Corrected the rules so that the
6379 accessibility of the object designated by an access object is that of the
6380 access type, even when no dereference is given. The accessibility was not
6381 specified in the past. This correction applies to both Ada 95 and Ada 2005.]}
6382
6383 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0024-1]}
6384 @ChgAdded{Version=[3],Text=[@b<Correction:> Corrected accessibility rules for
6385 access discriminants so that no cases are omitted.]}
6386
6387 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0051-1],ARef=[AI05-0234-1],ARef=[AI05-0235-1],ARef=[AI05-0284-1]}
6388 @ChgAdded{Version=[3],Text=[@b<Correction:> Corrected accessibility rules for
6389 anonymous access return types and access discriminants in return statements.]}
6390
6391 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0066-1]}
6392 @ChgAdded{Version=[3],Text=[@b<Correction:> Changed coextension rules so that
6393 coextensions that belong to an anonymous object are transfered to the ultimate
6394 object.]}
6395
6396 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0142-4],ARef=[AI05-0188-1],ARef=[AI05-0235-1]}
6397 @ChgAdded{Version=[3],Text=[Defined the accessibility of explicitly
6398 aliased parameters (see @RefSecNum{Subprogram Declarations}) and
6399 @nt{conditional_expression}s (see @RefSecNum{Conditional Expressions}).]}
6400
6401 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0234-1]}
6402 @ChgAdded{Version=[3],Text=[@b<Correction:> Defined the term @ldquote@;master
6403 of the call@rdquote to simplify other wording, especially that for the
6404 accessibility checks associated with return statements and explicitly aliased
6405 parameters.]}
6406
6407 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0270-1]}
6408 @ChgAdded{Version=[3],Text=[@b<Correction:> Defined the (omitted)
6409 accessibility level of null values when those are passed as the actual of an
6410 access-to-object parameter.]}
6411 @end{DiffWord2005}
6412
6413 @begin{Inconsistent2012}
6414 @ChgRef{Version=[5],Kind=[AddedNormal],ARef=[AI12-0278-1]}
6415 @ChgAdded{Version=[5],Text=[@Defn{inconsistencies with Ada 2012}@b<Correction:>
6416 Defined that the accessibility of a function that returns an anonymous
6417 access type is the same for implicit and explicit conversions to a named
6418 access type. This could cause code that is legal and does not raise an
6419 exception in original Ada 2012 to become illegal or raise
6420 Program_Error because of an accessibility failure in Ada 202x. This is more
6421 likely to prevent a dangling pointer bug than to prevent something useful.]}
6422
6423 @ChgRef{Version=[5],Kind=[AddedNormal],ARef=[AI12-0345-1]}
6424 @ChgAdded{Version=[5],Type=[Leading],Text=[@b<Correction:> Tightened the
6425 cases where an explicitly aliased parameter has special accessibility, to
6426 avoid needing to pass the required dynamic accessibility to functions that
6427 have explicitly alised parameters. The changes affects programs that use
6428 the dynamic accessibility of an explicitly aliased parameter within a return
6429 statement of a function (typically using anonymous access types). This can
6430 mean that a program that would have been legal and worked in Ada 2012 as
6431 defined would raise Program_Error or be rejected in Ada 202x. One such
6432 example is:]}
6433 @begin{Example}
6434 @ChgRef{Version=[5],Kind=[AddedNormal]}
6435 @ChgAdded{Version=[5],Text=[@key[type] Rec @key[is record]
6436 Comp : @key[aliased] Integer;
6437 ...
6438 @key[end record];]}
6439
6440 @ChgRef{Version=[5],Kind=[AddedNormal]}
6441 @ChgAdded{Version=[5],Text=[@key[function] F1 (A : @key[aliased in out] Rec) @key[return access] Integer @key[is]
6442 @key[function] F2 (B : @key[access] Integer) @key[return access] Integer
6443 @key[is] (B); -- @examcom{(1)}
6444 @key[begin]
6445 @key[return] F2 (A.Comp'Access); -- @examcom{(2)}
6446 @key[end] F1;]}
6447 @end{Example}
6448 @ChgRef{Version=[5],Kind=[AddedNormal]}
6449 @ChgAdded{Version=[5],Type=[Trailing],Text=[At (2), there is a check that the
6450 dynamic accessibility level of B is not deeper than the master of the call
6451 for F2 (which is defined to be the master of the call for F1). In Ada 2012,
6452 since the reference is inside of a return statement, the dynamic accessibility
6453 of A.Comp'Access is the master of the call for F1 - meaning the check at (2)
6454 should pass. In Ada 202x, the the dynamic accessibility of A.Comp'Access is
6455 local for for F1 - meaning the check at (2) should fail and raise
6456 Program_Error.]}
6457
6458 @ChgRef{Version=[5],Kind=[AddedNormal]}
6459 @ChgAdded{Version=[5],Text=[We're not aware of any Ada 2012 compilers that
6460 correctly implemented the rule as written (because of the overhead that is
6461 implied), so the practical effect of this change is to make the rules more
6462 consistent with actual practice.]}
6463
6464 @ChgRef{Version=[5],Kind=[AddedNormal],ARef=[AI12-0345-1]}
6465 @ChgAdded{Version=[5],Type=[Leading],Text=[@b<Correction:> Adjusted the rules
6466 so that using a part of a return object in a return expression does not
6467 break the connection between the inner and outer function calls. This
6468 means that some cases that (unnecessarily) failed an accessibility check in
6469 Ada 2012 will not do so in Ada 202x. This change will mostly remove latent
6470 problems from Ada code; very little code depends on an accessibility check
6471 failing.]}
6472 @end{Inconsistent2012}
6473
6474 @begin{Incompatible2012}
6475 @ChgRef{Version=[4],Kind=[AddedNormal],ARef=[AI12-0027-1]}
6476 @ChgAdded{Version=[4],Text=[@Defn{incompatibilities with Ada 2012}@b<Corrigendum:>
6477 Defined the accessibility of a value conversion, so that it is treated like
6478 an @nt{aggregate} built at the point of the conversion. This was
6479 previously unspecified, so this change might be
6480 incompatible if an Ada implementation treated the accessibility of such
6481 conversions as that of the operand type; in that case, previous legal
6482 conversions probably will become illegal as the lifetime of the conversion
6483 is very short. However, code that could tell this difference is fairly rare
6484 (taking 'Access of a component of a result of a type conversion), code
6485 depending on this accessibility was not portable, and such code could have
6486 created an immediately dangling pointer if the conversion actually made
6487 a copy (which is necessary in some instances).]}
6488
6489 @ChgRef{Version=[5],Kind=[AddedNormal],ARef=[AI12-0371-1]}
6490 @ChgAdded{Version=[5],Text=[The accessibility of a renaming of a formal
6491 subprogram in a generic package specification has changed to reflect the
6492 fact that a wrapper may be needed for the formal subprogram. Thus,
6493 'Access of such a renaming found in an instance that is not library-level
6494 may become illegal. We think this case is unlikely to occur in practice,
6495 and a simple workaround is available (rename the actual at the point of
6496 the instance, use that rename as the prefix of 'Access).]}
6497 @end{Incompatible2012}
6498
6499 @begin{DiffWord2012}
6500 @ChgRef{Version=[4],Kind=[AddedNormal],ARef=[AI12-0067-1]}
6501 @ChgAdded{Version=[4],Text=[@b<Corrigendum:> Corrected so that it is clear
6502 that explicitly aliased parameters in procedures have the same accessibility
6503 as other parameters. Only explicitly aliased parameters in functions are
6504 special.]}
6505
6506 @ChgRef{Version=[4],Kind=[AddedNormal],ARef=[AI12-0070-1]}
6507 @ChgAdded{Version=[4],Text=[@b<Corrigendum:> The accessibility of
6508 an anonymous access type of an @nt{extended_return_statement} is defined
6509 here rather than in @RefSecNum{Return Statements} so that all accessibility
6510 rules are here.]}
6511
6512 @ChgRef{Version=[4],Kind=[AddedNormal],ARef=[AI12-0089-1]}
6513 @ChgAdded{Version=[4],Text=[@b<Corrigendum:> Corrected a number of rules so
6514 that they clearly apply to generic functions as well as functions. (Remember,
6515 a generic function is not a function.)]}
6516
6517 @ChgRef{Version=[4],Kind=[AddedNormal],ARef=[AI12-0095-1]}
6518 @ChgAdded{Version=[4],Text=[@b<Corrigendum:> Moved the assume the worst rule
6519 about constrainedness of the prefix of attribute Access to
6520 @RefSecNum{Formal Private and Derived Types}, as a number of places in the
6521 Standard need this rule.]}
6522
6523 @ChgRef{Version=[4],Kind=[AddedNormal],ARef=[AI12-0157-1]}
6524 @ChgAdded{Version=[4],Text=[@b<Corrigendum:> Ensured that the statically
6525 deeper relationship applies within the return expression of an expression
6526 function. (Dynamic properties apply by equivalence, but static properties
6527 are handled separately.)]}
6528
6529 @ChgRef{Version=[5],Kind=[AddedNormal],ARef=[AI12-0064-2]}
6530 @ChgAdded{Version=[5],Text=[Added Nonblocking (see
6531 @RefSecNum{Intertask Communication}) matching to P'Access.]}
6532
6533 @ChgRef{Version=[5],Kind=[AddedNormal],ARef=[AI12-0156-1]}
6534 @ChgAdded{Version=[5],Text=[Added text to define the accessibility of
6535 anonymous access types declaring a loop parameter.]}
6536
6537 @ChgRef{Version=[5],Kind=[AddedNormal],ARef=[AI12-0236-1]}
6538 @ChgAdded{Version=[5],Text=[Added @nt{declare_expression}s to the
6539 accessibility rules.]}
6540
6541 @ChgRef{Version=[5],Kind=[AddedNormal],ARef=[AI12-0277-1]}
6542 @ChgAdded{Version=[5],Text=[@b<Correction:> Clarified the static level of
6543 explicitly aliased parameters.]}
6544 @end{DiffWord2012}
6545
6546
6547 @RMNewPageVer{Version=[3]}@Comment{For printed version of Ada 2012 RM}
6548 @LabeledClause{Declarative Parts}
6549
6550 @begin{Intro}
6551 @Redundant[A @nt<declarative_part> contains @nt<declarative_item>s
6552 (possibly none).]
6553 @end{Intro}
6554
6555 @begin{Syntax}
6556 @Syn{lhs=<declarative_part>,rhs="{@Syn2{declarative_item}}"}
6557
6558
6559 @Syn{lhs=<declarative_item>,rhs="
6560 @Syn2{basic_declarative_item} | @Syn2{body}"}
6561
6562 @ChgRef{Version=[1],Kind=[Revised],Ref=[8652/0009],ARef=[AI95-00137-01]}
6563 @Syn{lhs=<basic_declarative_item>,rhs="
6564 @Syn2{basic_declaration} | @Chg{New=[@Syn2{aspect_clause}],Old=[@Syn2{representation_clause}]} | @Syn2{use_clause}"}
6565
6566 @Syn{lhs=<body>,rhs="@Syn2{proper_body} | @Syn2{body_stub}"}
6567
6568 @Syn{lhs=<proper_body>,rhs="
6569 @Syn2{subprogram_body} | @Syn2{package_body} | @Syn2{task_body} | @Syn2{protected_body}"}
6570 @end{Syntax}
6571
6572 @begin{StaticSem}
6573 @ChgRef{Version=[2],Kind=[Added],ARef=[AI95-00420-01]}
6574 @ChgAdded{Version=[2],Text=[The list of @nt{declarative_item}s of a
6575 @nt{declarative_part} is called the @i{declaration list} of the
6576 @nt{declarative_part}.@PDefn2{Term=[declaration list],Sec=[declarative_part]}]}
6577 @end{StaticSem}
6578
6579 @begin{RunTime}
6580 @PDefn2{Term=[elaboration], Sec=(declarative_part)}
6581 The elaboration of a @nt{declarative_part} consists of the elaboration of
6582 the @nt{declarative_item}s, if any, in the order in which they are given
6583 in the @nt{declarative_part}.
6584
6585 @Defn{elaborated}
6586 An elaborable construct is in the @i(elaborated) state after the
6587 normal completion of its elaboration.
6588 Prior to that, it is @i(not yet elaborated).
6589 @begin{Ramification}
6590 The elaborated state is only important for bodies;
6591 certain uses of a body raise an exception if the body is not yet
6592 elaborated.
6593
6594 Note that "prior" implies before the start of elaboration,
6595 as well as during elaboration.
6596
6597 The use of the term "normal completion" implies that
6598 if the elaboration propagates an exception or is aborted, the
6599 declaration is not elaborated.
6600 RM83 missed the aborted case.
6601 @end{Ramification}
6602
6603 @IndexCheck{Elaboration_Check}
6604 For a construct that attempts to use a body,
6605 a check (Elaboration_Check) is performed, as follows:
6606 @begin{Itemize}
6607 @ChgRef{Version=[1],Kind=[Revised],Ref=[8652/0014],ARef=[AI95-00064-01]}
6608 For a call to a (non-protected) subprogram that has
6609 an explicit body, a check is made that the
6610 @Chg{New=[body],Old=[@nt{subprogram_body}]} is already elaborated.
6611 This check and the evaluations of any actual parameters of the call
6612 are done in an arbitrary order.@PDefn2{Term=[arbitrary order],Sec=[allowed]}
6613 @begin{Discussion}
6614 AI83-00180 specifies that there is no elaboration check for
6615 a subprogram defined by a @nt{pragma} Interface (or equivalently,
6616 @nt{pragma} Import). AI83-00430 specifies that there is no elaboration check
6617 for an enumeration literal. AI83-00406 specifies that the evaluation
6618 of parameters and the elaboration check occur in an arbitrary order.
6619 AI83-00406 applies to generic instantiation as well (see below).
6620
6621 @ChgRef{Version=[1],Kind=[Added],Ref=[8652/0014],ARef=[AI95-00064-01]}
6622 @ChgRef{Version=[3],Kind=[RevisedAdded],ARef=[AI05-0177-1]}
6623 @ChgAdded{Version=[1],Text=[A subprogram can be completed by a
6624 renaming-as-body@Chg{Version=[3],New=[, a @nt{null_procedure_declaration}, or
6625 an @nt{expression_function_declaration}],Old=[]}, and we need
6626 to make an elaboration check on such a body, so we use
6627 @lquotes@;body@rquotes@; rather than @nt{subprogram_body} above.]}
6628 @end{Discussion}
6629
6630 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0229-1]}
6631 For a call to a protected operation of a protected type
6632 (that has a body @em no check is performed if @Chg{Version=[3],New=[],Old=[a
6633 @nt{pragma} Import applies to]} the protected type@Chg{Version=[3],New=[ is
6634 imported @em see @RefSecNum{Interfacing Aspects}],Old=[]}),
6635 a check is made that the @nt<protected_body> is already elaborated.
6636 This check and the evaluations of any actual parameters of the call
6637 are done in an arbitrary order.@PDefn2{Term=[arbitrary order],Sec=[allowed]}
6638 @begin{Discussion}
6639 A protected type has only one elaboration @lquotes@;bit,@rquotes@; rather than
6640 one for each operation, because one call may result in evaluating
6641 the barriers of other entries, and because there are no elaborable
6642 declarations between the bodies of the operations. In fact,
6643 the elaboration of a @nt<protected_body> does not elaborate
6644 the enclosed bodies, since they are not considered independently
6645 elaborable.
6646
6647 Note that there is no elaboration check when calling a task entry.
6648 Task entry calls are permitted even before the associated @nt<task_body>
6649 has been seen. Such calls are simply queued until the task is
6650 activated and reaches a corresponding @nt<accept_statement>.
6651 We considered a similar rule for protected entries @em simply
6652 queuing all calls until the @nt<protected_body> was seen, but felt
6653 it was not worth the possible implementation overhead, particularly
6654 given that there might be multiple instances of the protected type.
6655 @end{Discussion}
6656
6657 For the activation of a task, a check is made by the
6658 activator that the @nt{task_body} is already elaborated.
6659 If two or more tasks are being activated together
6660 (see @RefSecNum{Task Execution - Task Activation}),
6661 as the result of the elaboration of
6662 a @nt{declarative_part} or the initialization
6663 for the object created by an allocator,
6664 this check is done for all of them before activating any
6665 of them.
6666 @begin{Reason}
6667 As specified by AI83-00149, the check is done by the
6668 activator, rather than by the task itself. If it were
6669 done by the task itself, it would be turned into a Tasking_Error
6670 in the activator, and the other tasks would still be activated.
6671 @end{Reason}
6672
6673 For the instantiation of a generic unit that has a body, a check is
6674 made that this body is already elaborated.
6675 This check and the evaluation of any @nt{explicit_generic_actual_parameter}s
6676 of the instantiation are done in an arbitrary order.@PDefn2{Term=[arbitrary order],Sec=[allowed]}
6677 @end{Itemize}
6678
6679 @Defn2{Term=[Program_Error],Sec=(raised by failure of runtime check)}
6680 The exception Program_Error is raised if any of these checks fails.
6681 @end{RunTime}
6682
6683 @begin{Extend83}
6684 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00114-01]}
6685 @Defn{extensions to Ada 83}
6686 The syntax for @nt{declarative_part} is modified to remove the ordering
6687 restrictions of Ada 83; that is, the distinction between
6688 @nt{basic_declarative_item}s and @ntf{later_declarative_item}s
6689 within @nt{declarative_part}s is removed.
6690 This means that things like @nt{use_clause}s and
6691 @Chg{Version=[2],New=[@nt{object_declaration}s],Old=[@ntf{variable_declaration}s]}
6692 can be freely intermixed with things like bodies.
6693
6694 The syntax rule for @nt{proper_body} now allows a @nt{protected_body},
6695 and the rules for elaboration checks now cover calls on
6696 protected operations.
6697 @end{Extend83}
6698
6699 @begin{DiffWord83}
6700 The syntax rule for @ntf{later_declarative_item} is removed;
6701 the syntax rule for @nt{declarative_item} is new.
6702
6703 RM83 defines @lquotes@;elaborated@rquotes@; and @lquotes@;not yet elaborated@rquotes@; for
6704 @nt{declarative_item}s here, and for other things in @RefSec{Declarations}.
6705 That's no longer necessary, since these terms are fully defined in
6706 @RefSecNum{Declarations}.
6707
6708 In RM83, all uses of @nt{declarative_part} are optional
6709 (except for the one in @nt{block_statement} with a @key(declare))
6710 which is sort of strange, since a @nt{declarative_part} can be empty,
6711 according to the syntax.
6712 That is, @nt{declarative_part}s are sort of @lquotes@;doubly optional@rquotes@;.
6713 In Ada 95, these @nt{declarative_part}s are always required
6714 (but can still be empty).
6715 To simplify description, we go further and say
6716 (see @RefSec(Block Statements)) that a
6717 @nt<block_statement> without an explicit @nt<declarative_part>
6718 is equivalent to one with an empty one.
6719 @end{DiffWord83}
6720
6721 @begin{DiffWord95}
6722 @ChgRef{Version=[2],Kind=[AddedNormal],Ref=[8652/0009],ARef=[AI95-00137-01]}
6723 @ChgAdded{Version=[2],Text=[@b<Corrigendum:> Changed representation clauses
6724 to aspect clauses to reflect that they are used for more than just
6725 representation.]}
6726
6727 @ChgRef{Version=[2],Kind=[AddedNormal],Ref=[8652/0014],ARef=[AI95-00064-01]}
6728 @ChgAdded{Version=[2],Text=[@b<Corrigendum:> Clarified that the elaboration
6729 check applies to all kinds of subprogram bodies.]}
6730
6731 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00420-01]}
6732 @ChgAdded{Version=[2],Text=[Defined @lquotes@;declaration list@rquotes to
6733 avoid confusion for various rules. Other kinds of declaration list are
6734 defined elsewhere.]}
6735 @end{DiffWord95}
6736
6737
6738 @LabeledSubClause{Completions of Declarations}
6739
6740 @begin{Intro}
6741 @ChgRef{Version=[1],Kind=[Revised],Ref=[8652/0014],ARef=[AI95-00064-01]}
6742 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0177-1]}
6743 Declarations sometimes come in two parts.
6744 @Defn{requires a completion}
6745 A declaration that requires a second part is said to @i(require completion).
6746 @Defn2{Term=[completion], Sec=(compile-time concept)}
6747 The second part is called the @i(completion) of the declaration (and of
6748 the entity declared),
6749 and is either another declaration, a body, or a @nt<pragma>.
6750 @Chg{New=[A @defn<body>@i<body> is a @nt<body>,
6751 an @nt<entry_body>,@Chg{Version=[3],New=[ a @nt{null_procedure_declaration} or an
6752 @nt{expression_function_declaration} that completes another declaration,],Old=[]} or
6753 a renaming-as-body
6754 (see @RefSecNum<Subprogram Renaming Declarations>).],Old=[]}
6755 @begin{Discussion}
6756 @Leading@keepnext@;Throughout the RM95, there are rules about completions that
6757 define the following:
6758 @begin{Itemize}
6759 Which declarations require a corresponding completion.
6760
6761 Which constructs can only serve as the completion
6762 of a declaration.
6763
6764 Where the completion of a declaration is allowed to be.
6765
6766 What kinds of completions are allowed to correspond to each kind of
6767 declaration that allows one.
6768 @end{Itemize}
6769
6770 Don't confuse this compile-time concept with
6771 the run-time concept of completion
6772 defined in @RefSecNum{Completion and Finalization}.
6773
6774 Note that the declaration of a private type (if limited) can be
6775 completed with the declaration of a task type, which is then completed
6776 with a body.
6777 Thus, a declaration can actually come in @i{three} parts.
6778
6779 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00217-06]}
6780 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0162-1]}
6781 @Chg{Version=[2],New=[@Chg{Version=[3],New=[An incomplete type (whether declared
6782 in the limited view of a package or not) may be completed by a private type
6783 declaration],Old=[In Ada 2005 the limited view of the package contains an
6784 incomplete view of the private type]}, so we can
6785 @Chg{Version=[3],New=[in fact ],Old=[]}have @i{four}
6786 parts@Chg{Version=[3],New=[],Old=[ now]}.],Old=[]}
6787
6788 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0229-1]}
6789 @ChgAdded{Version=[3],Text=[In Ada 2012, there are no language-defined pragmas
6790 that act as completions. Pragma Import (which is obsolescent) has the effect of
6791 setting aspect Import to True; such an aspect makes giving a completion illegal.
6792 The wording that allows pragmas as completions was left as it is harmless and
6793 appears in many places in this Standard.]}
6794 @end{Discussion}
6795 @end{Intro}
6796
6797 @begin{Resolution}
6798 @Leading@keepnext@;A construct that can be a completion
6799 is interpreted as the completion of a prior
6800 declaration only if:
6801 @begin(itemize)
6802 The declaration and the completion occur immediately within
6803 the same declarative region;
6804
6805 The defining name or @nt{defining_program_unit_name}
6806 in the completion is the same as in the declaration,
6807 or in the case of a @nt{pragma}, the @nt{pragma} applies to
6808 the declaration;
6809
6810 If the declaration is overloadable, then the completion
6811 either has a type-conformant profile,
6812 or is a @nt{pragma}.
6813 @Defn2{Term=[type conformance],Sec=(required)}
6814 @end(itemize)
6815 @end{Resolution}
6816
6817 @begin{Legality}
6818 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0229-1]}
6819 An implicit declaration shall not have a completion.
6820 @RootDefn{requires a completion}
6821 For any explicit declaration that is specified
6822 to @i(require completion), there shall be a corresponding explicit
6823 completion@Chg{Version=[3],New=[, unless the declared
6824 entity is imported (see @RefSecNum{Interfacing Aspects})],Old=[]}.
6825 @begin(Honest)
6826 @ChgRef{Version=[2],Kind=[Added],ARef=[AI95-00217-06]}
6827 @ChgAdded{Version=[2],Text=[The implicit declarations occurring in a
6828 limited view do have a completion (the explicit declaration occurring in the
6829 full view) but that's a special case, since the implicit declarations are
6830 actually built from the explicit ones. So they do not @i{require} a
6831 completion, they have one by @i{fiat}.]}
6832 @end{Honest}
6833
6834 @begin(Discussion)
6835 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0299-1]}
6836 The implicit declarations of predefined operators are not allowed to
6837 have a completion.
6838 Enumeration literals, although they are subprograms, are not allowed to have a
6839 corresponding @nt{subprogram_body}.
6840 That's because the completion rules are described in terms of constructs
6841 (@nt{subprogram_declaration}s) and not entities (subprograms).
6842 When a completion is required, it has to be explicit;
6843 the implicit null @nt{package_body} that @Chg{Version=[3],New=[Clause],Old=[Section]}
6844 @RefSecNum{Packages}
6845 talks about cannot serve as the completion of a
6846 @nt{package_declaration} if a completion is required.
6847 @end(Discussion)
6848
6849 At most one completion is allowed for a given declaration.
6850 Additional requirements on completions appear where each kind
6851 of completion is defined.
6852 @begin{Ramification}
6853 A subunit is not a completion;
6854 the stub is.
6855
6856 If the completion of a declaration is also a declaration,
6857 then @i{that} declaration might have a completion, too.
6858 For example, a limited private type can be completed with a task type,
6859 which can then be completed with a task body.
6860 This is not a violation of the @lquotes@;at most one completion@rquotes@; rule.
6861 @end{Ramification}
6862
6863 @Defn{completely defined}
6864 A type is @i(completely defined) at a place that is after its
6865 full type definition (if it has one) and after all of its
6866 subcomponent types are completely defined.
6867 A type shall be completely defined before it is frozen
6868 (see @RefSecNum{Freezing Rules} and
6869 @RefSecNum{Private Types and Private Extensions}).
6870 @begin(Reason)
6871 @comment{The following is a "fix" to keep consistent with v. 5.95;
6872 appearently 6.0 is different.
6873 @ChgRef{Version=[1],Kind=[Deleted]}
6874 @ChgDeleted{Version=[1],Text=[Old @b{Change}.]}}
6875
6876 Index types are always completely defined @em no need to mention them.
6877 There is no way for a completely defined type to depend on the value of
6878 a (still) deferred constant.
6879 @end(Reason)
6880 @end{Legality}
6881
6882 @begin{Notes}
6883 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0229-1]}
6884 Completions are in principle allowed for any kind of explicit declaration.
6885 However, for some kinds of declaration,
6886 the only allowed completion is @Chg{Version=[3],New=[an implementation-defined
6887 pragma], Old=[a @nt{pragma} Import]},
6888 and implementations are not required to @Chg{Version=[3],New=[have any
6889 such pragmas],Old=[support @nt{pragma} Import for
6890 every kind of entity]}.
6891 @begin(Discussion)
6892 @ChgRef{Version=[3],Kind=[Deleted],ARef=[AI05-0229-1]}
6893 @ChgDeleted{Version=[3],Text=[In fact, we expect that implementations
6894 will @i{not} support pragma
6895 Import of things like types @em it's hard to even define the
6896 semantics of what it would mean.
6897 Therefore, in practice, @i{not} every explicit declaration
6898 can have a completion.
6899 In any case, if an implementation chooses to support pragma Import for,
6900 say, types, it can place whatever restrictions on the feature it wants
6901 to. For example, it might want the @nt{pragma} to be a freezing point for
6902 the type.]}
6903 @end(Discussion)
6904
6905 There are rules that prevent premature uses of declarations that have a
6906 corresponding completion.
6907 The Elaboration_Checks of @RefSecNum{Declarative Parts} prevent such
6908 uses at run time for subprograms, protected operations, tasks, and
6909 generic units.
6910 The rules of @RefSec{Freezing Rules}
6911 prevent, at compile time, premature uses of other entities
6912 such as private types and deferred constants.
6913 @end{Notes}
6914
6915 @begin{DiffWord83}
6916 This subclause is new. It is intended to cover all
6917 kinds of completions of declarations, be they a body for a spec,
6918 a full type for an incomplete or private type, a full constant
6919 declaration for a deferred constant declaration, or a @nt{pragma} Import
6920 for any kind of entity.
6921 @end{DiffWord83}
6922
6923 @begin{DiffWord95}
6924 @ChgRef{Version=[2],Kind=[AddedNormal],Ref=[8652/0014],ARef=[AI95-00064-01]}
6925 @ChgAdded{Version=[2],Text=[@b<Corrigendum:> Added a definition of @i{body},
6926 which is different than @nt{body} or @key{body}.]}
6927 @end{DiffWord95}
6928
6929 @begin{DiffWord2005}
6930 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI95-0177-1]}
6931 @ChgAdded{Version=[3],Text=[Added null procedures and expression functions
6932 that are completions to the definition of @i<body>.]}
6933 @end{DiffWord2005}