Debian Codegraph @

source_2020/08.mss

raw
1 @Part(08, Root="ada.mss")
2
3 @Comment{$Date: 2020/06/03 00:09:00 $}
4 @LabeledSection{Visibility Rules}
5
6 @Comment{$Source: e:\\cvsroot/ARM/Source/08.mss,v $}
7 @Comment{$Revision: 1.116 $}
8
9 @begin{Intro}
10 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0299-1]}
11 @redundant[The rules defining the scope of declarations and the rules defining
12 which @nt{identifier}s, @nt{character_literal}s, and
13 @nt{operator_symbol}s are visible at (or from) various places in the text of
14 the program are described in this @Chg{Version=[3],New=[clause],Old=[section]}.
15 The formulation of these rules uses the notion of a declarative region.
16
17 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0299-1]}
18 As explained in @Chg{Version=[3],New=[Clause],Old=[Section]}
19 @RefSecNum{Declarations and Types},
20 a declaration declares a view of an entity
21 and associates a defining name with that view.
22 The view comprises an identification of the viewed entity,
23 and possibly additional properties.
24 A usage name denotes a declaration.
25 It also denotes the view declared by that declaration,
26 and denotes the entity of that view.
27 Thus, two different usage names might denote two different views of
28 the same entity; in this case they denote the same entity.]
29 @begin{Honest}
30 In some cases, a usage name that denotes a declaration
31 does not denote the view declared by that declaration,
32 nor the entity of that view,
33 but instead denotes a view of the current instance of the entity,
34 and denotes the current instance of the entity.
35 This sometimes happens when the usage name occurs inside
36 the declarative region of the declaration.
37 @end{Honest}
38 @end{Intro}
39
40 @begin{DiffWord83}
41 We no longer define the term @lquotes@;basic operation;@rquotes@;
42 thus we no longer have to worry about the visibility of them.
43 Since they were essentially always visible in Ada 83, this change has
44 no effect. The reason for this change is that the definition in Ada
45 83 was confusing, and not quite correct,
46 and we found it difficult to fix. For example, one
47 wonders why an @nt{if_statement} was not a basic operation of type
48 Boolean. For another example, one wonders what it meant for a basic
49 operation to be @lquotes@;inherent in@rquotes@; something.
50 Finally, this fixes the problem addressed by AI83-00027/07.
51 @end{DiffWord83}
52
53 @LabeledClause{Declarative Region}
54
55 @begin{StaticSem}
56 @leading@Defn2{Term=[declarative region], Sec=(of a construct)}
57 For each of the following constructs,
58 there is a portion of the program text
59 called its @i{declarative region},
60 @Redundant[within which nested declarations can occur]:
61 @begin(itemize)
62 any declaration, other than that of an enumeration type,
63 that is not a completion @Redundant[of a previous declaration];
64
65 @ChgRef{Version=[4],Kind=[Added],ARef=[AI12-0094-1]}
66 @ChgAdded{Version=[4],Text=[an @nt{access_definition};]}
67
68 @ChgRef{Version=[5],Kind=[Added],ARef=[AI12-0061-1]}
69 @ChgAdded{Version=[5],Text=[an @nt{iterated_component_association};]}
70
71 @ChgRef{Version=[5],Kind=[Added],ARef=[AI12-0308-1]}
72 @ChgAdded{Version=[5],Text=[an @nt{iterated_element_association};]}
73
74 @ChgRef{Version=[5],Kind=[Added],ARef=[AI05-0255-1],ARef=[AI12-0308-1]}
75 @ChgAdded{Version=[5],Text=[a @nt{quantified_expression};]}
76
77 @ChgRef{Version=[5],Kind=[Added],ARef=[AI12-0236-1]}
78 @ChgAdded{Version=[5],Text=[a @nt{declare_expression};]}
79
80 a @nt{block_statement};
81
82 a @nt{loop_statement};
83
84 @ChgRef{Version=[3],Kind=[Added],ARef=[AI05-0255-1]}
85 @ChgRef{Version=[5],Kind=[DeletedAdded],ARef=[AI12-0308-1]}
86 @ChgAdded{Version=[3],Text=[@Chg{Version=[5],New=[],Old=[a @nt{quantified_expression};]}]}
87
88 @ChgRef{Version=[2],Kind=[Added],ARef=[AI95-00318-02]}
89 @ChgRef{Version=[3],Kind=[RevisedAdded]}@Comment{Paragraph number changed}
90 @ChgAdded{Version=[2],Text=[an @nt{extended_return_statement};]}
91
92 an @nt{accept_statement};
93
94 an @nt{exception_handler}.
95 @end(itemize)
96
97 @begin{WideAbove}
98 @leading@;The declarative region includes the text of the construct
99 together with additional text determined @Redundant[(recursively)],
100 as follows:
101 @end{WideAbove}
102 @begin{Itemize}
103 If a declaration is included, so is its completion, if any.
104
105 If the declaration of a library unit
106 @Redundant[(including Standard @em
107 see @RefSecNum{Compilation Units - Library Units})] is included,
108 so are the declarations of any child units
109 @Redundant[(and their completions, by the previous rule)].
110 The child declarations occur after the declaration.
111
112 If a @nt{body_stub} is included,
113 so is the corresponding @nt{subunit}.
114
115 If a @nt{type_declaration} is included,
116 then so is a corresponding @nt{record_representation_clause},
117 if any.
118 @begin{Reason}
119 This is so that the @nt{component_declaration}s can be directly
120 visible in the @nt{record_representation_clause}.
121 @end{Reason}
122 @end{Itemize}
123
124 The declarative region of a declaration is also called the
125 @i{declarative region} of any view or entity declared by the
126 declaration.
127 @begin{Reason}
128 The constructs that have declarative regions
129 are the constructs that can have declarations nested inside them.
130 Nested declarations are declared in that declarative region.
131 The one exception is for enumeration literals;
132 although they are nested inside an enumeration type declaration,
133 they behave as if they were declared at the same level as the type.
134 @end{Reason}
135 @begin{Honest}
136 A declarative region does not include @nt{parent_unit_name}s.
137 @end{Honest}
138 @begin{Ramification}
139 A declarative region does not include @nt{context_clause}s.
140 @end{Ramification}
141
142 @Defn{occur immediately within}
143 @Defn{immediately within}
144 @Defn2{Term=[within],Sec=(immediately)}
145 @Defn{immediately enclosing}
146 @Defn2{Term=[enclosing],Sec=(immediately)}
147 A declaration occurs @i{immediately within} a declarative region if this
148 region is the innermost declarative region that
149 encloses the declaration
150 (the @i{immediately enclosing} declarative region),
151 not counting the declarative region (if any)
152 associated with the declaration itself.
153 @begin{Discussion}
154 Don't confuse the declarative region of a declaration
155 with the declarative region in which it immediately occurs.
156 @end{Discussion}
157
158 @redundant[@Defn{local to}
159 A declaration is @i{local} to a declarative region if
160 the declaration occurs immediately within the declarative region.]
161 @redundant[An entity is @i{local} to a declarative region if the entity is
162 declared by a declaration that is local to the declarative region.]
163 @begin{Ramification}
164 "Occurs immediately within" and "local to" are synonyms
165 (when referring to declarations).
166
167 Thus, @lquotes@;local to@rquotes@; applies to both declarations and entities,
168 whereas @lquotes@;occurs immediately within@rquotes@; only applies to declarations.
169 We use this term only informally; for cases where precision is required,
170 we use the term "occurs immediately within", since it is less likely to
171 cause confusion.
172 @end{Ramification}
173
174 @Defn{global to}
175 A declaration is @i{global} to a declarative region
176 if the declaration occurs immediately within
177 another declarative region that encloses the
178 declarative region.
179 An entity is @i{global} to a declarative region if the entity is
180 declared by a declaration that is global to the declarative region.
181 @end{StaticSem}
182
183 @begin{Notes}
184 The children of a parent library unit are inside the parent's
185 declarative region, even though they do not occur inside the
186 parent's declaration or body.
187 This implies that one can use (for example) "P.Q" to refer to
188 a child of P whose defining name is Q,
189 and that after "@key[use] P;" Q can refer (directly) to that child.
190
191 As explained above
192 and in @RefSec{Compilation Units - Library Units},
193 all library units are descendants of Standard,
194 and so are contained in the declarative region of Standard.
195 They are @i{not} inside the
196 declaration or body of Standard,
197 but they @i{are} inside its declarative region.
198
199 For a declarative region that comes in multiple parts,
200 the text of the declarative region does not contain any text that might appear
201 between the parts.
202 Thus, when a portion of a declarative region is said to extend from one
203 place to another in the declarative region,
204 the portion does not contain any text that
205 might appear between the parts of the declarative region.
206 @begin{Discussion}
207 It is necessary for the things that have a declarative region to
208 include
209 anything that contains declarations (except for enumeration type
210 declarations).
211 This includes any declaration that has a profile
212 (that is, @nt{subprogram_declaration},
213 @nt{subprogram_body},
214 @nt{entry_declaration},
215 @nt{subprogram_renaming_declaration},
216 @nt{formal_subprogram_declaration},
217 access-to-subprogram @nt{type_declaration}),
218 anything that has a @nt{discriminant_part}
219 (that is, various kinds of @nt{type_declaration}),
220 anything that has a @nt{component_list}
221 (that is, record @nt{type_declaration} and
222 record extension @nt{type_declaration}),
223 and finally the declarations of task and protected units and packages.
224 @end{Discussion}
225 @end{Notes}
226
227 @begin{DiffWord83}
228 @leading@;It was necessary to extend Ada 83's definition of declarative region
229 to take the following Ada 95 features into account:
230 @begin{Itemize}
231 Child library units.
232
233 Derived types/type extensions @em we need a declarative region for
234 inherited components and also for new components.
235
236 All the kinds of types that allow discriminants.
237
238 Protected units.
239
240 Entries that have bodies instead of accept statements.
241
242 The @nt{choice_parameter_specification} of an @nt{exception_handler}.
243
244 The formal parameters of access-to-subprogram types.
245
246 Renamings-as-body.
247 @end{Itemize}
248
249 Discriminated and access-to-subprogram type declarations
250 need a declarative region.
251 Enumeration type declarations cannot have one,
252 because you don't have to say "Color.Red" to refer to the literal Red
253 of Color.
254 For other type declarations,
255 it doesn't really matter whether or not there is an
256 associated declarative region,
257 so for simplicity, we give one to all types except enumeration types.
258
259 We now say that an @nt{accept_statement} has its own declarative
260 region, rather than being part of the declarative region of the
261 @nt{entry_declaration},
262 so that declarative regions are properly nested regions of text,
263 so that it makes sense to talk about "inner declarative regions,"
264 and "...extends to the end of a declarative region."
265 Inside an @nt{accept_statement}, the @nt{name} of one of the parameters
266 denotes the @nt{parameter_specification} of the @nt{accept_statement},
267 not that of the @nt{entry_declaration}. If the @nt{accept_statement} is
268 nested within a @nt{block_statement}, these
269 @nt{parameter_specification}s can hide declarations of the
270 @nt{block_statement}.
271 The semantics of such cases was unclear in RM83.
272 @begin{Honest}
273 Unfortunately, we have the same problem for the entry name
274 itself @em it should denote the @nt{accept_statement},
275 but @nt{accept_statement}s are not declarations.
276 They should be, and they should hide the entry from all visibility
277 within themselves.
278 @end{Honest}
279
280 Note that we can't generalize this to @ntf{entry_bodies},
281 or other bodies, because the @nt{declarative_part} of a
282 body is not supposed to contain (explicit) homographs of
283 things in the declaration.
284 It works for @nt{accept_statement}s only because an
285 @nt{accept_statement} does not have a @nt{declarative_part}.
286
287 To avoid confusion,
288 we use the term @lquotes@;local to@rquotes@; only informally in Ada 95.
289 Even RM83 used the term incorrectly (see, for example, RM83-12.3(13)).
290
291 In Ada 83, (root) library units were inside Standard;
292 it was not clear whether the declaration or body of Standard
293 was meant.
294 In Ada 95, they are children of Standard,
295 and so occur immediately within Standard's declarative
296 region, but not within either the declaration or the body.
297 (See RM83-8.6(2) and RM83-10.1.1(5).)
298 @end{DiffWord83}
299
300 @begin{DiffWord95}
301 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00318-02]}
302 @ChgAdded{Version=[2],Text=[@nt{Extended_return_statement}
303 (see @RefSecNum{Return Statements}) is added to the list
304 of constructs that have a declarative region.]}
305 @end{DiffWord95}
306
307 @begin{Extend2012}
308 @ChgRef{Version=[4],Kind=[AddedNormal],ARef=[AI12-0094-1]}
309 @ChgAdded{Version=[4],Text=[@Defn{extensions to Ada 2012}@b<Corrigendum:>
310 @nt{access_definition} is added to the list of constructs that have
311 a declarative region. This allows parameter names declared in anonymous
312 access type subprogram types to be the same as other names declared
313 outside. For instance:]}
314 @begin{Example}
315 @ChgRef{Version=[4],Kind=[AddedNormal]}
316 @ChgAdded{Version=[4],Text=[@key[type] Foo @key[is record]
317 A : Natural;
318 B : @key[access] procedure (A : Boolean);
319 @key[end record];]}
320 @end{Example}
321 @ChgRef{Version=[4],Kind=[AddedNormal]}
322 @ChgRef{Version=[5],Kind=[Revised],ARef=[AI12-0005-1]}
323 @ChgAdded{Version=[4],Text=[This is now legal, as one would expect; it
324 was illegal in previous versions of Ada as the parameter A and the
325 component A were homographs in the same declarative region
326 (see @RefSecNum{Visibility}). Note that some implementations already allow
327 this common sense interpretation, so this extension
328 @Chg{Version=[5],New=[might],Old=[may]} in fact
329 @Chg{Version=[5],New=[already ],Old=[]}be used in existing code.]}
330 @end{Extend2012}
331
332 @begin{DiffWord2012}
333 @ChgRef{Version=[5],Kind=[AddedNormal],ARef=[AI12-0061-1],ARef=[AI12-0236-1]}
334 @ChgAdded{Version=[5],Text=[Added @nt{iterated_component_association} and
335 @nt{declare_expression} to the rapidly expanding list of constructs
336 that have a declarative region.]}
337 @end{DiffWord2012}
338
339
340 @LabeledClause{Scope of Declarations}
341
342 @begin{Intro}
343 @redundant[For each declaration, the language rules define a certain
344 portion of the program text called the @i{scope} of the declaration.
345 The scope of a declaration is also called the scope of any view
346 or entity declared by the declaration.
347 Within the scope of an entity, and only there,
348 there are places where it is legal to refer
349 to the declared entity.
350 These places are defined by the rules of visibility and overloading.]
351 @end{Intro}
352
353 @begin{StaticSem}
354 @Leading@Defn2{Term=[immediate scope], Sec=(of a declaration)}
355 The @i{immediate scope} of a declaration
356 is a portion of the declarative region immediately enclosing
357 the declaration.
358 The immediate scope starts at the beginning of the declaration,
359 except in the case of an overloadable declaration,
360 in which case the immediate scope starts just after the place
361 where the profile of the callable entity is determined
362 (which is at the end of the @ntf<_specification> for the callable entity,
363 or at the end of the @nt<generic_instantiation> if an instance).
364 The immediate scope extends to the end of the declarative region,
365 with the following exceptions:
366 @begin{Reason}
367 The reason for making overloadable declarations with profiles
368 special is to simplify compilation:
369 until the compiler has determined the profile,
370 it doesn't know which other declarations are homographs of this one,
371 so it doesn't know which ones this one should hide.
372 Without this rule, two passes over the @ntf<_specification> or
373 @nt<generic_instantiation> would be required to
374 resolve names that denote things with the same name as this one.
375 @end{Reason}
376 @begin{Itemize}
377 The immediate scope of a @nt{library_item} includes only its semantic
378 dependents.
379 @begin{Reason}
380 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0299-1]}
381 @Chg{Version=[3],New=[Clause],Old=[Section]} 10 defines only a partial ordering of @nt{library_item}s.
382 Therefore, it is a good idea to restrict the immediate scope
383 (and the scope, defined below)
384 to semantic dependents.
385
386 @leading@;Consider also examples like this:
387 @begin{Example}
388 @key[package] P @key[is] @key[end] P;
389
390 @key[package] P.Q @key[is]
391 I : Integer := 0;
392 @key[end] P.Q;
393
394 @ChgRef{Version=[1],Kind=[Revised]}@ChgNote{Presentation AI-00080 - syntax error}
395 @key[with] P;
396 @key[package] R @key[is]
397 @key[package] X @key[renames] P;
398 @Chg{New=[J : Integer := ],Old=[]}X.Q.I@Chg{New=[],Old=[ := 17]}; --@RI{ Illegal!}
399 @key[end] R;
400 @end{Example}
401
402 The scope of P.Q does not contain R.
403 Hence, neither P.Q nor X.Q are visible within R.
404 However, the name R.X.Q would be visible in some other
405 library unit where both R and P.Q are visible
406 (assuming R were made legal by removing the offending declaration).
407 @end{Reason}
408 @begin{Ramification}
409 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00217-06]}
410 @ChgAdded{Version=[2],Text=[This rule applies to limited views as well as
411 @lquotes@;normal@rquotes library items. In that case, the semantic dependents
412 are the units that have a @nt{limited_with_clause} for the limited view.]}
413 @end{Ramification}
414 The immediate scope of
415 a declaration in the private part of a library unit does
416 not include the visible part of any
417 public descendant of that library unit.
418 @Pdefn2{Term=[descendant],Sec=(relationship with scope)}
419 @begin{Ramification}
420 In other words, a declaration in the private part can be
421 visible within the visible part, private part and body of a private
422 child unit.
423 On the other hand, such a declaration
424 can be visible within only the private part and body of a public
425 child unit.
426 @end{Ramification}
427 @begin{Reason}
428 The purpose of this rule is to prevent children from giving
429 private information to clients.
430 @end{Reason}
431 @begin{Ramification}
432 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00231-01]}
433 For a public child subprogram,
434 this means that the parent's private part is not visible in the
435 @Chg{Version=[2],New=[profile],Old=[@nt{formal_part}s]} of the declaration
436 and of the body.
437 This is true even for @ntf{subprogram_bodies} that are not
438 completions.
439 For a public child generic unit,
440 it means that the parent's private part is not visible in the
441 @nt{generic_formal_part}, as well as in
442 the first list of @nt{basic_declarative_item}s (for a generic package),
443 or the @Chg{Version=[2],New=[(syntactic) profile],Old=[@nt{formal_part}(s)]}
444 (for a generic subprogram).
445 @end{Ramification}
446 @end{Itemize}
447
448 @Defn{visible part}
449 @Redundant[The @i(visible part) of (a view of) an entity
450 is a portion of the text of its declaration
451 containing declarations that are visible from outside.]
452 @RootDefn{private part}
453 The @i{private part} of (a view of) an entity that has a visible part
454 contains all declarations within the declaration of
455 (the view of) the entity,
456 except those in the visible part;
457 @Redundant[these are not visible from outside.
458 Visible and private parts are defined only for these kinds of
459 entities: callable entities, other program units,
460 and composite types.]
461 @begin{Itemize}
462 @PDefn2{Term=[visible part], Sec=(of a view of a callable entity)}
463 The visible part of a view of a callable entity is its profile.
464
465 @PDefn2{Term=[visible part], Sec=(of a view of a composite type)}
466 The visible part of a composite type other than a task or protected type
467 consists of the declarations of
468 all components declared @Redundant[(explicitly or implicitly)]
469 within the @nt{type_declaration}.
470
471 @PDefn2{Term=[visible part], Sec=(of a generic unit)}
472 The visible part of a generic unit
473 includes the @nt{generic_formal_part}.
474 For a generic package, it also includes
475 the first list of @nt{basic_declarative_item}s of the
476 @nt{package_specification}.
477 For a generic subprogram, it also includes
478 the profile.
479 @begin{Reason}
480 Although there is no way to reference anything but the formals from
481 outside a generic unit, they are still in the visible part in the sense that
482 the corresponding declarations in an instance can be referenced
483 (at least in some cases).
484 In other words, these declarations have an effect on the outside world.
485 The visible part of a generic unit needs to be defined
486 this way in order to properly support
487 the rule that makes a parent's private part invisible within a
488 public child's visible part.
489 @end{Reason}
490 @begin{Ramification}
491 The visible part of an instance of a generic unit is as defined
492 for packages and subprograms;
493 it is not defined in terms of the visible part of a generic unit.
494 @end{Ramification}
495
496 @Redundant[The visible part of a package, task unit, or protected
497 unit consists of declarations in the program unit's declaration
498 other than those following the reserved word @key{private}, if any;
499 see @RefSecNum{Package Specifications and Declarations}
500 and @RefSecNum{Formal Packages} for packages,
501 @RefSecNum{Task Units and Task Objects} for task units,
502 and @RefSecNum{Protected Units and Protected Objects}
503 for protected units.]
504 @end{Itemize}
505
506 @Defn2{Term=[scope], Sec=(of a declaration)}
507 The scope of a declaration always
508 contains the immediate scope of the declaration.
509 In addition, for a given declaration that occurs immediately within
510 the visible part of an outer declaration,
511 or is a public child of an outer declaration,
512 the scope of the given declaration
513 extends to the end of the scope of the outer declaration,
514 except that the scope of a @nt{library_item} includes only its
515 semantic dependents.
516 @begin{Ramification}
517 Note the recursion.
518 If a declaration appears in the visible part of a library unit,
519 its scope extends to the end of the scope of the library unit,
520 but since that only includes dependents of the declaration of the library unit,
521 the scope of the inner declaration also only includes those dependents.
522 If X renames library package P,
523 which has a child Q, a @nt{with_clause} mentioning P.Q is necessary to
524 be able to refer to X.Q,
525 even if P.Q is visible at the place where X is declared.
526 @end{Ramification}
527
528 @ChgRef{Version=[2],Kind=[Added],ARef=[AI95-00408-01]}
529 @ChgRef{Version=[3],Kind=[RevisedAdded],ARef=[AI05-0183-1]}
530 @ChgAdded{Version=[2],Text=[@Defn2{Term=[scope], Sec=(of an attribute_@!definition_@!clause)}
531 The scope of an @nt{attribute_definition_clause} is identical to the scope of a
532 declaration that would occur at the point of the
533 @nt{attribute_definition_clause}.@Chg{Version=[3],New=[ The scope of an
534 @nt{aspect_specification} is identical to the scope of the associated
535 declaration.@Defn2{Term=[scope], Sec=(of an aspect_@!specification)}],Old=[]}]}
536
537 @Defn2{Term=[immediate scope], Sec=[of (a view of) an entity]}
538 The immediate scope of a declaration is also the immediate scope
539 of the entity or view declared by the declaration.
540 @Defn2{Term=[scope], Sec=[of (a view of) an entity]}
541 Similarly,
542 the scope of a declaration is also the scope
543 of the entity or view declared by the declaration.
544 @begin{Ramification}
545 @leading@;The rule for immediate scope implies the following:
546 @begin{Itemize}
547 If the declaration is that of a library unit,
548 then the immediate scope includes the declarative region of the
549 declaration itself, but not other places,
550 unless they are within the scope of a @nt{with_clause} that mentions the
551 library unit.
552
553 @NoPrefix@;It is necessary to attach the semantics of @nt{with_clause}s to
554 [immediate] scopes (as opposed to visibility),
555 in order for various rules to work properly.
556 A library unit should hide a homographic implicit declaration that
557 appears in its parent, but only within the scope of a @nt{with_clause}
558 that mentions the library unit.
559 Otherwise, we would violate the "legality determinable via semantic
560 dependences" rule of @RefSec{Program Structure and Compilation Issues}.
561 The declaration of a library unit should be allowed to be a homograph of
562 an explicit declaration in its parent's body,
563 so long as that body does not mention the library unit in a
564 @nt{with_clause}.
565
566 @NoPrefix@;This means that one cannot denote the declaration of the library unit,
567 but one might still be able to denote the library unit via another
568 view.
569
570 @NoPrefix@;A @nt{with_clause} does not make the declaration of a library unit
571 visible; the lack of a @nt{with_clause} prevents it from being visible.
572 Even if a library unit is mentioned in a @nt{with_clause},
573 its declaration can still be hidden.
574
575 The completion of the declaration of a library unit
576 (assuming that's also a declaration)
577 is not visible, neither directly nor by selection,
578 outside that completion.
579
580 The immediate scope of
581 a declaration immediately within the body of a library unit
582 does not include any child of that library unit.
583
584 @NoPrefix@;This is needed to prevent children from looking inside their
585 parent's body. The children are in the declarative region of the
586 parent, and they might be after the parent's body.
587 Therefore, the scope of a declaration that occurs immediately within
588 the body might include some children.
589 @end{Itemize}
590 @end{Ramification}
591
592 @ChgRef{Version=[4],Kind=[AddedNormal],ARef=[AI12-0003-1]}@Comment{As usual,
593 we let the paragraph numbers of non-normative text change}
594 @ChgAdded{Version=[4],Text=[The immediate scope of a pragma that is not used
595 as a configuration pragma is defined to be the@Defn2{Term=[immediate scope], Sec=(of a pragma)}
596 region extending from immediately after the pragma
597 to the end of the declarative region immediately enclosing the pragma.]}
598 @end{StaticSem}
599
600 @begin{Notes}
601 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0299-1]}
602 There are notations for denoting visible declarations
603 that are not directly visible.
604 For example, @nt{parameter_@!specification}s are in the visible part of a
605 @nt{subprogram_@!declaration} so that they can be used in
606 named-notation calls appearing outside the called subprogram.
607 For another example,
608 declarations of the visible part of a package can be denoted by expanded names
609 appearing outside the package,
610 and can be made directly visible by a @nt{use_clause}.
611 @begin{Ramification}
612 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00114-01]}
613 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0299-1]}
614 There are some obscure @Chg{Version=[2],New=[cases ],Old=[]}involving
615 generics @Chg{Version=[2],New=[],Old=[cases ]}in which there is
616 no such notation.
617 See @Chg{Version=[3],New=[Clause],Old=[Section]} @RefSecNum{Generic Units}.
618 @end{Ramification}
619 @end{Notes}
620
621 @begin{Extend83}
622 @Defn{extensions to Ada 83}
623 The fact that the immediate scope of an overloadable declaration does
624 not include its profile is new to Ada 95. It replaces
625 RM83-8.3(16), which said that within
626 a subprogram specification and within the formal part of an
627 entry declaration or accept statement, all declarations with
628 the same designator as the subprogram or entry were hidden from all
629 visibility.
630 The RM83-8.3(16) rule seemed to be overkill, and created both
631 implementation difficulties and unnecessary semantic complexity.
632 @end{Extend83}
633
634 @begin{DiffWord83}
635 We no longer need to talk about the scope of notations,
636 @nt{identifier}s, @nt{character_literal}s, and @nt{operator_symbol}s.
637
638 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0299-1]}
639 The notion of "visible part" has been extended in Ada 95.
640 The syntax of
641 task and protected units now allows private parts,
642 thus requiring us to be able to talk about the visible part as well.
643 It was necessary to extend the concept to subprograms
644 and to generic units, in order for the visibility rules
645 related to child library units to work properly.
646 It was necessary to define the concept separately for
647 generic formal packages, since their visible part is
648 slightly different from that of a normal package.
649 Extending the concept to composite types made the
650 definition of scope slightly simpler.
651 We define visible part for some things elsewhere,
652 since it makes a big difference to the user for those things.
653 For composite types and subprograms, however,
654 the concept is used only in arcane visibility rules,
655 so we localize it to this @Chg{Version=[3],New=[subclause],Old=[clause]}.
656
657 In Ada 83, the semantics of @nt{with_clause}s was described
658 in terms of visibility.
659 It is now described in terms of [immediate] scope.
660
661 @leading@;We have clarified that the following is illegal
662 (where Q and R are library units):
663 @begin{Example}
664 @key[package] Q @key[is]
665 I : Integer := 0;
666 @key[end] Q;
667
668 @key[package] R @key[is]
669 @key[package] X @key[renames] Standard;
670 X.Q.I := 17; --@RI{ Illegal!}
671 @key[end] R;
672 @end{Example}
673
674 even though Q is declared in the declarative region of Standard,
675 because R does not mention Q in a @nt{with_clause}.
676 @end{DiffWord83}
677
678 @begin{DiffWord95}
679 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00408-01]}
680 @ChgAdded{Version=[2],Text=[The scope of an @nt{attribute_definition_clause}
681 is defined so that it can be used to define the visibility of such a clause,
682 so @i<that> can be used by the stream attribute availability rules
683 (see @RefSecNum{Stream-Oriented Attributes}).]}
684 @end{DiffWord95}
685
686 @begin{DiffWord2005}
687 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0183-1]}
688 @ChgAdded{Version=[3],Text=[The scope of an @nt{aspect_specification}
689 is defined for similar reasons that it was defined for
690 @nt{attribute_definition_clause}s.]}
691 @end{DiffWord2005}
692
693 @begin{DiffWord2012}
694 @ChgRef{Version=[4],Kind=[AddedNormal],ARef=[AI12-0003-1]}
695 @ChgAdded{Version=[4],Text=[The immediate scope of a @nt{pragma} is
696 defined as it is used in other rules in the Standard.]}
697 @end{DiffWord2012}
698
699
700 @LabeledClause{Visibility}
701
702 @begin{Intro}
703 @redundant[@Defn{visibility rules}
704 The @i{visibility rules},
705 given below, determine which declarations are
706 visible and directly visible at each place within a program.
707 The visibility rules apply to both explicit and implicit declarations.]
708 @end{Intro}
709
710 @begin{StaticSem}
711 @Defn2{Term=[visibility], Sec=(direct)}
712 @Defn{directly visible}
713 @Defn{directly visible}
714 A declaration is defined to be @i{directly visible} at places
715 where a @nt<name> consisting of only an @nt{identifier} or
716 @nt{operator_symbol} is sufficient to denote the declaration;
717 that is, no @nt<selected_component> notation or special context
718 (such as preceding => in a named association) is necessary
719 to denote the declaration.
720 @Defn{visible}
721 A declaration is defined to be @i{visible} wherever it is
722 directly visible, as well as at other places where
723 some @nt<name> (such as a @nt<selected_component>) can denote
724 the declaration.
725
726 The syntactic category @nt<direct_name> is used to indicate
727 contexts where direct visibility is required.
728 The syntactic category @nt<selector_name> is used to indicate
729 contexts where visibility, but not direct visibility,
730 is required.
731
732 @Defn2{Term=[visibility], Sec=(immediate)}
733 @Defn2{Term=[visibility], Sec=(use clause)}
734 There are two kinds of direct visibility:
735 @i{immediate visibility} and @i{use-visibility}.
736 @Defn{immediately visible}
737 A declaration is immediately visible at a place if it is directly
738 visible because the place is within its immediate scope.
739 @Defn{use-visible}
740 A declaration is use-visible if it is directly visible
741 because of a @nt{use_clause} (see @RefSecNum{Use Clauses}).
742 Both conditions can apply.
743
744 @Defn{hiding}
745 A declaration can be @i{hidden}, either from direct visibility,
746 or from all visibility,
747 within certain parts of its scope.
748 @Defn{hidden from all visibility}
749 Where @i{hidden from all visibility},
750 it is not visible at all (neither using a @nt<direct_name>
751 nor a @nt<selector_name>).
752 @Defn{hidden from direct visibility}
753 Where @i{hidden from direct visibility}, only direct visibility is lost;
754 visibility using a @nt<selector_name> is still possible.
755
756 @redundant[@Defn{overloaded}
757 Two or more declarations are @i{overloaded} if
758 they all have the same defining name
759 and there is a place where they are all directly visible.]
760 @begin{Ramification}
761 Note that a @nt{name} can have more than one possible interpretation
762 even if it denotes a nonoverloadable entity.
763 For example, if there are two functions F that return records,
764 both containing a component called C, then
765 the name F.C has two possible interpretations,
766 even though component declarations are not overloadable.
767 @end{Ramification}
768
769 @Defn{overloadable}
770 The declarations of callable entities
771 @Redundant[(including enumeration literals)]
772 are @i{overloadable}@Redundant[,
773 meaning that overloading is allowed for them].
774 @begin{Ramification}
775 A @nt{generic_declaration} is not overloadable within its own
776 @nt{generic_formal_part}.
777 This follows from the rules about when a @nt{name} denotes a current
778 instance.
779 See AI83-00286. This implies that within a
780 @nt{generic_formal_part}, outer declarations with the same defining name
781 are hidden from direct visibility. It also implies that if a generic
782 formal parameter has the same defining name as the generic itself,
783 the formal parameter hides the generic from direct visibility.
784 @end{Ramification}
785
786 @Defn{homograph}
787 Two declarations are @i{homographs}
788 if they have the same defining name,
789 and, if both are overloadable,
790 their profiles are type conformant.
791 @PDefn{type conformance}
792 @redundant[An inner declaration hides any outer homograph from direct visibility.]
793
794
795 @ChgToGlossary{Version=[2],Kind=[AddedNormal],Term=<Overriding operation>,
796 Text=[@ChgAdded{Version=[2],Text=[An overriding operation
797 is one that replaces an inherited primitive operation. Operations may be marked
798 explicitly as overriding or not overriding.]}]}
799
800 @ChgRef{Version=[1],Kind=[Revised],Ref=[8652/0025],ARef=[AI95-00044-01]}
801 @leading@Redundant[Two homographs are not generally allowed
802 immediately within the same declarative region unless one
803 @i{overrides} the other (see Legality Rules below).]
804 @Defn{override}
805 @Chg{New=[The only declarations that are @Defn{overridable}@i{overridable} are
806 the implicit declarations for predefined operators and inherited primitive
807 subprograms.],Old=[]}
808 A declaration overrides another homograph that occurs
809 immediately within the same declarative region in the
810 following cases:
811 @begin{Itemize}
812 @ChgRef{Version=[1],Kind=[Revised],Ref=[8652/0025],ARef=[AI95-00044-01]}
813 @Chg{New=[A declaration that is not overridable overrides one that is overridable],
814 Old=[An explicit declaration overrides an implicit declaration of a primitive
815 subprogram]}, @Redundant[regardless of which declaration occurs first];
816 @begin{Ramification}
817 @ChgRef{Version=[1],Kind=[Revised],Ref=[8652/0025],ARef=[AI95-00044-01]}
818 And regardless of whether the @Chg{New=[nonoverridable],Old=[explicit]}
819 declaration is overloadable or not.
820 @Chg{New=[For example, @nt{statement_identifier}s are covered by this rule.],Old=[]}
821
822 The @lquotes@;regardless of which declaration occurs first@rquotes@;
823 is there because the explicit declaration could be a primitive subprogram
824 of a partial view, and then the full view might inherit a homograph.
825 We are saying that the explicit one wins
826 (within its scope), even though the implicit one comes later.
827
828 If the overriding declaration is also a subprogram,
829 then it is a primitive subprogram.
830
831 As explained in @RefSec{Private Operations},
832 some inherited primitive subprograms are never declared.
833 Such subprograms cannot be overridden,
834 although they can be reached by dispatching calls
835 in the case of a tagged type.
836 @end{Ramification}
837
838 The implicit declaration of an inherited operator overrides
839 that of a predefined operator;
840 @begin{Ramification}
841 In a previous version of Ada 9X, we tried to avoid the notion of
842 predefined operators, and say that they were inherited from some
843 magical root type.
844 However, this seemed like too much mechanism.
845 Therefore, a type can have a predefined "+" as well as an inherited "+".
846 The above rule says the inherited one wins.
847
848 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00114-01]}
849 The @lquotes@;regardless of which declaration occurs first@rquotes@; applies here
850 as well, in the case where @Chg{Version=[2],New=[@nt{derived_type_definition}],
851 Old=[@ntf{derived_type_declaration}]} in the visible
852 part of a public library unit derives from a private type declared in
853 the parent unit, and the full view of the parent type has additional
854 predefined operators, as explained in @RefSec{Private Operations}.
855 Those predefined operators can be overridden by inherited subprograms
856 implicitly declared earlier.
857 @end{Ramification}
858
859 An implicit declaration of an inherited subprogram
860 overrides a previous implicit declaration of an inherited
861 subprogram.
862
863 @ChgRef{Version=[2],Kind=[Added],ARef=[AI95-00251-01]}
864 @ChgAdded{Version=[2],Type=[Leading],Text=[If two or more homographs are
865 implicitly declared at the same place:]}
866
867 @begin{InnerItemize}
868 @ChgRef{Version=[2],Kind=[Added],ARef=[AI95-00251-01]}
869 @ChgAdded{Version=[2],Text=[If at least one is a subprogram that is neither a
870 null procedure nor an abstract subprogram, and does not require overriding (see
871 @RefSecNum{Abstract Types and Subprograms}), then they override those that are
872 null procedures, abstract subprograms, or require overriding. If more than one
873 such homograph remains that is not thus overridden, then they are all hidden
874 from all visibility.]}
875
876 @ChgRef{Version=[2],Kind=[Added],ARef=[AI95-00251-01]}
877 @ChgRef{Version=[5],Kind=[RevisedAdded],ARef=[AI12-0183-1]}
878 @ChgAdded{Version=[2],Text=[Otherwise (all are null procedures, abstract
879 subprograms, or require overriding), then any null procedure overrides all
880 abstract subprograms and all subprograms that require overriding; if more than
881 one such homograph remains that is not thus overridden, then if
882 @Chg{Version=[5],New=[the profiles of the remaining homographs],Old=[they]} are
883 all fully conformant with one another, one is chosen arbitrarily; if not, they
884 are all hidden from all visibility.
885 @Defn2{Term=[full conformance],Sec=(required)}]}
886
887 @begin{Discussion}
888 @ChgRef{Version=[2],Kind=[AddedNormal]}
889 @ChgAdded{Version=[2],Type=[Leading],Text=[In the case where the
890 implementation arbitrarily chooses one overrider from among a group
891 of inherited subprograms, users should not be able to determine which
892 member was chosen, as the set of inherited subprograms which are chosen
893 from must be fully conformant. This rule is needed in order to
894 allow]}
895
896 @begin{Example}
897 @ChgRef{Version=[2],Kind=[AddedNormal]}
898 @Chg{Version=[2],New=[@Key{package} Outer @Key{is}
899 @Key{package} P1 @Key{is}
900 @Key{type} Ifc1 @Key{is interface};
901 @Key{procedure} Null_Procedure (X : Ifc1) @Key{is null};
902 @Key{procedure} Abstract_Subp (X : Ifc1) @Key{is abstract};
903 @Key{end} P1;],Old=[]}
904
905 @ChgRef{Version=[2],Kind=[AddedNormal]}
906 @Chg{Version=[2],New=[ @Key{package} P2 @Key{is}
907 @Key{type} Ifc2 @Key{is interface};
908 @Key{procedure} Null_Procedure (X : Ifc2) @Key{is null};
909 @Key{procedure} Abstract_Subp (X : Ifc2) @Key{is abstract};
910 @Key{end} P2;],Old=[]}
911
912 @ChgRef{Version=[2],Kind=[AddedNormal]}
913 @Chg{Version=[2],New=[ @Key{type} T @Key{is abstract new} P1.Ifc1 @Key{and} P2.Ifc2 @Key{with null record};
914 @Key{end} Outer;],Old=[]}
915 @end{Example}
916
917 @ChgRef{Version=[2],Kind=[AddedNormal]}
918 @ChgAdded{Version=[2],Text=[without requiring that T explicitly override
919 any of its inherited operations.]}
920
921 @ChgRef{Version=[2],Kind=[AddedNormal]}
922 @ChgAdded{Version=[2],Text=[Full conformance is required here,
923 as we cannot allow the parameter names to differ. If they did differ, the
924 routine which was selected for overriding could be determined by using
925 named parameter notation in a call.]}
926
927 @ChgRef{Version=[2],Kind=[AddedNormal]}
928 @ChgAdded{Version=[2],Text=[When the subprograms do not conform,
929 we chose not to adopt the @lquotes@;use clause@rquotes rule which would make
930 them all visible resulting in likely ambiguity. If we had used such a rule,
931 any successful calls would be confusing; and the fact that there are no
932 Beaujolais-like effect to worry about means we can consider other rules.
933 The hidden-from-all-visibility homographs are still inherited
934 by further derivations, which avoids order-of-declaration dependencies
935 and other anomalies.]}
936
937 @ChgRef{Version=[2],Kind=[AddedNormal]}
938 @ChgAdded{Version=[2],Text=[We have to be careful to not include arbitrary
939 selection if the routines have real bodies. (This can happen in generics, see
940 the example in the incompatibilities section below.) We don't want the
941 ability to successfully call routines where the body executed depends on the
942 compiler or a phase of the moon.]}
943
944 @ChgRef{Version=[2],Kind=[AddedNormal]}
945 @ChgAdded{Version=[2],Text=[Note that if the type is concrete, abstract
946 subprograms are inherited as subprograms that require overriding. We include
947 functions that require overriding as well; these don't have real bodies, so
948 they can use the more liberal rules.]}
949 @end{Discussion}
950
951 @end{InnerItemize}
952
953 @Redundant[For an implicit declaration of a primitive subprogram in a
954 generic unit, there is a copy of this declaration in an instance.]
955 However, a whole new set of primitive subprograms is implicitly
956 declared for each type declared within the visible part of the instance.
957 These new declarations occur immediately after the type
958 declaration, and override the copied ones.
959 @Redundant[The copied ones can be called only from within the instance;
960 the new ones can be called only from outside the instance,
961 although for tagged types, the body of a new one can be executed
962 by a call to an old one.]
963 @begin{Discussion}
964 In addition, this is also stated redundantly (again),
965 and is repeated, in @RefSec{Generic Instantiation}.
966 The rationale for the rule is explained there.
967 @end{Discussion}
968 @begin{Honest}
969 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0042-1]}
970 @ChgAdded{Version=[3],Text=[The implicit subprograms declared when an
971 operation of a progenitor is implemented by an entry or subprogram also
972 override the appropriate implicitly declared inherited operations of the
973 progenitor.@PDefn2{Term=[override],Sec=[when implemented by]}]}
974 @end{Honest}
975 @end{Itemize}
976
977 @leading@Defn{visible}
978 @RootDefn{hidden from all visibility}
979 A declaration is visible within its scope,
980 except where hidden from all visibility,
981 as follows:
982 @begin{Itemize}
983 @PDefn2{Term=[hidden from all visibility], Sec=(for overridden declaration)}
984 An overridden declaration is hidden from all visibility within the
985 scope of the overriding declaration.
986 @begin{Ramification}
987 We have to talk about the scope of the overriding declaration,
988 not its visibility, because it hides
989 even when it is itself hidden.
990
991 Note that the scope of an explicit @nt{subprogram_declaration}
992 does not start until after its profile.
993 @end{Ramification}
994
995 @leading@PDefn2{Term=[hidden from all visibility], Sec=(within the declaration itself)}
996 A declaration is hidden from all visibility until the end of the
997 declaration, except:
998 @begin(InnerItemize)
999 For a record type or record extension,
1000 the declaration is hidden from all visibility only
1001 until the reserved word @b(record);
1002
1003 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00345-01]}
1004 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0177-1]}
1005 For a @nt{package_declaration}, @Chg{Version=[2],New=[],Old=[task declaration,
1006 protected declaration, ]}@nt{generic_@!package_@!declaration},
1007 @Chg{Version=[3],New=[],Old=[or ]}@nt{subprogram_@!body},
1008 @Chg{Version=[3],New=[or @nt{expression_@!function_@!declaration}, ],Old=[]}the
1009 declaration is hidden from all visibility only until the
1010 reserved word @key(is)
1011 of the declaration@Chg{Version=[2],New=[;],Old=[.]}
1012 @begin{Ramification}
1013 We're talking about the @key{is} of the construct itself, here,
1014 not some random @key{is} that might appear in a
1015 @nt{generic_formal_part}.
1016 @end{Ramification}
1017
1018 @ChgRef{Version=[2],Kind=[Added],ARef=[AI95-00345-01]}
1019 @ChgAdded{Version=[2],Text=[For a task declaration or protected declaration,
1020 the declaration is hidden from all visibility only
1021 until the reserved word @key(with) of the declaration if there is one, or the
1022 reserved word @key(is) of the declaration if there is no @key(with).]}
1023
1024 @begin{Honest}
1025 @ChgRef{Version=[2],Kind=[AddedNormal]}
1026 @ChgAdded{Version=[2],Text=[If there is neither a @key(with) nor @key(is),
1027 then the exception does not apply and the name is hidden from all
1028 visibility until the end of the declaration. This oddity was inherited
1029 from Ada 95.]}
1030 @end{Honest}
1031 @begin{Reason}
1032 @ChgRef{Version=[2],Kind=[AddedNormal]}
1033 @ChgAdded{Version=[2],Text=[We need the @lquotes@key(with) or @key(is)@rquotes
1034 rule so that the visibility within an @nt{interface_list} does not
1035 vary by construct. That would make it harder to complete private extensions
1036 and would complicate implementations.]}
1037 @end{Reason}
1038
1039 @end(InnerItemize)
1040
1041 @PDefn2{Term=[hidden from all visibility], Sec=(for a declaration completed by a subsequent declaration)}
1042 If the completion of a declaration is a declaration,
1043 then within the scope of the completion,
1044 the first declaration is hidden from all visibility.
1045 Similarly, a @nt{discriminant_@!specification} or
1046 @nt{parameter_@!specification} is hidden within the scope of a
1047 corresponding @nt{discriminant_@!specification} or
1048 @nt{parameter_@!specification} of a corresponding completion,
1049 or of a corresponding @nt{accept_@!statement}.
1050 @begin{Ramification}
1051 This rule means, for example, that within the scope of a
1052 @nt{full_type_declaration} that completes a
1053 @nt{private_type_declaration},
1054 the name of the type will denote the @nt{full_type_declaration},
1055 and therefore the full view of the type.
1056 On the other hand, if the completion is not a declaration,
1057 then it doesn't hide anything,
1058 and you can't denote it.
1059 @end{Ramification}
1060
1061 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00217-06],ARef=[AI95-00412-01]}
1062 @PDefn2{Term=[hidden from all visibility], Sec=(by lack of a @nt{with_clause})}
1063 The declaration of a library unit
1064 (including a @nt{library_unit_renaming_declaration})
1065 is hidden from all visibility @Chg{Version=[2],New=[],Old=[except ]}at
1066 places @Chg{Version=[2],New=[outside],Old=[that are within]} its declarative
1067 region @Chg{Version=[2],New=[that are not],Old=[or]} within the scope
1068 of a @Chg{Version=[2],New=[@nt{nonlimited_with_clause}],Old=[@nt{with_clause}]} that
1069 mentions it.@Chg{Version=[2],New=[ The limited view of a library package
1070 is hidden from all visibility at places that are not within the scope
1071 of a @nt{limited_with_clause} that mentions it; in addition, the limited view
1072 is hidden from all visibility within the declarative region of the package, as
1073 well as within the scope of any @nt{nonlimited_with_clause} that
1074 mentions the package. Where the declaration of the limited view of a
1075 package is visible, any name that denotes the package denotes the
1076 limited view, including those provided by a package renaming.],Old=[@Redundant[For
1077 each declaration or renaming of a generic unit as a child of
1078 some parent generic package, there is a corresponding declaration nested
1079 immediately within each instance of the parent.]
1080 Such a nested declaration is hidden from all visibility
1081 except at places that are
1082 within the scope of a @nt{with_clause} that mentions the child.]}
1083
1084 @begin{Discussion}
1085 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00217-06]}
1086 This is the rule that prevents @nt{with_clause}s from being
1087 transitive; the [immediate] scope includes indirect semantic dependents.
1088 @Chg{Version=[2],New=[This rule also prevents the limited view of a package
1089 from being visible in the same place as the full view of the package, which
1090 prevents various ripple effects.],Old=[]}
1091 @end{Discussion}
1092
1093 @ChgRef{Version=[2],Kind=[Added],ARef=[AI95-00217-06],ARef=[AI95-00412-01]}@ChgNote{Just moved from above}
1094 @ChgAdded{Version=[2],Text=[@Redundant[For each
1095 declaration or renaming of a generic unit as a child of
1096 some parent generic package, there is a corresponding declaration nested
1097 immediately within each instance of the parent.]
1098 Such a nested declaration is hidden from all visibility
1099 except at places that are
1100 within the scope of a @nt{with_clause} that mentions the child.]}
1101
1102 @end{Itemize}
1103
1104 @leading@Defn{directly visible}
1105 @Defn{immediately visible}
1106 @Defn2{Term=[visibility], Sec=(direct)}
1107 @Defn2{Term=[visibility], Sec=(immediate)}
1108 A declaration with a @nt{defining_identifier} or
1109 @nt{defining_operator_symbol} is immediately visible
1110 @Redundant[(and hence
1111 directly visible)] within its immediate scope
1112 @RootDefn{hidden from direct visibility} except where hidden
1113 from direct visibility, as follows:
1114 @begin{Itemize}
1115 @PDefn2{Term=[hidden from direct visibility], Sec=(by an inner homograph)}
1116 A declaration is hidden from direct visibility
1117 within the immediate scope of a homograph of the
1118 declaration, if the homograph occurs within an inner declarative
1119 region;
1120
1121 @PDefn2{Term=[hidden from direct visibility], Sec=(where hidden from all visibility)}
1122 A declaration is also hidden from direct visibility
1123 where hidden from all visibility.
1124 @end{Itemize}
1125
1126 @ChgRef{Version=[2],Kind=[Added],ARef=[AI95-00195-01],ARef=[AI95-00408-01]}
1127 @ChgRef{Version=[3],Kind=[RevisedAdded],ARef=[AI05-0183-1]}
1128 @ChgAdded{Version=[2],Text=[@PDefn2{Term=[visible], Sec=(attribute_@!definition_@!clause)}
1129 An @nt{attribute_definition_clause} @Chg{Version=[3],New=[or an
1130 @nt{aspect_specification}@PDefn2{Term=[visible], Sec=(aspect_@!specification)}
1131 ],Old=[]}is @i{visible} everywhere within its scope.]}
1132
1133 @end{StaticSem}
1134
1135 @begin{Resolution}
1136 @PDefn2{Term=[possible interpretation], Sec=(for @nt{direct_name}s)}
1137 A @nt{direct_name} shall resolve to denote a directly visible
1138 declaration whose defining name is the same as the @nt{direct_name}.
1139 @PDefn2{Term=[possible interpretation], Sec=(for @nt{selector_name}s)}
1140 A @nt{selector_name} shall resolve to denote
1141 a visible declaration whose defining name is the same as the
1142 @nt{selector_name}.
1143 @begin{Discussion}
1144 "The same as" has the obvious meaning here,
1145 so for +,
1146 the possible interpretations are declarations whose defining name is "+"
1147 (an @nt{operator_symbol}).
1148 @end{Discussion}
1149
1150 These rules on visibility and direct visibility do not apply
1151 in a @nt{context_clause}, a @nt{parent_unit_name},
1152 or a @nt{pragma} that appears at the place of a
1153 @nt{compilation_unit}.
1154 For those contexts, see the rules
1155 in @RefSec{Environment-Level Visibility Rules}.
1156 @begin{Ramification}
1157 Direct visibility is irrelevant for @nt{character_literal}s.
1158 In terms of overload resolution
1159 @nt{character_literal}s are similar to other literals,
1160 like @key{null} @em see @RefSecNum{Literals}.
1161 For @nt{character_literal}s, there is no need to worry about
1162 hiding, since there is no way to declare homographs.
1163 @end{Ramification}
1164 @end{Resolution}
1165
1166 @begin{Legality}
1167 @ChgRef{Version=[1],Kind=[Revised],Ref=[8652/0025],Ref=[8652/0026],ARef=[AI95-00044-01],ARef=[AI95-00150-01]}
1168 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00377-01]}
1169 @Chg{New=[A nonoverridable],Old=[An explicit]} declaration is illegal if there is a
1170 homograph occurring immediately within the same
1171 declarative region that is visible at the place of the
1172 declaration, and is not hidden from all visibility by the
1173 @Chg{New=[nonoverridable],Old=[explicit]} declaration.
1174 @Chg{New=[In addition, a type extension is illegal if somewhere within its
1175 immediate scope it has two visible components with the same name.],Old=[]}
1176 Similarly, the @nt<context_clause> for a @Chg{Version=[2],
1177 New=[compilation unit],Old=[@nt<subunit>]} is illegal if it mentions (in a
1178 @nt<with_clause>) some library unit, and there is a homograph
1179 of the library unit that is visible at the place of the @Chg{Version=[2],
1180 New=[compilation unit],Old=[corresponding stub]}, and the
1181 homograph and the mentioned library unit are both
1182 declared immediately within the same declarative region.@PDefn{generic contract issue}
1183 These rules also apply to dispatching operations declared
1184 in the visible part of an instance of a generic unit.
1185 However, they do not apply to other overloadable declarations in
1186 an instance@Redundant[; such declarations may have type conformant profiles
1187 in the instance, so long as the corresponding declarations in the generic
1188 were not type conformant].
1189 @PDefn{type conformance}
1190
1191 @begin{Discussion}
1192 @leading@;Normally, these rules just mean you can't explicitly
1193 declare two homographs
1194 immediately within the same declarative region.
1195 The wording is designed to handle the
1196 following special cases:
1197 @begin{Itemize}
1198 If the second declaration completes the first one,
1199 the second declaration is legal.
1200
1201 @leading@;If the body of a library unit contains an explicit homograph of
1202 a child of that same library unit, this is illegal only if the body
1203 mentions the child in its @nt<context_clause>, or if
1204 some subunit mentions the child.
1205 Here's an example:
1206 @begin{Example}
1207 @key[package] P @key[is]
1208 @key[end] P;
1209
1210 @key[package] P.Q @key[is]
1211 @key[end] P.Q;
1212
1213 @key[package] @key[body] P @key[is]
1214 Q : Integer; --@RI{ OK; we cannot see package P.Q here.}
1215 @key[procedure] Sub @key[is] @key[separate];
1216 @key[end] P;
1217
1218 @key[with] P.Q;
1219 @key[separate](P)
1220 @key[procedure] Sub @key[is] --@RI{ Illegal.}
1221 @key[begin]
1222 @key[null];
1223 @key[end] Sub;
1224 @end{Example}
1225
1226 @NoPrefix@;If package body P said "@key[with] P.Q;", then it would be illegal
1227 to declare the homograph Q: Integer. But it does not, so the
1228 body of P is OK.
1229 However, the subunit would be able to see both P.Q's,
1230 and is therefore illegal.
1231
1232 @NoPrefix@;A previous version of Ada 9X allowed the subunit,
1233 and said that references to P.Q would tend to be ambiguous.
1234 However, that was a bad idea, because it requires overload resolution
1235 to resolve references to directly visible nonoverloadable
1236 homographs, which is something compilers have never before been
1237 required to do.
1238
1239 @ChgRef{Version=[1],Kind=[Added],Ref=[8652/0026],Ref=[8652/0102],ARef=[AI95-00150-01],ARef=[AI95-00157-01]}
1240 @ChgAdded{Version=[1],Type=[Leading],Text=[If a type extension contains a
1241 component with
1242 the same name as a component in an ancestor type, there must be no place
1243 where both components are visible. For instance:]}
1244 @begin{Example}@ChgRef{Version=[1],Kind=[Added]}
1245 @Chg{New=[@key[package] A @key[is]
1246 @key[type] T @key[is tagged private];
1247 @key[package] B @key[is]
1248 @key[type] NT @key[is new] T @key[with record]
1249 I: Integer; -- @RI{Illegal because T.I is visible in the body.}
1250 @key[end record]; -- @RI{T.I is not visible here.}
1251 @key[end] B;
1252 @key[private]
1253 @key[type] T @key[is tagged record]
1254 I: Integer; -- @RI{Illegal because T.I is visible in the body.}
1255 @key[end record];
1256 @key[end] A;],Old=[]}
1257
1258 @ChgRef{Version=[1],Kind=[Added]}
1259 @ChgRef{Version=[2],Kind=[RevisedAdded],ARef=[AI95-00114-01]}
1260 @Chg{New=[@Chg{Version=[2],New=[],Old=[@key[package] A @key[is]
1261 ]}@key[package] @key[body] A @key[is]
1262 @key[package] @key[body] B @key[is]
1263 -- @RI{T.I becomes visible here.}
1264 @key[end] B;
1265 @key[end] A;],Old=[]}
1266
1267 @ChgRef{Version=[1],Kind=[Added]}
1268 @Chg{New=[@key[package] A.C @key[is]
1269 @key[type] NT2 @key[is new] A.T @key[with record]
1270 I: Integer; -- @RI{Illegal because T.I is visible in the private part.}
1271 @key[end record]; -- @RI{T.I is not visible here.}
1272 @key[private]
1273 -- @RI{T.I is visible here.}
1274 @key[end] A.C;],Old=[]}
1275
1276 @ChgRef{Version=[1],Kind=[Added]}
1277 @Chg{New=[@key[with] A;
1278 @key[package] D @key[is]
1279 @key[type] NT3 @key[is new] A.T @key[with record]
1280 I: Integer; -- @RI{Legal because T.I is never visible in this package.}
1281 @key[end record];
1282 @key[end] D;],Old=[]}
1283
1284 @ChgRef{Version=[1],Kind=[Added]}
1285 @Chg{New=[@key[with] D;
1286 @key[package] A.E @key[is]
1287 @key[type] NT4 @key[is new] D.NT3 @key[with null record];
1288 X : NT4;
1289 I1 : Integer := X.I; -- @RI{D.NT3.I}
1290 I2 : Integer := D.NT3(X).I; -- @RI{D.NT3.I}
1291 I3 : Integer := A.T(X).I; -- @RI{A.T.I}
1292 @key[end] A.E;],Old=[]}
1293 @end{Example}
1294 @ChgRef{Version=[1],Kind=[Added],Ref=[8652/0102],ARef=[AI95-00157-01]}
1295 @ChgAdded{Version=[1],NoPrefix=[T],Text=[D.NT3 can have a component I because
1296 the component I of the parent type is never visible. The parent component
1297 exists, of course, but is never declared for the type D.NT3. In the child
1298 package A.E, the component I of A.T is visible, but that does not change the
1299 fact that the A.T.I component was never declared for type D.NT3. Thus, A.E.NT4
1300 does not (visibly) inherit the component I from A.T, while it does inherit the
1301 component I from D.NT3. Of course, both components exist, and can be accessed
1302 by a type conversion as shown above. This behavior stems from the fact that
1303 every characteristic of a type (including components) must be declared
1304 somewhere in the innermost declarative region containing the type @em if the
1305 characteristic is never visible in that declarative region, it is never
1306 declared. Therefore, such characteristics do not suddenly become available even
1307 if they are in fact visible in some other scope.
1308 See @RefSecNum{Private Operations} for more on the rules.]}
1309
1310 @ChgRef{Version=[2],Kind=[Added],ARef=[AI95-00377-01]}
1311 @ChgAdded{Version=[2],Text=[It is illegal to mention both an explicit child of
1312 an instance, and a child of the generic from which the instance was
1313 instantiated. This is easier to understand with an example:]}
1314 @begin{Example}
1315 @ChgRef{Version=[2],Kind=[Added]}
1316 @Chg{Version=[2],New=[@key{generic}
1317 @key{package} G1 @key{is}
1318 @key{end} G1;],Old=[]}
1319
1320 @ChgRef{Version=[2],Kind=[Added]}
1321 @Chg{Version=[2],New=[@key{generic}
1322 @key{package} G1.G2 @key{is}
1323 @key{end} G1.G2;],Old=[]}
1324
1325 @ChgRef{Version=[2],Kind=[Added]}
1326 @Chg{Version=[2],New=[@key{with} G1;
1327 @key{package} I1 @key{is new} G1;],Old=[]}
1328
1329 @ChgRef{Version=[2],Kind=[Added]}
1330 @ChgAdded{Version=[2],Text=[@key{package} I1.G2 @key{renames} ...]}
1331
1332 @ChgRef{Version=[2],Kind=[Added]}
1333 @Chg{Version=[2],New=[@key{with} G1.G2;
1334 @key{with} I1.G2; -- @RI{Illegal}
1335 @key{package} Bad @key{is} ...],Old=[]}
1336 @end{Example}
1337
1338 @ChgRef{Version=[2],Kind=[Added]}
1339 @ChgRef{Version=[5],Kind=[RevisedAdded],ARef=[AI12-0300-1]}
1340 @ChgAdded{Version=[2],NoPrefix=[T],Text=[The context clause for Bad is illegal
1341 as I1 has an implicit declaration of I1.G2 based on the generic child G1.G2,
1342 as well as the mention of the explicit child I1.G2. As in the previous cases,
1343 this is illegal only if the context clause makes both children visible; the
1344 explicit child can be mentioned as long as the generic child is not (and
1345 vice@Chg{Version=[5],New=[ ],Old=[-]}versa).]}
1346 @end{Itemize}
1347
1348 Note that we need to be careful which things we make "hidden from all
1349 visibility" versus which things we make simply illegal for names to
1350 denote. The distinction is subtle.
1351 The rules that disallow names denoting components within a type
1352 declaration (see @RefSecNum{Discriminants}) do not make the components
1353 invisible at those places, so that the above rule makes components with
1354 the same name illegal.
1355 The same is true for the rule that disallows names denoting formal
1356 parameters within a @nt{formal_part} (see @RefSecNum{Subprogram Declarations}).
1357 @end{Discussion}
1358 @begin{Discussion}
1359 The part about instances is from AI83-00012.
1360 The reason it says @lquotes@;overloadable declarations@rquotes@; is because
1361 we don't want it to apply to type extensions that appear in an instance;
1362 components are not overloadable.
1363 @end{Discussion}
1364 @end{Legality}
1365
1366 @begin{Notes}
1367 Visibility for compilation units
1368 follows from the definition of the environment
1369 in @RefSecNum{The Compilation Process},
1370 except that it is necessary to apply a @nt{with_clause} to obtain
1371 visibility to a @nt{library_unit_declaration}
1372 or @nt{library_unit_renaming_declaration}.
1373
1374 In addition to the visibility rules given above,
1375 the meaning of the occurrence of a @nt{direct_name} or
1376 @nt{selector_name} at a given place in the text can depend on
1377 the overloading rules
1378 (see @RefSecNum{The Context of Overload Resolution}).
1379
1380 Not all contexts where an @nt<identifier>, @nt<character_literal>,
1381 or @nt<operator_symbol> are allowed require visibility of a corresponding
1382 declaration.
1383 Contexts where visibility is not required
1384 are identified by using one of these three syntactic categories
1385 directly in a syntax rule, rather than using @nt<direct_name> or
1386 @nt<selector_name>.
1387 @begin{Ramification}
1388 @leading@;An @nt{identifier}, @nt{character_literal} or @nt{operator_symbol}
1389 that occurs in one of the following contexts is not
1390 required to denote a visible or directly
1391 visible declaration:
1392 @begin{enumerate}
1393 A defining name.
1394
1395 The @nt{identifier}s or @nt{operator_symbol} that appear after the
1396 reserved word @key{end} in a @nt{proper_body}.
1397 Similarly for @lquotes@;@key{end loop}@rquotes@;, etc.
1398
1399 An @nt{attribute_designator}.
1400
1401 A @nt{pragma} @nt{identifier}.
1402
1403 A @SynI{pragma_argument_}@nt{identifier}.
1404
1405 An @nt{identifier} specific to a
1406 pragma used in a pragma argument.
1407
1408 @ChgRef{Version=[3],Kind=[Added],ARef=[AI05-0183-1]}
1409 @ChgAdded{Version=[3],Text=[An @nt{aspect_mark};]}
1410
1411 @ChgRef{Version=[3],Kind=[Added],ARef=[AI05-0183-1]}
1412 @ChgAdded{Version=[3],Text=[An @nt{identifier} specific to an aspect used
1413 in an @nt{aspect_definition}.]}
1414 @end{enumerate}
1415
1416 The visibility rules have nothing to do with the above cases;
1417 the meanings of such things are defined elsewhere.
1418 Reserved words are not @nt{identifier}s;
1419 the visibility rules don't apply to them either.
1420
1421 Because of the way we have defined "declaration",
1422 it is possible for a usage name to denote a @nt{subprogram_body}, either
1423 within that body, or (for a nonlibrary unit) after it
1424 (since the body hides the corresponding declaration, if any).
1425 Other bodies do not work that way.
1426 Completions of @nt{type_declaration}s and
1427 deferred constant declarations do work that way.
1428 @nt{Accept_statement}s are never denoted, although the
1429 @nt{parameter_specification}s in their profiles can be.
1430
1431 @leading@;The scope of a subprogram does not start until after its profile.
1432 Thus, the following is legal:
1433 @begin{Example}
1434 X : @key[constant] Integer := 17;
1435 ...
1436 @key[package] P @key[is]
1437 @key[procedure] X(Y : @key[in] Integer := X);
1438 @key[end] P;
1439 @end{Example}
1440
1441 The body of the subprogram will probably be illegal,
1442 however, since the constant X will be hidden by then.
1443
1444 @leading@;The rule is different for generic subprograms,
1445 since they are not overloadable;
1446 the following is illegal:
1447 @begin{Example}
1448 X : @key[constant] Integer := 17;
1449 @key[package] P @key[is]
1450 @key[generic]
1451 Z : Integer := X; --@RI{ Illegal!}
1452 @key[procedure] X(Y : @key[in] Integer := X); --@RI{ Illegal!}
1453 @key[end] P;
1454 @end{Example}
1455
1456 The constant X is hidden from direct visibility by the generic
1457 declaration.
1458 @end{Ramification}
1459 @end{Notes}
1460
1461 @begin{Extend83}
1462 @Defn{extensions to Ada 83}
1463 Declarations with the same defining
1464 name as that of a subprogram or entry being defined
1465 are nevertheless visible within
1466 the subprogram specification or entry declaration.
1467 @end{Extend83}
1468
1469 @begin{DiffWord83}
1470 The term @lquotes@;visible by selection@rquotes@; is no longer defined.
1471 We use the terms @lquotes@;directly visible@rquotes@; and @lquotes@;visible@rquotes@; (among other things).
1472 There are only two regions of text that are of interest, here: the
1473 region in which a declaration is visible,
1474 and the region in which it is directly visible.
1475
1476 Visibility is defined only for declarations.
1477 @end{DiffWord83}
1478
1479
1480 @begin{Incompatible95}
1481 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00251-01]}
1482 @ChgAdded{Version=[2],Type=[Leading],Text=[@Defn{incompatibilities with Ada 95}
1483 Added rules to handle the inheritance and overriding of
1484 multiple homographs for a single type declaration, in order to support
1485 multiple inheritance from interfaces. The new rules are intended to be
1486 compatible with the existing rules so that programs that do not use
1487 interfaces do not change their legality. However, there is a very rare
1488 case where this is not true:]}
1489 @begin{Example}
1490 @ChgRef{Version=[2],Kind=[AddedNormal]}
1491 @ChgAdded{Version=[2],Text=[@key{generic}
1492 @key{type} T1 @key{is private};
1493 @key{type} T2 @key{is private};
1494 @key{package} G @key{is}
1495 @key{type} T @key{is null record};
1496 @key{procedure} P (X : T; Y : T1);
1497 @key{procedure} P (X : T; Z : T2);
1498 @key{end} G;]]}
1499
1500 @ChgRef{Version=[2],Kind=[AddedNormal]}
1501 @ChgAdded{Version=[2],Text=[@key{package} I @key{is new} G (Integer, Integer); -- @RI[Exports homographs of P.]]}
1502
1503 @ChgRef{Version=[2],Kind=[AddedNormal]}
1504 @ChgAdded{Version=[2],Text=[@key{type} D @key{is new} I.T; -- @RI[Both Ps are inherited.]]}
1505
1506 @ChgRef{Version=[2],Kind=[AddedNormal]}
1507 @ChgAdded{Version=[2],Text=[Obj : D;]}
1508
1509 @ChgRef{Version=[2],Kind=[AddedNormal]}
1510 @ChgAdded{Version=[2],Text=[P (Obj, Z => 10); -- @RI[Legal in Ada 95, illegal in Ada 2005.]]}
1511 @end{Example}
1512 @ChgRef{Version=[2],Kind=[AddedNormal]}
1513 @ChgAdded{Version=[2],Text=[The call to P would resolve in Ada 95 by using the
1514 parameter name, while the procedures P would be hidden from all visibility
1515 in Ada 2005 and thus would not resolve.
1516 This case doesn't seem worth making the rules any more
1517 complex than they already are.]}
1518
1519 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00377-01]}
1520 @ChgAdded{Version=[2],Text=[@B[Amendment Correction:] A @nt{with_clause} is
1521 illegal if it would create a homograph of an implicitly declared generic
1522 child (see @RefSecNum{Compilation Units - Library Units}). An Ada 95 compiler
1523 could have allowed this, but which unit of the two units involved would be
1524 denoted wasn't specified, so any successful use isn't portable. Removing one
1525 of the two @nt{with_clause}s involved will fix the problem.]}
1526 @end{Incompatible95}
1527
1528 @begin{DiffWord95}
1529 @ChgRef{Version=[2],Kind=[AddedNormal],Ref=[8652/0025],ARef=[AI95-00044-01]}
1530 @ChgAdded{Version=[2],Text=[@b<Corrigendum:> Clarified the overriding rules so
1531 that "/=" and @nt{statement_identifier}s are covered.]}
1532
1533 @ChgRef{Version=[2],Kind=[AddedNormal],Ref=[8652/0026],ARef=[AI95-00150-01]}
1534 @ChgAdded{Version=[2],Text=[@b<Corrigendum:> Clarified that is it never
1535 possible for two components with the same name to be visible; any such program
1536 is illegal.]}
1537
1538 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00195-01],ARef=[AI95-00408-01]}
1539 @ChgAdded{Version=[2],Text=[The visibility of an
1540 @nt{attribute_definition_clause} is defined so that it can be used by the
1541 stream attribute availability rules (see @RefSecNum{Stream-Oriented Attributes}).]}
1542
1543 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00217-06]}
1544 @ChgAdded{Version=[2],Text=[The visibility of a limited view of a library
1545 package is defined (see @RefSecNum{Compilation Units - Library Units}).]}
1546 @end{DiffWord95}
1547
1548 @begin{DiffWord2005}
1549 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0177-1]}
1550 @ChgRef{Version=[4],Kind=[Revised],ARef=[AI12-0157-1]}
1551 @ChgAdded{Version=[3],Text=[Added wording so that the parameters of an
1552 @nt{expression_@!function_@!declaration} are visible in the
1553 @Chg{Version=[4],New=[return expression],Old=[@nt{expression}]}
1554 of the function. (It would be pretty useless without such a rule.)]}
1555
1556 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0183-1]}
1557 @ChgAdded{Version=[3],Text=[The visibility of an
1558 @nt{aspect_specification} is defined so that it can be used in various other
1559 rules.]}
1560 @end{DiffWord2005}
1561
1562
1563 @RMNewPageVer{Version=[2]}@Comment{For printed version of Ada 2005 RM}
1564 @LabeledAddedSubClause{Version=[2],Name=[Overriding Indicators]}
1565
1566 @begin{Intro}
1567 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00218-03]}
1568 @ChgAdded{Version=[2],Text=[An @nt{overriding_indicator} is used to declare
1569 that an operation is intended to override (or not override) an inherited
1570 operation.]}
1571 @end{Intro}
1572
1573 @begin{Syntax}
1574 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00218-03]}
1575 @AddedSyn{Version=[2],lhs=<@Chg{Version=[2],New=<overriding_indicator>,Old=<>}>,
1576 rhs="@Chg{Version=[2],New=<[@key{not}] @key{overriding}>,Old=<>}"}
1577 @end{Syntax}
1578
1579 @begin{Legality}
1580 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00218-03],ARef=[AI95-00348-01],ARef=[AI95-00397-01]}
1581 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0177-1]}
1582 @ChgAdded{Version=[2],Type=[Leading],Text=[If an
1583 @nt{abstract_@!subprogram_@!declaration},
1584 @nt{null_@!procedure_@!declaration},@Chg{Version=[3],New=[
1585 @nt{expression_@!function_@!declaration},],Old=[]}
1586 @nt{subprogram_body}, @nt{subprogram_@!body_stub},
1587 @nt{subprogram_@!renaming_@!declaration}, @nt{generic_@!instantiation} of a
1588 subprogram, or @nt{subprogram_@!declaration}
1589 other than a protected subprogram has an @nt{overriding_@!indicator}, then:]}
1590
1591 @begin{Itemize}
1592 @ChgRef{Version=[2],Kind=[AddedNormal]}
1593 @ChgAdded{Version=[2],Text=[the operation shall be a primitive operation for some
1594 type;]}
1595
1596 @ChgRef{Version=[2],Kind=[AddedNormal]}
1597 @ChgAdded{Version=[2],Text=[if the @nt{overriding_indicator} is
1598 @key{overriding}, then the operation shall override a homograph at the place of
1599 the declaration or body;]}
1600
1601 @begin{Honest}
1602 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0005-1]}
1603 @ChgAdded{Version=[3],Text=[This doesn't require that the overriding happen
1604 at precisely the place of the declaration or body; it only requires that the
1605 region in which the overriding is known to have happened includes this
1606 place. That is, the overriding can happen at or before the place of the
1607 declaration or body.]}
1608 @end{Honest}
1609
1610 @ChgRef{Version=[2],Kind=[AddedNormal]}
1611 @ChgAdded{Version=[2],Text=[if the @nt{overriding_indicator} is
1612 @key{not overriding}, then the operation shall not override any homograph
1613 (at any place).]}
1614 @end{Itemize}
1615
1616 @ChgRef{Version=[2],Kind=[AddedNormal]}
1617 @ChgAdded{Version=[2],Text=[@PDefn{generic contract issue}In addition to the
1618 places where @LegalityTitle normally
1619 apply, these rules also apply in the private part of an instance of a generic
1620 unit.]}
1621
1622 @begin{Discussion}
1623 @ChgRef{Version=[2],Kind=[AddedNormal]}
1624 @ChgAdded{Version=[2],Text=[The @Key{overriding} and @Key{not overriding} rules
1625 differ slightly. For @Key{overriding}, we want the indicator to reflect the
1626 overriding state at the place of the declaration; otherwise the indicator would
1627 be @LQuotes@;lying@RQuotes@;. Whether a homograph is implicitly declared after
1628 the declaration (see 7.3.1 to see how this can happen)
1629 has no impact on this check. However, @Key{not overriding} is different;
1630 @LQuotes@;lying@RQuotes@; would happen if a homograph declared later actually
1631 is overriding. So, we require this check to take into account later overridings.
1632 That can be implemented either by looking ahead, or by rechecking when
1633 additional operations are declared.]}
1634
1635 @ChgRef{Version=[2],Kind=[AddedNormal]}
1636 @ChgAdded{Version=[2],Text=[The @LQuotes@;no lying@RQuotes@; rules are
1637 needed to prevent a @nt{subprogram_declaration} and @nt{subprogram_body}
1638 from having contradictory @nt{overriding_indicator}s.]}
1639 @end{Discussion}
1640 @end{Legality}
1641
1642 @begin{Notes}
1643 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00397-01]}
1644 @ChgAdded{Version=[2],Text=[Rules for @nt{overriding_indicator}s of task and
1645 protected entries and of protected subprograms are found in
1646 @RefSecNum{Entries and Accept Statements}
1647 and @RefSecNum{Protected Units and Protected Objects}, respectively.]}
1648 @end{Notes}
1649
1650 @begin{Examples}
1651 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00433-01]}
1652 @ChgAdded{Version=[2],Type=[Leading],Text=[The use of
1653 @nt{overriding_indicator}s allows the detection of errors at compile-time that
1654 otherwise might not be detected at all. For instance, we might declare a
1655 security queue derived from the Queue interface of 3.9.4 as:]}
1656
1657 @begin{Example}
1658 @ChgRef{Version=[2],Kind=[AddedNormal]}
1659 @ChgAdded{Version=[2],Text=[@key{type} Security_Queue @key{is new} Queue @key{with record} ...;]}
1660
1661 @ChgRef{Version=[2],Kind=[AddedNormal]}
1662 @ChgAdded{Version=[2],Text=[@key{overriding}
1663 @key{procedure} Append(Q : @key{in out} Security_Queue; Person : @key{in} Person_Name);]}
1664
1665 @ChgRef{Version=[2],Kind=[AddedNormal]}
1666 @ChgRef{Version=[5],Kind=[Revised],ARef=[AI12-0178-1]}
1667 @ChgAdded{Version=[2],Text=[@key{overriding}
1668 @key{procedure} Remove_First(Q : @key{in out} Security_Queue; Person : @Chg{Version=[5],New=[@key{out}],Old=[@key{in}]} Person_Name);]}
1669
1670 @ChgRef{Version=[2],Kind=[AddedNormal]}
1671 @ChgAdded{Version=[2],Text=[@key{overriding}
1672 @key{function} Cur_Count(Q : @key{in} Security_Queue) @key{return} Natural;]}
1673
1674 @ChgRef{Version=[2],Kind=[AddedNormal]}
1675 @ChgAdded{Version=[2],Text=[@key{overriding}
1676 @key{function} Max_Count(Q : @key{in} Security_Queue) @key{return} Natural;]}
1677
1678 @ChgRef{Version=[2],Kind=[AddedNormal]}
1679 @ChgAdded{Version=[2],Text=[@key{not overriding}
1680 @key{procedure} Arrest(Q : @key{in out} Security_Queue; Person : @key{in} Person_Name);]}
1681 @end{Example}
1682
1683 @ChgRef{Version=[2],Kind=[AddedNormal]}
1684 @ChgAdded{Version=[2],Text=[The first four subprogram declarations guarantee
1685 that these subprograms will override the four subprograms inherited from the
1686 Queue interface. A misspelling in one of these subprograms will be detected
1687 by the implementation. Conversely, the declaration of Arrest guarantees that
1688 this is a new operation.]}
1689
1690 @begin{Discussion}
1691 @ChgRef{Version=[2],Kind=[AddedNormal]}
1692 @ChgAdded{Version=[2],Text=[In this case, the subprograms are abstract, so
1693 misspellings will get detected anyway. But for other subprograms
1694 (especially when deriving from concrete types), the error might never be
1695 detected, and a body other than the one the programmer intended might be
1696 executed without warning. Thus our new motto: @lquotes@;Overriding
1697 indicators @em don't derive a type without them!@rquotes]}
1698 @end{Discussion}
1699 @end{Examples}
1700
1701 @begin{Extend95}
1702 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00218-03]}
1703 @ChgAdded{Version=[2],Text=[@Defn{extensions to Ada 95}
1704 @nt{Overriding_indicator}s are new. These let the
1705 programmer state her overriding intentions to the compiler; if the compiler
1706 disagrees, an error will be produced rather than a hard to find bug.]}
1707 @end{Extend95}
1708
1709 @begin{DiffWord2005}
1710 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI95-0177-1]}
1711 @ChgAdded{Version=[3],Text=[Expression functions can have overriding
1712 indicators.]}
1713 @end{DiffWord2005}
1714
1715
1716 @RMNewPageVer{Version=[2]}@Comment{For printed version of Ada 2005 RM}
1717 @LabeledClause{Use Clauses}
1718
1719 @begin{Intro}
1720 @redundant[A @nt{use_package_clause} achieves direct visibility of declarations that
1721 appear in the visible part of a package;
1722 a @nt{use_type_clause} achieves direct visibility of the primitive
1723 operators of a type.]
1724 @end{Intro}
1725
1726 @begin{MetaRules}
1727 @Defn{equivalence of @nt{use_clause}s and @nt{selected_component}s}
1728 If and only if the visibility rules allow P.A,
1729 "@key[use] P;" should make A directly visible
1730 (barring name conflicts).
1731 This means, for example, that child library units, and
1732 generic formals of a formal package whose
1733 @nt{formal_package_actual_part} is (<>),
1734 should be made visible by
1735 a @nt{use_clause} for the appropriate package.
1736
1737 @Defn{Beaujolais effect}
1738 The rules for @nt{use_clause}s were carefully constructed to avoid
1739 so-called @i(Beaujolais) effects, where the addition or removal
1740 of a single @nt{use_clause}, or a single declaration in a "use"d
1741 package, would
1742 change the meaning of a program from one legal interpretation to another.
1743 @end{MetaRules}
1744
1745 @begin{Syntax}
1746 @Syn{lhs=<use_clause>,rhs="@Syn2{use_package_clause} | @Syn2{use_type_clause}"}
1747
1748
1749 @Syn{lhs=<use_package_clause>,rhs="@key{use} @SynI{package_}@Syn2{name} {, @SynI{package_}@Syn2{name}};"}
1750
1751 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0150-1]}
1752 @Syn{lhs=<use_type_clause>,rhs="@key[use] @Chg{Version=[3],New={[@key[all]] },Old=[]}@key[type] @Syn2{subtype_mark} {, @Syn2{subtype_mark}};"}
1753 @end{Syntax}
1754
1755 @begin{Legality}
1756 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00217-06]}
1757 A @SynI{package_}@nt{name} of a @nt{use_package_clause}
1758 shall denote @Chg{Version=[2],New=[a nonlimited view of ],Old=[]}a package.
1759 @begin{Ramification}
1760 This includes formal packages.
1761 @end{Ramification}
1762 @end{Legality}
1763
1764 @begin{StaticSem}
1765 @Defn2{Term=[scope], Sec=(of a @nt{use_clause})}
1766 For each @nt{use_clause},
1767 there is a certain region of text called the @i{scope} of the @nt{use_clause}.
1768 For a @nt{use_clause} within a @nt{context_clause} of a
1769 @nt{library_unit_declaration}
1770 or @nt{library_unit_renaming_declaration},
1771 the scope is the entire declarative region of the declaration.
1772 For a @nt{use_clause} within a @nt{context_clause} of a
1773 body, the scope is the entire body @Redundant[and any
1774 subunits (including multiply
1775 nested subunits).
1776 The scope does not include @nt<context_clause>s themselves.]
1777
1778 For a @nt{use_clause} immediately within a declarative region,
1779 the scope is the portion of the declarative region
1780 starting just after the @nt{use_clause}
1781 and extending to the end of the declarative region.
1782 However, the scope of a @nt{use_clause} in the private part of a library
1783 unit does not include the visible part of
1784 any public descendant of that library unit.
1785 @begin{Reason}
1786 @leading@;The exception echoes the similar exception for
1787 @lquotes@;immediate scope (of a declaration)@rquotes@;
1788 (see @RefSecNum{Scope of Declarations}).
1789 It makes @nt{use_clause}s work like this:
1790 @begin{Example}
1791 @key[package] P @key[is]
1792 @key[type] T @key[is] @key[range] 1..10;
1793 @key[end] P;
1794
1795 @key[with] P;
1796 @key[package] Parent @key[is]
1797 @key[private]
1798 @key[use] P;
1799 X : T;
1800 @key[end] Parent;
1801
1802 @key[package] Parent.Child @key[is]
1803 Y : T; --@RI{ Illegal!}
1804 Z : P.T;
1805 @key[private]
1806 W : T;
1807 @key[end] Parent.Child;
1808 @end{Example}
1809
1810 The declaration of Y is illegal because the scope of the @lquotes@;@key[use] P@rquotes@;
1811 does not include that place, so T is not directly visible there.
1812 The declarations of X, Z, and W are legal.
1813 @end{Reason}
1814
1815 @ChgRef{Version=[2],Kind=[Added],ARef=[AI95-00217-06]}
1816 @Chg{Version=[2],New=[A package is @i{named} in a @nt{use_package_clause} if
1817 it is denoted by a @SynI{package_}@nt{name} of that clause. A type is @i{named}
1818 in a @nt{use_type_clause} if it is determined by a @nt{subtype_mark} of that
1819 clause.@Defn2{Term=[named],Sec=[in a use clause]}],Old=[]}
1820
1821 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00217-06]}
1822 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0150-1]}
1823 @ChgAdded{Version=[3],Type=[Leading],Text=[]}@Comment{Dummy to add conditional leading}
1824 @Defn{potentially use-visible}
1825 For each package @Chg{Version=[2],New=[named in ],Old=[denoted by
1826 a @SynI{package_}@nt{name} of ]}a @nt{use_package_clause} whose scope
1827 encloses a place, each declaration that occurs immediately within
1828 the declarative region of the package is
1829 @i(potentially use-visible) at this place
1830 if the declaration is visible at this place.
1831 For each type @i(T) or @i(T)'Class @Chg{Version=[2],New=[named in ],Old=[
1832 determined by a @nt<subtype_mark> of ]}a @nt{use_type_clause} whose scope
1833 encloses a place, the declaration of each primitive operator of type @i(T)
1834 is potentially use-visible at this place
1835 if its declaration is visible at this place.@Chg{Version=[3], New=[ If a
1836 @nt{use_type_clause} whose scope encloses a place includes the reserved
1837 word @key[all], then the following entities are also potentially use-visible
1838 at this place if the declaration of the entity is visible at this place:],Old=[]}
1839 @begin{Itemize}
1840 @ChgRef{Version=[3],Kind=[Added],ARef=[AI05-0150-1]}
1841 @ChgAdded{Version=[3],Text=[Each primitive subprogram of @i<T> including each
1842 enumeration literal (if any);]}
1843
1844 @ChgRef{Version=[3],Kind=[Added],ARef=[AI05-0150-1]}
1845 @ChgAdded{Version=[3],Text=[Each subprogram that is declared immediately
1846 within the declarative region in which an ancestor type of @i<T> is declared
1847 and that operates on a class-wide type that covers @i<T>.]}
1848 @end{Itemize}
1849
1850 @begin{Ramification}
1851 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0150-1]}
1852 Primitive subprograms whose defining name is an @nt{identifier} are
1853 @i{not} made potentially visible by a
1854 @nt{use_type_clause}@Chg{Version=[3],New=[ unless reserved word @key[all] is
1855 included],Old=[]}.
1856 A @nt{use_type_clause} @Chg{Version=[3],New=[without @key[all] ],Old=[]}is only for operators.
1857
1858 The semantics described here should be similar
1859 to the semantics for expanded names given
1860 in @RefSec{Selected Components}
1861 so as to achieve the effect requested by
1862 the @lquotes@;principle of equivalence of @nt{use_clause}s and
1863 @nt{selected_component}s.@rquotes@;
1864 Thus, child library units and generic formal parameters of a formal
1865 package are
1866 potentially use-visible when their enclosing package is use'd.
1867
1868 The "visible at that place" part implies that
1869 applying a @nt{use_clause} to a parent unit does not make all of its
1870 children use-visible @em only those that have been made
1871 visible by a @nt{with_clause}.
1872 It also implies that we don't have to worry about hiding in the
1873 definition of "directly visible" @em a declaration cannot be use-visible
1874 unless it is visible.
1875
1876 Note that
1877 "@key[use type] T'Class;" is equivalent to "@key[use type] T;",
1878 which helps avoid breaking the generic contract model.
1879 @end{Ramification}
1880
1881 @ChgRef{Version=[3],Kind=[Added],ARef=[AI05-0131-1]}
1882 @ChgAdded{Version=[3],Text=[Certain implicit declarations may become
1883 potentially use-visible in certain contexts as described in
1884 @RefSecNum{Formal Subprograms}.]}
1885
1886
1887 @leading@Defn{use-visible}
1888 @Defn2{Term=[visibility],Sec=(use clause)}
1889 A declaration is @i{use-visible} if it is potentially use-visible,
1890 except in these naming-conflict cases:
1891 @begin{itemize}
1892 A potentially use-visible declaration is not use-visible if the place
1893 considered is within the immediate scope of a homograph of the
1894 declaration.
1895
1896 Potentially use-visible declarations that have the same @nt{identifier}
1897 are not use-visible unless each of them is an overloadable
1898 declaration.
1899 @begin{Ramification}
1900 Overloadable declarations don't cancel each other out,
1901 even if they are homographs,
1902 though if they are not distinguishable
1903 by formal parameter names or the presence or absence of
1904 @nt{default_expression}s, any use will be ambiguous.
1905 We only mention @nt{identifier}s here, because
1906 declarations named by @nt<operator_symbol>s are
1907 always overloadable, and hence never cancel each other.
1908 Direct visibility is irrelevant for @nt{character_literal}s.
1909 @end{Ramification}
1910 @end{itemize}
1911 @end{StaticSem}
1912
1913 @begin{RunTime}
1914 @PDefn2{Term=[elaboration], Sec=(use_clause)}
1915 The elaboration of a @nt{use_clause} has no effect.
1916 @end{RunTime}
1917
1918 @begin{Examples}
1919
1920 @leading@keepnext@i{Example of a use clause in a context clause:}
1921 @begin{Example}
1922 @key[with] Ada.Calendar; @key[use] Ada;
1923 @end{Example}
1924
1925 @begin{WideAbove}
1926 @leading@keepnext@i{Example of a use type clause:}
1927 @end{WideAbove}
1928 @begin{Example}
1929 @key[use type] Rational_Numbers.Rational; --@RI{ see @RefSecNum{Package Specifications and Declarations}}
1930 Two_Thirds: Rational_Numbers.Rational := 2/3;
1931 @end{Example}
1932
1933 @begin{Ramification}
1934 In @lquotes@;@key[use] X, Y;@rquotes@;, Y cannot refer to something made visible by the
1935 @lquotes@;@key[use]@rquotes@; of X.
1936 Thus, it's not (quite) equivalent to @lquotes@;@key[use] X; @key[use] Y;@rquotes@;.
1937
1938 If a given declaration is already immediately visible,
1939 then a @nt{use_clause} that makes it potentially use-visible
1940 has no effect.
1941 Therefore,
1942 a @nt{use_type_clause} for a type whose declaration appears
1943 in a place other than the visible part
1944 of a package has no effect;
1945 it cannot make a declaration use-visible
1946 unless that declaration is already immediately visible.
1947
1948 "@key[Use] @key[type] S1;" and "@key[use] @key[type] S2;"
1949 are equivalent if S1 and S2 are both subtypes of the same type.
1950 In particular,
1951 "@key[use] @key[type] S;" and "@key[use] @key[type] S'Base;"
1952 are equivalent.
1953 @end{Ramification}
1954 @begin{Reason}
1955 We considered adding a rule that prevented several declarations of
1956 views of the same entity that all have the same semantics from
1957 cancelling each other out.
1958 For example, if a (possibly implicit)
1959 @nt{subprogram_declaration} for "+" is potentially use-visible,
1960 and a fully conformant renaming of it is also potentially
1961 use-visible, then they (annoyingly) cancel each other out;
1962 neither one is use-visible.
1963 The considered rule would have made just one of them use-visible.
1964 We gave up on this idea due to the complexity of the rule.
1965 It would have had to account for both overloadable and
1966 nonoverloadable @nt{renaming_declaration}s,
1967 the case where the rule should apply only to some subset of the
1968 declarations with the same defining name,
1969 and the case of @nt{subtype_declaration}s
1970 (since they are claimed to be sufficient for renaming of subtypes).
1971 @end{Reason}
1972 @end{Examples}
1973
1974 @begin{Extend83}
1975 @Defn{extensions to Ada 83}
1976 The @nt{use_type_clause} is new to Ada 95.
1977 @end{Extend83}
1978
1979 @begin{DiffWord83}
1980 The phrase @lquotes@;omitting from this set any packages that
1981 enclose this place@rquotes@; is no longer necessary to avoid making something
1982 visible outside its scope, because we explicitly state that the
1983 declaration has to be visible in order to be
1984 potentially use-visible.
1985 @end{DiffWord83}
1986
1987
1988 @begin{DiffWord95}
1989 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00217-06]}
1990 @ChgAdded{Version=[2],Text=[Limited views of packages are not allowed in use clauses.
1991 Defined @i<named in a use clause> for use in other limited view rules (see
1992 @RefSecNum{Context Clauses - With Clauses}).]}
1993 @end{DiffWord95}
1994
1995 @begin{Extend2005}
1996 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0150-1]}
1997 @ChgAdded{Version=[3],Text=[@Defn{extensions to Ada 2005}The
1998 @key[use all type] version of the @nt{use_type_clause} is new to Ada 2012.
1999 It works similarly to prefixed views.]}
2000 @end{Extend2005}
2001
2002 @begin{DiffWord2005}
2003 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0131-1]}
2004 @ChgAdded{Version=[3],Text=[@b<Correction:> Added wording to allow other
2005 declarations to be potentially use-visible, to support corrections to
2006 formal subprograms.]}
2007 @end{DiffWord2005}
2008
2009
2010
2011 @LabeledClause{Renaming Declarations}
2012
2013 @begin{Intro}
2014 @redundant[A @nt{renaming_declaration} declares another name for an entity,
2015 such as an object, exception, package, subprogram, entry,
2016 or generic unit.
2017 Alternatively, a @nt{subprogram_renaming_declaration} can be the
2018 completion of a previous @nt{subprogram_declaration}.]
2019
2020 @ChgToGlossary{Version=[2],Kind=[Added],Term=<Renaming>,
2021 Text=<@ChgAdded{Version=[2],Text=[A @nt{renaming_declaration} is a declaration
2022 that does not define a new entity, but instead defines a view of an existing
2023 entity.]}>}
2024
2025 @end{Intro}
2026
2027 @begin{Syntax}
2028 @Syn{lhs=<renaming_declaration>,rhs="
2029 @Syn2{object_renaming_declaration}
2030 | @Syn2{exception_renaming_declaration}
2031 | @Syn2{package_renaming_declaration}
2032 | @Syn2{subprogram_renaming_declaration}
2033 | @Syn2{generic_renaming_declaration}"}
2034 @end{Syntax}
2035
2036 @begin{RunTime}
2037 @PDefn2{Term=[elaboration], Sec=(renaming_declaration)}
2038 The elaboration of a @nt{renaming_declaration} evaluates the @nt{name} that
2039 follows the reserved word @key{renames} and thereby determines the
2040 view and entity denoted by this name
2041 @Defn{renamed view}
2042 @Defn{renamed entity}
2043 (the @i{renamed view} and @i{renamed entity}).
2044 @Redundant[A @nt{name} that denotes the @nt{renaming_declaration}
2045 denotes (a new view of) the renamed entity.]
2046 @end{RunTime}
2047
2048 @begin{Notes}
2049 Renaming may be used to resolve name conflicts and to act as a
2050 shorthand. Renaming with a different @nt{identifier} or
2051 @nt{operator_symbol} does not hide the old @nt{name}; the new
2052 @nt{name} and the old @nt{name} need not be visible at the same
2053 places.
2054
2055 A task or protected object that is declared by an explicit
2056 @nt{object_declaration} can be renamed as an object. However, a
2057 single task or protected object cannot be renamed since the
2058 corresponding type is anonymous (meaning it has no nameable subtypes).
2059 For similar reasons, an object of an anonymous array or access type
2060 cannot be renamed.
2061
2062 @leading@keepnext@;A subtype defined without any additional constraint
2063 can be used to achieve the effect of renaming another subtype
2064 (including a task or protected subtype) as in
2065 @begin{Example}
2066 @key[subtype] Mode @key[is] Ada.Text_IO.File_Mode;
2067 @end{Example}
2068 @end{Notes}
2069
2070 @begin{DiffWord83}
2071 The second sentence of RM83-8.5(3),
2072 @lquotes@;At any point where a renaming declaration is visible,
2073 the identifier, or operator symbol of this declaration denotes the
2074 renamed entity.@rquotes@; is incorrect. It doesn't say directly visible.
2075 Also, such an @nt{identifier} might resolve to something else.
2076
2077 The verbiage about renamings being legal @lquotes@;only if exactly one...@rquotes@;,
2078 which appears in RM83-8.5(4) (for objects) and RM83-8.5(7) (for subprograms) is
2079 removed, because it follows from the normal rules about overload resolution.
2080 For language lawyers, these facts are obvious; for programmers, they are
2081 irrelevant, since failing these tests is highly unlikely.
2082 @end{DiffWord83}
2083
2084
2085 @LabeledSubClause{Object Renaming Declarations}
2086
2087 @begin{Intro}
2088 @redundant[An @nt{object_renaming_declaration} is used to rename an object.]
2089 @end{Intro}
2090
2091 @begin{Syntax}
2092 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00230-01],ARef=[AI95-00423-01]}
2093 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0183-1]}
2094 @ChgRef{Version=[5],Kind=[Revised],ARef=[AI12-0275-1]}
2095 @Syn{lhs=<object_renaming_declaration>,rhs="@Chg{Version=[2],New=[
2096 ],Old=[]}@Syn2{defining_identifier} @Chg{Version=[5],New=<[>,Old=<>}: @Chg{Version=[2],New=<[@Syn2{null_exclusion}] >,Old=<>}@Syn2{subtype_mark}@Chg{Version=[5],New=<]>,Old=<>} @key{renames} @SynI{object_}@Syn2{name}@Chg{Version=[3],New=<
2097 [@Syn2{aspect_specification}]>,Old=[]};@Chg{Version=[2],New=[
2098 | @Syn2{defining_identifier} : @Syn2{access_definition} @key{renames} @SynI{object_}@Syn2{name}@Chg{Version=[3],New=<
2099 [@Syn2{aspect_specification}]>,Old=[]};],Old=[]}"}
2100 @end{Syntax}
2101
2102 @begin{Resolution}
2103
2104 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00230-01],ARef=[AI95-00254-01],ARef=[AI95-00409-01]}
2105 @ChgRef{Version=[5],Kind=[Revised],ARef=[AI12-0275-1]}
2106 The type of the @SynI{object_}@nt{name} shall resolve to
2107 the type determined by the @nt{subtype_mark}@Chg{Version=[5],New=[, if
2108 present. If no @nt{subtype_mark} or @nt{access_definition} is present,
2109 the expected type of the @SynI{object_}@nt{name} is any type],
2110 Old=[@Chg{Version=[2],New=[,
2111 or in the case where the type is defined by an @nt{access_definition}, to an
2112 anonymous access type. If the anonymous access type is an access-to-object type,
2113 the type of the @SynI{object_}@nt{name}
2114 shall have the same designated type as that of the @nt{access_definition}.
2115 If the anonymous access type is an access-to-subprogram type,
2116 the type of the @SynI{object_}@nt{name} shall have a designated profile
2117 that is type conformant with that of the @nt{access_definition}],Old=[]}]}.
2118
2119 @ChgRef{Version=[5],Kind=[Added],ARef=[AI12-0275-1]}
2120 @ChgAdded{Version=[5],Text=[In the case where the type is defined by an
2121 @nt{access_definition}, the type of the
2122 @SynI{object_}@nt{name} shall resolve to an anonymous access type.
2123 If the anonymous access type is an access-to-object type,
2124 the type of the @SynI{object_}@nt{name}
2125 shall have the same designated type as that of the @nt{access_definition}.
2126 If the anonymous access type is an access-to-subprogram type,
2127 the type of the @SynI{object_}@nt{name} shall have a designated profile
2128 that is type conformant with that of the @nt{access_definition}.]}
2129
2130 @begin{Reason}
2131 @leading@;A previous version of Ada 9X used the usual
2132 @lquotes@;expected type@rquotes@; wording:@*
2133 @lquotes@;The expected type for the @SynI{object_}@nt{name} is
2134 that determined by the @nt{subtype_mark}.@rquotes@;@*
2135 We changed it so that this would be illegal:
2136 @begin{Example}
2137 X: T;
2138 Y: T'Class @key[renames] X; --@RI{ Illegal!}
2139 @end{Example}
2140
2141 @leading@;When the above was legal, it was unclear whether Y
2142 was of type T or T'Class.
2143 Note that we still allow this:
2144 @begin{Example}
2145 Z: T'Class := ...;
2146 W: T @key[renames] F(Z);
2147 @end{Example}
2148
2149 where F is a function with a controlling parameter and result.
2150 This is admittedly a bit odd.
2151
2152 Note that the matching rule for generic formal parameters of mode
2153 @key[in out] was changed to keep it consistent with the rule
2154 for renaming.
2155 That makes the rule different for @key[in] vs. @key[in out].
2156
2157 @end{Reason}
2158 @end{Resolution}
2159
2160 @begin{Legality}
2161 The renamed entity shall be an object.@Defn2{Term=[object],Sec=(required)}
2162
2163 @ChgRef{Version=[2],Kind=[Added],ARef=[AI95-00231-01],ARef=[AI95-00409-01]}
2164 @ChgAdded{Version=[2],Type=[Leading],Keepnext=[T],Text=[In the case
2165 where the type is defined by an @nt{access_definition},
2166 the type of the renamed object and the type defined by the
2167 @nt{access_definition}:]}
2168 @begin{Itemize}
2169 @ChgRef{Version=[2],Kind=[Added],ARef=[AI95-00231-01],ARef=[AI95-00409-01]}
2170 @ChgAdded{Version=[2],Text=[shall both be access-to-object types with
2171 statically matching designated subtypes and with both or neither being
2172 access-to-constant types; or
2173 @PDefn2{Term=[statically matching],Sec=(required)}]}
2174
2175 @ChgRef{Version=[2],Kind=[Added],ARef=[AI95-00409-01]}
2176 @ChgAdded{Version=[2],Text=[shall both be access-to-subprogram types with
2177 subtype conformant designated profiles.
2178 @Defn2{Term=[subtype conformance],Sec=(required)}]}
2179 @end{Itemize}
2180
2181 @ChgRef{Version=[2],Kind=[Added],ARef=[AI95-00423-01]}
2182 @ChgRef{Version=[5],Kind=[RevisedAdded],ARef=[AI12-0287-1]}
2183 @ChgAdded{Version=[2],Type=[Leading],Text=[For an
2184 @nt{object_renaming_declaration} with a @nt{null_exclusion} or an
2185 @nt{access_definition} that has a @nt{null_exclusion}@Chg{Version=[5],New=[,
2186 the subtype of the @Syni{object_}@nt{name} shall exclude null. In addition,
2187 if the @nt{object_renaming_declaration} occurs within the body of a
2188 generic unit @i{G} or within the body of a generic unit declared within the
2189 declarative region of generic unit @i{G}, then],Old=[]}:]}
2190
2191 @begin{Itemize}
2192 @ChgRef{Version=[2],Kind=[Added]}
2193 @ChgRef{Version=[5],Kind=[RevisedAdded],ARef=[AI12-0287-1]}
2194 @ChgAdded{Version=[2],Text=[if the @Syni{object_}@nt{name}
2195 @Chg{Version=[5],New=[statically ],Old=[]}denotes a
2196 generic formal object @Chg{Version=[5],New=[of mode @b<in out> ],Old=[]}of
2197 @Chg{Version=[5],New=[],Old=[a generic unit ]}@i{G},
2198 @Chg{Version=[5],New=[],Old=[and the
2199 @nt{object_renaming_declaration} occurs within the body of @i{G} or within
2200 the body of a generic unit declared within the declarative region of
2201 @i{G}, ]}then the declaration of @Chg{Version=[5],New=[that],Old=[the
2202 formal]} object @Chg{Version=[5],New=[],Old=[of @i{G} ]}shall have a
2203 @nt{null_exclusion};]}
2204
2205 @ChgRef{Version=[2],Kind=[Added]}
2206 @ChgRef{Version=[5],Kind=[RevisedAdded],ARef=[AI12-0287-1]}
2207 @ChgAdded{Version=[2],Text=[@Chg{Version=[5],New=[if],Old=[otherwise, the
2208 subtype of]} the @Syni{object_}@nt{name} @Chg{Version=[5],New=[statically
2209 denotes a call of a generic formal function of @i{G},
2210 then the declaration of the result of that function shall have a
2211 @nt{null_exclusion}],Old=[shall exclude null.
2212 @PDefn{generic contract issue}
2213 In addition to the places where @LegalityTitle normally apply
2214 (see @RefSecNum{Generic Instantiation}),
2215 this rule applies also in the private part of an
2216 instance of a generic unit]}.]}
2217 @end{Itemize}
2218
2219 @ChgRef{Version=[5],Kind=[Added],ARef=[AI12-0287-1]}
2220 @ChgAdded{Version=[5],Text=[@PDefn{generic contract issue}
2221 In addition to the places where @LegalityTitle normally apply
2222 (see @RefSecNum{Generic Instantiation}),
2223 this rule applies also in the private part of an
2224 instance of a generic unit.]}
2225
2226 @begin{Reason}
2227 @ChgRef{Version=[2],Kind=[AddedNormal]}
2228 @ChgRef{Version=[5],Kind=[Revised],ARef=[AI12-0287-1],ARef=[AI12-0005-1]}
2229 @ChgAdded{Version=[2],Type=[Leading],Text=[@Chg{Version=[5],New=[These rules
2230 prevent],Old=[This rule prevents]}
2231 @lquotes@;lying@rquotes.
2232 @b<Null> must never be the value of an object with an explicit
2233 @nt{null_exclusion}. The @Chg{Version=[5],New=[bullets are],Old=[first
2234 bullet is]} an assume-the-worst rule
2235 which prevents trouble in @Chg{Version=[5],New=[two],Old=[one]}
2236 obscure @Chg{Version=[5],New=[cases],Old=[case]}:]}
2237 @begin{Example}
2238 @ChgRef{Version=[2],Kind=[AddedNormal]}
2239 @ChgAdded{Version=[2],Text=[@key{type} Acc_I @key{is access} Integer;
2240 @key{subtype} Acc_NN_I @key{is not null} Acc_I;
2241 Obj : Acc_I := @key{null};]}
2242
2243 @ChgRef{Version=[2],Kind=[AddedNormal]}
2244 @ChgAdded{Version=[2],Text=[@key{generic}
2245 B : @key{in out} Acc_NN_I;
2246 @key{package} Gen @key{is}
2247 ...
2248 @key{end} Gen;]}
2249
2250 @ChgRef{Version=[2],Kind=[AddedNormal]}
2251 @ChgAdded{Version=[2],Text=[@key{package body} Gen @key{is}
2252 D : @key{not null} Acc_I @key{renames} B;
2253 @key{end} Gen;]}
2254
2255 @ChgRef{Version=[2],Kind=[AddedNormal]}
2256 @ChgAdded{Version=[2],Text=[@key{package} Inst @key{is new} Gen (B => Obj);]}
2257 @end{Example}
2258 @ChgRef{Version=[2],Kind=[AddedNormal]}
2259 @ChgRef{Version=[5],Kind=[Revised],ARef=[AI12-0287-1]}
2260 @ChgAdded{Version=[2],Text=[Without the first bullet rule, D would
2261 be legal, and contain the value @key{null}, because the rule about lying
2262 is satisfied for generic matching (Obj matches B; B does not explicitly
2263 state @key{not null}),
2264 @LegalityTitle are not rechecked in the body of any instance, and the
2265 template passes the lying rule as well. The
2266 @Chg{Version=[5],New=[second bullet handles a similar case involving
2267 formal functions. The rules are],Old=[rule is]} so complex because
2268 @Chg{Version=[5],New=[they have],Old=[it has]} to apply to formals used
2269 in bodies of child generics as well as in the bodies of generics.]}
2270 @end{Reason}
2271
2272 @ChgRef{Version=[1],Kind=[Revised],Ref=[8652/0017],ARef=[AI95-00184-01]}
2273 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00363-01]}
2274 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0008-1]}
2275 The renamed entity shall not be a subcomponent that depends on
2276 discriminants of @Chg{Version=[3],New=[an object],Old=[a variable]}
2277 whose nominal subtype is unconstrained@Chg{Version=[3],New=[],Old=[,]}
2278 unless @Chg{Version=[3],New=[the object is known to be constrained],
2279 Old=[this subtype is indefinite, or the variable is @Chg{Version=[2],
2280 New=[constrained by its initial value],Old=[aliased]}]}.
2281 A @nt{slice} of an array shall not be renamed if
2282 this restriction disallows renaming of the array.
2283 @Chg{New=[@PDefn{generic contract issue}In addition to the places where
2284 Legality Rules normally apply, these rules apply also in the private part of an
2285 instance of a generic unit.@Chg{Version=[3],New=[],Old=[ These rules also apply for a renaming that appears
2286 in the body of a generic unit, with the additional requirement that even if the
2287 nominal subtype of the variable is indefinite, its type shall not be a
2288 descendant of an untagged generic formal derived type.]}],Old=[]}
2289
2290 @begin{Reason}
2291 This prevents renaming of subcomponents that might
2292 disappear, which might leave dangling references.
2293 Similar restrictions exist for the Access attribute.
2294
2295 @ChgRef{Version=[1],Kind=[Added],Ref=[8652/0017],ARef=[AI95-00184-01]}
2296 @ChgRef{Version=[3],Kind=[RevisedAdded],ARef=[AI05-0008-1]}
2297 @ChgAdded{Version=[1],Type=[Leading],Text=[The @lquotes@;recheck on
2298 instantiation@rquotes@; @Chg{Version=[3],New=[requirement], Old=[and
2299 @lquotes@;assume-the-worst in the body@rquotes@;
2300 restrictions]} on generics @Chg{Version=[3],New=[is],Old=[are]}
2301 necessary to avoid renaming of components which
2302 could disappear even when the nominal subtype would prevent the problem:]}
2303
2304 @begin{Example}
2305 @ChgRef{Version=[1],Kind=[Added]}
2306 @Chg{New=[@key{type} T1 (D1 : Boolean) @key{is}
2307 @key{record}
2308 @key{case} D1 @key{is}
2309 @key{when} False =>
2310 C1 : Integer;
2311 @key{when} True =>
2312 @key{null};
2313 @key{end} @key{case};
2314 @key{end} @key{record};],Old=[]}
2315
2316 @ChgRef{Version=[1],Kind=[Added]}
2317 @Chg{New=[@key{generic}
2318 @key{type} F @key{is} @key{new} T1;
2319 X : @key{in out} F;
2320 @key{package} G @key{is}
2321 C1_Ren : Integer @key{renames} X.C1;
2322 @key{end} G;],Old=[]}
2323
2324 @ChgRef{Version=[1],Kind=[Added]}
2325 @Chg{New=[@key{type} T2 (D2 : Boolean := False) @key{is} @key{new} T1 (D1 => D2);
2326 @Comment{Blank line}
2327 Y : T2;
2328 @Comment{Blank line}
2329 @key{package} I @key{is new} G (T2, Y);
2330 @Comment{Blank line}
2331 Y := (D1 => True); -- @RI[Oops! What happened to I.C1_Ren?]],Old=[]}
2332 @end{Example}
2333
2334 @ChgRef{Version=[3],Kind=[Added],ARef=[AI05-0008-1]}
2335 @ChgAdded{Version=[3],Text=[In addition, the @ldquote@;known to be constrained@rdquote
2336 rules include assume-the-worst rules for generic bodies partially to
2337 prevent such problems.]}
2338
2339 @end{Reason}
2340 @begin{ImplNote}
2341 Note that if an implementation chooses to deallocate-then-reallocate
2342 on @nt{assignment_@!statement}s assigning to unconstrained definite objects,
2343 then it cannot represent renamings and access values as simple
2344 addresses, because the above rule does not apply to all components of
2345 such an object.
2346 @end{ImplNote}
2347 @begin{Ramification}
2348 If it is a generic formal object,
2349 then the assume-the-best or assume-the-worst rules are applied as
2350 appropriate.
2351 @end{Ramification}
2352 @end{Legality}
2353
2354 @begin{StaticSem}
2355 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00230-01],ARef=[AI95-00409-01]}
2356 An @nt{object_renaming_declaration} declares a new view
2357 @Redundant{of the renamed object} whose
2358 properties are identical to those of the renamed view.
2359 @Redundant[Thus, the properties of the renamed object are not affected by the
2360 @nt{renaming_declaration}.
2361 In particular, its value and whether or not it is a constant
2362 are unaffected; similarly, the@Chg{Version=[2],New=[ null exclusion or],Old=[]}
2363 constraints that apply to an object are
2364 not affected by renaming (any constraint implied by the
2365 @nt{subtype_mark} @Chg{Version=[2],New=[or @nt{access_definition} ],Old=[]}of
2366 the @nt{object_renaming_declaration} is ignored).]
2367 @begin{Discussion}
2368 Because the constraints are ignored,
2369 it is a good idea
2370 to use the nominal subtype of the renamed object
2371 when writing an @nt{object_renaming_declaration}.
2372
2373 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00409-01]}
2374 @ChgAdded{Version=[2],Text=[If no @nt{null_exclusion} is given in the
2375 renaming, the
2376 object may or may not exclude null. This is similar to the way that
2377 constraints need not match, and @key{constant} is not specified. The
2378 renaming defines a view of the
2379 renamed entity, inheriting the original properties.]}
2380 @end{Discussion}
2381 @end{StaticSem}
2382
2383 @begin{Examples}
2384 @leading@keepnext@i{Example of renaming an object:}
2385 @begin{Example}
2386 @key[declare]
2387 L : Person @key[renames] Leftmost_Person; --@RI{ see @RefSecNum{Incomplete Type Declarations}}
2388 @key[begin]
2389 L.Age := L.Age + 1;
2390 @key[end];
2391 @end{Example}
2392 @end{Examples}
2393
2394 @begin{DiffWord83}
2395 The phrase @lquotes@;subtype ... as defined in a corresponding
2396 object declaration, component declaration, or component subtype
2397 indication,@rquotes@; from RM83-8.5(5), is incorrect in Ada 95;
2398 therefore we removed it.
2399 It is incorrect in the case of an object with an indefinite
2400 unconstrained nominal subtype.
2401 @end{DiffWord83}
2402
2403 @begin{Incompatible95}
2404 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00363-01]}
2405 @ChgAdded{Version=[2],Type=[Leading],Text=[@Leading@;@Defn{incompatibilities with Ada 95}
2406 Aliased variables are not necessarily constrained in Ada
2407 2005 (see @RefSecNum{Array Types}). Therefore, a subcomponent of an aliased
2408 variable may disappear or change shape, and renaming such a subcomponent thus
2409 is illegal, while the same operation would have been legal in Ada 95. Note that
2410 most allocated objects are still constrained by their initial value (see
2411 @RefSecNum{Allocators}), and thus have no change in the
2412 legality of renaming for them. For example,
2413 using the type T2 of the previous example:]}
2414 @begin{Example}
2415 @ChgRef{Version=[2],Kind=[AddedNormal]}
2416 @ChgAdded{Version=[2],Text=[ AT2 : @key{aliased} T2;
2417 C1_Ren : Integer @key{renames} AT2.C1; -- @RI[Illegal in Ada 2005, legal in Ada 95]
2418 AT2 := (D1 => True); -- @RI[Raised Constraint_Error in Ada 95,]
2419 -- @RI[but does not in Ada 2005, so C1_Ren becomes]
2420 -- @RI[invalid when this is assigned.]]}
2421 @end{Example}
2422 @end{Incompatible95}
2423
2424 @begin{Extend95}
2425 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00230-01],ARef=[AI95-00231-01],ARef=[AI95-00254-01],ARef=[AI95-00409-01]}
2426 @ChgAdded{Version=[2],Text=[@Defn{extensions to Ada 95}
2427 A renaming can have an anonymous access type. In that case, the accessibility
2428 of the renaming is that of the original object (accessibility is not
2429 lost as it is for assignment to a component or stand-alone object).]}
2430
2431 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00231-01],ARef=[AI95-00423-01]}
2432 @ChgAdded{Version=[2],Text=[A renaming can have a @nt{null_exclusion}; if so,
2433 the renamed object must also exclude null, so that the @nt{null_exclusion}
2434 does not lie. On the other hand, if the renaming does not have a
2435 @nt{null_exclusion}. it excludes null if the renamed object does.]}
2436 @end{Extend95}
2437
2438 @begin{DiffWord95}
2439 @ChgRef{Version=[2],Kind=[AddedNormal],Ref=[8652/0017],ARef=[AI95-00184-01]}
2440 @ChgAdded{Version=[2],Text=[@b<Corrigendum:> Fixed to forbid renamings of
2441 depends-on-discriminant components if the type @i{might} be definite.]}
2442 @end{DiffWord95}
2443
2444 @begin{Incompatible2005}
2445 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0008-1]}
2446 @ChgAdded{Version=[3],Text=[@Defn{incompatibilities with Ada 2005}@b<Correction:>
2447 Simplified the description of when a discriminant-dependent component is
2448 allowed to be renamed @em it's now simply when the object is
2449 known to be constrained. This
2450 fixes a confusion as to whether a subcomponent of an object that is not
2451 certain to be constrained can be renamed. The fix introduces an
2452 incompatibility, as the rule did not apply in Ada 95 if the prefix was a
2453 constant; but it now applies no matter what kind of object is involved. The
2454 incompatibility is not too bad, since most kinds of constants are known to be
2455 constrained.]}
2456 @end{Incompatible2005}
2457
2458 @begin{Extend2005}
2459 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0183-1]}
2460 @ChgAdded{Version=[3],Text=[@Defn{extensions to Ada 2005}
2461 An optional @nt{aspect_specification} can be used in an
2462 @nt{object_renaming_declaration}.
2463 This is described in @RefSecNum{Aspect Specifications}.]}
2464 @end{Extend2005}
2465
2466 @begin{Incompatible2012}
2467 @ChgRef{Version=[5],Kind=[AddedNormal],ARef=[AI12-0287-1]}
2468 @ChgAdded{Version=[5],Text=[@Defn{incompatibilities with Ada 2005}@b<Correction:>
2469 The @LegalityTitle for renames with null exclusions no longer applies to
2470 generic formal objects of mode @b<in>, but does apply to renames of
2471 generic formal functions. This means a few unlikely programs are now illegal
2472 that were previously allowed by original Ada 2012, while more programs that
2473 were previously llegal will be allowed.]}
2474 @end{Incompatible2012}
2475
2476 @begin{Extend2012}
2477 @ChgRef{Version=[5],Kind=[AddedNormal],ARef=[AI12-0275-1]}
2478 @ChgAdded{Version=[5],Text=[@Defn{extensions to Ada 2012}
2479 The @nt{subtype_mark} in an object renaming is now optional,
2480 as the subtype information it provides is not trustworthy anyway
2481 (that comes from the renamed object and there is no requirement that
2482 it is the same as that of the object).]}
2483 @end{Extend2012}
2484
2485
2486
2487 @NotISORMNewPageVer{Version=[3]}@Comment{For printed version of Ada 2012 RM}
2488 @LabeledSubClause{Exception Renaming Declarations}
2489
2490 @begin{Intro}
2491 @redundant[An @nt{exception_renaming_declaration} is used to rename an exception.]
2492 @end{Intro}
2493
2494 @begin{Syntax}
2495 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0183-1]}
2496 @Syn{lhs=<exception_renaming_declaration>,rhs="@Syn2{defining_identifier} : @key{exception} @key{renames} @SynI{exception_}@Syn2{name}@Chg{Version=[3],New=<
2497 [@Syn2{aspect_specification}]>,Old=[]};"}
2498 @end{Syntax}
2499
2500 @begin{Legality}
2501 The renamed entity shall be an exception.
2502 @end{Legality}
2503
2504 @begin{StaticSem}
2505 An @nt{exception_renaming_declaration} declares a new view
2506 @Redundant{of the renamed exception}.
2507 @end{StaticSem}
2508
2509 @begin{Examples}
2510 @leading@keepnext@i{Example of renaming an exception:}
2511 @begin{Example}
2512 EOF : @key[exception] @key[renames] Ada.IO_Exceptions.End_Error; @RI{-- see @RefSecNum{Exceptions in Input-Output}}
2513 @end{Example}
2514 @end{Examples}
2515
2516 @begin{Extend2005}
2517 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0183-1]}
2518 @ChgAdded{Version=[3],Text=[@Defn{extensions to Ada 2005}
2519 An optional @nt{aspect_specification} can be used in an
2520 @nt{exception_renaming_declaration}.
2521 This is described in @RefSecNum{Aspect Specifications}.]}
2522 @end{Extend2005}
2523
2524
2525 @LabeledSubClause{Package Renaming Declarations}
2526
2527 @begin{Intro}
2528 @redundant[A @nt{package_renaming_declaration} is used to rename a package.]
2529 @end{Intro}
2530
2531 @begin{Syntax}
2532 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0183-1]}
2533 @Syn{lhs=<package_renaming_declaration>,rhs="@key{package} @Syn2{defining_program_unit_name} @key{renames} @SynI{package_}@Syn2{name}@Chg{Version=[3],New=<
2534 [@Syn2{aspect_specification}]>,Old=[]};"}
2535 @end{Syntax}
2536
2537 @begin{Legality}
2538 The renamed entity shall be a package.
2539
2540 @ChgRef{Version=[2],Kind=[Added],ARef=[AI95-00217-06],ARef=[AI95-00412-01]}
2541 @ChgAdded{Version=[2],Text=[If the @SynI{package_}@nt{name} of a
2542 @nt{package_renaming_declaration} denotes a limited view of a package @i{P},
2543 then a name that denotes the @nt{package_renaming_declaration} shall occur
2544 only within the immediate scope of the renaming or the scope of a
2545 @nt{with_clause} that mentions the package @i{P} or, if @i{P} is a nested
2546 package, the innermost library package enclosing @i{P}.]}
2547 @begin{Discussion}
2548 @ChgRef{Version=[2],Kind=[Added]}
2549 @ChgAdded{Version=[2],Text=[The use of a renaming that designates a limited
2550 view is restricted to locations where we know whether the view is limited
2551 or nonlimited (based on a @nt{with_clause}). We don't want to make an
2552 implicit limited view, as those are not transitive like a regular view.
2553 Implementations should be able to see all limited views needed based on the
2554 @nt{context_clause}.]}
2555 @end{Discussion}
2556 @end{Legality}
2557
2558 @begin{StaticSem}
2559 A @nt{package_renaming_declaration} declares a new view
2560 @Redundant{of the renamed package}.
2561
2562 @ChgRef{Version=[2],Kind=[Added],ARef=[AI95-00412-01]}
2563 @ChgAdded{Version=[2],Text=[@Redundant[At places where the declaration of the
2564 limited view of the renamed package is visible, a @nt{name} that denotes the
2565 @nt{package_renaming_declaration} denotes a limited view of the package (see
2566 @RefSecNum{Compilation Units - Library Units}).]]}
2567 @begin{TheProof}
2568 @ChgRef{Version=[2],Kind=[Added]}
2569 @ChgAdded{Version=[2],Text=[This rule is found in @RefSec{Visibility}.]}
2570 @end{TheProof}
2571 @end{StaticSem}
2572
2573 @begin{Examples}
2574 @leading@keepnext@i{Example of renaming a package:}
2575 @begin{Example}
2576 @key[package] TM @key[renames] Table_Manager;
2577 @end{Example}
2578 @end{Examples}
2579
2580 @begin{DiffWord95}
2581 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00217-06],ARef=[AI95-00412-01]}
2582 @ChgAdded{Version=[2],Text=[Uses of renamed limited views of packages can
2583 only be used within the scope of a with_clause for the renamed package.]}
2584 @end{DiffWord95}
2585
2586 @begin{Extend2005}
2587 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0183-1]}
2588 @ChgAdded{Version=[3],Text=[@Defn{extensions to Ada 2005}
2589 An optional @nt{aspect_specification} can be used in a
2590 @nt{package_renaming_declaration}.
2591 This is described in @RefSecNum{Aspect Specifications}.]}
2592 @end{Extend2005}
2593
2594
2595 @NotISORMNewPageVer{Version=[3]}@Comment{For printed version of Ada 2012 RM}
2596 @LabeledSubClause{Subprogram Renaming Declarations}
2597
2598 @begin{Intro}
2599 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0299-1]}
2600 A @nt{subprogram_renaming_declaration} can serve as the completion of
2601 a @nt{subprogram_declaration};
2602 @Defn{renaming-as-body}
2603 such a @nt{renaming_declaration} is called a @i{renaming-as-body}.
2604 @Defn{renaming-as-declaration}
2605 A @nt{subprogram_renaming_declaration} that is not a completion is
2606 called a @i{renaming-as-declaration}@Redundant[,
2607 and is used to rename a subprogram
2608 (possibly an enumeration literal) or an entry].
2609 @begin{Ramification}
2610 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0299-1]}
2611 A renaming-as-body is a declaration,
2612 as defined in @Chg{Version=[3],New=[Clause],Old=[Section]}
2613 @RefSecNum{Declarations and Types}.
2614 @end{Ramification}
2615 @end{Intro}
2616
2617 @begin{Syntax}
2618 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00218-03]}
2619 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0183-1]}
2620 @Syn{lhs=<subprogram_renaming_declaration>,rhs="@Chg{Version=[2],New=<
2621 [@Syn2{overriding_indicator}]
2622 >,Old=<>}@Syn2{subprogram_specification} @key{renames} @SynI{callable_entity_}@Syn2{name}@Chg{Version=[3],New=<
2623 [@Syn2{aspect_specification}]>,Old=[]};"}
2624 @end{Syntax}
2625
2626 @begin{Resolution}
2627 @PDefn2{Term=[expected profile],
2628 Sec=(subprogram_renaming_declaration)}
2629 The expected profile for the @i(callable_entity_)@nt<name>
2630 is the profile given in the @nt<subprogram_specification>.
2631 @end{Resolution}
2632
2633 @begin{Legality}
2634 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0239-1]}
2635 @ChgRef{Version=[5],Kind=[Revised],ARef=[AI12-0373-1]}
2636 The profile of a renaming-as-declaration shall
2637 be @Chg{Version=[3],New=[mode conformant@Chg{Version=[5],New=[],Old=[,]}],Old=[mode-conformant]}
2638 with that of the renamed callable entity.
2639 @Defn2{Term=[mode conformance],Sec=(required)}
2640
2641 @ChgRef{Version=[2],Kind=[Added],ARef=[AI95-00423-01]}
2642 @ChgAdded{Version=[2],Type=[Leading],Text=[For a parameter or result subtype of
2643 the @nt{subprogram_specification} that has an explicit @nt{null_exclusion}:]}
2644
2645 @begin{Itemize}
2646 @ChgRef{Version=[2],Kind=[Added]}
2647 @ChgRef{Version=[5],Kind=[RevisedAdded],ARef=[AI12-0287-1]}
2648 @ChgAdded{Version=[2],Text=[if the @Syni{callable_entity_}@nt{name}
2649 @Chg{Version=[5],New=[statically ],Old=[]}denotes a generic formal subprogram
2650 of a generic unit @i{G}, and the @nt{subprogram_renaming_declaration} occurs
2651 within the body of a generic unit @i{G} or within the body of a generic unit
2652 declared within the declarative region of the generic unit @i{G}, then the
2653 corresponding parameter or result subtype of the formal subprogram of @i{G}
2654 shall have a @nt{null_exclusion};]}
2655
2656 @ChgRef{Version=[2],Kind=[Added]}
2657 @ChgAdded{Version=[2],Text=[otherwise, the subtype of the corresponding
2658 parameter or result type of the renamed callable entity shall exclude null.
2659 @PDefn{generic contract issue}
2660 In addition to the places where @LegalityTitle normally apply
2661 (see @RefSecNum{Generic Instantiation}),
2662 this rule applies also in the private part of an
2663 instance of a generic unit.]}
2664 @end{Itemize}
2665
2666 @begin{Reason}
2667 @ChgRef{Version=[2],Kind=[AddedNormal]}
2668 @ChgAdded{Version=[2],Type=[Leading],Text=[This rule prevents
2669 @lquotes@;lying@rquotes.
2670 @b<Null> must never be the value of a parameter or result with an explicit
2671 @nt{null_exclusion}. The first bullet is an assume-the-worst rule
2672 which prevents trouble in generic bodies (including bodies of child
2673 units) when the formal subtype excludes null implicitly.]}
2674 @end{Reason}
2675
2676 @ChgRef{Version=[1],Kind=[Revised],Ref=[8652/0027],Ref=[8652/0028],ARef=[AI95-00135-01],ARef=[AI95-00145-01]}
2677 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0239-1]}
2678 The profile of a renaming-as-body
2679 @Chg{New=[],Old=[shall be subtype-conformant with that of the renamed
2680 callable entity, and ]}shall conform fully to that of the declaration it
2681 completes.
2682 @Defn2{Term=[full conformance],Sec=(required)}
2683 If the renaming-as-body completes that declaration
2684 before the subprogram it declares is frozen,
2685 @Chg{New=[the profile shall be @Chg{Version=[3],New=[mode conformant],Old=[mode-conformant]}
2686 @Defn2{Term=[mode conformance],Sec=(required)}with that of the renamed
2687 callable entity and ],Old=[]}the subprogram it declares
2688 takes its convention from the renamed subprogram;
2689 otherwise@Chg{New=[, the profile shall be @Chg{Version=[3],New=[subtype conformant],Old=[subtype-conformant]}
2690 with that of the
2691 renamed callable entity and],Old=[]} the convention of the renamed subprogram
2692 shall not be Intrinsic.
2693 @Defn2{Term=[subtype conformance],Sec=(required)}
2694 @Chg{New=[A renaming-as-body is illegal if the declaration occurs before the
2695 subprogram whose declaration it completes is frozen, and the renaming renames
2696 the subprogram itself, through one or more subprogram renaming declarations,
2697 none of whose subprograms has been frozen.],Old=[]}
2698 @begin{Reason}
2699 @ChgRef{Version=[1],Kind=[Revised]}
2700 The @Chg{New=[otherwise part of the second sentence],Old=[first part of the first sentence]}
2701 is to allow an implementation of a renaming-as-body
2702 as a single jump instruction to the target subprogram.
2703 Among other things, this prevents a subprogram from being completed with
2704 a renaming of an entry.
2705 (In most cases, the target of the jump can be filled in at link time.
2706 In some cases, such as a renaming of a name like "A(I).@key[all]", an indirect
2707 jump is needed. Note that the name is evaluated at renaming time, not at
2708 call time.)
2709
2710 @ChgRef{Version=[1],Kind=[Added],Ref=[8652/0028],ARef=[AI95-00145-01]}
2711 @Chg{New=[The first part of the second sentence is intended to allow
2712 renaming-as-body of predefined operators before the @nt{subprogram_declaration}
2713 is frozen. For some types (such as integer types), the parameter type for
2714 operators is the base type, and it would be very strange for@*
2715 @f{@ @ @ @key{function} Equal (A, B : @key{in} T) @key{return} Boolean;}@*
2716 @f{@ @ @ @key{function} Equal (A, B : @key{in} T) @key{return} Boolean @key{renames} "=";}@*
2717 to be illegal. (Note that predefined operators cannot be renamed this way
2718 after the @nt{subprogram_declaration} is frozen, as they have convention
2719 Intrinsic.)],Old=[]}
2720
2721 @ChgRef{Version=[1],Kind=[Revised]}
2722 The @Chg{New=[],Old=[second part of the ]}first sentence is
2723 the normal rule for completions of @nt{subprogram_declaration}s.
2724 @end{Reason}
2725 @begin{Ramification}
2726 An @nt{entry_declaration}, unlike a @nt{subprogram_declaration},
2727 cannot be completed with a @nt{renaming_@!declaration}.
2728 Nor can a @nt{generic_@!subprogram_@!declaration}.
2729
2730 The syntax rules prevent a protected subprogram declaration from being
2731 completed by a renaming.
2732 This is fortunate, because it allows us to avoid worrying about whether
2733 the implicit protected object parameter of a protected operation is
2734 involved in the conformance rules.
2735 @end{Ramification}
2736 @begin{Reason}
2737 @ChgRef{Version=[1],Kind=[Added],Ref=[8652/0027],ARef=[AI95-00135-01]}
2738 @ChgAdded{Version=[1],Text=[Circular renames before freezing is illegal, as the compiler
2739 would not be able to determine the convention of the subprogram. Other
2740 circular renames are handled below; see @BoundedTitle.]}
2741 @end{Reason}
2742
2743 @ChgRef{Version=[2],Kind=[Added],ARef=[AI95-00228-01]}
2744 @ChgAdded{Version=[2],Text=[The @Syni{callable_entity_}@nt{name} of a renaming
2745 shall not denote a subprogram that requires overriding
2746 (see @RefSecNum{Abstract Types and Subprograms}).]}
2747 @begin{Reason}
2748 @ChgRef{Version=[2],Kind=[Added],ARef=[AI95-00228-01]}
2749 @ChgAdded{Version=[2],Text=[Such a rename cannot be of the inherited subprogram
2750 (which requires overriding because it cannot be called),
2751 and thus cannot squirrel away a subprogram (see below). That would be
2752 confusing, so we make it illegal. The renaming is allowed after the
2753 overriding, as then the @nt{name} will denote the overriding subprogram,
2754 not the inherited one.]}
2755 @end{Reason}
2756
2757 @ChgRef{Version=[2],Kind=[Added],ARef=[AI95-00228-01]}
2758 @ChgAdded{Version=[2],Text=[The @Syni{callable_entity_}@nt{name} of a
2759 renaming-as-body shall not denote an abstract subprogram.]}
2760 @begin{Reason}
2761 @ChgRef{Version=[2],Kind=[Added],ARef=[AI95-00228-01]}
2762 @ChgAdded{Version=[2],Text=[Such a subprogram has no body, so it hardly
2763 can replace one in the program.]}
2764 @end{Reason}
2765
2766 @ChgRef{Version=[5],Kind=[Added],ARef=[AI12-0204-1]}
2767 @ChgAdded{Version=[5],Text=[If the @Syni{callable_entity_}@nt{name} of a
2768 renaming is a prefixed view, the prefix of that view shall denote an object
2769 for which renaming is allowed.]}
2770
2771 @begin{Reason}
2772 @ChgRef{Version=[5],Kind=[AddedNormal],ARef=[AI12-0204-1]}
2773 @ChgAdded{Version=[5],Text=[The prefix in such a case is essentially renamed
2774 and passed to any calls of the renamed subprogram. If the prefix isn't legal
2775 to rename, that doesn't make sense (and allowing it might end up passing a
2776 nonexistent object to some calls).]}
2777 @end{Reason}
2778
2779 A @nt{name} that denotes a formal parameter
2780 of the @nt{subprogram_specification}
2781 is not allowed within the @Syni{callable_entity_}@nt{name}.
2782 @begin{Reason}
2783 @leading@keepnext@;This is to prevent things like this:
2784 @begin{Example}
2785 @key[function] F(X : Integer) @key[return] Integer @key[renames] Table(X).@key[all];
2786 @end{Example}
2787
2788 @begin{WideAbove}
2789 @leading@;A similar rule in @RefSecNum{Subprogram Declarations}
2790 forbids things like this:
2791 @end{WideAbove}
2792 @begin{Example}
2793 @key[function] F(X : Integer; Y : Integer := X) @key[return] Integer;
2794 @end{Example}
2795 @end{Reason}
2796 @end{Legality}
2797
2798 @begin{StaticSem}
2799 A renaming-as-declaration
2800 declares a new view of the renamed entity.
2801 The profile of this new view takes its subtypes, parameter modes,
2802 and calling convention from the original profile of the
2803 callable entity, while taking the formal parameter
2804 @nt{name}s and @nt{default_expression}s from the profile given in the
2805 @nt{subprogram_renaming_declaration}.
2806 The new view is a function or procedure, never an entry.
2807 @begin{Honest}
2808 When renaming an entry as a procedure,
2809 the compile-time rules apply as if the new view is a procedure,
2810 but the run-time semantics of a call are that of an entry call.
2811 @end{Honest}
2812 @begin{Ramification}
2813 For example, it is illegal for the @nt{entry_call_statement} of a
2814 @nt{timed_entry_call} to call the new view.
2815 But what looks like a procedure call will do things like barrier
2816 waiting.
2817
2818 @ChgRef{Version=[1],Kind=[Added],Ref=[8652/0105],ARef=[AI95-00211-01]}
2819 @ChgRef{Version=[2],Kind=[RevisedAdded],ARef=[AI95-00228-01]}
2820 @ChgRef{Version=[3],Kind=[RevisedAdded],ARef=[AI05-0095-1]}
2821 @Chg{New=[All properties of the renamed entity are inherited by the new view
2822 unless otherwise stated by this International Standard. In particular, if the
2823 renamed entity is abstract@Chg{Version=[2],New=[],Old=[ or requires
2824 overriding (see @RefSecNum{Abstract Types and Subprograms})]}, the new view
2825 also is abstract@Chg{Version=[2],New=[.],Old=[ or requires overriding. (The
2826 renaming will often be illegal in these cases,
2827 as a renaming cannot be overridden.)]}],Old=[]}
2828 @ChgAdded{Version=[3],Text=[Similarly, if the renamed entity is not a program
2829 unit, then neither is the renaming. (Implicitly declared subprograms are not
2830 program units, see @RefSecNum{Separate Compilation}).]}
2831 @end{Ramification}
2832 @end{StaticSem}
2833
2834 @begin{RunTime}
2835 @ChgRef{Version=[1],Kind=[Added],Ref=[8652/0014],ARef=[AI95-00064-01]}
2836 @Chg{New=[For a call to a subprogram whose body is given as a renaming-as-body,
2837 the execution of the renaming-as-body is equivalent to the execution of a
2838 @nt{subprogram_body} that simply calls the renamed subprogram with its formal
2839 parameters as the actual parameters and, if it is a function, returns the
2840 value of the call.],Old=[]}
2841 @begin{Ramification}
2842 @ChgRef{Version=[1],Kind=[Added]}
2843 @ChgAdded{Version=[1],Text=[This implies that the subprogram completed by the
2844 renaming-as-body has its own elaboration check.]}
2845 @end{Ramification}
2846
2847 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0123-1]}
2848 For a call on a renaming of a dispatching subprogram that is overridden,
2849 if the overriding occurred before the renaming, then the body executed
2850 is that of the overriding declaration,
2851 even if the overriding declaration is not visible at the place of the renaming;
2852 otherwise, the inherited or predefined subprogram is
2853 called.@Chg{Version=[3],New=[ A corresponding rule applies to a call on a
2854 renaming of a predefined equality operator for an untagged record type.],Old=[]}
2855 @begin{Discussion}
2856 Note that whether or not the renaming is itself primitive has
2857 nothing to do with the renamed subprogram.
2858
2859 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0123-1]}
2860 Note that the above rule is only for tagged types@Chg{Version=[3],New=[ and
2861 equality of untagged record types],Old=[]}.
2862
2863 @leading@keepnext@;Consider the following example:
2864 @begin{Example}
2865 @key[package] P @key[is]
2866 @key[type] T @key[is] @key[tagged] @key[null] @key[record];
2867 @key[function] Predefined_Equal(X, Y : T) @key[return] Boolean @key[renames] "=";
2868 @key[private]
2869 @key[function] "="(X, Y : T) @key[return] Boolean; --@RI{ Override predefined "=".}
2870 @key[end] P;
2871
2872 @key[with] P; @key[use] P;
2873 @key[package] Q @key[is]
2874 @key[function] User_Defined_Equal(X, Y : T) @key[return] Boolean @key[renames] P."=";
2875 @key[end] Q;
2876 @end{Example}
2877
2878 A call on Predefined_Equal will execute the predefined equality operator
2879 of T, whereas a call on User_Defined_Equal will execute the body of the
2880 overriding declaration in the private part of P.
2881
2882 Thus a renaming allows one to squirrel away a copy of an inherited or
2883 predefined subprogram before later overriding it.@Defn{squirrel away}
2884 @end{Discussion}
2885 @end{RunTime}
2886
2887 @begin{Bounded}
2888 @ChgRef{Version=[1],Kind=[Added],Ref=[8652/0027],ARef=[AI95-00135-01]}
2889 @ChgAdded{Version=[1],Text=[If a subprogram directly or indirectly renames
2890 itself, then it is a bounded
2891 error to call that subprogram. Possible consequences are that Program_Error or
2892 Storage_Error is raised, or that the call results in infinite recursion.
2893 @Defn2{Term=[Program_Error],Sec=(raised by detection of a bounded error)}
2894 @Defn2{Term=[Storage_Error],Sec=(raised by detection of a bounded error)}]}
2895 @begin{Reason}
2896 @ChgRef{Version=[1],Kind=[Added],Ref=[8652/0027],ARef=[AI95-00135-01]}
2897 @ChgAdded{Version=[1],Text=[This has to be a bounded error, as it is possible
2898 for a renaming-as-body appearing in a package body to cause this problem.
2899 Thus it is not possible in general to detect this problem at compile time.]}
2900 @end{Reason}
2901 @end{Bounded}
2902
2903 @begin{Notes}
2904 A procedure can only be renamed as a procedure.
2905 A function whose @nt{defining_designator} is either an
2906 @nt{identifier} or an @nt{operator_symbol}
2907 can be renamed with either an
2908 @nt{identifier} or an @nt{operator_symbol};
2909 for renaming as an operator, the subprogram specification given in
2910 the @nt{renaming_declaration} is subject to the rules given in
2911 @RefSecNum{Overloading of Operators}
2912 for operator declarations. Enumeration literals can be
2913 renamed as functions; similarly, @nt{attribute_reference}s that
2914 denote functions (such as references to Succ and Pred) can be renamed
2915 as functions. An entry can only be renamed as a procedure; the new
2916 @nt{name} is only allowed to appear in contexts that allow a
2917 procedure @nt{name}. An entry of a family can be renamed, but an
2918 entry family cannot be renamed as a whole.
2919
2920
2921 The operators of the root numeric types cannot be renamed because the
2922 types in the profile are anonymous, so the corresponding specifications
2923 cannot be written; the same holds for certain attributes, such as Pos.
2924
2925
2926 @ChgRef{Version=[5],Kind=[Deleted],ARef=[AI12-0292-1]}
2927 @ChgDeleted{Version=[5],Text=[Calls with the new @nt{name} of
2928 a renamed entry are
2929 @nt{procedure_call_statement}s and are not allowed at places
2930 where the syntax requires an @nt{entry_call_statement} in
2931 @ntf{conditional_} and @nt{timed_entry_call}s,
2932 nor in an @nt{asynchronous_select}; similarly, the Count
2933 attribute is not available for the new @nt{name}.]}
2934
2935 The primitiveness of a renaming-as-declaration is determined by its
2936 profile, and by where it occurs, as for any declaration of
2937 (a view of) a subprogram;
2938 primitiveness is not determined by the renamed view.
2939 In order to perform a dispatching call,
2940 the subprogram name has to denote a primitive subprogram,
2941 not a nonprimitive renaming of a primitive subprogram.
2942 @begin{Reason}
2943 A @nt{subprogram_renaming_declaration} could more properly be called
2944 @ntf{renaming_@!as_@!subprogram_@!declaration}, since you're renaming something
2945 as a subprogram, but you're not necessarily renaming a subprogram.
2946 But that's too much of a mouthful. Or, alternatively, we could call it a
2947 @ntf{callable_@!entity_@!renaming_@!declaration}, but that's even worse.
2948 Not only is it a mouthful, it emphasizes the entity being renamed,
2949 rather than the new view, which we think is a bad idea.
2950 We'll live with the oddity.
2951 @end{Reason}
2952 @end{Notes}
2953
2954 @begin{Examples}
2955 @leading@keepnext@i{Examples of subprogram renaming declarations:}
2956 @begin{Example}
2957 @key[procedure] My_Write(C : @key[in] Character) @key[renames] Pool(K).Write; --@RI{ see @RefSecNum{Selected Components}}
2958
2959 @key[function] Real_Plus(Left, Right : Real ) @key[return] Real @key[renames] "+";
2960 @key[function] Int_Plus (Left, Right : Integer) @key[return] Integer @key[renames] "+";
2961
2962 @key[function] Rouge @key[return] Color @key[renames] Red; --@RI{ see @RefSecNum{Enumeration Types}}
2963 @key[function] Rot @key[return] Color @key[renames] Red;
2964 @key[function] Rosso @key[return] Color @key[renames] Rouge;
2965
2966 @key[function] Next(X : Color) @key[return] Color @key[renames] Color'Succ; --@RI{ see @RefSecNum{Enumeration Types}}
2967 @end{Example}
2968
2969 @begin{WideAbove}
2970 @leading@keepnext@i{Example of a subprogram renaming declaration with new parameter names:}
2971 @end{WideAbove}
2972 @begin{Example}
2973 @key[function] "*" (X,Y : Vector) @key[return] Real @key[renames] Dot_Product; --@RI{ see @RefSecNum{Subprogram Declarations}}
2974 @end{Example}
2975
2976 @begin{WideAbove}
2977 @leading@keepnext@i{Example of a subprogram renaming declaration with a new default expression:}
2978 @end{WideAbove}
2979 @begin{Example}
2980 @key[function] Minimum(L : Link := Head) @key[return] Cell @key[renames] Min_Cell; --@RI{ see @RefSecNum{Subprogram Declarations}}
2981 @end{Example}
2982 @end{Examples}
2983
2984 @begin{Extend95}
2985 @ChgRef{Version=[2],Kind=[AddedNormal],Ref=[8652/0028],ARef=[AI95-00145-01]}
2986 @ChgAdded{Version=[2],Text=[@Defn{extensions to Ada 95}
2987 @b<Corrigendum:> Allowed a renaming-as-body to be just
2988 mode conformant with the specification if the subprogram is not yet frozen.]}
2989
2990 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00218-03]}
2991 @ChgAdded{Version=[2],Text=[@nt{Overriding_indicator} (see
2992 @RefSecNum{Overriding Indicators}) is
2993 optionally added to subprogram renamings.]}
2994 @end{Extend95}
2995
2996 @begin{DiffWord95}
2997 @ChgRef{Version=[2],Kind=[AddedNormal],Ref=[8652/0014],ARef=[AI95-00064-01]}
2998 @ChgAdded{Version=[2],Text=[@b<Corrigendum:> Described the semantics of
2999 renaming-as-body, so that the location of elaboration checks is clear.]}
3000
3001 @ChgRef{Version=[2],Kind=[AddedNormal],Ref=[8652/0027],ARef=[AI95-00135-01]}
3002 @ChgAdded{Version=[2],Text=[@b<Corrigendum:> Clarified that circular
3003 renaming-as-body is illegal (if it can be detected in time) or a
3004 bounded error.]}
3005
3006 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00228-01]}
3007 @ChgAdded{Version=[2],Text=[@B[Amendment Correction:] Clarified that
3008 renaming a shall-be-overridden
3009 subprogram is illegal, as well as renaming-as-body an abstract subprogram.]}
3010
3011 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00423-01]}
3012 @ChgAdded{Version=[2],Text=[Added matching rules for @nt{null_exclusion}s.]}
3013 @end{DiffWord95}
3014
3015 @begin{Inconsistent2005}
3016 @ChgRef{Version=[3],Kind=[Added],ARef=[AI05-0123-1]}
3017 @ChgAdded{Version=[3],Text=[@Defn{inconsistencies with Ada 2005}
3018 Renaming of user-defined untagged record equality is now defined to call the
3019 overridden body so long as the overriding occurred before the renames.
3020 This could change the body called in unusual cases; the change is necessary
3021 to preserve the principle that the body called for an explicit call to
3022 "=" (via a renames in this case) is the same as the one inherited for a
3023 derived type and used in generics. Note that any renamings before the
3024 overriding will be unchanged. Any differences caused by the change will be
3025 rare and most likely will fix a bug.]}
3026 @end{Inconsistent2005}
3027
3028 @begin{Extend2005}
3029 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0183-1]}
3030 @ChgAdded{Version=[3],Text=[@Defn{extensions to Ada 2005}
3031 An optional @nt{aspect_specification} can be used in a
3032 @nt{subprogram_renaming_declaration}.
3033 This is described in @RefSecNum{Aspect Specifications}.]}
3034 @end{Extend2005}
3035
3036 @begin{Incompatible2012}
3037 @ChgRef{Version=[5],Kind=[AddedNormal],ARef=[AI12-0204-1]}
3038 @ChgAdded{Version=[5],Text=[@Defn{incompatibilities with Ada 2012}@b<Correction:>
3039 Added a rule to ensure that the prefix of a renaming of a prefixed view
3040 continues to exist during the life of a renames. If the prefix is a
3041 subcomponent that depends on discriminants, Ada 2005 and 2012
3042 would have allowed the prefix while Ada 202x would not. Without this change,
3043 explicit forms (renaming the object and then using that in calls) would be
3044 safer than the renaming; that's inconsistent with other kinds of renaming.]}
3045 @end{Incompatible2012}
3046
3047 @begin{DiffWord2012}
3048 @ChgRef{Version=[5],Kind=[AddedNormal],ARef=[AI12-0287-1]}
3049 @ChgAdded{Version=[5],Text=[@b<Correction:> Added wording to ensure that
3050 the object subject to a @LegalityName can be determined at compile-time.
3051 The alternative being nonsense, we treat this as a wording change.]}
3052 @end{DiffWord2012}
3053
3054
3055 @ISOOnlyRMNewPageVer{Version=[3]}@Comment{For ISO version of Ada 2012 Standard}
3056 @LabeledSubClause{Generic Renaming Declarations}
3057
3058 @begin{Intro}
3059 @redundant[A @nt{generic_renaming_declaration} is used to rename a generic unit.]
3060 @end{Intro}
3061
3062 @begin{Syntax}
3063 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0183-1]}
3064 @Syn{tabs=[P22], lhs=<generic_renaming_declaration>,rhs="
3065 @key{generic package}@\@Syn2{defining_program_unit_name} @key{renames} @SynI{generic_package_}@Syn2{name}@Chg{Version=[3],New=<
3066 [@Syn2{aspect_specification}]>,Old=[]};
3067 | @key{generic procedure}@\@Syn2{defining_program_unit_name} @key{renames} @SynI{generic_procedure_}@Syn2{name}@Chg{Version=[3],New=<
3068 [@Syn2{aspect_specification}]>,Old=[]};
3069 | @key{generic function}@\@Syn2{defining_program_unit_name} @key{renames} @SynI{generic_function_}@Syn2{name}@Chg{Version=[3],New=<
3070 [@Syn2{aspect_specification}]>,Old=[]};"}
3071 @end{Syntax}
3072
3073 @begin{Legality}
3074 The renamed entity shall be a generic unit of the corresponding kind.
3075 @end{Legality}
3076
3077 @begin{StaticSem}
3078 A @nt{generic_renaming_declaration} declares a new view
3079 @Redundant{of the renamed generic unit}.
3080 @end{StaticSem}
3081
3082 @begin{Notes}
3083 Although the properties of the new view are the same as those of the
3084 renamed view, the place where the @nt<generic_renaming_declaration> occurs
3085 may affect the legality of subsequent renamings and instantiations
3086 that denote the @nt<generic_renaming_declaration>,
3087 in particular if the renamed generic unit is a library unit
3088 (see @RefSecNum{Compilation Units - Library Units}).
3089 @end{Notes}
3090
3091 @begin{Examples}
3092 @leading@keepnext@i{Example of renaming a generic unit:}
3093 @begin{Example}
3094 @key[generic package] Enum_IO @key[renames] Ada.Text_IO.Enumeration_IO; @RI{-- see @RefSecNum{Input-Output for Enumeration Types}}
3095 @end{Example}
3096 @end{Examples}
3097
3098 @begin{Extend83}
3099 @Defn{extensions to Ada 83}
3100 Renaming of generic units is new to Ada 95.
3101 It is particularly important for renaming child library
3102 units that are generic units. For example, it might
3103 be used to rename Numerics.Generic_Elementary_Functions as simply
3104 Generic_Elementary_Functions, to match the name for
3105 the corresponding Ada-83-based package.
3106 @end{Extend83}
3107
3108 @begin{DiffWord83}
3109 The information in RM83-8.6, @lquotes@;The Package Standard,@rquotes@;
3110 has been updated for the child unit feature,
3111 and moved to @RefSecNum{Predefined Language Environment},
3112 except for the definition of @lquotes@;predefined type,@rquotes@;
3113 which has been moved to @RefSecNum{Type Declarations}.
3114 @end{DiffWord83}
3115
3116 @begin{Extend2005}
3117 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0183-1]}
3118 @ChgAdded{Version=[3],Text=[@Defn{extensions to Ada 2005}
3119 An optional @nt{aspect_specification} can be used in a
3120 @nt{generic_renaming_declaration}.
3121 This is described in @RefSecNum{Aspect Specifications}.]}
3122 @end{Extend2005}
3123
3124
3125 @LabeledClause{The Context of Overload Resolution}
3126
3127 @begin{Intro}
3128 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0299-1]}
3129 @redundant[@Defn{overload resolution}
3130 Because declarations can be overloaded,
3131 it is possible for an occurrence of a usage name
3132 to have more than one possible interpretation;
3133 in most cases, ambiguity is disallowed.
3134 This @Chg{Version=[3],New=[subclause],Old=[clause]} describes
3135 how the possible interpretations resolve
3136 to the actual interpretation.
3137
3138 @Defn{overloading rules}
3139 Certain rules of the language (the @ResolutionTitle)
3140 are considered @lquotes@;overloading rules@rquotes@;.
3141 If a possible interpretation violates an overloading rule,
3142 it is assumed not to be the intended interpretation;
3143 some other possible interpretation
3144 is assumed to be the actual interpretation.
3145 On the other hand,
3146 violations of nonoverloading rules do not affect which
3147 interpretation is chosen; instead,
3148 they cause the construct to be illegal.
3149 To be legal, there usually has to be exactly one acceptable
3150 interpretation of a construct that is a @lquotes@;complete context@rquotes@;,
3151 not counting any nested complete contexts.
3152
3153 @Defn2{Term=[grammar],Sec=(resolution of ambiguity)}
3154 The syntax rules of the language and the visibility rules
3155 given in @RefSecNum{Visibility}
3156 determine the possible interpretations.
3157 Most type checking rules
3158 (rules that require a particular type,
3159 or a particular class of types,
3160 for example)
3161 are overloading rules.
3162 Various rules for the matching of formal and actual parameters are
3163 overloading rules.]
3164 @end{Intro}
3165
3166 @begin{MetaRules}
3167 The type resolution rules are
3168 intended to minimize the need for implicit declarations
3169 and preference rules associated with implicit conversion and dispatching
3170 operations.
3171 @end{MetaRules}
3172
3173 @begin{Resolution}
3174 @leading@Defn{complete context}
3175 @Redundant{Overload resolution is applied separately to each
3176 @i{complete context},
3177 not counting inner complete contexts.}
3178 Each of the following constructs is a @i{complete context}:
3179 @begin{itemize}
3180 A @nt{context_item}.
3181
3182 A @nt{declarative_item} or declaration.
3183 @begin{Ramification}
3184 A @nt{loop_parameter_specification} is a declaration,
3185 and hence a complete context.
3186 @end{Ramification}
3187
3188 A @nt{statement}.
3189
3190 A @nt{pragma_argument_association}.
3191 @begin{Reason}
3192 We would make it the whole @nt{pragma},
3193 except that certain pragma arguments are allowed to be ambiguous,
3194 and ambiguity applies to a complete context.
3195 @end{Reason}
3196
3197 @ChgRef{Version=[4],Kind=[Revised],ARef=[AI12-0040-1]}
3198 The @Chg{Version=[4],New=[@SynI[selecting_]@nt{expression}],Old=[@nt{expression}]}
3199 of a @nt{case_statement}@Chg{Version=[4],New=[ or @nt{case_expression}],Old=[]}.
3200 @begin{Ramification}
3201 This means that the @nt{expression} is resolved without looking
3202 at the choices.
3203 @end{Ramification}
3204
3205 @ChgRef{Version=[5],Kind=[Added],ARef=[AI12-0125-3]}
3206 @ChgAdded{Version=[5],Text=[The @SynI<variable_>@nt{name} of an
3207 @nt{assignment_statement} @i<A>, if
3208 the @nt{expression} of @i<A> contains one or more @nt{target_name}s.]}
3209 @end{itemize}
3210
3211 @leading@Defn2{Term=[interpretation], Sec=(of a complete context)}
3212 @Defn2{Term=[overall interpretation], Sec=(of a complete context)}
3213 An (overall) @i{interpretation} of a complete context
3214 embodies its meaning, and includes
3215 the following information about the constituents of the complete
3216 context,
3217 not including constituents of inner complete contexts:
3218 @begin{Itemize}
3219 for each constituent of the complete context,
3220 to which syntactic categories it belongs,
3221 and by which syntax rules; and
3222 @begin{Ramification}
3223 Syntactic categor@i{ies} is plural here,
3224 because there are lots of trivial productions @em
3225 an @nt{expression} might also be all of the following,
3226 in this order: @nt{identifier},
3227 @nt{name},
3228 @nt{primary},
3229 @nt{factor},
3230 @nt{term},
3231 @nt{simple_expression}, and
3232 @nt{relation}.
3233 Basically, we're trying to capture all the information in the parse tree
3234 here, without using compiler-writer's jargon like @lquotes@;parse tree@rquotes@;.
3235 @end{Ramification}
3236
3237 for each usage name, which declaration it denotes
3238 (and, therefore, which view and which entity it denotes); and
3239 @begin{Ramification}
3240 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00382-01]}
3241 In most cases, a usage name denotes the view declared by the denoted
3242 declaration.
3243 However, in certain cases, a usage name that denotes a declaration and
3244 appears inside the declarative region of that same declaration, denotes
3245 the current instance of the declaration.
3246 For example, within a @nt{task_body}@Chg{Version=[2],New=[ other than in
3247 an @nt{access_definition}],Old=[]}, a usage name that denotes the
3248 @nt{task_type_declaration} denotes the object containing the
3249 currently executing task,
3250 and not the task type declared by the declaration.
3251 @end{Ramification}
3252
3253 for a complete context that is a @nt{declarative_item},
3254 whether or not it is a completion of a declaration,
3255 and (if so) which declaration it completes.
3256 @end{Itemize}
3257 @begin{Ramification}
3258 Unfortunately, we are not confident that the above list is complete.
3259 We'll have to live with that.
3260 @end{Ramification}
3261 @begin{Honest}
3262 For @lquotes@;possible@rquotes@; interpretations, the above information is tentative.
3263 @end{Honest}
3264 @begin{Discussion}
3265 A possible interpretation (an @i{input} to overload
3266 resolution) contains information about what a
3267 usage name @i{might} denote, but what it actually @i{does} denote
3268 requires overload resolution to determine.
3269 Hence the term @lquotes@;tentative@rquotes@; is needed for possible interpretations;
3270 otherwise, the definition would be circular.
3271 @end{Discussion}
3272
3273 @Defn{possible interpretation}
3274 A @i{possible interpretation} is one
3275 that obeys the syntax rules and the visibility rules.
3276 @Defn{acceptable interpretation}
3277 @Defn2{Term=[resolve],Sec=(overload resolution)}
3278 @Defn2{Term=[interpretation],Sec=(overload resolution)}
3279 An @i{acceptable interpretation} is a possible interpretation that
3280 obeys the @i{overloading rules}@Redundant{,
3281 that is, those rules that specify an expected type or
3282 expected profile, or specify how a construct shall @i(resolve)
3283 or be @i(interpreted).}
3284 @begin{Honest}
3285 One rule that falls into this category,
3286 but does not use the above-mentioned magic words,
3287 is the rule about numbers of parameter associations in a call
3288 (see @RefSecNum{Subprogram Calls}).
3289 @end{Honest}
3290 @begin{Ramification}
3291 The @ResolutionName@;s are the ones that appear under the
3292 @ResolutionTitle heading.
3293 Some @SyntaxName@;s are written in English, instead of BNF.
3294 No rule is a @SyntaxName or @ResolutionName unless it appears under the
3295 appropriate heading.
3296 @end{Ramification}
3297
3298 @Defn2{Term=[interpretation], Sec=(of a constituent of a complete context)}
3299 The @i{interpretation} of a constituent of a complete context is
3300 determined from the overall interpretation of the complete context as a
3301 whole.
3302 @Redundant{Thus,
3303 for example, @lquotes@;interpreted as a @nt{function_call},@rquotes@;
3304 means that the construct's interpretation says that it belongs
3305 to the syntactic category @nt{function_call}.}
3306
3307 @leading@Defn{denote}
3308 @Redundant[Each occurrence of]
3309 a usage name @i{denotes} the declaration determined by its
3310 interpretation.
3311 It also denotes the view declared by its denoted
3312 declaration, except in the following cases:
3313 @begin{Ramification}
3314 As explained below, a pragma argument is allowed to be ambiguous,
3315 so it can denote several declarations,
3316 and all of the views declared by those declarations.
3317 @end{Ramification}
3318 @begin(itemize)
3319 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00382-01]}
3320 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0287-1]}
3321 @Defn2{Term=[current instance], Sec=(of a type)}
3322 If a usage name appears within the declarative region of a
3323 @nt{type_declaration} and denotes that same @nt{type_declaration},
3324 then it denotes the @i{current instance} of the type (rather than
3325 the type itself)@Chg{Version=[2],New=[; the],Old=[. The]} current
3326 instance of a type is the object or value
3327 of the type that is associated with the execution that
3328 evaluates the usage name.@Chg{Version=[2],New=[ @Chg{Version=[3],
3329 New=[ Similarly, if a usage name appears within the declarative region
3330 of a @nt{subtype_declaration} and denotes that same @nt{subtype_declaration},
3331 then it denotes the current instance of the subtype. These rules do],
3332 Old=[This rule does]} not apply if the usage name appears within the @nt{subtype_mark} of an
3333 @nt{access_definition} for an access-to-object type, or within the subtype
3334 of a parameter or result of an access-to-subprogram type.],Old=[]}
3335 @begin{Reason}
3336 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00382-01]}
3337 This is needed, for example, for references to the Access attribute
3338 from within the @nt{type_declaration}.
3339 Also, within a @nt{task_body} or @nt{protected_body},
3340 we need to be able to denote the current task or protected object.
3341 (For a @nt{single_task_declaration} or
3342 @nt{single_protected_declaration}, the rule about current instances
3343 is not needed.)@Chg{Version=[2],New=[ We exclude anonymous access types
3344 so that they can be used to create self-referencing types in the natural
3345 manner (otherwise such types would be illegal).],Old=[]}
3346 @end{Reason}
3347 @begin{Discussion}
3348 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00382-01]}
3349 @ChgAdded{Version=[2],Text=[The phrase @lquotes@;within the @nt{subtype_mark}@rquotes@;
3350 in the @lquotes@;this rule does not apply@rquotes@; part is intended to cover
3351 a case like @key{access} T'Class appearing within the declarative region of
3352 T: here T denotes the type, not the current instance.]}
3353 @end{Discussion}
3354
3355 @ChgRef{Version=[4],Kind=[Added],ARef=[AI12-0068-1]}
3356 @ChgRef{Version=[5],Kind=[Revised],ARef=[AI12-0324-1]}
3357 @ChgAdded{Version=[4],NoPrefix=[T],Text=[Within an @nt{aspect_specification}
3358 for a type or subtype, the current instance represents a value of the type;
3359 it is not an object. The nominal subtype of this value is given by the
3360 subtype itself (the first subtype in the case of a @nt{type_declaration}),
3361 prior to applying any predicate specified directly on the type or subtype. If
3362 the type or subtype is by-reference, the associated object
3363 @Chg{Version=[5],New=[of],Old=[with]} the value is the object associated (see
3364 @RefSecNum{Formal Parameter Modes}) with the
3365 @Chg{Version=[5],New=[evaluation],Old=[execution]} of the usage name.]}
3366
3367 @begin{Ramification}
3368 @ChgRef{Version=[4],Kind=[AddedNormal]}
3369 @ChgAdded{Version=[4],Text=[For the purposes of @LegalityTitle, the current
3370 instance acts as a value within an @nt{aspect_specification}. It might
3371 really be an object (and has to be for a by-reference type), but
3372 that isn't discoverable by direct use of the name of the current instance.]}
3373 @end{Ramification}
3374
3375 @Defn2{Term=[current instance], Sec=(of a generic unit)}
3376 If a usage name appears within the declarative region of a
3377 @nt{generic_declaration} (but not within its @nt{generic_formal_part})
3378 and it denotes that same @nt{generic_declaration}, then it
3379 denotes the @i{current instance} of the generic unit (rather than
3380 the generic unit itself).
3381 See also @RefSecNum{Generic Instantiation}.
3382 @begin{Honest}
3383 The current instance of a generic unit is the instance created
3384 by whichever @nt{generic_instantiation} is of interest at any
3385 given time.
3386 @end{Honest}
3387 @begin{Ramification}
3388 Within a @nt{generic_formal_part}, a @nt{name} that denotes the
3389 @nt{generic_declaration} denotes the generic unit,
3390 which implies that it is not overloadable.
3391 @end{Ramification}
3392 @end(itemize)
3393
3394 A usage name that denotes a view also denotes the entity of that view.
3395 @begin{Ramification}
3396 Usually, a usage name denotes only one declaration,
3397 and therefore one view and one entity.
3398 @end{Ramification}
3399
3400 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00231-01]}
3401 @leading@RootDefn[expected type]
3402 The @i(expected type) for a given @nt<expression>, @nt<name>,
3403 or other construct determines, according to the @i{type resolution
3404 rules} given below, the types considered for the construct during
3405 overload resolution.
3406 @Defn{type resolution rules}
3407 @Redundant[
3408 The type resolution rules provide support for class-wide programming,
3409 universal @Chg{Version=[2],New=[],Old=[numeric ]}literals, dispatching
3410 operations, and anonymous access types:]
3411 @begin{Ramification}
3412 Expected types are defined throughout the RM95.
3413 The most important definition is that, for a
3414 subprogram, the expected type for the
3415 actual parameter is the type of the formal parameter.
3416
3417 The type resolution rules are trivial unless either the
3418 actual or expected type is universal, class-wide, or of
3419 an anonymous access type.
3420 @end{Ramification}
3421 @begin{Itemize}
3422 @PDefn2{Term=[type resolution rules],
3423 Sec=(if any type in a specified class of types is expected)}
3424 @PDefn2{Term=[type resolution rules],
3425 Sec=(if expected type is universal or class-wide)}
3426 If a construct is expected to be of any type in a class of types,
3427 or of the universal or class-wide type for a class,
3428 then the type of the construct shall resolve to a type in that class
3429 or to a universal type that covers the class.
3430 @begin{Ramification}
3431 This matching rule handles (among other things) cases like the
3432 Val attribute, which denotes a function that takes a parameter of type
3433 @i(universal_integer).
3434
3435 @ChgRef{Version=[1],Kind=[Revised]}@ChgNote{Presentation AI-00021 - Quoted text doesn't match}
3436 The last part of the rule,
3437 @lquotes@;or to a universal type that @Chg{New=[covers],Old=[includes]} the
3438 class@rquotes implies that if the expected type for an expression is
3439 @i{universal_fixed}, then an expression whose type is @i{universal_real}
3440 (such as a real literal) is OK.
3441 @end{Ramification}
3442
3443 @leading@PDefn2{Term=[type resolution rules],
3444 Sec=(if expected type is specific)}
3445 If the expected type for a construct is a specific type @i(T), then the type
3446 of the construct shall resolve either to @i(T), or:
3447 @begin{Ramification}
3448 @PDefn{Beaujolais effect}
3449 This rule is @i{not} intended to create a preference for the specific
3450 type @em such a preference would cause Beaujolais effects.
3451 @end{Ramification}
3452 @begin(Inneritemize)
3453 to @i(T)'Class; or
3454 @begin{Ramification}
3455 This will only be legal as part of a call on a dispatching operation;
3456 see @RefSec(Dispatching Operations of Tagged Types).
3457 Note that that rule is not a @ResolutionName.
3458 @end{Ramification}
3459
3460 to a universal type that covers @i(T); or
3461
3462 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00230-01],ARef=[AI95-00231-01],ARef=[AI95-00254-01],ARef=[AI95-00409-01]}
3463 when @i(T) is @Chg{Version=[2],New=[a specific],Old=[an]} anonymous
3464 access@Chg{Version=[2],New=[-to-object],Old=[]} type
3465 (see @RefSecNum{Access Types}) with designated type @i(D),
3466 to an access-to-@Chg{Version=[2],New=[object],Old=[variable]} type
3467 whose designated type is @i(D)'Class or is covered by
3468 @i(D)@Chg{Version=[2],New=[; or],Old=[.]}
3469
3470 @begin{Ramification}
3471 @ChgRef{Version=[2],Kind=[Deleted],ARef=[AI95-00409-01]}
3472 @ChgNote{We use Chg here, rather than ChgDeleted so that the prefix is
3473 left behind.}@Chg{Version=[2],New=[],Old=[Because it says @lquotes@;access-to-variable@rquotes@;
3474 instead of @lquotes@;access-to-object,@rquotes@;
3475 two subprograms that differ only in that one has a parameter
3476 of an access-to-constant type,
3477 and the other has an
3478 access parameter,
3479 are distinguishable during overload resolution.]}
3480
3481 The case where the actual is access-to-@i(D)'Class will only
3482 be legal as part of a call on a dispatching operation;
3483 see @RefSec(Dispatching Operations of Tagged Types).
3484 Note that that rule is not a @ResolutionName.
3485 @end{Ramification}
3486
3487 @ChgRef{Version=[3],Kind=[Added],ARef=[AI05-0149-1]}
3488 @ChgAdded{Version=[3],Text=[when @i(T) is a named general access-to-object type
3489 (see @RefSecNum{Access Types}) with designated type @i(D), to an anonymous
3490 access-to-object type whose designated type covers or is covered by @i(D);
3491 or]}
3492
3493 @ChgRef{Version=[2],Kind=[Added],ARef=[AI95-00254-01],ARef=[AI95-00409-01]}
3494 @ChgRef{Version=[3],Kind=[RevisedAdded],ARef=[AI05-0239-1]}
3495 @ChgAdded{Version=[2],Text=[when @i(T) is an anonymous access-to-subprogram
3496 type (see @RefSecNum{Access Types}), to an access-to-subprogram type
3497 whose designated profile is @Chg{Version=[3],New=[type conformant],Old=[type-conformant]} with that of @i{T}.]}
3498
3499 @end(Inneritemize)
3500 @end{Itemize}
3501
3502
3503 @RootDefn[expected profile]
3504 In certain contexts,
3505 @Redundant[such as in a @nt{subprogram_renaming_declaration},]
3506 the @ResolutionTitle define an @i(expected profile) for a given
3507 @nt<name>;
3508 @Defn2{Term=[profile resolution rule],
3509 Sec=(@nt<name> with a given expected profile)}
3510 in such cases, the @nt{name}
3511 shall resolve to the name of a callable entity whose profile is type
3512 conformant with the expected profile.
3513 @Defn2{Term=[type conformance],Sec=(required)}
3514 @begin{Ramification}
3515 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0239-1]}
3516 The parameter and result @i{sub}types are not used in overload
3517 resolution.
3518 Only type conformance of profiles
3519 is considered during overload resolution.
3520 Legality rules generally require at least @Chg{Version=[3],New=[mode conformance],Old=[mode-conformance]}
3521 in addition, but those rules are not used in overload resolution.
3522 @end{Ramification}
3523 @end{Resolution}
3524
3525 @begin{Legality}
3526 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00332-01]}
3527 @Defn2{Term=[single], Sec=[class expected type]}
3528 When @Chg{Version=[2],New=[],Old=[the expected type for ]}a construct is
3529 @Chg{Version=[2],New=[one that requires that its expected type],
3530 Old=[required to]}
3531 be a @i<single> type in a given class, the type
3532 @Chg{Version=[2],New=[of],Old=[expected for]}
3533 the construct shall be determinable solely
3534 from the context in which the construct appears,
3535 excluding the construct itself,
3536 but using the requirement that it be in the given class@Chg{Version=[2],
3537 New=[],Old=[; the type of the construct is then this single expected type]}.
3538 Furthermore, the context shall not be one that expects any type in
3539 some class that contains types of the given class;
3540 in particular, the construct shall not be the operand of a
3541 @nt{type_conversion}.
3542
3543 @begin{Ramification}
3544 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00230-01]}@ChgNote{Null no longer requires a single type}
3545 For example, the expected type for @Chg{Version=[2],New=[a string literal],
3546 Old=[the literal @key{null}]} is required to be a
3547 single @Chg{Version=[2],New=[string],Old=[access]} type.
3548 But the expected type for the operand of a @nt{type_conversion} is
3549 any type.
3550 Therefore, @Chg{Version=[2],New=[a string literal],
3551 Old=[the literal @key{null}]} is not allowed as the operand of a
3552 @nt{type_conversion}.
3553 This is true even if there is only one @Chg{Version=[2],New=[string],
3554 Old=[access]} type in scope@Chg{Version=[2],New=[ (which is never the
3555 case)],Old=[]}.
3556 The reason for these rules is so that the compiler will not have to
3557 search @lquotes@;everywhere@rquotes@; to see if there is exactly one type
3558 in a class in scope.
3559 @end{Ramification}
3560 @begin{Discussion}
3561 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00332-01]}
3562 @ChgAdded{Version=[2],Text=[The first sentence is carefully worded so that it
3563 only mentions @lquotes@;expected type@rquotes as part of identifying the
3564 interesting case, but doesn't require that the context actually provide such
3565 an expected type. This allows such constructs to be used inside of constructs
3566 that don't provide an expected type (like qualified expressions and renames).
3567 Otherwise, such constructs wouldn't allow @nt{aggregate}s, 'Access, and so
3568 on.]}
3569 @end{Discussion}
3570
3571 @ChgRef{Version=[3],Kind=[Added],ARef=[AI05-0102-1],ARef=[AI05-0149-1],ARef=[AI05-0299-1]}
3572 @ChgRef{Version=[4],Kind=[RevisedAdded],ARef=[AI12-0039-1]}
3573 @ChgAdded{Version=[3],Text=[Other than for the
3574 @Chg{Version=[4],New=[@SynI{tested_}@nt{simple_expression}],Old=[@nt{simple_expression}]}
3575 of a membership test, if the expected type for a @nt{name} or @nt{expression}
3576 is not the same as the actual type of the @nt{name} or @nt{expression}, the
3577 actual type shall be convertible to the expected type (see
3578 @RefSecNum{Type Conversions});@Defn2{Term=[implicit conversion],
3579 Sec=[legality]}@PDefn2{Term=[convertible],Sec=(required)} further, if the
3580 expected type is a named access-to-object type with designated type @i<D1> and
3581 the actual type is an anonymous access-to-object type with designated type
3582 @i<D2>, then @i<D1> shall cover @i<D2>, and the @nt{name} or @nt{expression}
3583 shall denote a view with an accessibility level for which the statically deeper
3584 relationship applies@Redundant[; in particular it shall not denote an access
3585 parameter nor a stand-alone access object].]}
3586
3587 @begin{Reason}
3588 @ChgRef{Version=[3],Kind=[AddedNormal]}
3589 @ChgAdded{Version=[3],Text=[This rule prevents an implicit conversion that
3590 would be illegal if it was an explicit conversion. For instance, this
3591 prevents assigning an access-to-constant value into a stand-alone anonymous
3592 access-to-variable object. It also covers convertibility of the designated
3593 type and accessibility checks.]}
3594
3595 @ChgRef{Version=[3],Kind=[AddedNormal]}
3596 @ChgAdded{Version=[3],Text=[The rule also minimizes cases of implicit
3597 conversions when the tag check or the accessibility check might fail. We
3598 word it this way because access discriminants should also be disallowed if
3599 their enclosing object is designated by an access parameter.]}
3600 @end{Reason}
3601 @begin{Ramification}
3602 @ChgRef{Version=[3],Kind=[AddedNormal]}
3603 @ChgAdded{Version=[3],Text=[This rule does not apply to expressions that
3604 don't have expected types (such as the operand of a qualified expression or
3605 the expression of a renames). We don't need a rule like this in those cases,
3606 as the type needs to be the same; there is no implicit conversion.]}
3607 @end{Ramification}
3608
3609 A complete context shall have at least one acceptable interpretation;
3610 if there is exactly one, then that one is chosen.
3611 @begin{Ramification}
3612 This, and the rule below
3613 about ambiguity, are the ones that suck in all the @SyntaxName@;s and
3614 @ResolutionName@;s as compile-time rules.
3615 Note that this and the ambiguity rule have to be @LegalityName@;s.
3616 @end{Ramification}
3617
3618 @Defn2{Term=[preference], Sec=(for root numeric operators and @nt<range>s)}
3619 There is a @i{preference} for the primitive operators (and @nt<range>s)
3620 of the root numeric
3621 types @i{root_integer} and @i{root_real}.
3622 In particular,
3623 if two acceptable interpretations of a constituent of a complete
3624 context differ only in that one is for a primitive operator (or
3625 @nt<range>) of the
3626 type @i{root_integer} or @i{root_real}, and the other is not,
3627 the interpretation using the primitive operator (or @nt<range>)
3628 of the root numeric type is @i{preferred}.
3629
3630 @begin{Reason}
3631 @leading@;The reason for this preference is so that expressions involving
3632 literals and named numbers can be unambiguous.
3633 For example, without the preference rule, the following would be ambiguous:
3634 @begin{Example}
3635 @ChgRef{Version=[1],Kind=[Revised]}@ChgNote{Presentation AI-00022}
3636 N : @key[constant] := 123;
3637 @key[if] N > 100 @key[then] --@RI{ Preference for root_integer "@Chg{New=[>],Old=[<]}" operator.}
3638 ...
3639 @key[end] @key[if];
3640 @end{Example}
3641 @end{Reason}
3642
3643 @ChgRef{Version=[3],Kind=[Added],ARef=[AI05-0149-1]}
3644 @ChgAdded{Version=[3],Text=[Similarly,
3645 there is a preference for the equality operators of the @i{universal_access}
3646 type (see @RefSecNum{Relational Operators and Membership Tests}). If two
3647 acceptable interpretations of a constituent of a
3648 complete context differ only in that one is for an equality operator of the
3649 @i{universal_access} type, and the other is not, the interpretation using the
3650 equality operator of the @i{universal_access} type is
3651 preferred.@Defn2{Term=[preference], Sec=(for universal access equality operators)}]}
3652
3653 @begin{Reason}
3654 @ChgRef{Version=[3],Kind=[AddedNormal]}
3655 @ChgAdded{Version=[3],Text=[This preference is necessary because of
3656 implicit conversion from an anonymous access type to a named access type,
3657 which would allow the equality operator of any named access type to be used
3658 to compare anonymous access values (and that way lies madness).]}
3659 @end{Reason}
3660
3661 For a complete context, if there is exactly one
3662 overall acceptable interpretation where each constituent's interpretation
3663 is the same as or preferred (in the
3664 above sense) over those in all other overall acceptable interpretations, then
3665 that one overall acceptable interpretation is chosen.
3666 @Defn{ambiguous}
3667 Otherwise, the complete context is @i{ambiguous}.
3668
3669 A complete context other than a @nt{pragma_argument_association}
3670 shall not be ambiguous.
3671
3672 A complete context that is a @nt{pragma_argument_association}
3673 is allowed to be ambiguous (unless otherwise specified
3674 for the particular pragma),
3675 but only
3676 if every acceptable interpretation of the pragma argument is as a
3677 @nt{name} that statically denotes a callable entity.
3678 @PDefn2{Term=[denote],Sec=(name used as a pragma argument)}
3679 Such a @nt{name} denotes
3680 all of the declarations determined by its interpretations,
3681 and all of the views declared by these declarations.
3682 @begin{Ramification}
3683 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00224-01]}@ChgNote{Pragma is obsolete}
3684 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0229-1]}
3685 This applies to Inline, Suppress,
3686 Import, Export, and Convention @nt{pragma}s.
3687 For example, it is OK to say @lquotes@;@key[pragma] @Chg{Version=[2],
3688 New=[Export(C, Entity_Name],Old=[Suppress(Elaboration_Check, On]}
3689 => P.Q);@rquotes@;, even if there are two directly visible P's, and
3690 there are two Q's declared in the visible part of each P.
3691 In this case, P.Q denotes four different declarations.
3692 This rule also applies to certain pragmas defined in the
3693 Specialized Needs Annexes.
3694 It almost applies to Pure, Elaborate_Body, and Elaborate_All @nt{pragma}s,
3695 but those can't have overloading for other reasons.
3696 @Chg{Version=[3],New=[ Note that almost all of
3697 these pragmas are obsolescent (see @RefSecNum{Specific Suppression of Checks} and
3698 @RefSecNum{Aspect-related Pragmas}), and a major reason is that this rule
3699 has proven to be too broad in practice (it is common to want to specify something
3700 on a single subprogram of an overloaded set, that can't be done easily with this
3701 rule). @nt{Aspect_specification}s,
3702 which are given on individual declarations, are preferred in Ada 2012.],Old=[]}
3703
3704 Note that if a pragma argument denotes a @i{call} to a callable
3705 entity, rather than the entity itself,
3706 this exception does not apply, and ambiguity is disallowed.
3707
3708 Note that we need to carefully define which pragma-related rules are
3709 @ResolutionName@;s,
3710 so that, for example, a @nt{pragma} Inline does not pick up
3711 subprograms declared in enclosing declarative regions,
3712 and therefore make itself illegal.
3713
3714 We say @lquotes@;statically denotes@rquotes@; in the above rule in order to avoid
3715 having to worry about how many times the @nt{name} is evaluated,
3716 in case it denotes more than one callable entity.
3717 @end{Ramification}
3718 @end{Legality}
3719
3720 @begin{Notes}
3721 If a usage name has only one acceptable interpretation,
3722 then it denotes the corresponding entity.
3723 However, this does not mean that the usage name is necessarily legal
3724 since other requirements exist which are not considered for overload
3725 resolution; for example, the fact that an expression is static, whether
3726 an object is constant, mode and subtype conformance rules, freezing
3727 rules, order of elaboration, and so on.
3728
3729 @NoPrefix@;Similarly, subtypes are not considered for overload resolution (the
3730 violation of a constraint does not make a program illegal but raises an
3731 exception during program execution).
3732 @end{Notes}
3733
3734 @begin{Incompatible83}
3735 @Defn{incompatibilities with Ada 83}
3736 @PDefn{Beaujolais effect}
3737 The new preference rule for operators of root numeric types
3738 is upward incompatible,
3739 but only in cases that involved @i(Beaujolais) effects in Ada 83.
3740 Such cases are ambiguous in Ada 95.
3741 @end{Incompatible83}
3742
3743 @begin{Extend83}
3744 @Defn{extensions to Ada 83}
3745 The rule that allows an expected type to match an actual expression of a
3746 universal type,
3747 in combination with the new preference rule for operators of root numeric
3748 types, subsumes the Ada 83 "implicit conversion" rules
3749 for universal types.
3750 @end{Extend83}
3751
3752 @begin{DiffWord83}
3753 In Ada 83, it is not clear what the @lquotes@;syntax rules@rquotes@; are.
3754 AI83-00157 states that a certain textual rule is a syntax rule,
3755 but it's still not clear how one tells in general which textual rules are
3756 syntax rules.
3757 We have solved the problem by stating exactly which
3758 rules are syntax rules @em the ones that appear under the @lquotes@;@SyntaxTitle@rquotes@;
3759 heading.
3760
3761 RM83 has a long list of the @lquotes@;forms@rquotes@; of rules that are to be
3762 used in overload resolution (in addition to the syntax rules).
3763 It is not clear exactly which rules fall under each form.
3764 We have solved the problem by explicitly
3765 marking all rules that are used in overload resolution.
3766 Thus, the list of kinds of rules is unnecessary.
3767 It is replaced with some introductory
3768 (intentionally vague)
3769 text explaining the basic idea
3770 of what sorts of rules are overloading rules.
3771
3772 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0299-1]}
3773 It is not clear from RM83 what information is embodied in a @lquotes@;meaning@rquotes@;
3774 or an @lquotes@;interpretation.@rquotes@;
3775 @lquotes@;Meaning@rquotes@; and @lquotes@;interpretation@rquotes@; were intended to be synonymous;
3776 we now use the latter only in defining the rules about overload
3777 resolution.
3778 @lquotes@;Meaning@rquotes@; is used only informally.
3779 This @Chg{Version=[3],New=[subclause],Old=[clause]} attempts to clarify what
3780 is meant by @lquotes@;interpretation.@rquotes@;
3781
3782 @NoPrefix@;For example,
3783 RM83 does not make it clear that overload resolution is required in
3784 order to match @ntf{subprogram_bodies} with their corresponding
3785 declarations (and even to tell whether a given @nt{subprogram_body}
3786 is the completion of a previous declaration).
3787 Clearly, the information needed to do this is part of the
3788 @lquotes@;interpretation@rquotes@; of a @nt{subprogram_body}.
3789 The resolution of such things is defined in terms of
3790 the @lquotes@;expected profile@rquotes@; concept.
3791 Ada 95 has some new cases where expected profiles
3792 are needed @em the resolution of P'Access,
3793 where P might denote a subprogram,
3794 is an example.
3795
3796 @Leading@NoPrefix@;RM83-8.7(2) might seem to imply that an interpretation
3797 embodies information about what is denoted by each usage name,
3798 but not information about which syntactic category each construct belongs to.
3799 However, it seems necessary to include such information,
3800 since the Ada grammar is highly ambiguous.
3801 For example, X(Y) might be a @nt{function_call} or an
3802 @nt{indexed_component}, and no context-free/syntactic information can
3803 tell the difference.
3804 It seems like we should view X(Y) as being, for example, @lquotes@;interpreted as a
3805 @nt{function_call}@rquotes@; (if that's what overload resolution decides it is).
3806 Note that there are examples where the denotation of each usage name
3807 does not imply the syntactic category.
3808 However, even if that were not true, it seems that intuitively,
3809 the interpretation includes that information.
3810 Here's an example:
3811 @begin{Example}
3812 @key[type] T;
3813 @key[type] A @key[is] @key[access] T;
3814 @key[type] T @key[is] @key[array](Integer @key[range] 1..10) @key[of] A;
3815 I : Integer := 3;
3816 @key[function] F(X : Integer := 7) @key[return] A;
3817 Y : A := F(I); --@RI{ Ambiguous? (We hope so.)}
3818 @end{Example}
3819
3820 @ChgRef{Version=[1],Kind=[Revised]}@ChgNote{To be consistent with 8652/0006}
3821 @NoPrefix@;Consider the declaration of Y (a complete context).
3822 In the above example, overload resolution can easily determine the
3823 declaration, and therefore the entity,
3824 denoted by Y, A, F, and I.
3825 However, given all of that information,
3826 we still don't know whether F(I) is a @nt{function_call}
3827 or an @nt{indexed_component} whose @Chg{New=[@nt{prefix}],Old=[prefix]} is
3828 a @nt{function_call}.
3829 (In the latter case, it is equivalent to F(7).@key[all](I).)
3830
3831 @NoPrefix@;It seems clear that the declaration of Y ought to be considered
3832 ambiguous.
3833 We describe that by saying that there are two interpretations,
3834 one as a @nt{function_call}, and one as an @nt{indexed_component}.
3835 These interpretations are both acceptable to the overloading
3836 rules.
3837 Therefore, the complete context is ambiguous, and therefore illegal.
3838
3839 @PDefn{Beaujolais effect}
3840 It is the intent that the Ada 95 preference rule for root numeric
3841 operators is more locally enforceable than that of RM83-4.6(15).
3842 It should also eliminate interpretation shifts due to the
3843 addition or removal of a @nt{use_clause}
3844 (the so called @i{Beaujolais} effect).
3845
3846 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00114-01]}
3847 RM83-8.7 seems to be missing some complete contexts,
3848 such as @nt{pragma_argument_association}s,
3849 @nt{declarative_item}s that are not
3850 declarations or @Chg{Version=[2],New=[@nt{aspect_clause}s],
3851 Old=[@nt{representation_clause}s]},
3852 and @nt{context_item}s.
3853 We have added these, and also replaced the @lquotes@;must be determinable@rquotes@;
3854 wording of RM83-5.4(3) with the notion that the expression of a
3855 @nt{case_statement} is a complete context.
3856
3857 Cases like the Val attribute are now handled using the normal type
3858 resolution rules, instead of having special cases that explicitly allow
3859 things like @lquotes@;any integer type.@rquotes@;
3860 @end{DiffWord83}
3861
3862 @begin{Incompatible95}
3863 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00409-01]}
3864 @ChgAdded{Version=[2],Type=[Leading],Text=[@Defn{incompatibilities with Ada 95}
3865 Ada 95 allowed name resolution to distinguish between anonymous
3866 access-to-variable and access-to-constant types. This is similar to
3867 distinguishing between subprograms with @key{in} and @key{in out} parameters,
3868 which is known to be bad. Thus, that part of the rule was dropped as we now
3869 have anonymous access-to-constant types, making this much more likely.]}
3870 @begin{Example}
3871 @ChgRef{Version=[2],Kind=[AddedNormal]}
3872 @ChgAdded{Version=[2],Text=[@key{type} Cacc @key{is access constant} Integer;
3873 @key{procedure} Proc (Acc : @key{access} Integer) ...
3874 @key{procedure} Proc (Acc : Cacc) ...
3875 List : Cacc := ...;
3876 Proc (List); -- @RI[OK in Ada 95, ambiguous in Ada 2005.]]}
3877 @end{Example}
3878 @ChgRef{Version=[2],Kind=[AddedNormal]}
3879 @ChgAdded{Version=[2],Text=[If there is any code like this (such code should
3880 be rare), it will be ambiguous in Ada 2005.]}
3881 @end{Incompatible95}
3882
3883 @begin{Extend95}
3884 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00230-01],ARef=[AI95-00231-01],ARef=[AI95-00254-01]}
3885 @ChgAdded{Version=[2],Text=[@Defn{extensions to Ada 95}
3886 Generalized the anonymous access resolution rules to support the new
3887 capabilities of anonymous access types (that is, access-to-subprogram and
3888 access-to-constant).]}
3889
3890 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00382-01]}
3891 @ChgAdded{Version=[2],Type=[Leading],Text=[We now allow the creation of
3892 self-referencing types via anonymous access types. This is an extension
3893 in unusual cases involving task and protected types. For example:]}
3894 @begin{Example}
3895 @ChgRef{Version=[2],Kind=[AddedNormal]}
3896 @ChgAdded{Version=[2],Text=[@key{task type} T;]}
3897
3898 @ChgRef{Version=[2],Kind=[AddedNormal]}
3899 @ChgAdded{Version=[2],Text=[@key{task body} T @key{is}
3900 @key{procedure} P (X : @key{access} T) @key{is} -- @RI[Illegal in Ada 95, legal in Ada 2005]
3901 ...
3902 @key{end} P;
3903 @key{begin}
3904 ...
3905 @key{end} T;]}
3906 @end{Example}
3907 @end{Extend95}
3908
3909 @begin{DiffWord95}
3910 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00332-01]}
3911 @ChgAdded{Version=[2],Text=[Corrected the @lquotes@;single expected
3912 type@rquotes@; so that it works in contexts that don't have expected types
3913 (like object renames and qualified expressions). This fixes a hole in Ada 95
3914 that appears to prohibit using @nt{aggregate}s, 'Access, character literals,
3915 string literals, and @nt{allocator}s in qualified expressions.]}
3916 @end{DiffWord95}
3917
3918 @begin{Incompatible2005}
3919 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0149-1]}
3920 @ChgAdded{Version=[3],Text=[@Defn{incompatibilities with Ada 2005}Implicit
3921 conversion is now allowed from anonymous access-to-object types to
3922 general access-to-object types. Such conversions can make calls ambiguous.
3923 That can only happen when there are two visible subprograms with the same name
3924 and have profiles that differ only by a parameter that is of a named or
3925 anonymous access type, and the actual argument is of an anonymous access type.
3926 This should be rare, as many possible calls would be ambiguous even in Ada
3927 2005 (including @nt{allocator}s and any actual of a named access type if the
3928 designated types are the same).]}
3929 @end{Incompatible2005}
3930
3931 @begin{Extend2005}
3932 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0149-1]}
3933 @ChgAdded{Version=[3],Text=[@Defn{extensions to Ada 2005}Implicit conversion
3934 is allowed from anonymous access-to-object types to general access-to-object
3935 types if the designated type is convertible and runtime checks are minimized.
3936 See also the incompatibilities section.]}
3937 @end{Extend2005}
3938
3939 @begin{DiffWord2005}
3940 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0102-1]}
3941 @ChgAdded{Version=[3],Text=[Added a requirement
3942 here that implicit conversions are convertible to the appropriate type.
3943 This rule was scattered about the Standard, we moved a single generalized
3944 version here.]}
3945 @end{DiffWord2005}
3946
3947 @begin{Inconsistent2012}
3948 @ChgRef{Version=[4],Kind=[AddedNormal],ARef=[AI12-0068-1]}
3949 @ChgAdded{Version=[4],Text=[@Defn{inconsistencies with Ada 2012}@b<Corrigendum:>
3950 Added a rule to specify that the current instance of a type or subtype is
3951 a value within an @nt{aspect_specification}. This could be inconsistent if
3952 a predicate or invariant uses the Constrained attribute on the current
3953 instance (it will always be False now, while it might have returned True
3954 in original Ada 2012). More likely, a usage of a current instance as a prefix
3955 of an attribute will become illegal (such as Size or Alignment). Any such
3956 code is very tricky. Moreover, as this is a new feature of Ada 2012, there
3957 are not that many predicates and invariants, and the ones that exist are
3958 very unlikely to be this tricky. Thus we do not believe that there will be
3959 any practical effect to this change, other than to explicitly allow
3960 common implementation strategies.]}
3961 @end{Inconsistent2012}
3962
3963 @begin{DiffWord2012}
3964 @ChgRef{Version=[4],Kind=[AddedNormal],ARef=[AI12-0040-1]}
3965 @ChgAdded{Version=[4],Text=[@b<Corrigendum:> Added wording to clarify that
3966 the @SynI{selecting_}@nt{expression} of a @nt{case_expression} is a
3967 complete context, just like that of a @nt{case_statement}. Clearly, everyone
3968 expects these to work the same way. Moreover, since it would be a lot of extra
3969 work to treat @nt{case_expression}s differently, it is quite unlikely that any
3970 compiler would implement the much more complicated resolution necessary (and
3971 we are not aware of any that did). Therefore, we didn't document this as a
3972 potential incompatibility.]}
3973
3974 @ChgRef{Version=[5],Kind=[AddedNormal],ARef=[AI12-0125-3]}
3975 @ChgAdded{Version=[5],Text=[Added a resolution rule for @nt{target_name}
3976 (see @RefSecNum{Target Name Symbols}).]}
3977 @end{DiffWord2012}
3978