Debian Codegraph @

source_2012/08.mss

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