From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00 autolearn=unavailable autolearn_force=no version=3.4.4 Path: eternal-september.org!reader01.eternal-september.org!reader02.eternal-september.org!news.eternal-september.org!mx02.eternal-september.org!.POSTED!not-for-mail From: Natasha Kerensikova Newsgroups: comp.lang.ada Subject: Re: Generic instantiation before actual subprogram body Date: Thu, 4 Dec 2014 10:03:46 +0000 (UTC) Organization: A noiseless patient Spider Message-ID: References: Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit Injection-Date: Thu, 4 Dec 2014 10:03:46 +0000 (UTC) Injection-Info: mx02.eternal-september.org; posting-host="76a49b86bc3e16725b7cfca3d85cb4c8"; logging-data="3758"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/su4cTVWyL147XXbs8Dvxg" User-Agent: slrn/1.0.1 (FreeBSD) Cancel-Lock: sha1:xIIV++RXgRgDRGyAaUNamRtkIZg= Xref: news.eternal-september.org comp.lang.ada:23858 Date: 2014-12-04T10:03:46+00:00 List-Id: On 2014-12-04, J-P. Rosen wrote: > Le 04/12/2014 09:48, Natasha Kerensikova a écrit : >> My question is now, in which set of circumstances is it allowed (or >> forbidden) to instantiate a generic with a subprogram whose body has not >> yet been seen by the compiler? > RM2012(11.5(20)): > "When [...] a generic instantiation is elaborated, check that the body > of the corresponding unit has already been elaborated." This is the body of the generic unit, while my question was about the body of the actual subprograms use in the generic instantiation to match for the formal subprogram parameters in the generic. Since the generic unit is another unit, I don't expect moving the instantiation in the source text to have any effect. While the Program_Error I mentioned was about the position of the instantiation with regard to actual subprogram bodies. It really looked like that: with Generic_Procedure; package body Which_Raises_Program_Error is procedure Local_Procedure; procedure Instantiated is new Generic_Procedure (Local_Procedure); procedure Local_Procedure is begin end Local_Procedure; procedure Public_Procedure is begin Instantiated; end Public_Procedure; end Which_Raises_Program_Error; package body Which_Does_Not_Raise_Program_Error is procedure Local_Procedure; procedure Local_Procedure is begin end Local_Procedure; procedure Instantiated is new Generic_Procedure (Local_Procedure); procedure Public_Procedure is begin Instantiated; end Public_Procedure; end Which_Does_Not_Raise_Program_Error; It was really a problem related to the position of the instantiation (Instantiated in the example) relative to the body of an actual subprogram (here Local_Procedure). If I understand correctly, one obvious way to reach this effect is when a generic package uses a formal function to initialize a global variable. The function call would be elaborated when the generic package is instantiated, so that would be a function call whose body has not yet been seen, so Program_Error. I'm quite sure this wasn't the case I encountered, so I'm looking for other ways an actual body can influence a generic instance. Are there any? Or maybe my memory is playing tricks on me, confusing actual subprogram body and generic unit body? Though I don't remember having ever tried to instantiate a generic in the same compilation unit where I define it. Would that mean that a subprogram whose body has not yet been seen can always be used as an actual for a generic instantiation, except when used immediately like in the package example above? > FYI: to find it, go to the index, and follow the references for > "Program_Error". I tried that, though it was after I lost hope of understanding the influences between elaboration and instantiation using only the ARM. I'll try again more thoroughly when I have some free time. Thanks for your insights, Natasha