!standard 03.11.01(04) 04-02-05 AI95-00369/00 !standard D.07(04) !class binding interpretation 03-12-17 !status received 03-12-17 !priority Low !difficulty Easy !subject Types that need finalization !summary !question !recommendation !wording !discussion --!corrigendum !example !ACATS test !appendix !topic Request for nitpicky wording change !reference 3.11.1(4) !from Adam Beneschan 03-12-17 !discussion I'd like to request a change in the wording of a clause. 3.11.1(2-4) says, in part: A construct that can be a completion is interpreted as the completion of a prior declaration only if: . . . in the case of a pragma, the pragma applies to the declaration; I think this last clause should be changed to "the pragma applies to the entity denoted by the declaration", or something to that effect. The current wording actually confused me for a while. I was trying to determine whether this was legal: package Pak2 is procedure Proc2 (X : Integer); procedure Proc2 (X, Y : Integer); procedure Proc2 (X, Y, Z : Integer); private procedure Ren_Proc2 (X, Y : Integer) renames Proc2; pragma Import (C, Ren_Proc2, "Proc2"); end Pak2; One would, of course, want to do something like this when a number of overloaded subprograms are declared and one wishes to apply the Import pragma to a specific one. The question is: is the Import pragma a completion of the second Proc2 declaration? (It would have to be, since B.1(22) says that an Import pragma must be a completion, and I don't think a subprogram_renaming_declaration allows a completion.) If 3.11.1(4) made it clear that the Import pragma was the completion of Proc2, there wouldn't be a problem. But since 3.11.1(4) refers to a pragma applying to a declaration, this confused me for a while, since if pragmas are thought of as applying to declarations, the Import pragma should apply to the subprogram_renaming_declaration of Ren_Proc2, not to the second subprogram_declaration of Proc2. On searching the RM, I couldn't find anywhere else where a pragma was said to apply to a *declaration*. Whenever a pragma "applies to" something, it's always an entity, or a subprogram, or a library unit, or something else. So I've convinced myself that the Import pragma applies to the second Proc2 and is thus a completion. But I think that for consistency, and to prevent confusion, I think it's a good idea to change the wording of 3.11.1(4) so that it doesn't talk about a pragma that applies to a declaration. **************************************************************** From: Tucker Taft Sent: Wednesday, December 17, 2003 1:42 PM > I think this last clause should be changed to "the pragma applies to > the entity denoted by the declaration", or something to that effect. I don't think we want this, although you may be right that some wording clarification is needed. > The current wording actually confused me for a while. I was trying to > determine whether this was legal: > > package Pak2 is > procedure Proc2 (X : Integer); > procedure Proc2 (X, Y : Integer); > procedure Proc2 (X, Y, Z : Integer); > > private > procedure Ren_Proc2 (X, Y : Integer) renames Proc2; > pragma Import (C, Ren_Proc2, "Proc2"); > end Pak2; > > One would, of course, want to do something like this when a number of > overloaded subprograms are declared and one wishes to apply the Import > pragma to a specific one. Perhaps, but that is not what I would recommend (though there is a lot of leeway in how implementations support pragma Import). I would recommend the following: procedure Proc2(X, Y : Integer); ... private procedure Proc2_Nonoverloaded(X, Y : Integer); pragma Import(C, Proc2_Nonoverloaded, "Proc2"); procedure Proc2(X, Y : Integer) renames Proc2_Nonoverloaded; > ... The question is: is the Import pragma a > completion of the second Proc2 declaration? No, I don't think that was the intent. > ... (It would have to be, > since B.1(22) says that an Import pragma must be a completion, and I > don't think a subprogram_renaming_declaration allows a completion.) Again, whether import is allowed for a particular kind of declaration is largely up to the implementation. Ada 83 created this mess with pragma Inline. But now that we have renaming-as-body, I think that is the preferred way to accomplish these kinds of things. That is, define the overloaded declaration by renaming the non-overloaded one, rather than vice-versa. And apply the pragma to the non-overloaded one. Then there isn't any confusion. I agree that in the case of renaming, the wording about pragma Import is confusing. It is very clear that pragma Import is the completion for a *declaration*, and that only declarations have completions. It is a bit weird to talk about an entity having a completion. Entities are *defined by* their declaration and their declaration's completion, if any. It seems clear that program-unit pragmas (and all representation pragmas) apply to entities. 13.1(8) permits the local_name of the representation pragma to denote a renaming, provided it is a subprogram renaming of a subprogram defined in the same immediate scope. But it is similarly clear that pragma Import acts as a completion, and completions are associated with *declaration*s. So there is a bit of a wording problem. **************************************************************** From: Gary Dismukes Sent: Wednesday, December 17, 2003 2:20 PM Tuck wrote: > I agree that in the case of renaming, the wording about > pragma Import is confusing. It is very clear that > pragma Import is the completion for a *declaration*, > and that only declarations have completions. > It is a bit weird to talk about an entity having a completion. > Entities are *defined by* their declaration and their declaration's > completion, if any. But note that 3.11.1(1) states: 1 Declarations sometimes come in two parts. {requires a completion} A declaration that requires a second part is said to require completion. {completion (compile-time concept)} The second part is called the completion of the declaration (and of the entity declared), and is either another declaration, a body, or a pragma. The last sentence clearly indicates that entities also have completions. **************************************************************** From: Tucker Taft Sent: Wednesday, December 17, 2003 5:00 PM > The last sentence clearly indicates that entities also have completions. Right you are! So maybe the wording isn't that far off. I guess the question is now whether we expect an import applied to a renaming to actually apply to the renamed object. I never imagined that before (and I suspect our compiler does not handle it), but it seems it would be consistent with pragma inline. **************************************************************** From: Gary Dismukes Sent: Wednesday, December 17, 2003 5:35 PM That was my thought as well (that it would be consistent with Inline). If that seems right, then a wording change to say "applies to the entity" as suggested by Adam would seem reasonable, since that's the terminology normally used for pragmas. ****************************************************************